react-native-screens icon indicating copy to clipboard operation
react-native-screens copied to clipboard

fix(Android): status bar insets for formSheet

Open kligarski opened this issue 7 months ago • 1 comments

Description

Status bar insets were not handled properly when opening the formSheet with initial height that was greater than safe content area. The bug is directly connected with how BottomSheetBehavior works. For unknown reasons, onChildLayout sometimes isn't called after BottomSheetBehavior's insets handler runs. In this PR, we override Screen's setOnApplyWindowInsetsListener (used by BottomSheetBehavior to register its handler), to make sure to request the layout after the listener runs.

The problem

On first layout, BottomSheetBehavior registers the inset listener which updates insetsTop field. In onLayoutChild, BottomSheetBehavior uses insetsTop value to calculate childHeight which is then used to calculate fitToContentsOffset. fitToContentsOffset is returned from getExpandedOffset() if isFitToContents == true (which is the case for single and two detents in screens). If isFitToContents == false (i.e. we use 3 detents), getExpandedOffset() uses insetsTop directly. When layout wasn't called after the insets handler, previous value was used which caused the sheet to go under the status bar.

Fixes https://github.com/software-mansion/react-native-screens/issues/2896.

Changes

  • add custom setter for onApplyWindowInsetsListener
  • add Test2896 test screen (unable to create e2e test because content behind formSheet still has visibility = VISIBLE)

Screenshots / GIFs

Before After

Test code and steps to reproduce

Run example app and open Test2896 test screen.

Checklist

  • [x] Included code example that can be used to test this change
  • [x] Ensured that CI passes

kligarski avatar May 16 '25 10:05 kligarski

Any chance that we get this PR released soon?

ilteoood avatar Jun 24 '25 07:06 ilteoood

The work is continued here: https://github.com/software-mansion/react-native-screens/pull/3336

t0maboro avatar Nov 13 '25 12:11 t0maboro