UNPKG

react-native-bars

Version:

Components to control your app status and navigation bars.

121 lines (88 loc) 4.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NavigationBar = void 0; var React = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _module = require("./module"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } 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; } const isSupportedPlatform = _reactNative.Platform.OS === "android" && _reactNative.Platform.Version >= 27; 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)) { _module.NativeModule === null || _module.NativeModule === void 0 ? void 0 : _module.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; } } exports.NavigationBar = NavigationBar; _defineProperty(NavigationBar, "propsStack", []); _defineProperty(NavigationBar, "immediate", null); _defineProperty(NavigationBar, "mergedProps", null); _defineProperty(NavigationBar, "currentHeight", _module.NativeModule === null || _module.NativeModule === void 0 ? void 0 : _module.NativeModule.navigationBarHeight); //# sourceMappingURL=NavigationBar.js.map