@react-native-ohos/react-native-bars
Version:
Components to control your app status and navigation bars.
94 lines (92 loc) • 3.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.StatusBar = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _NativeRNBars = _interopRequireDefault(require("./NativeRNBars"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function createStackEntry({
animated = false,
barStyle = "light-content"
}) {
return {
animated,
barStyle
};
}
class StatusBar extends React.Component {
static propsStack = [];
static immediate = null;
static mergedProps = null;
static pushStackEntry(props) {
// const entry = createStackEntry(props);
StatusBar.propsStack.push(props);
StatusBar.updatePropsStack();
return props;
}
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 = 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 or if current props are unavailable.
if (oldProps?.barStyle !== lastEntry.barStyle) {
if (_reactNative.Platform.OS === "harmony") {
_NativeRNBars.default?.setStatusBarStyle(lastEntry.barStyle);
} else {
_reactNative.StatusBar.setBarStyle(lastEntry.barStyle, lastEntry.animated);
}
}
// Update the current props values.
StatusBar.mergedProps = {
...lastEntry
};
} else {
// Reset current props when the stack is empty.
StatusBar.mergedProps = null;
}
});
}
stackEntry = null;
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;
//# sourceMappingURL=StatusBar.js.map
;