Adjust story map height if there are no results

This commit is contained in:
Isaac 2024-06-17 21:08:02 +04:00
parent 5b204f6122
commit 7b18d52644
4 changed files with 41 additions and 22 deletions

View File

@ -57,7 +57,7 @@ public final class LocationMapHeaderNode: ASDisplayNode {
private let placesButtonNode: HighlightableButtonNode private let placesButtonNode: HighlightableButtonNode
private let shadowNode: ASImageNode private let shadowNode: ASImageNode
private var validLayout: (ContainerViewLayout, CGFloat, CGFloat, CGFloat, CGSize)? private var validLayout: (ContainerViewLayout, CGFloat, CGFloat, CGFloat, CGFloat, CGSize)?
public init(presentationData: PresentationData, toggleMapModeSelection: @escaping () -> Void, goToUserLocation: @escaping () -> Void, setupProximityNotification: @escaping (Bool) -> Void = { _ in }, showPlacesInThisArea: @escaping () -> Void = {}) { public init(presentationData: PresentationData, toggleMapModeSelection: @escaping () -> Void, goToUserLocation: @escaping () -> Void, setupProximityNotification: @escaping (Bool) -> Void = { _ in }, showPlacesInThisArea: @escaping () -> Void = {}) {
self.presentationData = presentationData self.presentationData = presentationData
@ -143,9 +143,9 @@ public final class LocationMapHeaderNode: ASDisplayNode {
self.displayingPlacesButton = displayingPlacesButton self.displayingPlacesButton = displayingPlacesButton
self.proximityNotification = proximityNotification self.proximityNotification = proximityNotification
if updateLayout, let (layout, navigationBarHeight, topPadding, offset, size) = self.validLayout { if updateLayout, let (layout, navigationBarHeight, topPadding, controlsTopPadding, offset, size) = self.validLayout {
let transition: ContainedViewLayoutTransition = animated ? .animated(duration: 0.3, curve: .spring) : .immediate let transition: ContainedViewLayoutTransition = animated ? .animated(duration: 0.3, curve: .spring) : .immediate
self.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: topPadding, offset: offset, size: size, transition: transition) self.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: topPadding, controlsTopPadding: controlsTopPadding, offset: offset, size: size, transition: transition)
} }
} }
@ -177,8 +177,8 @@ public final class LocationMapHeaderNode: ASDisplayNode {
} }
} }
public func updateLayout(layout: ContainerViewLayout, navigationBarHeight: CGFloat, topPadding: CGFloat, offset: CGFloat, size: CGSize, transition: ContainedViewLayoutTransition) { public func updateLayout(layout: ContainerViewLayout, navigationBarHeight: CGFloat, topPadding: CGFloat, controlsTopPadding: CGFloat, offset: CGFloat, size: CGSize, transition: ContainedViewLayoutTransition) {
self.validLayout = (layout, navigationBarHeight, topPadding, offset, size) self.validLayout = (layout, navigationBarHeight, topPadding, controlsTopPadding, offset, size)
let mapHeight: CGFloat = floor(layout.size.height * 1.3) + layout.intrinsicInsets.top * 2.0 let mapHeight: CGFloat = floor(layout.size.height * 1.3) + layout.intrinsicInsets.top * 2.0
let mapFrame = CGRect(x: 0.0, y: floorToScreenPixels((size.height - mapHeight + navigationBarHeight) / 2.0) + offset + floor(layout.intrinsicInsets.top * 0.5), width: size.width, height: mapHeight) let mapFrame = CGRect(x: 0.0, y: floorToScreenPixels((size.height - mapHeight + navigationBarHeight) / 2.0) + offset + floor(layout.intrinsicInsets.top * 0.5), width: size.width, height: mapHeight)
@ -209,7 +209,7 @@ public final class LocationMapHeaderNode: ASDisplayNode {
transition.updateAlpha(node: self.notificationButtonNode, alpha: self.proximityNotification != nil ? 1.0 : 0.0) transition.updateAlpha(node: self.notificationButtonNode, alpha: self.proximityNotification != nil ? 1.0 : 0.0)
transition.updateAlpha(node: self.optionsSecondSeparatorNode, alpha: self.proximityNotification != nil ? 1.0 : 0.0) transition.updateAlpha(node: self.optionsSecondSeparatorNode, alpha: self.proximityNotification != nil ? 1.0 : 0.0)
transition.updateFrame(node: self.optionsBackgroundNode, frame: CGRect(x: size.width - inset - panelButtonSize.width - panelInset * 2.0 - layout.safeInsets.right, y: navigationBarHeight + topPadding + inset, width: panelButtonSize.width + panelInset * 2.0, height: panelHeight + panelInset * 2.0)) transition.updateFrame(node: self.optionsBackgroundNode, frame: CGRect(x: size.width - inset - panelButtonSize.width - panelInset * 2.0 - layout.safeInsets.right, y: navigationBarHeight + controlsTopPadding + inset, width: panelButtonSize.width + panelInset * 2.0, height: panelHeight + panelInset * 2.0))
let alphaTransition = ContainedViewLayoutTransition.animated(duration: 0.2, curve: .easeInOut) let alphaTransition = ContainedViewLayoutTransition.animated(duration: 0.2, curve: .easeInOut)
let optionsAlpha: CGFloat = size.height > 160.0 + navigationBarHeight && !self.forceIsHidden ? 1.0 : 0.0 let optionsAlpha: CGFloat = size.height > 160.0 + navigationBarHeight && !self.forceIsHidden ? 1.0 : 0.0
@ -218,8 +218,8 @@ public final class LocationMapHeaderNode: ASDisplayNode {
public var forceIsHidden: Bool = false { public var forceIsHidden: Bool = false {
didSet { didSet {
if let (layout, navigationBarHeight, topPadding, offset, size) = self.validLayout { if let (layout, navigationBarHeight, topPadding, controlsTopPadding, offset, size) = self.validLayout {
self.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: topPadding, offset: offset, size: size, transition: .immediate) self.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: topPadding, controlsTopPadding: controlsTopPadding, offset: offset, size: size, transition: .immediate)
} }
} }
} }

View File

@ -902,7 +902,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
strongSelf.listOffset = max(0.0, offset) strongSelf.listOffset = max(0.0, offset)
let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(0.0, offset + overlap))) let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(0.0, offset + overlap)))
listTransition.updateFrame(node: strongSelf.headerNode, frame: headerFrame) listTransition.updateFrame(node: strongSelf.headerNode, frame: headerFrame)
strongSelf.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: strongSelf.state.displayingMapModeOptions ? 38.0 : 0.0, offset: 0.0, size: headerFrame.size, transition: listTransition) strongSelf.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: strongSelf.state.displayingMapModeOptions ? 38.0 : 0.0, controlsTopPadding: strongSelf.state.displayingMapModeOptions ? 38.0 : 0.0, offset: 0.0, size: headerFrame.size, transition: listTransition)
strongSelf.layoutEmptyResultsPlaceholder(transition: listTransition) strongSelf.layoutEmptyResultsPlaceholder(transition: listTransition)
} }
@ -1116,7 +1116,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: headerHeight)) let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: headerHeight))
transition.updateFrame(node: self.headerNode, frame: headerFrame) transition.updateFrame(node: self.headerNode, frame: headerFrame)
self.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationHeight, topPadding: self.state.displayingMapModeOptions ? optionsHeight : 0.0, offset: 0.0, size: headerFrame.size, transition: transition) self.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationHeight, topPadding: self.state.displayingMapModeOptions ? optionsHeight : 0.0, controlsTopPadding: self.state.displayingMapModeOptions ? optionsHeight : 0.0, offset: 0.0, size: headerFrame.size, transition: transition)
let (duration, curve) = listViewAnimationDurationAndCurve(transition: transition) let (duration, curve) = listViewAnimationDurationAndCurve(transition: transition)
let scrollToItem: ListViewScrollToItem? let scrollToItem: ListViewScrollToItem?

View File

@ -714,7 +714,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
strongSelf.listOffset = max(0.0, offset) strongSelf.listOffset = max(0.0, offset)
let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(0.0, offset + overlap))) let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(0.0, offset + overlap)))
listTransition.updateFrame(node: strongSelf.headerNode, frame: headerFrame) listTransition.updateFrame(node: strongSelf.headerNode, frame: headerFrame)
strongSelf.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: strongSelf.state.displayingMapModeOptions ? 38.0 : 0.0, offset: 0.0, size: headerFrame.size, transition: listTransition) strongSelf.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationBarHeight, topPadding: strongSelf.state.displayingMapModeOptions ? 38.0 : 0.0, controlsTopPadding: strongSelf.state.displayingMapModeOptions ? 38.0 : 0.0, offset: 0.0, size: headerFrame.size, transition: listTransition)
} }
self.listNode.beganInteractiveDragging = { [weak self] _ in self.listNode.beganInteractiveDragging = { [weak self] _ in
@ -952,7 +952,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: headerHeight)) let headerFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: headerHeight))
transition.updateFrame(node: self.headerNode, frame: headerFrame) transition.updateFrame(node: self.headerNode, frame: headerFrame)
self.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationHeight, topPadding: self.state.displayingMapModeOptions ? optionsHeight : 0.0, offset: 0.0, size: headerFrame.size, transition: transition) self.headerNode.updateLayout(layout: layout, navigationBarHeight: navigationHeight, topPadding: self.state.displayingMapModeOptions ? optionsHeight : 0.0, controlsTopPadding: self.state.displayingMapModeOptions ? optionsHeight : 0.0, offset: 0.0, size: headerFrame.size, transition: transition)
let (duration, curve) = listViewAnimationDurationAndCurve(transition: transition) let (duration, curve) = listViewAnimationDurationAndCurve(transition: transition)

View File

@ -2715,16 +2715,20 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, ASScr
} }
private func updateHistory(items: SparseItemGrid.Items, pinnedIds: Set<Int32>, synchronous: Bool, reloadAtTop: Bool) { private func updateHistory(items: SparseItemGrid.Items, pinnedIds: Set<Int32>, synchronous: Bool, reloadAtTop: Bool) {
var transition: ContainedViewLayoutTransition = .immediate
if case .location = self.scope, let previousItems = self.items, previousItems.items.count == 0, previousItems.count != 0, items.items.count == 0, items.count == 0 {
transition = .animated(duration: 0.3, curve: .spring)
}
self.items = items self.items = items
self.pinnedIds = pinnedIds self.pinnedIds = pinnedIds
self.isEmptyUpdated(self.isEmpty)
if let (size, topInset, sideInset, bottomInset, deviceMetrics, visibleHeight, isScrollingLockedAtTop, expandProgress, navigationHeight, presentationData) = self.currentParams { if let (size, topInset, sideInset, bottomInset, deviceMetrics, visibleHeight, isScrollingLockedAtTop, expandProgress, navigationHeight, presentationData) = self.currentParams {
var gridSnapshot: UIView? var gridSnapshot: UIView?
if reloadAtTop { if reloadAtTop {
gridSnapshot = self.itemGrid.view.snapshotView(afterScreenUpdates: false) gridSnapshot = self.itemGrid.view.snapshotView(afterScreenUpdates: false)
} }
self.update(size: size, topInset: topInset, sideInset: sideInset, bottomInset: bottomInset, deviceMetrics: deviceMetrics, visibleHeight: visibleHeight, isScrollingLockedAtTop: isScrollingLockedAtTop, expandProgress: expandProgress, navigationHeight: navigationHeight, presentationData: presentationData, synchronous: false, transition: .immediate) self.update(size: size, topInset: topInset, sideInset: sideInset, bottomInset: bottomInset, deviceMetrics: deviceMetrics, visibleHeight: visibleHeight, isScrollingLockedAtTop: isScrollingLockedAtTop, expandProgress: expandProgress, navigationHeight: navigationHeight, presentationData: presentationData, synchronous: false, transition: transition)
self.updateSelectedItems(animated: false) self.updateSelectedItems(animated: false)
if let gridSnapshot = gridSnapshot { if let gridSnapshot = gridSnapshot {
self.view.addSubview(gridSnapshot) self.view.addSubview(gridSnapshot)
@ -2733,6 +2737,8 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, ASScr
}) })
} }
} }
self.isEmptyUpdated(self.isEmpty)
if !self.didSetReady { if !self.didSetReady {
self.didSetReady = true self.didSetReady = true
@ -3074,27 +3080,39 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, ASScr
private func gridScrollingOffsetUpdated(transition: ContainedViewLayoutTransition) { private func gridScrollingOffsetUpdated(transition: ContainedViewLayoutTransition) {
if let _ = self.mapNode, let currentParams = self.currentParams { if let _ = self.mapNode, let currentParams = self.currentParams {
self.updateMapLayout(size: currentParams.size, topInset: currentParams.topInset, deviceMetrics: currentParams.deviceMetrics, transition: transition) self.updateMapLayout(size: currentParams.size, topInset: currentParams.topInset, bottomInset: currentParams.bottomInset, deviceMetrics: currentParams.deviceMetrics, transition: transition)
} }
} }
private var effectiveMapHeight: CGFloat = 0.0 private var effectiveMapHeight: CGFloat = 0.0
private func updateMapLayout(size: CGSize, topInset: CGFloat, deviceMetrics: DeviceMetrics, transition: ContainedViewLayoutTransition) { private func updateMapLayout(size: CGSize, topInset: CGFloat, bottomInset: CGFloat, deviceMetrics: DeviceMetrics, transition: ContainedViewLayoutTransition) {
guard let mapNode = self.mapNode else { guard let mapNode = self.mapNode else {
return return
} }
let mapOverscrollInset: CGFloat = 300.0
var mapHeight = min(size.width, size.height) var mapHeight = min(size.width, size.height)
mapHeight = min(mapHeight, floor(size.height * 0.389)) mapHeight = min(mapHeight, floor(size.height * 0.389))
let mapOverscrollInset: CGFloat = size.height - mapHeight
self.effectiveMapHeight = mapHeight - self.additionalNavigationHeight self.effectiveMapHeight = mapHeight - self.additionalNavigationHeight
let mapSize = CGSize(width: size.width, height: mapHeight + mapOverscrollInset) let mapSize = CGSize(width: size.width, height: mapHeight + mapOverscrollInset)
let mapFrame = CGRect(origin: CGPoint(x: 0.0, y: topInset - mapOverscrollInset - self.itemGrid.scrollingOffset - self.additionalNavigationHeight), size: mapSize) var controlsTopPadding = mapOverscrollInset + self.additionalNavigationHeight
let effectiveScrollingOffset: CGFloat
if let items = self.items, items.items.isEmpty, items.count == 0 {
effectiveScrollingOffset = -size.height * 0.5 + 60.0 + bottomInset
} else {
effectiveScrollingOffset = self.itemGrid.scrollingOffset
}
controlsTopPadding += min(0.0, effectiveScrollingOffset)
let mapFrame = CGRect(origin: CGPoint(x: 0.0, y: topInset - mapOverscrollInset - effectiveScrollingOffset - self.additionalNavigationHeight), size: mapSize)
transition.updateFrame(node: mapNode, frame: mapFrame) transition.updateFrame(node: mapNode, frame: mapFrame)
let mapOffset = min(floorToScreenPixels(effectiveScrollingOffset * 0.5), mapSize.height)
mapNode.updateLayout( mapNode.updateLayout(
layout: ContainerViewLayout( layout: ContainerViewLayout(
size: mapSize, size: mapSize,
@ -3110,7 +3128,8 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, ASScr
), ),
navigationBarHeight: 0.0, navigationBarHeight: 0.0,
topPadding: mapOverscrollInset + self.additionalNavigationHeight, topPadding: mapOverscrollInset + self.additionalNavigationHeight,
offset: min(floorToScreenPixels(self.itemGrid.scrollingOffset * 0.5), mapSize.height), controlsTopPadding: controlsTopPadding,
offset: mapOffset,
size: mapSize, size: mapSize,
transition: transition transition: transition
) )
@ -3162,7 +3181,7 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, ASScr
let mapInfoTopInset: CGFloat = -6.0 let mapInfoTopInset: CGFloat = -6.0
let mapInfoFrame = CGRect(origin: CGPoint(x: 0.0, y: mapFrame.maxY + mapInfoTopInset), size: mapInfoLayout.contentSize) let mapInfoFrame = CGRect(origin: CGPoint(x: 0.0, y: mapFrame.maxY + mapInfoTopInset), size: mapInfoLayout.contentSize)
mapInfoNode.frame = mapInfoFrame transition.updateFrame(node: mapInfoNode, frame: mapInfoFrame)
mapInfoReadyAndApply().1(ListViewItemApply(isOnScreen: true)) mapInfoReadyAndApply().1(ListViewItemApply(isOnScreen: true))
self.effectiveMapHeight += mapInfoLayout.contentSize.height + mapInfoTopInset self.effectiveMapHeight += mapInfoLayout.contentSize.height + mapInfoTopInset
@ -3217,7 +3236,7 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, ASScr
var gridTopInset = topInset var gridTopInset = topInset
if self.mapNode != nil { if self.mapNode != nil {
self.updateMapLayout(size: size, topInset: topInset, deviceMetrics: deviceMetrics, transition: transition) self.updateMapLayout(size: size, topInset: topInset, bottomInset: bottomInset, deviceMetrics: deviceMetrics, transition: transition)
gridTopInset += self.effectiveMapHeight gridTopInset += self.effectiveMapHeight
let mapOptionsNode: LocationOptionsNode let mapOptionsNode: LocationOptionsNode