Fix sheet getting set to previous height on rapid content changes
The KVO callback was calling updateLayout(), which has two problems for content-driven updates: 1. The prevLayoutDetentIdentifier guard can block updates. When updateDetents triggers animateChanges, the delegate callback sheetPresentationControllerDidChangeSelectedDetentIdentifier fires and updates selectedDetentIdentifier to the system-assigned custom detent identifier. On the next KVO callback, prevLayoutDetentIdentifier (.medium) no longer matches selectedDetentIdentifier, so the update is silently dropped. 2. Re-reading frame.size.height from the view hierarchy instead of using the observed bounds can return a stale value during rapid layout passes. Fix: have the KVO callback call updateDetents directly with the observed height, bypassing both the guard and the frame re-read. The guard in updateLayout() is preserved for the manual/fallback code path. https://claude.ai/code/session_01Rp7ef1h3fKh6fhStcjqLJ5
This commit is contained in:
@@ -162,6 +162,9 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
|
|||||||
|
|
||||||
// Observe the content view's bounds via KVO so that height changes are detected
|
// Observe the content view's bounds via KVO so that height changes are detected
|
||||||
// purely on the native side, without a JS bridge round-trip through onLayout.
|
// purely on the native side, without a JS bridge round-trip through onLayout.
|
||||||
|
// Calls updateDetents directly with the observed height rather than going through
|
||||||
|
// updateLayout(), which has a prevLayoutDetentIdentifier guard that can block
|
||||||
|
// legitimate content-driven updates when detent identifiers drift during animations.
|
||||||
private func startObservingContentHeight() {
|
private func startObservingContentHeight() {
|
||||||
self.contentHeightObservation?.invalidate()
|
self.contentHeightObservation?.invalidate()
|
||||||
|
|
||||||
@@ -177,7 +180,9 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
|
|||||||
let newBounds = change.newValue,
|
let newBounds = change.newValue,
|
||||||
oldBounds.height != newBounds.height,
|
oldBounds.height != newBounds.height,
|
||||||
newBounds.height > 0 else { return }
|
newBounds.height > 0 else { return }
|
||||||
self.updateLayout()
|
let clampedHeight = self.clampHeight(newBounds.height)
|
||||||
|
self.sheetVc?.updateDetents(contentHeight: clampedHeight, preventExpansion: self.preventExpansion)
|
||||||
|
self.selectedDetentIdentifier = self.sheetVc?.getCurrentDetentIdentifier()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user