UNPKG

react-native-bars

Version:

Components to control your app status and navigation bars.

104 lines (80 loc) 2.98 kB
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import * as React from "react"; import { Platform } from "react-native"; import { NativeModule } from "./module"; const isSupportedPlatform = Platform.OS === "android" && Platform.Version >= 27; export class NavigationBar extends React.Component { constructor() { super(...arguments); _defineProperty(this, "stackEntry", null); } static createStackEntry(_ref) { let { barStyle = "light-content" } = _ref; return { barStyle }; } static pushStackEntry(props) { const entry = NavigationBar.createStackEntry(props); NavigationBar.propsStack.push(entry); NavigationBar.updatePropsStack(); return entry; } static popStackEntry(entry) { const index = NavigationBar.propsStack.indexOf(entry); if (index !== -1) { NavigationBar.propsStack.splice(index, 1); } NavigationBar.updatePropsStack(); } static replaceStackEntry(entry, props) { const newEntry = NavigationBar.createStackEntry(props); const index = NavigationBar.propsStack.indexOf(entry); if (index !== -1) { NavigationBar.propsStack[index] = newEntry; } NavigationBar.updatePropsStack(); return newEntry; } static updatePropsStack() { // Send the update to the native module only once at the end of the frame. if (NavigationBar.immediate !== null) { clearImmediate(NavigationBar.immediate); } NavigationBar.immediate = setImmediate(() => { const oldProps = NavigationBar.mergedProps; const lastEntry = NavigationBar.propsStack[NavigationBar.propsStack.length - 1]; if (isSupportedPlatform && lastEntry != null && ( // Update only if style have changed. !oldProps || oldProps.barStyle !== lastEntry.barStyle)) { NativeModule === null || NativeModule === void 0 ? void 0 : NativeModule.setNavigationBarStyle(lastEntry.barStyle); } // Update the current prop values. NavigationBar.mergedProps = { barStyle: "light-content", ...lastEntry }; }); } componentDidMount() { this.stackEntry = NavigationBar.pushStackEntry(this.props); } componentDidUpdate() { if (this.stackEntry) { this.stackEntry = NavigationBar.replaceStackEntry(this.stackEntry, this.props); } } componentWillUnmount() { if (this.stackEntry) { NavigationBar.popStackEntry(this.stackEntry); } } render() { return null; } } _defineProperty(NavigationBar, "propsStack", []); _defineProperty(NavigationBar, "immediate", null); _defineProperty(NavigationBar, "mergedProps", null); _defineProperty(NavigationBar, "currentHeight", NativeModule === null || NativeModule === void 0 ? void 0 : NativeModule.navigationBarHeight); //# sourceMappingURL=NavigationBar.js.map