Closed 1280103995 closed 2 years ago
@1280103995 Can you publish all your styles.xml
? Give more info about how you tested it? (device, android version)
@1280103995 Can you publish all your
styles.xml
? Give more info about how you tested it? (device, android version)
I cloned your repository and only modified the content of App.txs
in the example, so you can read the source code for the content of style.xml
.
My device is: Samsung Galaxy A51 (Android 11)
style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Allow drawing under the system bars background -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:fitsSystemWindows">false</item>
<!-- Set status bar background transparent -->
<item name="android:statusBarColor">@android:color/transparent</item>
<!-- Navigation bar will stay translucent on Android < 8.1 -->
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
styles-v27.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Allow drawing under the system bars background -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:fitsSystemWindows">false</item>
<!-- Set system bars background transparent -->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<!-- Disable auto contrasted system bars background (on Android 10+) -->
<item name="android:enforceStatusBarContrast" tools:targetApi="q">false</item>
<item name="android:enforceNavigationBarContrast" tools:targetApi="q">false</item>
</style>
</resources>
I guess the problem is here in StatusBar.tsx
:
if (
lastEntry != null &&
// Update only if style have changed.
(!oldProps || oldProps.barStyle !== lastEntry.barStyle)
) {
When I changed to: if (oldProps?.barStyle !== lastEntry.barStyle)
, this problem can be solved.
I found a new problem. Set light-content
and dark-content
on the two pages in BottomTabNavigator (react-navigation) respectively. After switching tabs back and forth, the status bar color will remain one color.
@1280103995 You removed the lastEntry != null
check?
A neat solution could be to exposes initial setting (set in MainActivity
) and put it in propsStack
at start.
@1280103995你取消了
lastEntry != null
支票?一个巧妙的解决方案可能是公开初始设置(在 中设置
MainActivity
)并propsStack
在开始时将其放入。
Canceling lastEntry != null
is just a preliminary judgment, and the condition of if needs more detailed debugging.
✅ Solved. The issue was a bit tedious: on pressing back to quit the app the propsStack
was emptied (because all components are unmounted, each one will pop from the stack on componentWillUnmount
), but mergedProps
wasn't reset to null
.
Now when calling updatePropsStack
if the stack size is zero, mergedProps
is resetted.
Update and check by yourself 🙂
On v1.1.0, this issue has been resolved.:clap::clap:
Some extra words (not related to the library): Setting up a transparent Bar on Android is indeed a difficult task. :sweat_smile:
For example: 1.TextInput is covered by the keyboard.
Use react-native-safe-area-context. It exposes a hook to update insets dynamically 🙂
Bug summary
In order to cooperate with the library
react-native-bootsplash
, a dark style is set in MainActivity:RNBars.init(MainActivity.this, "dark-content");
(this is no problem).Then set the default
light-content
inApp.tsx
. After exiting the app, restart the app and you will see that the status bar style has changed todark-content
.Library version
1.0.4
Environment info
Steps to reproduce
1.Modify App.tsx in the
example
: Changeconst [isLightStatus, setIsLightStatus] = React.useState(false);
toconst [isLightStatus, setIsLightStatus] = React.useState(true);
.2.Exit the app, restart the app. (Click the virtual back button, the app is still on the recently used app screen)
Reproducible sample code