testshallpass / react-native-dropdownalert

An alert to notify users about an error or something else
MIT License
1.85k stars 252 forks source link

StatusBar backgroundColor doesn't go to its default value when moving between screens and when user holds the notification with his finger till it closes #169

Closed aqos156 closed 5 years ago

aqos156 commented 5 years ago

Short Description

StatusBar backgroundColor doesn't change to its default value when moving between screens and reseting the navigator stack via react native navigation.

This behaviour could be wanted in a case of having screen where we display the alert and the user navigates at the same time via this.props.navigation.navigate, but we still want the user to see that an alert was displayed. So the StatusBar backgroundColor changes to indicate that a dropdown was displayed.

We generally don't want this behaviour when we are navigating between screens and reseting the navigator stack at the same time. (ex. code to reset stack and navigate to another screen this.props.navigation.dispatch( StackActions.reset({ index: 0, actions: [ NavigationActions.navigate({ routeName: YOUR_ROUTE_NAME }) ] }) );)

Steps to Reproduce / Code Snippets / Usage

  1. Have two screens in a stack navigator
  2. Show alert in one of the two screens and immediately navigate to another screen with this bit code that resets the stack: this.props.navigation.dispatch( StackActions.reset({ index: 0, actions: [ NavigationActions.navigate({ routeName: YOUR_ROUTE_NAME }) ] }) );
  3. See that the status bar color has persisted. (If we add <StatusBar> component to this screen with the backgroundColor poperty set, then we don't see the dropdown color anymore.)
  4. BUT! If we now navigate back to the original screen with dropdown (with the same piece of code as mentioned above and don't display the dropdown) then we can observe that the color of the dropdown has persisted even after leaving this screen.

Expected Results

StatusBar color not changing back to its default value

Additional Information

aqos156 commented 5 years ago

In further investigations it seems that iOS (tested on 12.1.2) isn't affected and also at the same time versions of android which do not support custom StatusBar backgroundColor are not affected. We could make this fix platform specific for android only.

aqos156 commented 5 years ago

The fix that I presented two days ago fixes this issue on Android and doesn't seem to raise any other issues on iOS (tho not tested thoroughly).

Now when user resets the stack and navigates, the color changes back to default and if the user uses the this.props.navigation.navigate method, the color of StatusBar stays displayed until the alert automatically hides itself.

aqos156 commented 5 years ago

@testshallpass Users of may app have found another occourance of this weird behaviour.

You can replicate this by following these steps: Start the example project, trigger a dropdown and hold your finger over it. Now wait untill the dropdown closes itself (you may have to lift your finger and place it back again a few times) The background color of status bar stays set to active.

Tested on android 9.0 Needs more testing

aqos156 commented 5 years ago

I have added a fix for the issue specified above within the previous pull req.