diff --git a/android/src/main/java/com/swmansion/rnscreens/InsetsObserverProxy.kt b/android/src/main/java/com/swmansion/rnscreens/InsetsObserverProxy.kt index dd5468284..8da1f52ed 100644 --- a/android/src/main/java/com/swmansion/rnscreens/InsetsObserverProxy.kt +++ b/android/src/main/java/com/swmansion/rnscreens/InsetsObserverProxy.kt @@ -23,10 +23,7 @@ object InsetsObserverProxy : OnApplyWindowInsetsListener { ): WindowInsetsCompat { var rollingInsets = if (shouldForwardInsetsToView) { - WindowInsetsCompat.toWindowInsetsCompat( - v.onApplyWindowInsets(insets.toWindowInsets()), - v, - ) + ViewCompat.onApplyWindowInsets(v, insets) } else { insets } @@ -57,8 +54,10 @@ object InsetsObserverProxy : OnApplyWindowInsetsListener { } } - fun unregisterOnView(view: View) { - ViewCompat.setOnApplyWindowInsetsListener(view, null) + fun unregister() { + getObservedView()?.takeIf { hasBeenRegistered }?.let { + ViewCompat.setOnApplyWindowInsetsListener(it, null) + } } private fun getObservedView(): View? = eventSourceView.get() diff --git a/android/src/main/java/com/swmansion/rnscreens/ScreenWindowTraits.kt b/android/src/main/java/com/swmansion/rnscreens/ScreenWindowTraits.kt index c56ede148..37aefe87b 100644 --- a/android/src/main/java/com/swmansion/rnscreens/ScreenWindowTraits.kt +++ b/android/src/main/java/com/swmansion/rnscreens/ScreenWindowTraits.kt @@ -163,7 +163,6 @@ object ScreenWindowTraits { InsetsObserverProxy.registerOnView(decorView) InsetsObserverProxy.addOnApplyWindowInsetsListener(windowInsetsListener) } else { - InsetsObserverProxy.unregisterOnView(decorView) InsetsObserverProxy.removeOnApplyWindowInsetsListener(windowInsetsListener) } ViewCompat.requestApplyInsets(decorView) diff --git a/apps/Example.tsx b/apps/Example.tsx index 49381ab30..ba27c3579 100644 --- a/apps/Example.tsx +++ b/apps/Example.tsx @@ -39,10 +39,6 @@ import { GestureHandlerRootView } from 'react-native-gesture-handler'; enableFreeze(); -if (Platform.OS === 'android') { - StatusBar.setTranslucent(true); -} - const SCREENS: Record< string, { diff --git a/apps/src/tests/TestAndroidTransitions.tsx b/apps/src/tests/TestAndroidTransitions.tsx new file mode 100644 index 000000000..0d98e720e --- /dev/null +++ b/apps/src/tests/TestAndroidTransitions.tsx @@ -0,0 +1,102 @@ +import { NavigationContainer, RouteProp } from "@react-navigation/native"; +import { NativeStackNavigationProp, createNativeStackNavigator } from "@react-navigation/native-stack"; +// import { NativeStackNavigationProp, createNativeStackNavigator } from "react-native-screens/native-stack"; +import React from "react"; +import { Button, TextInput, View } from "react-native"; + +type RouteParamList = { + Home: undefined; + Second: undefined; + FormSheet: undefined; + Modal: undefined; + NestedStackHost: undefined; +} + +type RouteProps = { + navigation: NativeStackNavigationProp, + route: RouteProp, +} + +const Stack = createNativeStackNavigator(); +// const Stack = createNativeStackNavigator(); + +function Home({ navigation }: RouteProps<'Home'>): React.JSX.Element { + return ( + + +