@react-navigation/core
Version:
Core utilities for building navigators
30 lines (28 loc) • 1.98 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useScheduleUpdate = useScheduleUpdate;
var React = _interopRequireWildcard(require("react"));
var _NavigationBuilderContext = require("./NavigationBuilderContext.js");
var _useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* When screen config changes, we want to update the navigator in the same update phase.
* However, navigation state is in the root component and React won't let us update it from a child.
* This is a workaround for that, the scheduled update is stored in the ref without actually calling setState.
* It lets all subsequent updates access the latest state so it stays correct.
* Then we call setState during after the component updates.
*/
function useScheduleUpdate(callback) {
const {
scheduleUpdate,
flushUpdates
} = React.useContext(_NavigationBuilderContext.NavigationBuilderContext);
// FIXME: This is potentially unsafe
// However, since we are using sync store, it might be fine
scheduleUpdate(callback);
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(flushUpdates);
}
//# sourceMappingURL=useScheduleUpdate.js.map
;