react-native-bars
Version:
Components to control your app status and navigation bars.
127 lines (94 loc) • 4.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.StatusBar = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _module = require("./module");
var _RNStatusBar$currentH;
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; }
class StatusBar extends React.Component {
constructor() {
super(...arguments);
_defineProperty(this, "stackEntry", null);
}
static createStackEntry(_ref) {
let {
animated = false,
barStyle = "light-content"
} = _ref;
return {
animated,
barStyle
};
}
static pushStackEntry(props) {
const entry = StatusBar.createStackEntry(props);
StatusBar.propsStack.push(entry);
StatusBar.updatePropsStack();
return entry;
}
static popStackEntry(entry) {
const index = StatusBar.propsStack.indexOf(entry);
if (index !== -1) {
StatusBar.propsStack.splice(index, 1);
}
StatusBar.updatePropsStack();
}
static replaceStackEntry(entry, props) {
const newEntry = StatusBar.createStackEntry(props);
const index = StatusBar.propsStack.indexOf(entry);
if (index !== -1) {
StatusBar.propsStack[index] = newEntry;
}
StatusBar.updatePropsStack();
return newEntry;
}
static updatePropsStack() {
// Send the update to the native module only once at the end of the frame.
if (StatusBar.immediate !== null) {
clearImmediate(StatusBar.immediate);
}
StatusBar.immediate = setImmediate(() => {
const oldProps = StatusBar.mergedProps;
const lastEntry = StatusBar.propsStack[StatusBar.propsStack.length - 1];
if (lastEntry != null && ( // Update only if style have changed.
!oldProps || oldProps.barStyle !== lastEntry.barStyle)) {
if (_reactNative.Platform.OS === "android") {
_module.NativeModule === null || _module.NativeModule === void 0 ? void 0 : _module.NativeModule.setStatusBarStyle(lastEntry.barStyle);
} else {
_reactNative.StatusBar.setBarStyle(lastEntry.barStyle, lastEntry.animated);
}
} // Update the current prop values.
StatusBar.mergedProps = {
barStyle: "light-content",
...lastEntry
};
});
}
componentDidMount() {
this.stackEntry = StatusBar.pushStackEntry(this.props);
}
componentDidUpdate() {
if (this.stackEntry) {
this.stackEntry = StatusBar.replaceStackEntry(this.stackEntry, this.props);
}
}
componentWillUnmount() {
if (this.stackEntry) {
StatusBar.popStackEntry(this.stackEntry);
}
}
render() {
return null;
}
}
exports.StatusBar = StatusBar;
_defineProperty(StatusBar, "propsStack", []);
_defineProperty(StatusBar, "immediate", null);
_defineProperty(StatusBar, "mergedProps", null);
_defineProperty(StatusBar, "currentHeight", (_RNStatusBar$currentH = _reactNative.StatusBar.currentHeight) !== null && _RNStatusBar$currentH !== void 0 ? _RNStatusBar$currentH : undefined);
//# sourceMappingURL=StatusBar.js.map