Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vitorleonel/bfb898568a6421d0b0ea1e966072e9c9 to your computer and use it in GitHub Desktop.
Save vitorleonel/bfb898568a6421d0b0ea1e966072e9c9 to your computer and use it in GitHub Desktop.
StatusBarConfig.js
import { StatusBar, Platform } from "react-native";
const getActiveRouteName = navigationState => {
if (!navigationState) return null;
const route = navigationState.routes[navigationState.index];
if (route.routes) {
return getActiveRouteName(route);
}
return route.routeName;
};
const defineStatusBar = (barStyle, backgroundColor) => {
StatusBar.setBarStyle(barStyle);
if (Platform.OS == "android") {
StatusBar.setBackgroundColor(backgroundColor, true);
}
};
export default (_, currentState, action) => {
if (!action.type.includes("NAVIGATE") && !action.type.includes("BACK"))
return;
const currentScreen = getActiveRouteName(currentState);
switch (currentScreen) {
case "Questions":
defineStatusBar("light-content", "#000");
break;
default:
defineStatusBar("dark-content", "#fff");
break;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment