Skip to content

Commit 53e45a3

Browse files
authored
feat(Android): deprecate status/navigation bar edge to edge related props in native code (#2913)
## Description Deprecate native props and methods related to status/navigation bars that will be no longer relevant after edge-to-edge is enforced (they were deprecated already in this PR: #2638). ## Changes - deprecate deprecate status/navigation bar edge to edge related props in native code - add EdgeToEdge detection utility - prevent adding `ScreenWindowTraits`' `windowInsetsListener` to `InsetsObserverProxy` if edge-to-edge is enabled ## Checklist - [ ] Ensured that CI passes
1 parent 6b1de35 commit 53e45a3

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

android/src/main/java/com/swmansion/rnscreens/Screen.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ class Screen(
363363
fragmentWrapper?.let { ScreenWindowTraits.setHidden(this, it.tryGetActivity()) }
364364
}
365365

366+
@Deprecated(
367+
"For apps targeting SDK 35 or above this prop has no effect because " +
368+
"edge-to-edge is enabled by default and the status bar is always translucent.",
369+
)
366370
var isStatusBarTranslucent: Boolean? = null
367371
set(statusBarTranslucent) {
368372
if (statusBarTranslucent != null) {
@@ -378,6 +382,10 @@ class Screen(
378382
}
379383
}
380384

385+
@Deprecated(
386+
"For apps targeting SDK 35 or above this prop has no effect because " +
387+
"edge-to-edge is enabled by default and the status bar is always translucent.",
388+
)
381389
var statusBarColor: Int? = null
382390
set(statusBarColor) {
383391
if (statusBarColor != null) {
@@ -393,6 +401,9 @@ class Screen(
393401
}
394402
}
395403

404+
@Deprecated(
405+
"For all apps targeting Android SDK 35 or above edge-to-edge is enabled by default. ",
406+
)
396407
var navigationBarColor: Int? = null
397408
set(navigationBarColor) {
398409
if (navigationBarColor != null) {
@@ -407,6 +418,9 @@ class Screen(
407418
}
408419
}
409420

421+
@Deprecated(
422+
"For all apps targeting Android SDK 35 or above edge-to-edge is enabled by default. ",
423+
)
410424
var isNavigationBarTranslucent: Boolean? = null
411425
set(navigationBarTranslucent) {
412426
if (navigationBarTranslucent != null) {

android/src/main/java/com/swmansion/rnscreens/ScreenWindowTraits.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.swmansion.rnscreens
22

33
import android.animation.ArgbEvaluator
44
import android.animation.ValueAnimator
5-
import android.annotation.TargetApi
65
import android.app.Activity
76
import android.content.pm.ActivityInfo
87
import android.graphics.Color
@@ -19,6 +18,7 @@ import com.facebook.react.bridge.GuardedRunnable
1918
import com.facebook.react.bridge.ReactContext
2019
import com.facebook.react.bridge.UiThreadUtil
2120
import com.swmansion.rnscreens.Screen.WindowTraits
21+
import com.swmansion.rnscreens.utils.EdgeToEdgePackageDetector
2222

2323
object ScreenWindowTraits {
2424
// Methods concerning statusBar management were taken from `react-native`'s status bar module:
@@ -86,6 +86,10 @@ object ScreenWindowTraits {
8686
activity.requestedOrientation = orientation
8787
}
8888

89+
@Deprecated(
90+
"For apps targeting SDK 35 or above this prop has no effect because " +
91+
"edge-to-edge is enabled by default and the status bar is always translucent.",
92+
)
8993
internal fun setColor(
9094
screen: Screen,
9195
activity: Activity?,
@@ -142,19 +146,22 @@ object ScreenWindowTraits {
142146
}
143147
}
144148

149+
@Deprecated(
150+
"For apps targeting SDK 35 or above this prop has no effect because " +
151+
"edge-to-edge is enabled by default and the status bar is always translucent.",
152+
)
145153
internal fun setTranslucent(
146154
screen: Screen,
147155
activity: Activity?,
148156
context: ReactContext?,
149157
) {
150-
if (activity == null || context == null) {
158+
if (activity == null || context == null || EdgeToEdgePackageDetector.ENABLED) {
151159
return
152160
}
153161
val screenForTranslucent = findScreenForTrait(screen, WindowTraits.TRANSLUCENT)
154162
val translucent = screenForTranslucent?.isStatusBarTranslucent ?: false
155163
UiThreadUtil.runOnUiThread(
156164
object : GuardedRunnable(context.exceptionHandler) {
157-
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
158165
override fun runGuarded() {
159166
// If the status bar is translucent hook into the window insets calculations
160167
// and consume all the top insets so no padding will be added under the status bar.
@@ -194,6 +201,9 @@ object ScreenWindowTraits {
194201

195202
// Methods concerning navigationBar management were taken from `react-native-navigation`'s repo:
196203
// https://github.com/wix/react-native-navigation/blob/9bb70d81700692141a2c505c081c2d86c7f9c66e/lib/android/app/src/main/java/com/reactnativenavigation/utils/SystemUiUtils.kt
204+
@Deprecated(
205+
"For all apps targeting Android SDK 35 or above edge-to-edge is enabled by default. ",
206+
)
197207
internal fun setNavigationBarColor(
198208
screen: Screen,
199209
activity: Activity?,
@@ -214,11 +224,14 @@ object ScreenWindowTraits {
214224
window.navigationBarColor = color
215225
}
216226

227+
@Deprecated(
228+
"For all apps targeting Android SDK 35 or above edge-to-edge is enabled by default. ",
229+
)
217230
internal fun setNavigationBarTranslucent(
218231
screen: Screen,
219232
activity: Activity?,
220233
) {
221-
if (activity == null) {
234+
if (activity == null || EdgeToEdgePackageDetector.ENABLED) {
222235
return
223236
}
224237

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.swmansion.rnscreens.utils
2+
3+
// https://github.com/zoontek/react-native-edge-to-edge/blob/main/react-native-is-edge-to-edge/README.md
4+
object EdgeToEdgePackageDetector {
5+
// we cannot detect edge-to-edge, but we can detect react-native-edge-to-edge install
6+
val ENABLED: Boolean =
7+
try {
8+
Class.forName("com.zoontek.rnedgetoedge.EdgeToEdgePackage")
9+
true
10+
} catch (exception: ClassNotFoundException) {
11+
false
12+
}
13+
}

0 commit comments

Comments
 (0)