[WIP] Inline forums

This commit is contained in:
Ali
2022-11-16 01:43:02 +04:00
parent f2b0d699d9
commit 152fd01567
22 changed files with 631 additions and 175 deletions

View File

@@ -35,7 +35,7 @@ struct ChatListNodeListViewTransition {
let animateCrossfade: Bool
}
final class ChatListHighlightedLocation {
final class ChatListHighlightedLocation: Equatable {
let location: ChatLocation
let progress: CGFloat
@@ -47,6 +47,16 @@ final class ChatListHighlightedLocation {
func withUpdatedProgress(_ progress: CGFloat) -> ChatListHighlightedLocation {
return ChatListHighlightedLocation(location: location, progress: progress)
}
static func ==(lhs: ChatListHighlightedLocation, rhs: ChatListHighlightedLocation) -> Bool {
if lhs.location != rhs.location {
return false
}
if lhs.progress != rhs.progress {
return false
}
return true
}
}
public final class ChatListNodeInteraction {
@@ -84,6 +94,9 @@ public final class ChatListNodeInteraction {
public var searchTextHighightState: String?
var highlightedChatLocation: ChatListHighlightedLocation?
var isInlineMode: Bool = false
var inlineNavigationLocation: ChatListHighlightedLocation?
let animationCache: AnimationCache
let animationRenderer: MultiAnimationRenderer
@@ -871,7 +884,9 @@ public final class ChatListNode: ListView {
public var selectionLimit: Int32 = 100
public var reachedSelectionLimit: ((Int32) -> Void)?
public init(context: AccountContext, location: ChatListControllerLocation, chatListFilter: ChatListFilter? = nil, previewing: Bool, fillPreloadItems: Bool, mode: ChatListNodeMode, theme: PresentationTheme, fontSize: PresentationFontSize, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, nameSortOrder: PresentationPersonNameOrder, nameDisplayOrder: PresentationPersonNameOrder, animationCache: AnimationCache, animationRenderer: MultiAnimationRenderer, disableAnimations: Bool) {
private var visibleTopInset: CGFloat?
public init(context: AccountContext, location: ChatListControllerLocation, chatListFilter: ChatListFilter? = nil, previewing: Bool, fillPreloadItems: Bool, mode: ChatListNodeMode, theme: PresentationTheme, fontSize: PresentationFontSize, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, nameSortOrder: PresentationPersonNameOrder, nameDisplayOrder: PresentationPersonNameOrder, animationCache: AnimationCache, animationRenderer: MultiAnimationRenderer, disableAnimations: Bool, isInlineMode: Bool) {
self.context = context
self.location = location
self.chatListFilter = chatListFilter
@@ -1156,6 +1171,7 @@ public final class ChatListNode: ListView {
self.peerSelected?(peer, threadId, true, true, nil)
})
})
nodeInteraction.isInlineMode = isInlineMode
let viewProcessingQueue = self.viewProcessingQueue
@@ -1929,6 +1945,9 @@ public final class ChatListNode: ListView {
guard let strongSelf = self else {
return
}
if !strongSelf.dequeuedInitialTransitionOnLayout {
return
}
let atTop: Bool
var revealHiddenItems: Bool = false
switch offset {
@@ -2255,11 +2274,15 @@ public final class ChatListNode: ListView {
var scrollToItem = transition.scrollToItem
if transition.adjustScrollToFirstItem {
var offset: CGFloat = 0.0
switch self.visibleContentOffset() {
case let .known(value) where abs(value) < .ulpOfOne:
offset = 0.0
default:
offset = -navigationBarSearchContentHeight
if let visibleTopInset = self.visibleTopInset {
offset = visibleTopInset - self.insets.top
} else {
switch self.visibleContentOffset() {
case let .known(value) where abs(value) < .ulpOfOne:
offset = 0.0
default:
offset = -navigationBarSearchContentHeight
}
}
scrollToItem = ListViewScrollToItem(index: 0, position: .top(offset), animated: false, curve: .Default(duration: 0.0), directionHint: .Up)
}
@@ -2316,8 +2339,34 @@ public final class ChatListNode: ListView {
}
}
public func updateLayout(transition: ContainedViewLayoutTransition, updateSizeAndInsets: ListViewUpdateSizeAndInsets) {
self.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: [.Synchronous, .LowLatency], scrollToItem: nil, updateSizeAndInsets: updateSizeAndInsets, stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in })
public func fixContentOffset(offset: CGFloat) {
let _ = self.scrollToOffsetFromTop(offset, animated: false)
/*let scrollToItem: ListViewScrollToItem = ListViewScrollToItem(index: 0, position: .top(-offset), animated: false, curve: .Default(duration: 0.0), directionHint: .Up)
self.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: [.Synchronous], scrollToItem: scrollToItem, updateSizeAndInsets: nil, stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in })*/
}
public func updateLayout(transition: ContainedViewLayoutTransition, updateSizeAndInsets: ListViewUpdateSizeAndInsets, visibleTopInset: CGFloat, inlineNavigationLocation: ChatListControllerLocation?) {
self.visibleTopInset = visibleTopInset
self.visualInsets = UIEdgeInsets(top: visibleTopInset, left: 0.0, bottom: 0.0, right: 0.0)
var highlightedLocation: ChatListHighlightedLocation?
if case let .forum(peerId) = inlineNavigationLocation {
highlightedLocation = ChatListHighlightedLocation(location: .peer(id: peerId), progress: 1.0)
}
var navigationLocationUpdated = false
if self.interaction?.inlineNavigationLocation != highlightedLocation {
self.interaction?.inlineNavigationLocation = highlightedLocation
navigationLocationUpdated = true
}
var options: ListViewDeleteAndInsertOptions = [.Synchronous, .LowLatency]
if navigationLocationUpdated {
options.insert(.ForceUpdate)
options.insert(.AnimateInsertion)
}
self.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: options, scrollToItem: nil, updateSizeAndInsets: updateSizeAndInsets, stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in })
if !self.dequeuedInitialTransitionOnLayout {
self.dequeuedInitialTransitionOnLayout = true