1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = useLinkBuilder;
|
7 | var _core = require("@react-navigation/core");
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | var _LinkingContext = _interopRequireDefault(require("./LinkingContext"));
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 | 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); }
|
12 | 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; }
|
13 | const getRootStateForNavigate = (navigation, state) => {
|
14 | const parent = navigation.getParent();
|
15 | if (parent) {
|
16 | const parentState = parent.getState();
|
17 | return getRootStateForNavigate(parent, {
|
18 | index: 0,
|
19 | routes: [{
|
20 | ...parentState.routes[parentState.index],
|
21 | state: state
|
22 | }]
|
23 | });
|
24 | }
|
25 | return state;
|
26 | };
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function useLinkBuilder() {
|
33 | const navigation = React.useContext(_core.NavigationHelpersContext);
|
34 | const linking = React.useContext(_LinkingContext.default);
|
35 | const buildLink = React.useCallback((name, params) => {
|
36 | const {
|
37 | options
|
38 | } = linking;
|
39 | if ((options === null || options === void 0 ? void 0 : options.enabled) === false) {
|
40 | return undefined;
|
41 | }
|
42 | const state = navigation ? getRootStateForNavigate(navigation, {
|
43 | index: 0,
|
44 | routes: [{
|
45 | name,
|
46 | params
|
47 | }]
|
48 | }) :
|
49 |
|
50 |
|
51 | {
|
52 | index: 0,
|
53 | routes: [{
|
54 | name,
|
55 | params
|
56 | }]
|
57 | };
|
58 | const path = options !== null && options !== void 0 && options.getPathFromState ? options.getPathFromState(state, options === null || options === void 0 ? void 0 : options.config) : (0, _core.getPathFromState)(state, options === null || options === void 0 ? void 0 : options.config);
|
59 | return path;
|
60 | }, [linking, navigation]);
|
61 | return buildLink;
|
62 | }
|
63 |
|
\ | No newline at end of file |