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