Skip to content

Commit

Permalink
fix(Android): modal insets not applying (#2371)
Browse files Browse the repository at this point in the history
## Description

This PR fixes the insets not applying on modal screens.
I brought back the missing logic, that was removed
[here](85a4196#diff-49e80f92048eb21d46beae35985ce78f79217693be04df175e5e679878d0f2c7L155)
to `InsetsObserverProxy`

Note: Without this change the insets are applied correctly after
navigating to a screen with `presentation: formSheet` at least once.

## Changes

- removed unused `unregister` fun from InsetsObserverProxy
- added `unregisterOnView` that resembles the previously removed logic

<!--
Please describe things you've changed here, make a **high level**
overview, if change is simple you can omit this section.

For example:

- Updated `about.md` docs

-->

## Screenshots / GIFs

### Before
![Screenshot 2024-10-02 at 13 07
51](https://github.com/user-attachments/assets/ac875c7d-c661-46da-b832-fea2dafeba10)

### After
![Screenshot 2024-10-02 at 13 54
15](https://github.com/user-attachments/assets/304a011b-4289-4813-bb4a-e1b5b10e73a0)

## Test code and steps to reproduce

- use `Stack Presentation` in the Example app
- set `headerShown: false` for the modal screen
- open the modal screen

## Checklist

- [x] Ensured that CI passes
  • Loading branch information
alduzy authored Oct 10, 2024
1 parent bcd7faf commit 6154c2b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ object InsetsObserverProxy : OnApplyWindowInsetsListener {
}
}

fun unregister() {
eventSourceView.get()?.takeIf { hasBeenRegistered }?.let {
ViewCompat.setOnApplyWindowInsetsListener(it, null)
}
fun unregisterOnView(view: View) {
ViewCompat.setOnApplyWindowInsetsListener(view, null)
}

private fun getObservedView(): View? = eventSourceView.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ object ScreenWindowTraits {
InsetsObserverProxy.registerOnView(decorView)
InsetsObserverProxy.addOnApplyWindowInsetsListener(windowInsetsListener)
} else {
InsetsObserverProxy.unregisterOnView(decorView)
InsetsObserverProxy.removeOnApplyWindowInsetsListener(windowInsetsListener)
}
ViewCompat.requestApplyInsets(decorView)
Expand Down

0 comments on commit 6154c2b

Please sign in to comment.