@@ -27,6 +27,7 @@ import com.google.android.material.shape.CornerFamily
2727import com.google.android.material.shape.MaterialShapeDrawable
2828import com.google.android.material.shape.ShapeAppearanceModel
2929import com.swmansion.rnscreens.bottomsheet.isSheetFitToContents
30+ import com.swmansion.rnscreens.bottomsheet.useSingleDetent
3031import com.swmansion.rnscreens.bottomsheet.usesFormSheetPresentation
3132import com.swmansion.rnscreens.events.HeaderHeightChangeEvent
3233import com.swmansion.rnscreens.events.SheetDetentChangedEvent
@@ -103,6 +104,9 @@ class Screen(
103104 field = value
104105 }
105106
107+ private val isNativeStackScreen: Boolean
108+ get() = container is ScreenStack
109+
106110 init {
107111 // we set layout params as WindowManager.LayoutParams to workaround the issue with TextInputs
108112 // not displaying modal menus (e.g., copy/paste or selection). The missing menus are due to the
@@ -132,11 +136,7 @@ class Screen(
132136 val height = bottom - top
133137
134138 if (isSheetFitToContents()) {
135- sheetBehavior?.let {
136- if (it.maxHeight != height) {
137- it.maxHeight = height
138- }
139- }
139+ sheetBehavior?.useSingleDetent(height)
140140
141141 if (! BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ) {
142142 // On old architecture we delay enter transition in order to wait for initial frame.
@@ -173,23 +173,31 @@ class Screen(
173173 r : Int ,
174174 b : Int ,
175175 ) {
176- if (container is ScreenStack && changed) {
176+ // In case of form sheet we get layout notification a bit later, in `onBottomSheetBehaviorDidLayout`
177+ // after the attached behaviour laid out this view.
178+ if (changed && isNativeStackScreen && ! usesFormSheetPresentation()) {
177179 val width = r - l
178180 val height = b - t
179181
180- if (BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ) {
181- updateScreenSizeFabric(width, height, t)
182- } else {
183- updateScreenSizePaper(width, height)
184- }
182+ dispatchShadowStateUpdate(width, height, t)
185183
186- footer?.onParentLayout(changed, l, t, r, b, container !! .height)
184+ // FormSheet has no header in current model.
187185 notifyHeaderHeightChange(t)
186+ }
187+ }
188188
189- if (! BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ) {
190- maybeTriggerPostponedTransition()
191- }
189+ internal fun onBottomSheetBehaviorDidLayout (coordinatorLayoutDidChange : Boolean ) {
190+ if (! usesFormSheetPresentation()) {
191+ return
192+ }
193+ if (coordinatorLayoutDidChange && isNativeStackScreen) {
194+ dispatchShadowStateUpdate(width, height, top)
195+ }
196+ if (! BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ) {
197+ maybeTriggerPostponedTransition()
192198 }
199+
200+ footer?.onParentLayout(coordinatorLayoutDidChange, left, top, right, bottom, container!! .height)
193201 }
194202
195203 private fun maybeTriggerPostponedTransition () {
@@ -214,6 +222,21 @@ class Screen(
214222 )
215223 }
216224
225+ /* *
226+ * @param offsetY ignored on old architecture
227+ */
228+ private fun dispatchShadowStateUpdate (
229+ width : Int ,
230+ height : Int ,
231+ offsetY : Int ,
232+ ) {
233+ if (BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ) {
234+ updateScreenSizeFabric(width, height, offsetY)
235+ } else {
236+ updateScreenSizePaper(width, height)
237+ }
238+ }
239+
217240 val headerConfig: ScreenStackHeaderConfig ?
218241 get() = children.find { it is ScreenStackHeaderConfig } as ? ScreenStackHeaderConfig
219242
@@ -487,6 +510,11 @@ class Screen(
487510 isStable : Boolean ,
488511 ) {
489512 dispatchSheetDetentChanged(detentIndex, isStable)
513+ // There is no need to update shadow state for transient sheet states -
514+ // we are unsure of the exact sheet position anyway.
515+ if (BuildConfig .IS_NEW_ARCHITECTURE_ENABLED && isStable) {
516+ updateScreenSizeFabric(width, height, top)
517+ }
490518 }
491519
492520 private fun dispatchSheetDetentChanged (
0 commit comments