From 421c4abd02160df1c0b4037507271cc8db852618 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Mar 2026 07:26:52 +0000 Subject: [PATCH] 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 --- modules/bottom-sheet/ios/SheetView.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/bottom-sheet/ios/SheetView.swift b/modules/bottom-sheet/ios/SheetView.swift index 8d9f07da58..320b58a5dd 100644 --- a/modules/bottom-sheet/ios/SheetView.swift +++ b/modules/bottom-sheet/ios/SheetView.swift @@ -162,6 +162,9 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate { // 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. + // 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() { self.contentHeightObservation?.invalidate() @@ -177,7 +180,9 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate { let newBounds = change.newValue, oldBounds.height != newBounds.height, 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() } }