@react-navigation/native
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = createMemoryHistory; | ||
| var _nonSecure = require("nanoid/non-secure"); | ||
| function createMemoryHistory() { | ||
| let index = 0; | ||
| let items = []; | ||
| // Pending callbacks for `history.go(n)` | ||
| // We might modify the callback stored if it was interrupted, so we have a ref to identify it | ||
| const pending = []; | ||
| const interrupt = () => { | ||
| // If another history operation was performed we need to interrupt existing ones | ||
| // This makes sure that calls such as `history.replace` after `history.go` don't happen | ||
| // Since otherwise it won't be correct if something else has changed | ||
| pending.forEach(it => { | ||
| const cb = it.cb; | ||
| it.cb = () => cb(true); | ||
| }); | ||
| }; | ||
| const history = { | ||
| get index() { | ||
| var _window$history$state; | ||
| // We store an id in the state instead of an index | ||
| // Index could get out of sync with in-memory values if page reloads | ||
| const id = (_window$history$state = window.history.state) === null || _window$history$state === void 0 ? void 0 : _window$history$state.id; | ||
| if (id) { | ||
| const index = items.findIndex(item => item.id === id); | ||
| return index > -1 ? index : 0; | ||
| } | ||
| return 0; | ||
| }, | ||
| get(index) { | ||
| return items[index]; | ||
| }, | ||
| backIndex(_ref) { | ||
| let { | ||
| path | ||
| } = _ref; | ||
| // We need to find the index from the element before current to get closest path to go back to | ||
| for (let i = index - 1; i >= 0; i--) { | ||
| const item = items[i]; | ||
| if (item.path === path) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }, | ||
| push(_ref2) { | ||
| let { | ||
| path, | ||
| state | ||
| } = _ref2; | ||
| interrupt(); | ||
| const id = (0, _nonSecure.nanoid)(); | ||
| // When a new entry is pushed, all the existing entries after index will be inaccessible | ||
| // So we remove any existing entries after the current index to clean them up | ||
| items = items.slice(0, index + 1); | ||
| items.push({ | ||
| path, | ||
| state, | ||
| id | ||
| }); | ||
| index = items.length - 1; | ||
| // We pass empty string for title because it's ignored in all browsers except safari | ||
| // We don't store state object in history.state because: | ||
| // - browsers have limits on how big it can be, and we don't control the size | ||
| // - while not recommended, there could be non-serializable data in state | ||
| window.history.pushState({ | ||
| id | ||
| }, '', path); | ||
| }, | ||
| replace(_ref3) { | ||
| var _window$history$state2; | ||
| let { | ||
| path, | ||
| state | ||
| } = _ref3; | ||
| interrupt(); | ||
| const id = ((_window$history$state2 = window.history.state) === null || _window$history$state2 === void 0 ? void 0 : _window$history$state2.id) ?? (0, _nonSecure.nanoid)(); | ||
| // Need to keep the hash part of the path if there was no previous history entry | ||
| // or the previous history entry had the same path | ||
| let pathWithHash = path; | ||
| if (!items.length || items.findIndex(item => item.id === id) < 0) { | ||
| // There are two scenarios for creating an array with only one history record: | ||
| // - When loaded id not found in the items array, this function by default will replace | ||
| // the first item. We need to keep only the new updated object, otherwise it will break | ||
| // the page when navigating forward in history. | ||
| // - This is the first time any state modifications are done | ||
| // So we need to push the entry as there's nothing to replace | ||
| pathWithHash = pathWithHash + location.hash; | ||
| items = [{ | ||
| path: pathWithHash, | ||
| state, | ||
| id | ||
| }]; | ||
| index = 0; | ||
| } else { | ||
| if (items[index].path === path) { | ||
| pathWithHash = pathWithHash + location.hash; | ||
| } | ||
| items[index] = { | ||
| path, | ||
| state, | ||
| id | ||
| }; | ||
| } | ||
| window.history.replaceState({ | ||
| id | ||
| }, '', pathWithHash); | ||
| }, | ||
| // `history.go(n)` is asynchronous, there are couple of things to keep in mind: | ||
| // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire. | ||
| // - each `history.go(n)` call will trigger a separate `popstate` event with correct location. | ||
| // - the `popstate` event fires before the next frame after calling `history.go(n)`. | ||
| // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can. | ||
| go(n) { | ||
| interrupt(); | ||
| // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory | ||
| // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app. | ||
| const nextIndex = index + n; | ||
| const lastItemIndex = items.length - 1; | ||
| if (n < 0 && !items[nextIndex]) { | ||
| // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item. | ||
| n = -index; | ||
| index = 0; | ||
| } else if (n > 0 && nextIndex > lastItemIndex) { | ||
| // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there. | ||
| n = lastItemIndex - index; | ||
| index = lastItemIndex; | ||
| } else { | ||
| index = nextIndex; | ||
| } | ||
| if (n === 0) { | ||
| return; | ||
| } | ||
| // When we call `history.go`, `popstate` will fire when there's history to go back to | ||
| // So we need to somehow handle following cases: | ||
| // - There's history to go back, `history.go` is called, and `popstate` fires | ||
| // - `history.go` is called multiple times, we need to resolve on respective `popstate` | ||
| // - No history to go back, but `history.go` was called, browser has no API to detect it | ||
| return new Promise((resolve, reject) => { | ||
| const done = interrupted => { | ||
| clearTimeout(timer); | ||
| if (interrupted) { | ||
| reject(new Error('History was changed during navigation.')); | ||
| return; | ||
| } | ||
| // There seems to be a bug in Chrome regarding updating the title | ||
| // If we set a title just before calling `history.go`, the title gets lost | ||
| // However the value of `document.title` is still what we set it to | ||
| // It's just not displayed in the tab bar | ||
| // To update the tab bar, we need to reset the title to something else first (e.g. '') | ||
| // And set the title to what it was before so it gets applied | ||
| // It won't work without setting it to empty string coz otherwise title isn't changing | ||
| // Which means that the browser won't do anything after setting the title | ||
| const { | ||
| title | ||
| } = window.document; | ||
| window.document.title = ''; | ||
| window.document.title = title; | ||
| resolve(); | ||
| }; | ||
| pending.push({ | ||
| ref: done, | ||
| cb: done | ||
| }); | ||
| // If navigation didn't happen within 100ms, assume that it won't happen | ||
| // This may not be accurate, but hopefully it won't take so much time | ||
| // In Chrome, navigation seems to happen instantly in next microtask | ||
| // But on Firefox, it seems to take much longer, around 50ms from our testing | ||
| // We're using a hacky timeout since there doesn't seem to be way to know for sure | ||
| const timer = setTimeout(() => { | ||
| const index = pending.findIndex(it => it.ref === done); | ||
| if (index > -1) { | ||
| pending[index].cb(); | ||
| pending.splice(index, 1); | ||
| } | ||
| }, 100); | ||
| const onPopState = () => { | ||
| var _window$history$state3; | ||
| const id = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id; | ||
| const currentIndex = items.findIndex(item => item.id === id); | ||
| // Fix createMemoryHistory.index variable's value | ||
| // as it may go out of sync when navigating in the browser. | ||
| index = Math.max(currentIndex, 0); | ||
| const last = pending.pop(); | ||
| window.removeEventListener('popstate', onPopState); | ||
| last === null || last === void 0 ? void 0 : last.cb(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| window.history.go(n); | ||
| }); | ||
| }, | ||
| // The `popstate` event is triggered when history changes, except `pushState` and `replaceState` | ||
| // If we call `history.go(n)` ourselves, we don't want it to trigger the listener | ||
| // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener | ||
| listen(listener) { | ||
| const onPopState = () => { | ||
| if (pending.length) { | ||
| // This was triggered by `history.go(n)`, we shouldn't call the listener | ||
| return; | ||
| } | ||
| listener(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| return () => window.removeEventListener('popstate', onPopState); | ||
| } | ||
| }; | ||
| return history; | ||
| } | ||
| //# sourceMappingURL=createMemoryHistory.js.map |
| {"version":3,"names":["createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","nanoid","slice","length","pushState","replace","pathWithHash","location","hash","replaceState","go","n","nextIndex","lastItemIndex","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","Math","max","last","pop","removeEventListener","addEventListener","listen","listener"],"sourceRoot":"../../src","sources":["createMemoryHistory.tsx"],"mappings":";;;;;;AACA;AAWe,SAASA,mBAAmB,GAAG;EAC5C,IAAIC,KAAK,GAAG,CAAC;EACb,IAAIC,KAAsB,GAAG,EAAE;;EAE/B;EACA;EACA,MAAMC,OAAgE,GAAG,EAAE;EAE3E,MAAMC,SAAS,GAAG,MAAM;IACtB;IACA;IACA;IACAD,OAAO,CAACE,OAAO,CAAEC,EAAE,IAAK;MACtB,MAAMC,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| ||
| value: true | ||
| }); | ||
| exports.default = useBackButton; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _reactNative = require("react-native"); | ||
| 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 useBackButton(ref) { | ||
| React.useEffect(() => { | ||
| const subscription = _reactNative.BackHandler.addEventListener('hardwareBackPress', () => { | ||
| const navigation = ref.current; | ||
| if (navigation == null) { | ||
| return false; | ||
| } | ||
| if (navigation.canGoBack()) { | ||
| navigation.goBack(); | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| return () => subscription.remove(); | ||
| }, [ref]); | ||
| } | ||
| //# sourceMappingURL=useBackButton.native.js.map |
| {"version":3,"names":["useBackButton","ref","React","useEffect","subscription","BackHandler","addEventListener","navigation","current","canGoBack","goBack","remove"],"sourceRoot":"../../src","sources":["useBackButton.native.tsx"],"mappings":";;;;;;AAIA;AACA;AAA2C;AAAA;AAE5B,SAASA,aAAa,CACnCC,GAA2D,EAC3D;EACAC,KAAK,CAACC,SAAS,CAAC,MAAM;IACpB,MAAMC,YAAY,GAAGC,wBAAW,CAACC,gBAAgB,CAC/C,mBAAmB,EACnB,MAAM;MACJ,MAAMC,UAAU,GAAGN,GAAG,CAACO,OAAO;MAE9B,IAAID,UAAU,IAAI,IAAI,EAAE;QACtB,OAAO,KAAK;MACd;MAEA,IAAIA,UAAU,CAACE,SAAS,EAAE,EAAE;QAC1BF,UAAU,CAACG,MAAM,EAAE;QAEnB,OAAO,IAAI;MACb;MAEA,OAAO,KAAK;IACd,CAAC,CACF;IAED,OAAO,MAAMN,YAAY,CAACO,MAAM,EAAE;EACpC,CAAC,EAAE,CAACV,GAAG,CAAC,CAAC;AACX"} |
| import { nanoid } from 'nanoid/non-secure'; | ||
| export default function createMemoryHistory() { | ||
| let index = 0; | ||
| let items = []; | ||
| // Pending callbacks for `history.go(n)` | ||
| // We might modify the callback stored if it was interrupted, so we have a ref to identify it | ||
| const pending = []; | ||
| const interrupt = () => { | ||
| // If another history operation was performed we need to interrupt existing ones | ||
| // This makes sure that calls such as `history.replace` after `history.go` don't happen | ||
| // Since otherwise it won't be correct if something else has changed | ||
| pending.forEach(it => { | ||
| const cb = it.cb; | ||
| it.cb = () => cb(true); | ||
| }); | ||
| }; | ||
| const history = { | ||
| get index() { | ||
| var _window$history$state; | ||
| // We store an id in the state instead of an index | ||
| // Index could get out of sync with in-memory values if page reloads | ||
| const id = (_window$history$state = window.history.state) === null || _window$history$state === void 0 ? void 0 : _window$history$state.id; | ||
| if (id) { | ||
| const index = items.findIndex(item => item.id === id); | ||
| return index > -1 ? index : 0; | ||
| } | ||
| return 0; | ||
| }, | ||
| get(index) { | ||
| return items[index]; | ||
| }, | ||
| backIndex(_ref) { | ||
| let { | ||
| path | ||
| } = _ref; | ||
| // We need to find the index from the element before current to get closest path to go back to | ||
| for (let i = index - 1; i >= 0; i--) { | ||
| const item = items[i]; | ||
| if (item.path === path) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }, | ||
| push(_ref2) { | ||
| let { | ||
| path, | ||
| state | ||
| } = _ref2; | ||
| interrupt(); | ||
| const id = nanoid(); | ||
| // When a new entry is pushed, all the existing entries after index will be inaccessible | ||
| // So we remove any existing entries after the current index to clean them up | ||
| items = items.slice(0, index + 1); | ||
| items.push({ | ||
| path, | ||
| state, | ||
| id | ||
| }); | ||
| index = items.length - 1; | ||
| // We pass empty string for title because it's ignored in all browsers except safari | ||
| // We don't store state object in history.state because: | ||
| // - browsers have limits on how big it can be, and we don't control the size | ||
| // - while not recommended, there could be non-serializable data in state | ||
| window.history.pushState({ | ||
| id | ||
| }, '', path); | ||
| }, | ||
| replace(_ref3) { | ||
| var _window$history$state2; | ||
| let { | ||
| path, | ||
| state | ||
| } = _ref3; | ||
| interrupt(); | ||
| const id = ((_window$history$state2 = window.history.state) === null || _window$history$state2 === void 0 ? void 0 : _window$history$state2.id) ?? nanoid(); | ||
| // Need to keep the hash part of the path if there was no previous history entry | ||
| // or the previous history entry had the same path | ||
| let pathWithHash = path; | ||
| if (!items.length || items.findIndex(item => item.id === id) < 0) { | ||
| // There are two scenarios for creating an array with only one history record: | ||
| // - When loaded id not found in the items array, this function by default will replace | ||
| // the first item. We need to keep only the new updated object, otherwise it will break | ||
| // the page when navigating forward in history. | ||
| // - This is the first time any state modifications are done | ||
| // So we need to push the entry as there's nothing to replace | ||
| pathWithHash = pathWithHash + location.hash; | ||
| items = [{ | ||
| path: pathWithHash, | ||
| state, | ||
| id | ||
| }]; | ||
| index = 0; | ||
| } else { | ||
| if (items[index].path === path) { | ||
| pathWithHash = pathWithHash + location.hash; | ||
| } | ||
| items[index] = { | ||
| path, | ||
| state, | ||
| id | ||
| }; | ||
| } | ||
| window.history.replaceState({ | ||
| id | ||
| }, '', pathWithHash); | ||
| }, | ||
| // `history.go(n)` is asynchronous, there are couple of things to keep in mind: | ||
| // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire. | ||
| // - each `history.go(n)` call will trigger a separate `popstate` event with correct location. | ||
| // - the `popstate` event fires before the next frame after calling `history.go(n)`. | ||
| // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can. | ||
| go(n) { | ||
| interrupt(); | ||
| // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory | ||
| // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app. | ||
| const nextIndex = index + n; | ||
| const lastItemIndex = items.length - 1; | ||
| if (n < 0 && !items[nextIndex]) { | ||
| // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item. | ||
| n = -index; | ||
| index = 0; | ||
| } else if (n > 0 && nextIndex > lastItemIndex) { | ||
| // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there. | ||
| n = lastItemIndex - index; | ||
| index = lastItemIndex; | ||
| } else { | ||
| index = nextIndex; | ||
| } | ||
| if (n === 0) { | ||
| return; | ||
| } | ||
| // When we call `history.go`, `popstate` will fire when there's history to go back to | ||
| // So we need to somehow handle following cases: | ||
| // - There's history to go back, `history.go` is called, and `popstate` fires | ||
| // - `history.go` is called multiple times, we need to resolve on respective `popstate` | ||
| // - No history to go back, but `history.go` was called, browser has no API to detect it | ||
| return new Promise((resolve, reject) => { | ||
| const done = interrupted => { | ||
| clearTimeout(timer); | ||
| if (interrupted) { | ||
| reject(new Error('History was changed during navigation.')); | ||
| return; | ||
| } | ||
| // There seems to be a bug in Chrome regarding updating the title | ||
| // If we set a title just before calling `history.go`, the title gets lost | ||
| // However the value of `document.title` is still what we set it to | ||
| // It's just not displayed in the tab bar | ||
| // To update the tab bar, we need to reset the title to something else first (e.g. '') | ||
| // And set the title to what it was before so it gets applied | ||
| // It won't work without setting it to empty string coz otherwise title isn't changing | ||
| // Which means that the browser won't do anything after setting the title | ||
| const { | ||
| title | ||
| } = window.document; | ||
| window.document.title = ''; | ||
| window.document.title = title; | ||
| resolve(); | ||
| }; | ||
| pending.push({ | ||
| ref: done, | ||
| cb: done | ||
| }); | ||
| // If navigation didn't happen within 100ms, assume that it won't happen | ||
| // This may not be accurate, but hopefully it won't take so much time | ||
| // In Chrome, navigation seems to happen instantly in next microtask | ||
| // But on Firefox, it seems to take much longer, around 50ms from our testing | ||
| // We're using a hacky timeout since there doesn't seem to be way to know for sure | ||
| const timer = setTimeout(() => { | ||
| const index = pending.findIndex(it => it.ref === done); | ||
| if (index > -1) { | ||
| pending[index].cb(); | ||
| pending.splice(index, 1); | ||
| } | ||
| }, 100); | ||
| const onPopState = () => { | ||
| var _window$history$state3; | ||
| const id = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id; | ||
| const currentIndex = items.findIndex(item => item.id === id); | ||
| // Fix createMemoryHistory.index variable's value | ||
| // as it may go out of sync when navigating in the browser. | ||
| index = Math.max(currentIndex, 0); | ||
| const last = pending.pop(); | ||
| window.removeEventListener('popstate', onPopState); | ||
| last === null || last === void 0 ? void 0 : last.cb(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| window.history.go(n); | ||
| }); | ||
| }, | ||
| // The `popstate` event is triggered when history changes, except `pushState` and `replaceState` | ||
| // If we call `history.go(n)` ourselves, we don't want it to trigger the listener | ||
| // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener | ||
| listen(listener) { | ||
| const onPopState = () => { | ||
| if (pending.length) { | ||
| // This was triggered by `history.go(n)`, we shouldn't call the listener | ||
| return; | ||
| } | ||
| listener(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| return () => window.removeEventListener('popstate', onPopState); | ||
| } | ||
| }; | ||
| return history; | ||
| } | ||
| //# sourceMappingURL=createMemoryHistory.js.map |
| {"version":3,"names":["nanoid","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","pathWithHash","location","hash","replaceState","go","n","nextIndex","lastItemIndex","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","Math","max","last","pop","removeEventListener","addEventListener","listen","listener"],"sourceRoot":"../../src","sources":["createMemoryHistory.ts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,EAAE;UAClB;UACA;QACF;QAEAiC,QAAQ,EAAE;MACZ,CAAC;MAED3C,MAAM,CAACyC,gBAAgB,CAAC,UAAU,EAAEP,UAAU,CAAC;MAE/C,OAAO,MAAMlC,MAAM,CAACwC,mBAAmB,CAAC,UAAU,EAAEN,UAAU,CAAC;IACjE;EACF,CAAC;EAED,OAAOpC,OAAO;AAChB"} |
| import * as React from 'react'; | ||
| import { BackHandler } from 'react-native'; | ||
| export default function useBackButton(ref) { | ||
| React.useEffect(() => { | ||
| const subscription = BackHandler.addEventListener('hardwareBackPress', () => { | ||
| const navigation = ref.current; | ||
| if (navigation == null) { | ||
| return false; | ||
| } | ||
| if (navigation.canGoBack()) { | ||
| navigation.goBack(); | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| return () => subscription.remove(); | ||
| }, [ref]); | ||
| } | ||
| //# sourceMappingURL=useBackButton.native.js.map |
| {"version":3,"names":["React","BackHandler","useBackButton","ref","useEffect","subscription","addEventListener","navigation","current","canGoBack","goBack","remove"],"sourceRoot":"../../src","sources":["useBackButton.native.tsx"],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,WAAW,QAAQ,cAAc;AAE1C,eAAe,SAASC,aAAa,CACnCC,GAA2D,EAC3D;EACAH,KAAK,CAACI,SAAS,CAAC,MAAM;IACpB,MAAMC,YAAY,GAAGJ,WAAW,CAACK,gBAAgB,CAC/C,mBAAmB,EACnB,MAAM;MACJ,MAAMC,UAAU,GAAGJ,GAAG,CAACK,OAAO;MAE9B,IAAID,UAAU,IAAI,IAAI,EAAE;QACtB,OAAO,KAAK;MACd;MAEA,IAAIA,UAAU,CAACE,SAAS,EAAE,EAAE;QAC1BF,UAAU,CAACG,MAAM,EAAE;QAEnB,OAAO,IAAI;MACb;MAEA,OAAO,KAAK;IACd,CAAC,CACF;IAED,OAAO,MAAML,YAAY,CAACM,MAAM,EAAE;EACpC,CAAC,EAAE,CAACR,GAAG,CAAC,CAAC;AACX"} |
| {"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../../../src/__mocks__/window.tsx"],"names":[],"mappings":"AAiEA,QAAA,MAAM,MAAM;;;;;;;yBApDO,GAAG,KAAK,MAAM,QAAQ,MAAM;4BASzB,GAAG,KAAK,MAAM,QAAQ,MAAM;cAO1C,MAAM;;;;6BAwBkB,UAAU,YAAY,MAAM,IAAI;gCAM7B,UAAU,YAAY,MAAM,IAAI;;CAelE,CAAC;AAEF,eAAe,MAAM,CAAC"} |
| import type { NavigationState } from '@react-navigation/core'; | ||
| type HistoryRecord = { | ||
| id: string; | ||
| state: NavigationState; | ||
| path: string; | ||
| }; | ||
| export default function createMemoryHistory(): { | ||
| readonly index: number; | ||
| get(index: number): HistoryRecord; | ||
| backIndex({ path }: { | ||
| path: string; | ||
| }): number; | ||
| push({ path, state }: { | ||
| path: string; | ||
| state: NavigationState; | ||
| }): void; | ||
| replace({ path, state }: { | ||
| path: string; | ||
| state: NavigationState; | ||
| }): void; | ||
| go(n: number): Promise<void> | undefined; | ||
| listen(listener: () => void): () => void; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=createMemoryHistory.d.ts.map |
| {"version":3,"file":"createMemoryHistory.d.ts","sourceRoot":"","sources":["../../../src/createMemoryHistory.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9D,KAAK,aAAa,GAAG;IAEnB,EAAE,EAAE,MAAM,CAAC;IAEX,KAAK,EAAE,eAAe,CAAC;IAEvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,mBAAmB;;eAiC5B,MAAM;;cAIW,MAAM;;;cAaJ,MAAM;eAAS,eAAe;;;cAmB3B,MAAM;eAAS,eAAe;;UAkCzD,MAAM;qBA2FK,MAAM,IAAI;EAiB9B"} |
| {"version":3,"file":"extractPathFromURL.d.ts","sourceRoot":"","sources":["../../../src/extractPathFromURL.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,sBA0BzE"} |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzD,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,cAAc,wBAAwB,CAAC"} |
| {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/Link.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAY,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGhF,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,KAAK,KAAK,CAAC,SAAS,SAAS,eAAe,CAAC,aAAa,IAAI;IAC5D,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IAClB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CACR,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG,qBAAqB,KACvE,IAAI,CAAC;CACX,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG;IACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,SAAS,SAAS,eAAe,CAAC,aAAa,EAAE,EAC5E,EAAE,EACF,MAAM,EACN,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,SAAS,CAAC,mCAqBlB"} |
| {"version":3,"file":"LinkingContext.d.ts","sourceRoot":"","sources":["../../../src/LinkingContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,QAAA,MAAM,cAAc;aACT,eAAe,aAAa,CAAC,GAAG,SAAS;EAC1B,CAAC;AAI3B,eAAe,cAAc,CAAC"} |
| {"version":3,"file":"NavigationContainer.d.ts","sourceRoot":"","sources":["../../../src/NavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,wBAAwB,EACxB,sBAAsB,EAGvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAM3E,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,yBAAyB,EAAE,OAAO,CACpC,sBAAsB,CAAC,GAAG,CAAC,EAC3B;QAAE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,CAAA;KAAE,CAC1C,CAAC;CACH;AAID,KAAK,KAAK,CAAC,SAAS,SAAS,EAAE,IAAI,wBAAwB,GAAG;IAC5D,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AA2GF,QAAA,MAAM,mBAAmB;;;eA9GZ,MAAM,SAAS;;qBAEV,IAAI;;;MAkHjB,MAAM,YAAY,CAAC;AAExB,eAAe,mBAAmB,CAAC"} |
| {"version":3,"file":"ServerContainer.d.ts","sourceRoot":"","sources":["../../../src/ServerContainer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAsB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAMlD;;;;;;GAMG;;;;AACH,wBAsCG"} |
| {"version":3,"file":"ServerContext.d.ts","sourceRoot":"","sources":["../../../src/ServerContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,QAAA,MAAM,aAAa,8CAElB,CAAC;AAEF,eAAe,aAAa,CAAC"} |
| {"version":3,"file":"DarkTheme.d.ts","sourceRoot":"","sources":["../../../../src/theming/DarkTheme.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,QAAA,MAAM,SAAS,EAAE,KAUhB,CAAC;AAEF,eAAe,SAAS,CAAC"} |
| {"version":3,"file":"DefaultTheme.d.ts","sourceRoot":"","sources":["../../../../src/theming/DefaultTheme.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,QAAA,MAAM,YAAY,EAAE,KAUnB,CAAC;AAEF,eAAe,YAAY,CAAC"} |
| {"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../../../src/theming/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGtC,QAAA,MAAM,YAAY,sBAA2C,CAAC;AAI9D,eAAe,YAAY,CAAC"} |
| {"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theming/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGtC,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,KAAK,eAI/D"} |
| {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../../../src/theming/useTheme.tsx"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,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AI,CAAC,CAAC;IACrC;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,CAAC;IAClD;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,CAAC;IAClD;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,yBAAyB,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,CACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,EACxC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,KAC7B,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;CACtD,CAAC"} |
| {"version":3,"file":"useBackButton.d.ts","sourceRoot":"","sources":["../../../src/useBackButton.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,QAI1D"} |
| import type { NavigationContainerRef, ParamListBase } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| export default function useBackButton(ref: React.RefObject<NavigationContainerRef<ParamListBase>>): void; | ||
| //# sourceMappingURL=useBackButton.native.d.ts.map |
| {"version":3,"file":"useBackButton.native.d.ts","sourceRoot":"","sources":["../../../src/useBackButton.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,QAwB5D"} |
| {"version":3,"file":"useDocumentTitle.d.ts","sourceRoot":"","sources":["../../../src/useDocumentTitle.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,OAAc,EACd,SAA6D,GAC9D,GAAE,oBAAyB,QAwB7B"} |
| {"version":3,"file":"useDocumentTitle.native.d.ts","sourceRoot":"","sources":["../../../src/useDocumentTitle.native.tsx"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,gBAAgB,SAEvC"} |
| {"version":3,"file":"useLinkBuilder.d.ts","sourceRoot":"","sources":["../../../src/useLinkBuilder.tsx"],"names":[],"mappings":"AA2CA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,WAK3B,MAAM,WAAW,MAAM,wBA6BjC"} |
| {"version":3,"file":"useLinking.d.ts","sourceRoot":"","sources":["../../../src/useLinking.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,sBAAsB,EAEtB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA4C9C;;GAEG;AACH,eAAO,MAAM,MAAM,OAAQ,MAAM,QAAQ,IAAI,CAAC,eAM7C,CAAC;AAIF,KAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,GAAG;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,WAAW,EACX,OAAc,EACd,MAAM,EACN,gBAA0C,EAC1C,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsTX"} |
| {"version":3,"file":"useLinking.native.d.ts","sourceRoot":"","sources":["../../../src/useLinking.native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EACtB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C,KAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,GAAG;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,WAAW,EACX,OAAc,EACd,QAAQ,EACR,MAAM,EACN,MAAM,EACN,aAQI,EACJ,SAmBC,EACD,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2JX"} |
| {"version":3,"file":"useLinkProps.d.ts","sourceRoot":"","sources":["../../../src/useLinkProps.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAKjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAY,MAAM,cAAc,CAAC;AAG/D,OAAkB,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAE5C,KAAK,KAAK,CAAC,SAAS,SAAS,eAAe,CAAC,aAAa,IAAI;IAC5D,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IAClB,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AA+BF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAAS,SAAS,eAAe,CAAC,aAAa,EAC/C,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC;;;kBAO1B,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG,qBAAqB;EA6D9E"} |
| {"version":3,"file":"useLinkTo.d.ts","sourceRoot":"","sources":["../../../src/useLinkTo.tsx"],"names":[],"mappings":"AASA,MAAM,MAAM,EAAE,CACZ,SAAS,SAAS,eAAe,CAAC,aAAa,GAAG,eAAe,CAAC,aAAa,EAC/E,SAAS,SAAS,MAAM,SAAS,GAAG,MAAM,SAAS,IAEjD,MAAM,GACN,CAAC,SAAS,SAAS,SAAS,CAAC,SAAS,CAAC,GACnC;IACE,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC/B,GACD;IACE,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC,CAAC;AAEX,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,SAAS,SAAS,eAAe,CAAC,aAAa,UAMxC,GAAG,SAAS,CAAC,UAuCrB"} |
| {"version":3,"file":"useScrollToTop.d.ts","sourceRoot":"","sources":["../../../src/useScrollToTop.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,KAAK,aAAa,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpE,KAAK,cAAc,GACf;IAAE,WAAW,IAAI,IAAI,CAAA;CAAE,GACvB;IAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;CAAE,GAC1C;IAAE,cAAc,CAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAC1E;IAAE,uBAAuB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;CAAE,CAAC;AAE9D,KAAK,iBAAiB,GAClB;IAAE,kBAAkB,IAAI,KAAK,CAAC,SAAS,GAAG,UAAU,CAAA;CAAE,GACtD;IAAE,OAAO,IAAI,cAAc,CAAA;CAAE,GAC7B,cAAc,CAAC;AA8BnB,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,QAgExC"} |
| {"version":3,"file":"useThenable.d.ts","sourceRoot":"","sources":["../../../src/useThenable.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,4BAsClE"} |
| import type { NavigationState } from '@react-navigation/core'; | ||
| import { nanoid } from 'nanoid/non-secure'; | ||
| type HistoryRecord = { | ||
| // Unique identifier for this record to match it with window.history.state | ||
| id: string; | ||
| // Navigation state object for the history entry | ||
| state: NavigationState; | ||
| // Path of the history entry | ||
| path: string; | ||
| }; | ||
| export default function createMemoryHistory() { | ||
| let index = 0; | ||
| let items: HistoryRecord[] = []; | ||
| // Pending callbacks for `history.go(n)` | ||
| // We might modify the callback stored if it was interrupted, so we have a ref to identify it | ||
| const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = []; | ||
| const interrupt = () => { | ||
| // If another history operation was performed we need to interrupt existing ones | ||
| // This makes sure that calls such as `history.replace` after `history.go` don't happen | ||
| // Since otherwise it won't be correct if something else has changed | ||
| pending.forEach((it) => { | ||
| const cb = it.cb; | ||
| it.cb = () => cb(true); | ||
| }); | ||
| }; | ||
| const history = { | ||
| get index(): number { | ||
| // We store an id in the state instead of an index | ||
| // Index could get out of sync with in-memory values if page reloads | ||
| const id = window.history.state?.id; | ||
| if (id) { | ||
| const index = items.findIndex((item) => item.id === id); | ||
| return index > -1 ? index : 0; | ||
| } | ||
| return 0; | ||
| }, | ||
| get(index: number) { | ||
| return items[index]; | ||
| }, | ||
| backIndex({ path }: { path: string }) { | ||
| // We need to find the index from the element before current to get closest path to go back to | ||
| for (let i = index - 1; i >= 0; i--) { | ||
| const item = items[i]; | ||
| if (item.path === path) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }, | ||
| push({ path, state }: { path: string; state: NavigationState }) { | ||
| interrupt(); | ||
| const id = nanoid(); | ||
| // When a new entry is pushed, all the existing entries after index will be inaccessible | ||
| // So we remove any existing entries after the current index to clean them up | ||
| items = items.slice(0, index + 1); | ||
| items.push({ path, state, id }); | ||
| index = items.length - 1; | ||
| // We pass empty string for title because it's ignored in all browsers except safari | ||
| // We don't store state object in history.state because: | ||
| // - browsers have limits on how big it can be, and we don't control the size | ||
| // - while not recommended, there could be non-serializable data in state | ||
| window.history.pushState({ id }, '', path); | ||
| }, | ||
| replace({ path, state }: { path: string; state: NavigationState }) { | ||
| interrupt(); | ||
| const id = window.history.state?.id ?? nanoid(); | ||
| // Need to keep the hash part of the path if there was no previous history entry | ||
| // or the previous history entry had the same path | ||
| let pathWithHash = path; | ||
| if (!items.length || items.findIndex((item) => item.id === id) < 0) { | ||
| // There are two scenarios for creating an array with only one history record: | ||
| // - When loaded id not found in the items array, this function by default will replace | ||
| // the first item. We need to keep only the new updated object, otherwise it will break | ||
| // the page when navigating forward in history. | ||
| // - This is the first time any state modifications are done | ||
| // So we need to push the entry as there's nothing to replace | ||
| pathWithHash = pathWithHash + location.hash; | ||
| items = [{ path: pathWithHash, state, id }]; | ||
| index = 0; | ||
| } else { | ||
| if (items[index].path === path) { | ||
| pathWithHash = pathWithHash + location.hash; | ||
| } | ||
| items[index] = { path, state, id }; | ||
| } | ||
| window.history.replaceState({ id }, '', pathWithHash); | ||
| }, | ||
| // `history.go(n)` is asynchronous, there are couple of things to keep in mind: | ||
| // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire. | ||
| // - each `history.go(n)` call will trigger a separate `popstate` event with correct location. | ||
| // - the `popstate` event fires before the next frame after calling `history.go(n)`. | ||
| // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can. | ||
| go(n: number) { | ||
| interrupt(); | ||
| // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory | ||
| // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app. | ||
| const nextIndex = index + n; | ||
| const lastItemIndex = items.length - 1; | ||
| if (n < 0 && !items[nextIndex]) { | ||
| // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item. | ||
| n = -index; | ||
| index = 0; | ||
| } else if (n > 0 && nextIndex > lastItemIndex) { | ||
| // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there. | ||
| n = lastItemIndex - index; | ||
| index = lastItemIndex; | ||
| } else { | ||
| index = nextIndex; | ||
| } | ||
| if (n === 0) { | ||
| return; | ||
| } | ||
| // When we call `history.go`, `popstate` will fire when there's history to go back to | ||
| // So we need to somehow handle following cases: | ||
| // - There's history to go back, `history.go` is called, and `popstate` fires | ||
| // - `history.go` is called multiple times, we need to resolve on respective `popstate` | ||
| // - No history to go back, but `history.go` was called, browser has no API to detect it | ||
| return new Promise<void>((resolve, reject) => { | ||
| const done = (interrupted?: boolean) => { | ||
| clearTimeout(timer); | ||
| if (interrupted) { | ||
| reject(new Error('History was changed during navigation.')); | ||
| return; | ||
| } | ||
| // There seems to be a bug in Chrome regarding updating the title | ||
| // If we set a title just before calling `history.go`, the title gets lost | ||
| // However the value of `document.title` is still what we set it to | ||
| // It's just not displayed in the tab bar | ||
| // To update the tab bar, we need to reset the title to something else first (e.g. '') | ||
| // And set the title to what it was before so it gets applied | ||
| // It won't work without setting it to empty string coz otherwise title isn't changing | ||
| // Which means that the browser won't do anything after setting the title | ||
| const { title } = window.document; | ||
| window.document.title = ''; | ||
| window.document.title = title; | ||
| resolve(); | ||
| }; | ||
| pending.push({ ref: done, cb: done }); | ||
| // If navigation didn't happen within 100ms, assume that it won't happen | ||
| // This may not be accurate, but hopefully it won't take so much time | ||
| // In Chrome, navigation seems to happen instantly in next microtask | ||
| // But on Firefox, it seems to take much longer, around 50ms from our testing | ||
| // We're using a hacky timeout since there doesn't seem to be way to know for sure | ||
| const timer = setTimeout(() => { | ||
| const index = pending.findIndex((it) => it.ref === done); | ||
| if (index > -1) { | ||
| pending[index].cb(); | ||
| pending.splice(index, 1); | ||
| } | ||
| }, 100); | ||
| const onPopState = () => { | ||
| const id = window.history.state?.id; | ||
| const currentIndex = items.findIndex((item) => item.id === id); | ||
| // Fix createMemoryHistory.index variable's value | ||
| // as it may go out of sync when navigating in the browser. | ||
| index = Math.max(currentIndex, 0); | ||
| const last = pending.pop(); | ||
| window.removeEventListener('popstate', onPopState); | ||
| last?.cb(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| window.history.go(n); | ||
| }); | ||
| }, | ||
| // The `popstate` event is triggered when history changes, except `pushState` and `replaceState` | ||
| // If we call `history.go(n)` ourselves, we don't want it to trigger the listener | ||
| // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener | ||
| listen(listener: () => void) { | ||
| const onPopState = () => { | ||
| if (pending.length) { | ||
| // This was triggered by `history.go(n)`, we shouldn't call the listener | ||
| return; | ||
| } | ||
| listener(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| return () => window.removeEventListener('popstate', onPopState); | ||
| }, | ||
| }; | ||
| return history; | ||
| } |
| import type { | ||
| NavigationContainerRef, | ||
| ParamListBase, | ||
| } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { BackHandler } from 'react-native'; | ||
| export default function useBackButton( | ||
| ref: React.RefObject<NavigationContainerRef<ParamListBase>> | ||
| ) { | ||
| React.useEffect(() => { | ||
| const subscription = BackHandler.addEventListener( | ||
| 'hardwareBackPress', | ||
| () => { | ||
| const navigation = ref.current; | ||
| if (navigation == null) { | ||
| return false; | ||
| } | ||
| if (navigation.canGoBack()) { | ||
| navigation.goBack(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| ); | ||
| return () => subscription.remove(); | ||
| }, [ref]); | ||
| } |
@@ -7,18 +7,14 @@ "use strict"; | ||
| exports.default = extractPathFromURL; | ||
| var _escapeStringRegexp = _interopRequireDefault(require("escape-string-regexp")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function extractPathFromURL(prefixes, url) { | ||
| for (const prefix of prefixes) { | ||
| var _prefix$match$, _prefix$match; | ||
| const protocol = (_prefix$match$ = (_prefix$match = prefix.match(/^[^:]+:/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[0]) !== null && _prefix$match$ !== void 0 ? _prefix$match$ : ''; | ||
| const host = prefix.replace(new RegExp("^".concat((0, _escapeStringRegexp.default)(protocol))), '').replace(/\/+/g, '/') // Replace multiple slash (//) with single ones | ||
| var _prefix$match; | ||
| const protocol = ((_prefix$match = prefix.match(/^[^:]+:/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[0]) ?? ''; | ||
| const host = prefix.replace(new RegExp(`^${(0, _escapeStringRegexp.default)(protocol)}`), '').replace(/\/+/g, '/') // Replace multiple slash (//) with single ones | ||
| .replace(/^\//, ''); // Remove extra leading slash | ||
| const prefixRegex = new RegExp("^".concat((0, _escapeStringRegexp.default)(protocol), "(/)*").concat(host.split('.').map(it => it === '*' ? '[^/]+' : (0, _escapeStringRegexp.default)(it)).join('\\.'))); | ||
| const normalizedURL = url.replace(/\/+/g, '/'); | ||
| const prefixRegex = new RegExp(`^${(0, _escapeStringRegexp.default)(protocol)}(/)*${host.split('.').map(it => it === '*' ? '[^/]+' : (0, _escapeStringRegexp.default)(it)).join('\\.')}`); | ||
| const [originAndPath, searchParams] = url.split('?'); | ||
| const normalizedURL = originAndPath.replace(/\/+/g, '/').concat(searchParams ? `?${searchParams}` : ''); | ||
| if (prefixRegex.test(normalizedURL)) { | ||
@@ -28,5 +24,4 @@ return normalizedURL.replace(prefixRegex, ''); | ||
| } | ||
| return undefined; | ||
| } | ||
| //# sourceMappingURL=extractPathFromURL.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["extractPathFromURL.tsx"],"names":["extractPathFromURL","prefixes","url","prefix","protocol","match","host","replace","RegExp","prefixRegex","split","map","it","join","normalizedURL","test","undefined"],"mappings":";;;;;;;AAAA;;;;AAEe,SAASA,kBAAT,CAA4BC,QAA5B,EAAgDC,GAAhD,EAA6D;AAC1E,OAAK,MAAMC,MAAX,IAAqBF,QAArB,EAA+B;AAAA;;AAC7B,UAAMG,QAAQ,sCAAGD,MAAM,CAACE,KAAP,CAAa,SAAb,CAAH,kDAAG,cAA0B,CAA1B,CAAH,2DAAmC,EAAjD;AACA,UAAMC,IAAI,GAAGH,MAAM,CAChBI,OADU,CACF,IAAIC,MAAJ,YAAe,iCAAmBJ,QAAnB,CAAf,EADE,EAC8C,EAD9C,EAEVG,OAFU,CAEF,MAFE,EAEM,GAFN,EAEW;AAFX,KAGVA,OAHU,CAGF,KAHE,EAGK,EAHL,CAAb,CAF6B,CAKN;;AAEvB,UAAME,WAAW,GAAG,IAAID,MAAJ,YACd,iCAAmBJ,QAAnB,CADc,iBACqBE,IAAI,CACxCI,KADoC,CAC9B,GAD8B,EAEpCC,GAFoC,CAE/BC,EAAD,IAASA,EAAE,KAAK,GAAP,GAAa,OAAb,GAAuB,iCAAmBA,EAAnB,CAFA,EAGpCC,IAHoC,CAG/B,KAH+B,CADrB,EAApB;AAOA,UAAMC,aAAa,GAAGZ,GAAG,CAACK,OAAJ,CAAY,MAAZ,EAAoB,GAApB,CAAtB;;AAEA,QAAIE,WAAW,CAACM,IAAZ,CAAiBD,aAAjB,CAAJ,EAAqC;AACnC,aAAOA,aAAa,CAACP,OAAd,CAAsBE,WAAtB,EAAmC,EAAnC,CAAP;AACD;AACF;;AAED,SAAOO,SAAP;AACD","sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nexport default function extractPathFromURL(prefixes: string[], url: string) {\n for (const prefix of prefixes) {\n const protocol = prefix.match(/^[^:]+:/)?.[0] ?? '';\n const host = prefix\n .replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '')\n .replace(/\\/+/g, '/') // Replace multiple slash (//) with single ones\n .replace(/^\\//, ''); // Remove extra leading slash\n\n const prefixRegex = new RegExp(\n `^${escapeStringRegexp(protocol)}(/)*${host\n .split('.')\n .map((it) => (it === '*' ? '[^/]+' : escapeStringRegexp(it)))\n .join('\\\\.')}`\n );\n\n const normalizedURL = url.replace(/\\/+/g, '/');\n\n if (prefixRegex.test(normalizedURL)) {\n return normalizedURL.replace(prefixRegex, '');\n }\n }\n\n return undefined;\n}\n"]} | ||
| {"version":3,"names":["extractPathFromURL","prefixes","url","prefix","protocol","match","host","replace","RegExp","escapeStringRegexp","prefixRegex","split","map","it","join","originAndPath","searchParams","normalizedURL","concat","test","undefined"],"sourceRoot":"../../src","sources":["extractPathFromURL.tsx"],"mappings":";;;;;;AAAA;AAAsD;AAEvC,SAASA,kBAAkB,CAACC,QAAkB,EAAEC,GAAW,EAAE;EAC1E,KAAK,MAAMC,MAAM,IAAIF,QAAQ,EAAE;IAAA;IAC7B,MAAMG,QAAQ,GAAG,kBAAAD,MAAM,CAACE,KAAK,CAAC,SAAS,CAAC,kDAAvB,cAA0B,CAAC,CAAC,KAAI,EAAE;IACnD,MAAMC,IAAI,GAAGH,MAAM,CAChBI,OAAO,CAAC,IAAIC,MAAM,CAAE,IAAG,IAAAC,2BAAkB,EAACL,QAAQ,CAAE,EAAC,CAAC,EAAE,EAAE,CAAC,CAC3DG,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAA,CACrBA,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;;IAEvB,MAAMG,WAAW,GAAG,IAAIF,MAAM,CAC3B,IAAG,IAAAC,2BAAkB,EAACL,QAAQ,CAAE,OAAME,IAAI,CACxCK,KAAK,CAAC,GAAG,CAAC,CACVC,GAAG,CAAEC,EAAE,IAAMA,EAAE,KAAK,GAAG,GAAG,OAAO,GAAG,IAAAJ,2BAAkB,EAACI,EAAE,CAAE,CAAC,CAC5DC,IAAI,CAAC,KAAK,CAAE,EAAC,CACjB;IAED,MAAM,CAACC,aAAa,EAAEC,YAAY,CAAC,GAAGd,GAAG,CAACS,KAAK,CAAC,GAAG,CAAC;IACpD,MAAMM,aAAa,GAAGF,aAAa,CAChCR,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CACpBW,MAAM,CAACF,YAAY,GAAI,IAAGA,YAAa,EAAC,GAAG,EAAE,CAAC;IAEjD,IAAIN,WAAW,CAACS,IAAI,CAACF,aAAa,CAAC,EAAE;MACnC,OAAOA,aAAa,CAACV,OAAO,CAACG,WAAW,EAAE,EAAE,CAAC;IAC/C;EACF;EAEA,OAAOU,SAAS;AAClB"} |
+48
-74
@@ -7,68 +7,67 @@ "use strict"; | ||
| var _exportNames = { | ||
| Link: true, | ||
| LinkingContext: true, | ||
| NavigationContainer: true, | ||
| useBackButton: true, | ||
| useScrollToTop: true, | ||
| ServerContainer: true, | ||
| DarkTheme: true, | ||
| DefaultTheme: true, | ||
| DarkTheme: true, | ||
| ThemeProvider: true, | ||
| useTheme: true, | ||
| Link: true, | ||
| useLinking: true, | ||
| useLinkBuilder: true, | ||
| useLinkProps: true, | ||
| useLinkTo: true, | ||
| useLinkProps: true, | ||
| useLinkBuilder: true, | ||
| ServerContainer: true | ||
| useScrollToTop: true | ||
| }; | ||
| Object.defineProperty(exports, "NavigationContainer", { | ||
| Object.defineProperty(exports, "DarkTheme", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _NavigationContainer.default; | ||
| return _DarkTheme.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "useBackButton", { | ||
| Object.defineProperty(exports, "DefaultTheme", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _useBackButton.default; | ||
| return _DefaultTheme.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "useScrollToTop", { | ||
| Object.defineProperty(exports, "Link", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _useScrollToTop.default; | ||
| return _Link.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "DefaultTheme", { | ||
| Object.defineProperty(exports, "LinkingContext", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _DefaultTheme.default; | ||
| return _LinkingContext.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "DarkTheme", { | ||
| Object.defineProperty(exports, "NavigationContainer", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _DarkTheme.default; | ||
| return _NavigationContainer.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "ThemeProvider", { | ||
| Object.defineProperty(exports, "ServerContainer", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _ThemeProvider.default; | ||
| return _ServerContainer.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "useTheme", { | ||
| Object.defineProperty(exports, "ThemeProvider", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _useTheme.default; | ||
| return _ThemeProvider.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "Link", { | ||
| Object.defineProperty(exports, "useLinkBuilder", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _Link.default; | ||
| return _useLinkBuilder.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "useLinking", { | ||
| Object.defineProperty(exports, "useLinkProps", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _useLinking.default; | ||
| return _useLinkProps.default; | ||
| } | ||
@@ -82,76 +81,51 @@ }); | ||
| }); | ||
| Object.defineProperty(exports, "useLinkProps", { | ||
| Object.defineProperty(exports, "useScrollToTop", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _useLinkProps.default; | ||
| return _useScrollToTop.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "useLinkBuilder", { | ||
| Object.defineProperty(exports, "useTheme", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _useLinkBuilder.default; | ||
| return _useTheme.default; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "ServerContainer", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _ServerContainer.default; | ||
| } | ||
| }); | ||
| var _core = require("@react-navigation/core"); | ||
| Object.keys(_core).forEach(function (key) { | ||
| var _Link = _interopRequireDefault(require("./Link")); | ||
| var _LinkingContext = _interopRequireDefault(require("./LinkingContext")); | ||
| var _NavigationContainer = _interopRequireDefault(require("./NavigationContainer")); | ||
| var _ServerContainer = _interopRequireDefault(require("./ServerContainer")); | ||
| var _DarkTheme = _interopRequireDefault(require("./theming/DarkTheme")); | ||
| var _DefaultTheme = _interopRequireDefault(require("./theming/DefaultTheme")); | ||
| var _ThemeProvider = _interopRequireDefault(require("./theming/ThemeProvider")); | ||
| var _useTheme = _interopRequireDefault(require("./theming/useTheme")); | ||
| var _types = require("./types"); | ||
| Object.keys(_types).forEach(function (key) { | ||
| if (key === "default" || key === "__esModule") return; | ||
| if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
| if (key in exports && exports[key] === _core[key]) return; | ||
| if (key in exports && exports[key] === _types[key]) return; | ||
| Object.defineProperty(exports, key, { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _core[key]; | ||
| return _types[key]; | ||
| } | ||
| }); | ||
| }); | ||
| var _NavigationContainer = _interopRequireDefault(require("./NavigationContainer")); | ||
| var _useBackButton = _interopRequireDefault(require("./useBackButton")); | ||
| var _useLinkBuilder = _interopRequireDefault(require("./useLinkBuilder")); | ||
| var _useLinkProps = _interopRequireDefault(require("./useLinkProps")); | ||
| var _useLinkTo = _interopRequireDefault(require("./useLinkTo")); | ||
| var _useScrollToTop = _interopRequireDefault(require("./useScrollToTop")); | ||
| var _DefaultTheme = _interopRequireDefault(require("./theming/DefaultTheme")); | ||
| var _DarkTheme = _interopRequireDefault(require("./theming/DarkTheme")); | ||
| var _ThemeProvider = _interopRequireDefault(require("./theming/ThemeProvider")); | ||
| var _useTheme = _interopRequireDefault(require("./theming/useTheme")); | ||
| var _Link = _interopRequireDefault(require("./Link")); | ||
| var _useLinking = _interopRequireDefault(require("./useLinking")); | ||
| var _useLinkTo = _interopRequireDefault(require("./useLinkTo")); | ||
| var _useLinkProps = _interopRequireDefault(require("./useLinkProps")); | ||
| var _useLinkBuilder = _interopRequireDefault(require("./useLinkBuilder")); | ||
| var _ServerContainer = _interopRequireDefault(require("./ServerContainer")); | ||
| var _types = require("./types"); | ||
| Object.keys(_types).forEach(function (key) { | ||
| var _core = require("@react-navigation/core"); | ||
| Object.keys(_core).forEach(function (key) { | ||
| if (key === "default" || key === "__esModule") return; | ||
| if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
| if (key in exports && exports[key] === _types[key]) return; | ||
| if (key in exports && exports[key] === _core[key]) return; | ||
| Object.defineProperty(exports, key, { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _types[key]; | ||
| return _core[key]; | ||
| } | ||
| }); | ||
| }); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from '@react-navigation/core';\n\nexport { default as NavigationContainer } from './NavigationContainer';\n\nexport { default as useBackButton } from './useBackButton';\nexport { default as useScrollToTop } from './useScrollToTop';\n\nexport { default as DefaultTheme } from './theming/DefaultTheme';\nexport { default as DarkTheme } from './theming/DarkTheme';\nexport { default as ThemeProvider } from './theming/ThemeProvider';\nexport { default as useTheme } from './theming/useTheme';\n\nexport { default as Link } from './Link';\nexport { default as useLinking } from './useLinking';\nexport { default as useLinkTo } from './useLinkTo';\nexport { default as useLinkProps } from './useLinkProps';\nexport { default as useLinkBuilder } from './useLinkBuilder';\n\nexport { default as ServerContainer } from './ServerContainer';\n\nexport * from './types';\n"]} | ||
| {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAAuC"} |
+10
-19
@@ -7,15 +7,8 @@ "use strict"; | ||
| exports.default = Link; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _reactNative = require("react-native"); | ||
| var _useLinkProps = _interopRequireDefault(require("./useLinkProps")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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; } | ||
| /** | ||
@@ -29,7 +22,8 @@ * Component to render link to another screen using a path. | ||
| */ | ||
| function Link({ | ||
| to, | ||
| action, | ||
| ...rest | ||
| }) { | ||
| function Link(_ref) { | ||
| let { | ||
| to, | ||
| action, | ||
| ...rest | ||
| } = _ref; | ||
| const props = (0, _useLinkProps.default)({ | ||
@@ -39,14 +33,11 @@ to, | ||
| }); | ||
| const onPress = e => { | ||
| if ('onPress' in rest) { | ||
| var _rest$onPress; | ||
| (_rest$onPress = rest.onPress) === null || _rest$onPress === void 0 ? void 0 : _rest$onPress.call(rest, e); | ||
| } | ||
| props.onPress(e); | ||
| }; | ||
| return /*#__PURE__*/React.createElement(_reactNative.Text, { ...props, | ||
| return /*#__PURE__*/React.createElement(_reactNative.Text, { | ||
| ...props, | ||
| ...rest, | ||
@@ -53,0 +44,0 @@ ..._reactNative.Platform.select({ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["Link.tsx"],"names":["Link","to","action","rest","props","onPress","e","React","createElement","Text","Platform","select","web","onClick","default"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;;;;;;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,IAAT,CAAc;AAAEC,EAAAA,EAAF;AAAMC,EAAAA,MAAN;AAAc,KAAGC;AAAjB,CAAd,EAA8C;AAC3D,QAAMC,KAAK,GAAG,2BAAa;AAAEH,IAAAA,EAAF;AAAMC,IAAAA;AAAN,GAAb,CAAd;;AAEA,QAAMG,OAAO,GACXC,CADc,IAEX;AACH,QAAI,aAAaH,IAAjB,EAAuB;AAAA;;AACrB,uBAAAA,IAAI,CAACE,OAAL,qEAAAF,IAAI,EAAWG,CAAX,CAAJ;AACD;;AAEDF,IAAAA,KAAK,CAACC,OAAN,CAAcC,CAAd;AACD,GARD;;AAUA,sBAAOC,KAAK,CAACC,aAAN,CAAoBC,iBAApB,EAA0B,EAC/B,GAAGL,KAD4B;AAE/B,OAAGD,IAF4B;AAG/B,OAAGO,sBAASC,MAAT,CAAgB;AACjBC,MAAAA,GAAG,EAAE;AAAEC,QAAAA,OAAO,EAAER;AAAX,OADY;AAEjBS,MAAAA,OAAO,EAAE;AAAET,QAAAA;AAAF;AAFQ,KAAhB;AAH4B,GAA1B,CAAP;AAQD","sourcesContent":["import * as React from 'react';\nimport { Text, TextProps, GestureResponderEvent, Platform } from 'react-native';\nimport type { NavigationAction } from '@react-navigation/core';\nimport useLinkProps from './useLinkProps';\n\ntype Props = {\n to: string;\n action?: NavigationAction;\n target?: string;\n onPress?: (\n e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => void;\n} & (TextProps & { children: React.ReactNode });\n\n/**\n * Component to render link to another screen using a path.\n * Uses an anchor tag on the web.\n *\n * @param props.to Absolute path to screen (e.g. `/feeds/hot`).\n * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.\n * @param props.children Child elements to render the content.\n */\nexport default function Link({ to, action, ...rest }: Props) {\n const props = useLinkProps({ to, action });\n\n const onPress = (\n e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => {\n if ('onPress' in rest) {\n rest.onPress?.(e);\n }\n\n props.onPress(e);\n };\n\n return React.createElement(Text, {\n ...props,\n ...rest,\n ...Platform.select({\n web: { onClick: onPress } as any,\n default: { onPress },\n }),\n });\n}\n"]} | ||
| {"version":3,"names":["Link","to","action","rest","props","useLinkProps","onPress","e","React","createElement","Text","Platform","select","web","onClick","default"],"sourceRoot":"../../src","sources":["Link.tsx"],"mappings":";;;;;;AACA;AACA;AAEA;AAA0C;AAAA;AAAA;AAe1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,IAAI,OAIP;EAAA,IAJyD;IAC5EC,EAAE;IACFC,MAAM;IACN,GAAGC;EACa,CAAC;EACjB,MAAMC,KAAK,GAAG,IAAAC,qBAAY,EAAY;IAAEJ,EAAE;IAAEC;EAAO,CAAC,CAAC;EAErD,MAAMI,OAAO,GACXC,CAA0E,IACvE;IACH,IAAI,SAAS,IAAIJ,IAAI,EAAE;MAAA;MACrB,iBAAAA,IAAI,CAACG,OAAO,kDAAZ,mBAAAH,IAAI,EAAWI,CAAC,CAAC;IACnB;IAEAH,KAAK,CAACE,OAAO,CAACC,CAAC,CAAC;EAClB,CAAC;EAED,oBAAOC,KAAK,CAACC,aAAa,CAACC,iBAAI,EAAE;IAC/B,GAAGN,KAAK;IACR,GAAGD,IAAI;IACP,GAAGQ,qBAAQ,CAACC,MAAM,CAAC;MACjBC,GAAG,EAAE;QAAEC,OAAO,EAAER;MAAQ,CAAQ;MAChCS,OAAO,EAAE;QAAET;MAAQ;IACrB,CAAC;EACH,CAAC,CAAC;AACJ"} |
@@ -7,9 +7,5 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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; } | ||
| const LinkingContext = /*#__PURE__*/React.createContext({ | ||
@@ -16,0 +12,0 @@ options: undefined |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["LinkingContext.tsx"],"names":["LinkingContext","React","createContext","options","undefined","displayName"],"mappings":";;;;;;;AAAA;;;;;;AAGA,MAAMA,cAAc,gBAAGC,KAAK,CAACC,aAAN,CAEpB;AAAEC,EAAAA,OAAO,EAAEC;AAAX,CAFoB,CAAvB;AAIAJ,cAAc,CAACK,WAAf,GAA6B,gBAA7B;eAEeL,c","sourcesContent":["import * as React from 'react';\nimport type { LinkingOptions } from './types';\n\nconst LinkingContext = React.createContext<{\n options: LinkingOptions | undefined;\n}>({ options: undefined });\n\nLinkingContext.displayName = 'LinkingContext';\n\nexport default LinkingContext;\n"]} | ||
| {"version":3,"names":["LinkingContext","React","createContext","options","undefined","displayName"],"sourceRoot":"../../src","sources":["LinkingContext.tsx"],"mappings":";;;;;;AACA;AAA+B;AAAA;AAI/B,MAAMA,cAAc,gBAAGC,KAAK,CAACC,aAAa,CAEvC;EAAEC,OAAO,EAAEC;AAAU,CAAC,CAAC;AAE1BJ,cAAc,CAACK,WAAW,GAAG,gBAAgB;AAAC,eAE/BL,cAAc;AAAA"} |
@@ -7,29 +7,16 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var _core = require("@react-navigation/core"); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _core = require("@react-navigation/core"); | ||
| var _LinkingContext = _interopRequireDefault(require("./LinkingContext")); | ||
| var _DefaultTheme = _interopRequireDefault(require("./theming/DefaultTheme")); | ||
| var _ThemeProvider = _interopRequireDefault(require("./theming/ThemeProvider")); | ||
| var _DefaultTheme = _interopRequireDefault(require("./theming/DefaultTheme")); | ||
| var _LinkingContext = _interopRequireDefault(require("./LinkingContext")); | ||
| var _useBackButton = _interopRequireDefault(require("./useBackButton")); | ||
| var _useDocumentTitle = _interopRequireDefault(require("./useDocumentTitle")); | ||
| var _useLinking = _interopRequireDefault(require("./useLinking")); | ||
| var _useThenable = _interopRequireDefault(require("./useThenable")); | ||
| var _useLinking = _interopRequireDefault(require("./useLinking")); | ||
| var _useDocumentTitle = _interopRequireDefault(require("./useDocumentTitle")); | ||
| var _useBackButton = _interopRequireDefault(require("./useBackButton")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
| 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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
| global.REACT_NAVIGATION_DEVTOOLS = new WeakMap(); | ||
| /** | ||
@@ -49,11 +36,15 @@ * Container component which holds the navigation state designed for React Native apps. | ||
| */ | ||
| const NavigationContainer = /*#__PURE__*/React.forwardRef(function NavigationContainer({ | ||
| theme = _DefaultTheme.default, | ||
| linking, | ||
| fallback = null, | ||
| documentTitle, | ||
| onReady, | ||
| ...rest | ||
| }, ref) { | ||
| function NavigationContainerInner(_ref, ref) { | ||
| let { | ||
| theme = _DefaultTheme.default, | ||
| linking, | ||
| fallback = null, | ||
| documentTitle, | ||
| onReady, | ||
| ...rest | ||
| } = _ref; | ||
| const isLinkingEnabled = linking ? linking.enabled !== false : false; | ||
| if (linking !== null && linking !== void 0 && linking.config) { | ||
| (0, _core.validatePathConfig)(linking.config); | ||
| } | ||
| const refContainer = React.useRef(null); | ||
@@ -65,2 +56,3 @@ (0, _useBackButton.default)(refContainer); | ||
| } = (0, _useLinking.default)(refContainer, { | ||
| independent: rest.independent, | ||
| enabled: isLinkingEnabled, | ||
@@ -70,2 +62,21 @@ prefixes: [], | ||
| }); | ||
| // Add additional linking related info to the ref | ||
| // This will be used by the devtools | ||
| React.useEffect(() => { | ||
| if (refContainer.current) { | ||
| REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, { | ||
| get linking() { | ||
| return { | ||
| ...linking, | ||
| enabled: isLinkingEnabled, | ||
| prefixes: (linking === null || linking === void 0 ? void 0 : linking.prefixes) ?? [], | ||
| getStateFromPath: (linking === null || linking === void 0 ? void 0 : linking.getStateFromPath) ?? _core.getStateFromPath, | ||
| getPathFromState: (linking === null || linking === void 0 ? void 0 : linking.getPathFromState) ?? _core.getPathFromState, | ||
| getActionFromState: (linking === null || linking === void 0 ? void 0 : linking.getActionFromState) ?? _core.getActionFromState | ||
| }; | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| const [isResolved, initialState] = (0, _useThenable.default)(getInitialState); | ||
@@ -84,7 +95,5 @@ React.useImperativeHandle(ref, () => refContainer.current); | ||
| var _onReadyRef$current; | ||
| (_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 ? void 0 : _onReadyRef$current.call(onReadyRef); | ||
| } | ||
| }, [isReady]); | ||
| if (!isReady) { | ||
@@ -95,3 +104,2 @@ // This is temporary until we have Suspense for data-fetching | ||
| } | ||
| return /*#__PURE__*/React.createElement(_LinkingContext.default.Provider, { | ||
@@ -105,5 +113,6 @@ value: linkingContext | ||
| })))); | ||
| }); | ||
| } | ||
| const NavigationContainer = /*#__PURE__*/React.forwardRef(NavigationContainerInner); | ||
| var _default = NavigationContainer; | ||
| exports.default = _default; | ||
| //# sourceMappingURL=NavigationContainer.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["NavigationContainer.tsx"],"names":["NavigationContainer","React","forwardRef","theme","DefaultTheme","linking","fallback","documentTitle","onReady","rest","ref","isLinkingEnabled","enabled","refContainer","useRef","getInitialState","prefixes","isResolved","initialState","useImperativeHandle","current","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K,CAACa,MAAN,CAAaN,OAAb,CAAnB;AAEAP,EAAAA,KAAK,CAACyB,SAAN,CAAgB,MAAM;AACpBD,IAAAA,UAAU,CAACL,OAAX,GAAqBZ,OAArB;AACD,GAFD;AAIAP,EAAAA,KAAK,CAACyB,SAAN,CAAgB,MAAM;AACpB,QAAIF,OAAJ,EAAa;AAAA;;AACX,6BAAAC,UAAU,CAACL,OAAX,iFAAAK,UAAU;AACX;AACF,GAJD,EAIG,CAACD,OAAD,CAJH;;AAMA,MAAI,CAACA,OAAL,EAAc;AACZ;AACA;AACA,WAAOlB,QAAP;AACD;;AAED,sBACE,oBAAC,uBAAD,CAAgB,QAAhB;AAAyB,IAAA,KAAK,EAAEe;AAAhC,kBACE,oBAAC,sBAAD;AAAe,IAAA,KAAK,EAAElB;AAAtB,kBACE,oBAAC,6BAAD,eACMM,IADN;AAEE,IAAA,YAAY,EACVA,IAAI,CAACS,YAAL,IAAqB,IAArB,GAA4BA,YAA5B,GAA2CT,IAAI,CAACS,YAHpD;AAKE,IAAA,GAAG,EAAEL;AALP,KADF,CADF,CADF;AAaD,CA/D2B,CAA5B;eAiEeb,mB","sourcesContent":["import * as React from 'react';\nimport {\n BaseNavigationContainer,\n NavigationContainerProps,\n NavigationContainerRef,\n} from '@react-navigation/core';\nimport ThemeProvider from './theming/ThemeProvider';\nimport DefaultTheme from './theming/DefaultTheme';\nimport LinkingContext from './LinkingContext';\nimport useThenable from './useThenable';\nimport useLinking from './useLinking';\nimport useDocumentTitle from './useDocumentTitle';\nimport useBackButton from './useBackButton';\nimport type { Theme, LinkingOptions, DocumentTitleOptions } from './types';\n\ntype Props = NavigationContainerProps & {\n theme?: Theme;\n linking?: LinkingOptions;\n fallback?: React.ReactNode;\n documentTitle?: DocumentTitleOptions;\n onReady?: () => void;\n};\n\n/**\n * Container component which holds the navigation state designed for React Native apps.\n * This should be rendered at the root wrapping the whole app.\n *\n * @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).\n * @param props.onReady Callback which is called after the navigation tree mounts.\n * @param props.onStateChange Callback which is called with the latest navigation state when it changes.\n * @param props.theme Theme object for the navigators.\n * @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.\n * @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.\n * @param props.documentTitle Options to configure the document title on Web. Updating document title is handled by default unless `documentTitle.enabled` is `false`.\n * @param props.children Child elements to render the content.\n * @param props.ref Ref object which refers to the navigation object containing helper methods.\n */\nconst NavigationContainer = React.forwardRef(function NavigationContainer(\n {\n theme = DefaultTheme,\n linking,\n fallback = null,\n documentTitle,\n onReady,\n ...rest\n }: Props,\n ref?: React.Ref<NavigationContainerRef | null>\n) {\n const isLinkingEnabled = linking ? linking.enabled !== false : false;\n\n const refContainer = React.useRef<NavigationContainerRef>(null);\n\n useBackButton(refContainer);\n useDocumentTitle(refContainer, documentTitle);\n\n const { getInitialState } = useLinking(refContainer, {\n enabled: isLinkingEnabled,\n prefixes: [],\n ...linking,\n });\n\n const [isResolved, initialState] = useThenable(getInitialState);\n\n React.useImperativeHandle(ref, () => refContainer.current);\n\n const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);\n\n const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;\n\n const onReadyRef = React.useRef(onReady);\n\n React.useEffect(() => {\n onReadyRef.current = onReady;\n });\n\n React.useEffect(() => {\n if (isReady) {\n onReadyRef.current?.();\n }\n }, [isReady]);\n\n if (!isReady) {\n // This is temporary until we have Suspense for data-fetching\n // Then the fallback will be handled by a parent `Suspense` component\n return fallback as React.ReactElement;\n }\n\n return (\n <LinkingContext.Provider value={linkingContext}>\n <ThemeProvider value={theme}>\n <BaseNavigationContainer\n {...rest}\n initialState={\n rest.initialState == null ? initialState : rest.initialState\n }\n ref={refContainer}\n />\n </ThemeProvider>\n </LinkingContext.Provider>\n );\n});\n\nexport default NavigationContainer;\n"]} | ||
| {"version":3,"names":["global","REACT_NAVIGATION_DEVTOOLS","WeakMap","NavigationContainerInner","ref","theme","DefaultTheme","linking","fallback","documentTitle","onReady","rest","isLinkingEnabled","enabled","config","validatePathConfig","refContainer","React","useRef","useBackButton","useDocumentTitle","getInitialState","useLinking","independent","prefixes","useEffect","current","set","getStateFromPath","getPathFromState","getActionFromState","isResolved","initialState","useThenable","useImperativeHandle","linkingContext","useMemo","options","isReady","onReadyRef","NavigationContainer","forwardRef"],"sourceRoot":"../../src","sources":["NavigationContainer.tsx"],"mappings":";;;;;;AAAA;AAUA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AAAwC;AAAA;AAAA;AAAA;AASxCA,MAAM,CAACC,yBAAyB,GAAG,IAAIC,OAAO,EAAE;AAUhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,wBAAwB,OAS/BC,GAA6D,EAC7D;EAAA,IATA;IACEC,KAAK,GAAGC,qBAAY;IACpBC,OAAO;IACPC,QAAQ,GAAG,IAAI;IACfC,aAAa;IACbC,OAAO;IACP,GAAGC;EACiB,CAAC;EAGvB,MAAMC,gBAAgB,GAAGL,OAAO,GAAGA,OAAO,CAACM,OAAO,KAAK,KAAK,GAAG,KAAK;EAEpE,IAAIN,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEO,MAAM,EAAE;IACnB,IAAAC,wBAAkB,EAACR,OAAO,CAACO,MAAM,CAAC;EACpC;EAEA,MAAME,YAAY,GAChBC,KAAK,CAACC,MAAM,CAAwC,IAAI,CAAC;EAE3D,IAAAC,sBAAa,EAACH,YAAY,CAAC;EAC3B,IAAAI,yBAAgB,EAACJ,YAAY,EAAEP,aAAa,CAAC;EAE7C,MAAM;IAAEY;EAAgB,CAAC,GAAG,IAAAC,mBAAU,EAACN,YAAY,EAAE;IACnDO,WAAW,EAAEZ,IAAI,CAACY,WAAW;IAC7BV,OAAO,EAAED,gBAAgB;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,OAAO,GAAGhB,OAAO;EAC9B,CAAC,CAAC;EAEFO,KAAK,CAACQ,SAAS,CAAC,MAAM;IACpB,IAAIa,OAAO,EAAE;MAAA;MACX,uBAAAC,UAAU,CAACb,OAAO,wDAAlB,yBAAAa,UAAU,CAAY;IACxB;EACF,CAAC,EAAE,CAACD,OAAO,CAAC,CAAC;EAEb,IAAI,CAACA,OAAO,EAAE;IACZ;IACA;IACA,OAAO9B,QAAQ;EACjB;EAEA,oBACE,oBAAC,uBAAc,CAAC,QAAQ;IAAC,KAAK,EAAE2B;EAAe,gBAC7C,oBAAC,sBAAa;IAAC,KAAK,EAAE9B;EAAM,gBAC1B,oBAAC,6BAAuB,eAClBM,IAAI;IACR,YAAY,EACVA,IAAI,CAACqB,YAAY,IAAI,IAAI,GAAGA,YAAY,GAAGrB,IAAI,CAACqB,YACjD;IACD,GAAG,EAAEhB;EAAa,GAClB,CACY,CACQ;AAE9B;AAEA,MAAMwB,mBAAmB,gBAAGvB,KAAK,CAACwB,UAAU,CAACtC,wBAAwB,CAM9C;AAAC,eAETqC,mBAAmB;AAAA"} |
@@ -7,15 +7,8 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var _core = require("@react-navigation/core"); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _core = require("@react-navigation/core"); | ||
| var _ServerContext = _interopRequireDefault(require("./ServerContext")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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; } | ||
| /** | ||
@@ -28,6 +21,7 @@ * Container component for server rendering. | ||
| */ | ||
| var _default = /*#__PURE__*/React.forwardRef(function ServerContainer({ | ||
| children, | ||
| location | ||
| }, ref) { | ||
| var _default = /*#__PURE__*/React.forwardRef(function ServerContainer(_ref, ref) { | ||
| let { | ||
| children, | ||
| location | ||
| } = _ref; | ||
| React.useEffect(() => { | ||
@@ -37,3 +31,2 @@ console.error("'ServerContainer' should only be used on the server with 'react-dom/server' for SSR."); | ||
| const current = {}; | ||
| if (ref) { | ||
@@ -44,8 +37,8 @@ const value = { | ||
| } | ||
| }; | ||
| }; // We write to the `ref` during render instead of `React.useImperativeHandle` | ||
| // We write to the `ref` during render instead of `React.useImperativeHandle` | ||
| // This is because `useImperativeHandle` will update the ref after 'commit', | ||
| // and there's no 'commit' phase during SSR. | ||
| // Mutating ref during render is unsafe in concurrent mode, but we don't care about it for SSR. | ||
| if (typeof ref === 'function') { | ||
@@ -58,3 +51,2 @@ ref(value); | ||
| } | ||
| return /*#__PURE__*/React.createElement(_ServerContext.default.Provider, { | ||
@@ -68,4 +60,3 @@ value: { | ||
| }); | ||
| exports.default = _default; | ||
| //# sourceMappingURL=ServerContainer.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ServerContainer.tsx"],"names":["React","forwardRef","ServerContainer","children","location","ref","useEffect","console","error","current","value","getCurrentOptions","options"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;4BACeA,KAAK,CAACC,UAAN,CAAiB,SAASC,eAAT,CAC9B;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAD8B,EAE9BC,GAF8B,EAG9B;AACAL,EAAAA,KAAK,CAACM,SAAN,CAAgB,MAAM;AACpBC,IAAAA,OAAO,CAACC,KAAR,CACE,sFADF;AAGD,GAJD,EAIG,EAJH;AAMA,QAAMC,OAA6B,GAAG,EAAtC;;AAEA,MAAIJ,GAAJ,EAAS;AACP,UAAMK,KAAK,GAAG;AACZC,MAAAA,iBAAiB,GAAG;AAClB,eAAOF,OAAO,CAACG,OAAf;AACD;;AAHW,KAAd,CADO,CAOP;AACA;AACA;AACA;;AACA,QAAI,OAAOP,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,MAAAA,GAAG,CAACK,KAAD,CAAH;AACD,KAFD,MAEO;AACL;AACAL,MAAAA,GAAG,CAACI,OAAJ,GAAcC,KAAd;AACD;AACF;;AAED,sBACE,oBAAC,sBAAD,CAAe,QAAf;AAAwB,IAAA,KAAK,EAAE;AAAEN,MAAAA;AAAF;AAA/B,kBACE,oBAAC,0BAAD,CAAsB,QAAtB;AAA+B,IAAA,KAAK,EAAEK;AAAtC,KACGN,QADH,CADF,CADF;AAOD,CAtCc,C","sourcesContent":["import * as React from 'react';\nimport { CurrentRenderContext } from '@react-navigation/core';\nimport ServerContext, { ServerContextType } from './ServerContext';\nimport type { ServerContainerRef } from './types';\n\ntype Props = ServerContextType & {\n children: React.ReactNode;\n};\n\n/**\n * Container component for server rendering.\n *\n * @param props.location Location object to base the initial URL for SSR.\n * @param props.children Child elements to render the content.\n * @param props.ref Ref object which contains helper methods.\n */\nexport default React.forwardRef(function ServerContainer(\n { children, location }: Props,\n ref: React.Ref<ServerContainerRef>\n) {\n React.useEffect(() => {\n console.error(\n \"'ServerContainer' should only be used on the server with 'react-dom/server' for SSR.\"\n );\n }, []);\n\n const current: { options?: object } = {};\n\n if (ref) {\n const value = {\n getCurrentOptions() {\n return current.options;\n },\n };\n\n // We write to the `ref` during render instead of `React.useImperativeHandle`\n // This is because `useImperativeHandle` will update the ref after 'commit',\n // and there's no 'commit' phase during SSR.\n // Mutating ref during render is unsafe in concurrent mode, but we don't care about it for SSR.\n if (typeof ref === 'function') {\n ref(value);\n } else {\n // @ts-expect-error: the TS types are incorrect and say that ref.current is readonly\n ref.current = value;\n }\n }\n\n return (\n <ServerContext.Provider value={{ location }}>\n <CurrentRenderContext.Provider value={current}>\n {children}\n </CurrentRenderContext.Provider>\n </ServerContext.Provider>\n );\n});\n"]} | ||
| {"version":3,"names":["React","forwardRef","ServerContainer","ref","children","location","useEffect","console","error","current","value","getCurrentOptions","options"],"sourceRoot":"../../src","sources":["ServerContainer.tsx"],"mappings":";;;;;;AAAA;AACA;AAEA;AAAmE;AAAA;AAAA;AAOnE;AACA;AACA;AACA;AACA;AACA;AACA;AANA,4BAOeA,KAAK,CAACC,UAAU,CAAC,SAASC,eAAe,OAEtDC,GAAkC,EAClC;EAAA,IAFA;IAAEC,QAAQ;IAAEC;EAAgB,CAAC;EAG7BL,KAAK,CAACM,SAAS,CAAC,MAAM;IACpBC,OAAO,CAACC,KAAK,CACX,sFAAsF,CACvF;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,OAA6B,GAAG,CAAC,CAAC;EAExC,IAAIN,GAAG,EAAE;IACP,MAAMO,KAAK,GAAG;MACZC,iBAAiB,GAAG;QAClB,OAAOF,OAAO,CAACG,OAAO;MACxB;IACF,CAAC;;IAED;IACA;IACA;IACA;IACA,IAAI,OAAOT,GAAG,KAAK,UAAU,EAAE;MAC7BA,GAAG,CAACO,KAAK,CAAC;IACZ,CAAC,MAAM;MACL;MACAP,GAAG,CAACM,OAAO,GAAGC,KAAK;IACrB;EACF;EAEA,oBACE,oBAAC,sBAAa,CAAC,QAAQ;IAAC,KAAK,EAAE;MAAEL;IAAS;EAAE,gBAC1C,oBAAC,0BAAoB,CAAC,QAAQ;IAAC,KAAK,EAAEI;EAAQ,GAC3CL,QAAQ,CACqB,CACT;AAE7B,CAAC,CAAC;AAAA"} |
@@ -7,9 +7,5 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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; } | ||
| const ServerContext = /*#__PURE__*/React.createContext(undefined); | ||
@@ -16,0 +12,0 @@ var _default = ServerContext; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ServerContext.tsx"],"names":["ServerContext","React","createContext","undefined"],"mappings":";;;;;;;AAAA;;;;;;AASA,MAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAN,CACpBC,SADoB,CAAtB;eAIeH,a","sourcesContent":["import * as React from 'react';\n\nexport type ServerContextType = {\n location?: {\n pathname: string;\n search: string;\n };\n};\n\nconst ServerContext = React.createContext<ServerContextType | undefined>(\n undefined\n);\n\nexport default ServerContext;\n"]} | ||
| {"version":3,"names":["ServerContext","React","createContext","undefined"],"sourceRoot":"../../src","sources":["ServerContext.tsx"],"mappings":";;;;;;AAAA;AAA+B;AAAA;AAS/B,MAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAa,CACvCC,SAAS,CACV;AAAC,eAEaH,aAAa;AAAA"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["DarkTheme.tsx"],"names":["DarkTheme","dark","colors","primary","background","card","text","border","notification"],"mappings":";;;;;;AAEA,MAAMA,SAAgB,GAAG;AACvBC,EAAAA,IAAI,EAAE,IADiB;AAEvBC,EAAAA,MAAM,EAAE;AACNC,IAAAA,OAAO,EAAE,mBADH;AAENC,IAAAA,UAAU,EAAE,cAFN;AAGNC,IAAAA,IAAI,EAAE,iBAHA;AAINC,IAAAA,IAAI,EAAE,oBAJA;AAKNC,IAAAA,MAAM,EAAE,iBALF;AAMNC,IAAAA,YAAY,EAAE;AANR;AAFe,CAAzB;eAYeR,S","sourcesContent":["import type { Theme } from '../types';\n\nconst DarkTheme: Theme = {\n dark: true,\n colors: {\n primary: 'rgb(10, 132, 255)',\n background: 'rgb(1, 1, 1)',\n card: 'rgb(18, 18, 18)',\n text: 'rgb(229, 229, 231)',\n border: 'rgb(39, 39, 41)',\n notification: 'rgb(255, 69, 58)',\n },\n};\n\nexport default DarkTheme;\n"]} | ||
| {"version":3,"names":["DarkTheme","dark","colors","primary","background","card","text","border","notification"],"sourceRoot":"../../../src","sources":["theming/DarkTheme.tsx"],"mappings":";;;;;;AAEA,MAAMA,SAAgB,GAAG;EACvBC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE;IACNC,OAAO,EAAE,mBAAmB;IAC5BC,UAAU,EAAE,cAAc;IAC1BC,IAAI,EAAE,iBAAiB;IACvBC,IAAI,EAAE,oBAAoB;IAC1BC,MAAM,EAAE,iBAAiB;IACzBC,YAAY,EAAE;EAChB;AACF,CAAC;AAAC,eAEaR,SAAS;AAAA"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["DefaultTheme.tsx"],"names":["DefaultTheme","dark","colors","primary","background","card","text","border","notification"],"mappings":";;;;;;AAEA,MAAMA,YAAmB,GAAG;AAC1BC,EAAAA,IAAI,EAAE,KADoB;AAE1BC,EAAAA,MAAM,EAAE;AACNC,IAAAA,OAAO,EAAE,kBADH;AAENC,IAAAA,UAAU,EAAE,oBAFN;AAGNC,IAAAA,IAAI,EAAE,oBAHA;AAINC,IAAAA,IAAI,EAAE,iBAJA;AAKNC,IAAAA,MAAM,EAAE,oBALF;AAMNC,IAAAA,YAAY,EAAE;AANR;AAFkB,CAA5B;eAYeR,Y","sourcesContent":["import type { Theme } from '../types';\n\nconst DefaultTheme: Theme = {\n dark: false,\n colors: {\n primary: 'rgb(0, 122, 255)',\n background: 'rgb(242, 242, 242)',\n card: 'rgb(255, 255, 255)',\n text: 'rgb(28, 28, 30)',\n border: 'rgb(216, 216, 216)',\n notification: 'rgb(255, 59, 48)',\n },\n};\n\nexport default DefaultTheme;\n"]} | ||
| {"version":3,"names":["DefaultTheme","dark","colors","primary","background","card","text","border","notification"],"sourceRoot":"../../../src","sources":["theming/DefaultTheme.tsx"],"mappings":";;;;;;AAEA,MAAMA,YAAmB,GAAG;EAC1BC,IAAI,EAAE,KAAK;EACXC,MAAM,EAAE;IACNC,OAAO,EAAE,kBAAkB;IAC3BC,UAAU,EAAE,oBAAoB;IAChCC,IAAI,EAAE,oBAAoB;IAC1BC,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAE,oBAAoB;IAC5BC,YAAY,EAAE;EAChB;AACF,CAAC;AAAC,eAEaR,YAAY;AAAA"} |
@@ -7,13 +7,7 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _DefaultTheme = _interopRequireDefault(require("./DefaultTheme")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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; } | ||
| const ThemeContext = /*#__PURE__*/React.createContext(_DefaultTheme.default); | ||
@@ -20,0 +14,0 @@ ThemeContext.displayName = 'ThemeContext'; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ThemeContext.tsx"],"names":["ThemeContext","React","createContext","DefaultTheme","displayName"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAGA,MAAMA,YAAY,gBAAGC,KAAK,CAACC,aAAN,CAA2BC,qBAA3B,CAArB;AAEAH,YAAY,CAACI,WAAb,GAA2B,cAA3B;eAEeJ,Y","sourcesContent":["import * as React from 'react';\nimport DefaultTheme from './DefaultTheme';\nimport type { Theme } from '../types';\n\nconst ThemeContext = React.createContext<Theme>(DefaultTheme);\n\nThemeContext.displayName = 'ThemeContext';\n\nexport default ThemeContext;\n"]} | ||
| {"version":3,"names":["ThemeContext","React","createContext","DefaultTheme","displayName"],"sourceRoot":"../../../src","sources":["theming/ThemeContext.tsx"],"mappings":";;;;;;AAAA;AAGA;AAA0C;AAAA;AAAA;AAE1C,MAAMA,YAAY,gBAAGC,KAAK,CAACC,aAAa,CAAQC,qBAAY,CAAC;AAE7DH,YAAY,CAACI,WAAW,GAAG,cAAc;AAAC,eAE3BJ,YAAY;AAAA"} |
@@ -7,17 +7,12 @@ "use strict"; | ||
| exports.default = ThemeProvider; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _ThemeContext = _interopRequireDefault(require("./ThemeContext")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 ThemeProvider({ | ||
| value, | ||
| children | ||
| }) { | ||
| 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 ThemeProvider(_ref) { | ||
| let { | ||
| value, | ||
| children | ||
| } = _ref; | ||
| return /*#__PURE__*/React.createElement(_ThemeContext.default.Provider, { | ||
@@ -24,0 +19,0 @@ value: value |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ThemeProvider.tsx"],"names":["ThemeProvider","value","children"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAQe,SAASA,aAAT,CAAuB;AAAEC,EAAAA,KAAF;AAASC,EAAAA;AAAT,CAAvB,EAAmD;AAChE,sBACE,oBAAC,qBAAD,CAAc,QAAd;AAAuB,IAAA,KAAK,EAAED;AAA9B,KAAsCC,QAAtC,CADF;AAGD","sourcesContent":["import * as React from 'react';\nimport ThemeContext from './ThemeContext';\nimport type { Theme } from '../types';\n\ntype Props = {\n value: Theme;\n children: React.ReactNode;\n};\n\nexport default function ThemeProvider({ value, children }: Props) {\n return (\n <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>\n );\n}\n"]} | ||
| {"version":3,"names":["ThemeProvider","value","children"],"sourceRoot":"../../../src","sources":["theming/ThemeProvider.tsx"],"mappings":";;;;;;AAAA;AAGA;AAA0C;AAAA;AAAA;AAO3B,SAASA,aAAa,OAA6B;EAAA,IAA5B;IAAEC,KAAK;IAAEC;EAAgB,CAAC;EAC9D,oBACE,oBAAC,qBAAY,CAAC,QAAQ;IAAC,KAAK,EAAED;EAAM,GAAEC,QAAQ,CAAyB;AAE3E"} |
@@ -7,13 +7,7 @@ "use strict"; | ||
| exports.default = useTheme; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _ThemeContext = _interopRequireDefault(require("./ThemeContext")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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 useTheme() { | ||
@@ -20,0 +14,0 @@ const theme = React.useContext(_ThemeContext.default); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useTheme.tsx"],"names":["useTheme","theme","React","useContext","ThemeContext"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAEe,SAASA,QAAT,GAAoB;AACjC,QAAMC,KAAK,GAAGC,KAAK,CAACC,UAAN,CAAiBC,qBAAjB,CAAd;AAEA,SAAOH,KAAP;AACD","sourcesContent":["import * as React from 'react';\nimport ThemeContext from './ThemeContext';\n\nexport default function useTheme() {\n const theme = React.useContext(ThemeContext);\n\n return theme;\n}\n"]} | ||
| {"version":3,"names":["useTheme","theme","React","useContext","ThemeContext"],"sourceRoot":"../../../src","sources":["theming/useTheme.tsx"],"mappings":";;;;;;AAAA;AAEA;AAA0C;AAAA;AAAA;AAE3B,SAASA,QAAQ,GAAG;EACjC,MAAMC,KAAK,GAAGC,KAAK,CAACC,UAAU,CAACC,qBAAY,CAAC;EAE5C,OAAOH,KAAK;AACd"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| //# sourceMappingURL=types.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]} | ||
| {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.tsx"],"mappings":""} |
@@ -7,31 +7,6 @@ "use strict"; | ||
| exports.default = useBackButton; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _reactNative = require("react-native"); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 useBackButton(ref) { | ||
| React.useEffect(() => { | ||
| const subscription = _reactNative.BackHandler.addEventListener('hardwareBackPress', () => { | ||
| const navigation = ref.current; | ||
| if (navigation == null) { | ||
| return false; | ||
| } | ||
| if (navigation.canGoBack()) { | ||
| navigation.goBack(); | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| return () => subscription.remove(); | ||
| }, [ref]); | ||
| function useBackButton(_) { | ||
| // No-op | ||
| // BackHandler is not available on web | ||
| } | ||
| //# sourceMappingURL=useBackButton.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useBackButton.tsx"],"names":["useBackButton","ref","React","useEffect","subscription","BackHandler","addEventListener","navigation","current","canGoBack","goBack","remove"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAGe,SAASA,aAAT,CACbC,GADa,EAEb;AACAC,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpB,UAAMC,YAAY,GAAGC,yBAAYC,gBAAZ,CACnB,mBADmB,EAEnB,MAAM;AACJ,YAAMC,UAAU,GAAGN,GAAG,CAACO,OAAvB;;AAEA,UAAID,UAAU,IAAI,IAAlB,EAAwB;AACtB,eAAO,KAAP;AACD;;AAED,UAAIA,UAAU,CAACE,SAAX,EAAJ,EAA4B;AAC1BF,QAAAA,UAAU,CAACG,MAAX;AAEA,eAAO,IAAP;AACD;;AAED,aAAO,KAAP;AACD,KAhBkB,CAArB;;AAmBA,WAAO,MAAMN,YAAY,CAACO,MAAb,EAAb;AACD,GArBD,EAqBG,CAACV,GAAD,CArBH;AAsBD","sourcesContent":["import * as React from 'react';\nimport { BackHandler } from 'react-native';\nimport type { NavigationContainerRef } from '@react-navigation/core';\n\nexport default function useBackButton(\n ref: React.RefObject<NavigationContainerRef>\n) {\n React.useEffect(() => {\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n () => {\n const navigation = ref.current;\n\n if (navigation == null) {\n return false;\n }\n\n if (navigation.canGoBack()) {\n navigation.goBack();\n\n return true;\n }\n\n return false;\n }\n );\n\n return () => subscription.remove();\n }, [ref]);\n}\n"]} | ||
| {"version":3,"names":["useBackButton","_"],"sourceRoot":"../../src","sources":["useBackButton.tsx"],"mappings":";;;;;;AAKe,SAASA,aAAa,CACnCC,CAAyD,EACzD;EACA;EACA;AAAA"} |
@@ -7,20 +7,13 @@ "use strict"; | ||
| exports.default = useDocumentTitle; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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; } | ||
| /** | ||
| * Set the document title for the active screen | ||
| */ | ||
| function useDocumentTitle(ref, { | ||
| enabled = true, | ||
| formatter = (options, route) => { | ||
| var _options$title; | ||
| return (_options$title = options === null || options === void 0 ? void 0 : options.title) !== null && _options$title !== void 0 ? _options$title : route === null || route === void 0 ? void 0 : route.name; | ||
| } | ||
| } = {}) { | ||
| function useDocumentTitle(ref) { | ||
| let { | ||
| enabled = true, | ||
| formatter = (options, route) => (options === null || options === void 0 ? void 0 : options.title) ?? (route === null || route === void 0 ? void 0 : route.name) | ||
| } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
| React.useEffect(() => { | ||
@@ -30,5 +23,3 @@ if (!enabled) { | ||
| } | ||
| const navigation = ref.current; | ||
| if (navigation) { | ||
@@ -38,3 +29,2 @@ const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute()); | ||
| } | ||
| return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', e => { | ||
@@ -41,0 +31,0 @@ const title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute()); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useDocumentTitle.tsx"],"names":["useDocumentTitle","ref","enabled","formatter","options","route","title","name","React","useEffect","navigation","current","getCurrentOptions","getCurrentRoute","document","addListener","e","data"],"mappings":";;;;;;;AAAA;;;;;;AAIA;AACA;AACA;AACe,SAASA,gBAAT,CACbC,GADa,EAEb;AACEC,EAAAA,OAAO,GAAG,IADZ;AAEEC,EAAAA,SAAS,GAAG,CAACC,OAAD,EAAUC,KAAV;AAAA;;AAAA,6BAAoBD,OAApB,aAAoBA,OAApB,uBAAoBA,OAAO,CAAEE,KAA7B,2DAAsCD,KAAtC,aAAsCA,KAAtC,uBAAsCA,KAAK,CAAEE,IAA7C;AAAA;AAFd,IAG0B,EALb,EAMb;AACAC,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpB,QAAI,CAACP,OAAL,EAAc;AACZ;AACD;;AAED,UAAMQ,UAAU,GAAGT,GAAG,CAACU,OAAvB;;AAEA,QAAID,UAAJ,EAAgB;AACd,YAAMJ,KAAK,GAAGH,SAAS,CACrBO,UAAU,CAACE,iBAAX,EADqB,EAErBF,UAAU,CAACG,eAAX,EAFqB,CAAvB;AAKAC,MAAAA,QAAQ,CAACR,KAAT,GAAiBA,KAAjB;AACD;;AAED,WAAOI,UAAP,aAAOA,UAAP,uBAAOA,UAAU,CAAEK,WAAZ,CAAwB,SAAxB,EAAoCC,CAAD,IAAO;AAC/C,YAAMV,KAAK,GAAGH,SAAS,CAACa,CAAC,CAACC,IAAF,CAAOb,OAAR,EAAiBM,UAAjB,aAAiBA,UAAjB,uBAAiBA,UAAU,CAAEG,eAAZ,EAAjB,CAAvB;AAEAC,MAAAA,QAAQ,CAACR,KAAT,GAAiBA,KAAjB;AACD,KAJM,CAAP;AAKD,GArBD;AAsBD","sourcesContent":["import * as React from 'react';\nimport type { NavigationContainerRef } from '@react-navigation/core';\nimport type { DocumentTitleOptions } from './types';\n\n/**\n * Set the document title for the active screen\n */\nexport default function useDocumentTitle(\n ref: React.RefObject<NavigationContainerRef>,\n {\n enabled = true,\n formatter = (options, route) => options?.title ?? route?.name,\n }: DocumentTitleOptions = {}\n) {\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const navigation = ref.current;\n\n if (navigation) {\n const title = formatter(\n navigation.getCurrentOptions(),\n navigation.getCurrentRoute()\n );\n\n document.title = title;\n }\n\n return navigation?.addListener('options', (e) => {\n const title = formatter(e.data.options, navigation?.getCurrentRoute());\n\n document.title = title;\n });\n });\n}\n"]} | ||
| {"version":3,"names":["useDocumentTitle","ref","enabled","formatter","options","route","title","name","React","useEffect","navigation","current","getCurrentOptions","getCurrentRoute","document","addListener","e","data"],"sourceRoot":"../../src","sources":["useDocumentTitle.tsx"],"mappings":";;;;;;AAIA;AAA+B;AAAA;AAI/B;AACA;AACA;AACe,SAASA,gBAAgB,CACtCC,GAA2D,EAK3D;EAAA,IAJA;IACEC,OAAO,GAAG,IAAI;IACdC,SAAS,GAAG,CAACC,OAAO,EAAEC,KAAK,KAAK,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,KAAK,MAAID,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEE,IAAI;EACzC,CAAC,uEAAG,CAAC,CAAC;EAE5BC,KAAK,CAACC,SAAS,CAAC,MAAM;IACpB,IAAI,CAACP,OAAO,EAAE;MACZ;IACF;IAEA,MAAMQ,UAAU,GAAGT,GAAG,CAACU,OAAO;IAE9B,IAAID,UAAU,EAAE;MACd,MAAMJ,KAAK,GAAGH,SAAS,CACrBO,UAAU,CAACE,iBAAiB,EAAE,EAC9BF,UAAU,CAACG,eAAe,EAAE,CAC7B;MAEDC,QAAQ,CAACR,KAAK,GAAGA,KAAK;IACxB;IAEA,OAAOI,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,WAAW,CAAC,SAAS,EAAGC,CAAC,IAAK;MAC/C,MAAMV,KAAK,GAAGH,SAAS,CAACa,CAAC,CAACC,IAAI,CAACb,OAAO,EAAEM,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEG,eAAe,EAAE,CAAC;MAEtEC,QAAQ,CAACR,KAAK,GAAGA,KAAK;IACxB,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ"} |
@@ -7,5 +7,5 @@ "use strict"; | ||
| exports.default = useDocumentTitle; | ||
| function useDocumentTitle() {// Noop for React Native | ||
| function useDocumentTitle() { | ||
| // Noop for React Native | ||
| } | ||
| //# sourceMappingURL=useDocumentTitle.native.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useDocumentTitle.native.tsx"],"names":["useDocumentTitle"],"mappings":";;;;;;;AAAe,SAASA,gBAAT,GAA4B,CACzC;AACD","sourcesContent":["export default function useDocumentTitle() {\n // Noop for React Native\n}\n"]} | ||
| {"version":3,"names":["useDocumentTitle"],"sourceRoot":"../../src","sources":["useDocumentTitle.native.tsx"],"mappings":";;;;;;AAAe,SAASA,gBAAgB,GAAG;EACzC;AAAA"} |
@@ -7,18 +7,10 @@ "use strict"; | ||
| exports.default = useLinkBuilder; | ||
| var _core = require("@react-navigation/core"); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _core = require("@react-navigation/core"); | ||
| var _LinkingContext = _interopRequireDefault(require("./LinkingContext")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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; } | ||
| const getRootStateForNavigate = (navigation, state) => { | ||
| const parent = navigation.getParent(); | ||
| if (parent) { | ||
@@ -28,3 +20,4 @@ const parentState = parent.getState(); | ||
| index: 0, | ||
| routes: [{ ...parentState.routes[parentState.index], | ||
| routes: [{ | ||
| ...parentState.routes[parentState.index], | ||
| state: state | ||
@@ -34,5 +27,5 @@ }] | ||
| } | ||
| return state; | ||
| }; | ||
| /** | ||
@@ -42,4 +35,2 @@ * Build destination link for a navigate action. | ||
| */ | ||
| function useLinkBuilder() { | ||
@@ -52,7 +43,5 @@ const navigation = React.useContext(_core.NavigationHelpersContext); | ||
| } = linking; | ||
| if ((options === null || options === void 0 ? void 0 : options.enabled) === false) { | ||
| return undefined; | ||
| } | ||
| const state = navigation ? getRootStateForNavigate(navigation, { | ||
@@ -64,3 +53,4 @@ index: 0, | ||
| }] | ||
| }) : // If we couldn't find a navigation object in context, we're at root | ||
| }) : | ||
| // If we couldn't find a navigation object in context, we're at root | ||
| // So we'll construct a basic state object to use | ||
@@ -67,0 +57,0 @@ { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinkBuilder.tsx"],"names":["getRootStateForNavigate","navigation","state","parent","getParent","parentState","getState","index","routes","useLinkBuilder","React","useContext","NavigationHelpersContext","linking","LinkingContext","buildLink","useCallback","name","params","options","enabled","undefined","path","getPathFromState","config"],"mappings":";;;;;;;AAAA;;AACA;;AAOA;;;;;;;;AAWA,MAAMA,uBAAuB,GAAG,CAC9BC,UAD8B,EAE9BC,KAF8B,KAGb;AACjB,QAAMC,MAAM,GAAGF,UAAU,CAACG,SAAX,EAAf;;AAEA,MAAID,MAAJ,EAAY;AACV,UAAME,WAAW,GAAGF,MAAM,CAACG,QAAP,EAApB;AAEA,WAAON,uBAAuB,CAACG,MAAD,EAAS;AACrCI,MAAAA,KAAK,EAAE,CAD8B;AAErCC,MAAAA,MAAM,EAAE,CACN,EACE,GAAGH,WAAW,CAACG,MAAZ,CAAmBH,WAAW,CAACE,KAA/B,CADL;AAEEL,QAAAA,KAAK,EAAEA;AAFT,OADM;AAF6B,KAAT,CAA9B;AASD;;AAED,SAAOA,KAAP;AACD,CArBD;AAuBA;AACA;AACA;AACA;;;AACe,SAASO,cAAT,GAA0B;AACvC,QAAMR,UAAU,GAAGS,KAAK,CAACC,UAAN,CAAiBC,8BAAjB,CAAnB;AACA,QAAMC,OAAO,GAAGH,KAAK,CAACC,UAAN,CAAiBG,uBAAjB,CAAhB;AAEA,QAAMC,SAAS,GAAGL,KAAK,CAACM,WAAN,CAChB,CAACC,IAAD,EAAeC,MAAf,KAAmC;AACjC,UAAM;AAAEC,MAAAA;AAAF,QAAcN,OAApB;;AAEA,QAAI,CAAAM,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEC,OAAT,MAAqB,KAAzB,EAAgC;AAC9B,aAAOC,SAAP;AACD;;AAED,UAAMnB,KAAK,GAAGD,UAAU,GACpBD,uBAAuB,CAACC,UAAD,EAAa;AAClCM,MAAAA,KAAK,EAAE,CAD2B;AAElCC,MAAAA,MAAM,EAAE,CAAC;AAAES,QAAAA,IAAF;AAAQC,QAAAA;AAAR,OAAD;AAF0B,KAAb,CADH,GAKpB;AACA;AACA;AACEX,MAAAA,KAAK,EAAE,CADT;AAEEC,MAAAA,MAAM,EAAE,CAAC;AAAES,QAAAA,IAAF;AAAQC,QAAAA;AAAR,OAAD;AAFV,KAPJ;AAYA,UAAMI,IAAI,GAAGH,OAAO,SAAP,IAAAA,OAAO,WAAP,IAAAA,OAAO,CAAEI,gBAAT,GACTJ,OAAO,CAACI,gBAAR,CAAyBrB,KAAzB,EAAgCiB,OAAhC,aAAgCA,OAAhC,uBAAgCA,OAAO,CAAEK,MAAzC,CADS,GAET,4BAAiBtB,KAAjB,EAAwBiB,OAAxB,aAAwBA,OAAxB,uBAAwBA,OAAO,CAAEK,MAAjC,CAFJ;AAIA,WAAOF,IAAP;AACD,GAzBe,EA0BhB,CAACT,OAAD,EAAUZ,UAAV,CA1BgB,CAAlB;AA6BA,SAAOc,SAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {\n NavigationHelpers,\n NavigationHelpersContext,\n NavigationProp,\n ParamListBase,\n getPathFromState,\n} from '@react-navigation/core';\nimport LinkingContext from './LinkingContext';\n\ntype NavigationObject =\n | NavigationHelpers<ParamListBase>\n | NavigationProp<ParamListBase>;\n\ntype MinimalState = {\n index: number;\n routes: { name: string; params?: object; state?: MinimalState }[];\n};\n\nconst getRootStateForNavigate = (\n navigation: NavigationObject,\n state: MinimalState\n): MinimalState => {\n const parent = navigation.getParent();\n\n if (parent) {\n const parentState = parent.getState();\n\n return getRootStateForNavigate(parent, {\n index: 0,\n routes: [\n {\n ...parentState.routes[parentState.index],\n state: state,\n },\n ],\n });\n }\n\n return state;\n};\n\n/**\n * Build destination link for a navigate action.\n * Useful for showing anchor tags on the web for buttons that perform navigation.\n */\nexport default function useLinkBuilder() {\n const navigation = React.useContext(NavigationHelpersContext);\n const linking = React.useContext(LinkingContext);\n\n const buildLink = React.useCallback(\n (name: string, params?: object) => {\n const { options } = linking;\n\n if (options?.enabled === false) {\n return undefined;\n }\n\n const state = navigation\n ? getRootStateForNavigate(navigation, {\n index: 0,\n routes: [{ name, params }],\n })\n : // If we couldn't find a navigation object in context, we're at root\n // So we'll construct a basic state object to use\n {\n index: 0,\n routes: [{ name, params }],\n };\n\n const path = options?.getPathFromState\n ? options.getPathFromState(state, options?.config)\n : getPathFromState(state, options?.config);\n\n return path;\n },\n [linking, navigation]\n );\n\n return buildLink;\n}\n"]} | ||
| {"version":3,"names":["getRootStateForNavigate","navigation","state","parent","getParent","parentState","getState","index","routes","useLinkBuilder","React","useContext","NavigationHelpersContext","linking","LinkingContext","buildLink","useCallback","name","params","options","enabled","undefined","path","getPathFromState","config"],"sourceRoot":"../../src","sources":["useLinkBuilder.tsx"],"mappings":";;;;;;AAAA;AAOA;AAEA;AAA8C;AAAA;AAAA;AAW9C,MAAMA,uBAAuB,GAAG,CAC9BC,UAA4B,EAC5BC,KAAmB,KACF;EACjB,MAAMC,MAAM,GAAGF,UAAU,CAACG,SAAS,EAAE;EAErC,IAAID,MAAM,EAAE;IACV,MAAME,WAAW,GAAGF,MAAM,CAACG,QAAQ,EAAE;IAErC,OAAON,uBAAuB,CAACG,MAAM,EAAE;MACrCI,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE,CACN;QACE,GAAGH,WAAW,CAACG,MAAM,CAACH,WAAW,CAACE,KAAK,CAAC;QACxCL,KAAK,EAAEA;MACT,CAAC;IAEL,CAAC,CAAC;EACJ;EAEA,OAAOA,KAAK;AACd,CAAC;;AAED;AACA;AACA;AACA;AACe,SAASO,cAAc,GAAG;EACvC,MAAMR,UAAU,GAAGS,KAAK,CAACC,UAAU,CAACC,8BAAwB,CAAC;EAC7D,MAAMC,OAAO,GAAGH,KAAK,CAACC,UAAU,CAACG,uBAAc,CAAC;EAEhD,MAAMC,SAAS,GAAGL,KAAK,CAACM,WAAW,CACjC,CAACC,IAAY,EAAEC,MAAe,KAAK;IACjC,MAAM;MAAEC;IAAQ,CAAC,GAAGN,OAAO;IAE3B,IAAI,CAAAM,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,OAAO,MAAK,KAAK,EAAE;MAC9B,OAAOC,SAAS;IAClB;IAEA,MAAMnB,KAAK,GAAGD,UAAU,GACpBD,uBAAuB,CAACC,UAAU,EAAE;MAClCM,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE,CAAC;QAAES,IAAI;QAAEC;MAAO,CAAC;IAC3B,CAAC,CAAC;IACF;IACA;IACA;MACEX,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE,CAAC;QAAES,IAAI;QAAEC;MAAO,CAAC;IAC3B,CAAC;IAEL,MAAMI,IAAI,GAAGH,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEI,gBAAgB,GAClCJ,OAAO,CAACI,gBAAgB,CAACrB,KAAK,EAAEiB,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,MAAM,CAAC,GAChD,IAAAD,sBAAgB,EAACrB,KAAK,EAAEiB,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,MAAM,CAAC;IAE5C,OAAOF,IAAI;EACb,CAAC,EACD,CAACT,OAAO,EAAEZ,UAAU,CAAC,CACtB;EAED,OAAOc,SAAS;AAClB"} |
+96
-322
@@ -7,225 +7,11 @@ "use strict"; | ||
| exports.default = useLinking; | ||
| exports.series = void 0; | ||
| var _core = require("@react-navigation/core"); | ||
| var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal")); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _core = require("@react-navigation/core"); | ||
| var _nonSecure = require("nanoid/non-secure"); | ||
| var _createMemoryHistory = _interopRequireDefault(require("./createMemoryHistory")); | ||
| var _ServerContext = _interopRequireDefault(require("./ServerContext")); | ||
| 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; } | ||
| const createMemoryHistory = () => { | ||
| let index = 0; | ||
| let items = []; // Pending callbacks for `history.go(n)` | ||
| // We might modify the callback stored if it was interrupted, so we have a ref to identify it | ||
| const pending = []; | ||
| const interrupt = () => { | ||
| // If another history operation was performed we need to interrupt existing ones | ||
| // This makes sure that calls such as `history.replace` after `history.go` don't happen | ||
| // Since otherwise it won't be correct if something else has changed | ||
| pending.forEach(it => { | ||
| const cb = it.cb; | ||
| it.cb = () => cb(true); | ||
| }); | ||
| }; | ||
| const history = { | ||
| get index() { | ||
| var _window$history$state; | ||
| // We store an id in the state instead of an index | ||
| // Index could get out of sync with in-memory values if page reloads | ||
| const id = (_window$history$state = window.history.state) === null || _window$history$state === void 0 ? void 0 : _window$history$state.id; | ||
| if (id) { | ||
| const index = items.findIndex(item => item.id === id); | ||
| return index > -1 ? index : 0; | ||
| } | ||
| return 0; | ||
| }, | ||
| get(index) { | ||
| return items[index]; | ||
| }, | ||
| backIndex({ | ||
| path | ||
| }) { | ||
| // We need to find the index from the element before current to get closest path to go back to | ||
| for (let i = index - 1; i >= 0; i--) { | ||
| const item = items[i]; | ||
| if (item.path === path) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }, | ||
| push({ | ||
| path, | ||
| state | ||
| }) { | ||
| interrupt(); | ||
| const id = (0, _nonSecure.nanoid)(); // When a new entry is pushed, all the existing entries after index will be inaccessible | ||
| // So we remove any existing entries after the current index to clean them up | ||
| items = items.slice(0, index + 1); | ||
| items.push({ | ||
| path, | ||
| state, | ||
| id | ||
| }); | ||
| index = items.length - 1; // We pass empty string for title because it's ignored in all browsers except safari | ||
| // We don't store state object in history.state because: | ||
| // - browsers have limits on how big it can be, and we don't control the size | ||
| // - while not recommended, there could be non-serializable data in state | ||
| window.history.pushState({ | ||
| id | ||
| }, '', path); | ||
| }, | ||
| replace({ | ||
| path, | ||
| state | ||
| }) { | ||
| var _window$history$state2, _window$history$state3; | ||
| interrupt(); | ||
| const id = (_window$history$state2 = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id) !== null && _window$history$state2 !== void 0 ? _window$history$state2 : (0, _nonSecure.nanoid)(); | ||
| if (items.length) { | ||
| items[index] = { | ||
| path, | ||
| state, | ||
| id | ||
| }; | ||
| } else { | ||
| // This is the first time any state modifications are done | ||
| // So we need to push the entry as there's nothing to replace | ||
| items.push({ | ||
| path, | ||
| state, | ||
| id | ||
| }); | ||
| } | ||
| window.history.replaceState({ | ||
| id | ||
| }, '', path); | ||
| }, | ||
| // `history.go(n)` is asynchronous, there are couple of things to keep in mind: | ||
| // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire. | ||
| // - each `history.go(n)` call will trigger a separate `popstate` event with correct location. | ||
| // - the `popstate` event fires before the next frame after calling `history.go(n)`. | ||
| // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can. | ||
| go(n) { | ||
| interrupt(); | ||
| if (n > 0) { | ||
| // We shouldn't go forward more than available index | ||
| n = Math.min(n, items.length - 1); | ||
| } else if (n < 0) { | ||
| // We shouldn't go back more than the 0 index | ||
| // Otherwise we'll exit the page | ||
| n = index + n < 0 ? -index : n; | ||
| } | ||
| if (n === 0) { | ||
| return; | ||
| } | ||
| index += n; // When we call `history.go`, `popstate` will fire when there's history to go back to | ||
| // So we need to somehow handle following cases: | ||
| // - There's history to go back, `history.go` is called, and `popstate` fires | ||
| // - `history.go` is called multiple times, we need to resolve on respective `popstate` | ||
| // - No history to go back, but `history.go` was called, browser has no API to detect it | ||
| return new Promise((resolve, reject) => { | ||
| const done = interrupted => { | ||
| clearTimeout(timer); | ||
| if (interrupted) { | ||
| reject(new Error('History was changed during navigation.')); | ||
| return; | ||
| } // There seems to be a bug in Chrome regarding updating the title | ||
| // If we set a title just before calling `history.go`, the title gets lost | ||
| // However the value of `document.title` is still what we set it to | ||
| // It's just not displayed in the tab bar | ||
| // To update the tab bar, we need to reset the title to something else first (e.g. '') | ||
| // And set the title to what it was before so it gets applied | ||
| // It won't work without setting it to empty string coz otherwise title isn't changing | ||
| // Which means that the browser won't do anything after setting the title | ||
| const { | ||
| title | ||
| } = window.document; | ||
| window.document.title = ''; | ||
| window.document.title = title; | ||
| resolve(); | ||
| }; | ||
| pending.push({ | ||
| ref: done, | ||
| cb: done | ||
| }); // If navigation didn't happen within 100ms, assume that it won't happen | ||
| // This may not be accurate, but hopefully it won't take so much time | ||
| // In Chrome, navigation seems to happen instantly in next microtask | ||
| // But on Firefox, it seems to take much longer, around 50ms from our testing | ||
| // We're using a hacky timeout since there doesn't seem to be way to know for sure | ||
| const timer = setTimeout(() => { | ||
| const index = pending.findIndex(it => it.ref === done); | ||
| if (index > -1) { | ||
| pending[index].cb(); | ||
| pending.splice(index, 1); | ||
| } | ||
| }, 100); | ||
| const onPopState = () => { | ||
| const last = pending.pop(); | ||
| window.removeEventListener('popstate', onPopState); | ||
| last === null || last === void 0 ? void 0 : last.cb(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| window.history.go(n); | ||
| }); | ||
| }, | ||
| // The `popstate` event is triggered when history changes, except `pushState` and `replaceState` | ||
| // If we call `history.go(n)` ourselves, we don't want it to trigger the listener | ||
| // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener | ||
| listen(listener) { | ||
| const onPopState = () => { | ||
| if (pending.length) { | ||
| // This was triggered by `history.go(n)`, we shouldn't call the listener | ||
| return; | ||
| } | ||
| listener(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| return () => window.removeEventListener('popstate', onPopState); | ||
| } | ||
| }; | ||
| return history; | ||
| }; | ||
| /** | ||
@@ -235,10 +21,8 @@ * Find the matching navigation state that changed between 2 navigation states | ||
| */ | ||
| const findMatchingState = (a, b) => { | ||
| if (a === undefined || b === undefined || a.key !== b.key) { | ||
| return [undefined, undefined]; | ||
| } // Tab and drawer will have `history` property, but stack will have history in `routes` | ||
| } | ||
| // Tab and drawer will have `history` property, but stack will have history in `routes` | ||
| const aHistoryLength = a.history ? a.history.length : a.routes.length; | ||
@@ -249,3 +33,5 @@ const bHistoryLength = b.history ? b.history.length : b.routes.length; | ||
| const aChildState = aRoute.state; | ||
| const bChildState = bRoute.state; // Stop here if this is the state object that changed: | ||
| const bChildState = bRoute.state; | ||
| // Stop here if this is the state object that changed: | ||
| // - history length is different | ||
@@ -255,73 +41,60 @@ // - focused routes are different | ||
| // - child state keys are different | ||
| if (aHistoryLength !== bHistoryLength || aRoute.key !== bRoute.key || aChildState === undefined || bChildState === undefined || aChildState.key !== bChildState.key) { | ||
| return [a, b]; | ||
| } | ||
| return findMatchingState(aChildState, bChildState); | ||
| }; | ||
| /** | ||
| * Run async function in series as it's called. | ||
| */ | ||
| const series = cb => { | ||
| // Whether we're currently handling a callback | ||
| let handling = false; | ||
| let queue = []; | ||
| const callback = async () => { | ||
| try { | ||
| if (handling) { | ||
| // If we're currently handling a previous event, wait before handling this one | ||
| // Add the callback to the beginning of the queue | ||
| queue.unshift(callback); | ||
| return; | ||
| } | ||
| handling = true; | ||
| await cb(); | ||
| } finally { | ||
| handling = false; | ||
| if (queue.length) { | ||
| // If we have queued items, handle the last one | ||
| const last = queue.pop(); | ||
| last === null || last === void 0 ? void 0 : last(); | ||
| } | ||
| } | ||
| let queue = Promise.resolve(); | ||
| const callback = () => { | ||
| queue = queue.then(cb); | ||
| }; | ||
| return callback; | ||
| }; | ||
| let isUsingLinking = false; | ||
| function useLinking(ref, { | ||
| enabled = true, | ||
| config, | ||
| getStateFromPath = _core.getStateFromPath, | ||
| getPathFromState = _core.getPathFromState, | ||
| getActionFromState = _core.getActionFromState | ||
| }) { | ||
| exports.series = series; | ||
| let linkingHandlers = []; | ||
| function useLinking(ref, _ref) { | ||
| let { | ||
| independent, | ||
| enabled = true, | ||
| config, | ||
| getStateFromPath = _core.getStateFromPath, | ||
| getPathFromState = _core.getPathFromState, | ||
| getActionFromState = _core.getActionFromState | ||
| } = _ref; | ||
| React.useEffect(() => { | ||
| if (enabled !== false && isUsingLinking) { | ||
| throw new Error(['Looks like you have configured linking in multiple places. This is likely an error since URL integration should only be handled in one place to avoid conflicts. Make sure that:', "- You are not using both 'linking' prop and 'useLinking'", "- You don't have 'useLinking' in multiple components"].join('\n').trim()); | ||
| } else { | ||
| isUsingLinking = enabled !== false; | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return undefined; | ||
| } | ||
| if (independent) { | ||
| return undefined; | ||
| } | ||
| if (enabled !== false && linkingHandlers.length) { | ||
| console.error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", '- Only a single instance of the root component is rendered'].join('\n').trim()); | ||
| } | ||
| const handler = Symbol(); | ||
| if (enabled !== false) { | ||
| linkingHandlers.push(handler); | ||
| } | ||
| return () => { | ||
| isUsingLinking = false; | ||
| const index = linkingHandlers.indexOf(handler); | ||
| if (index > -1) { | ||
| linkingHandlers.splice(index, 1); | ||
| } | ||
| }; | ||
| }); | ||
| const [history] = React.useState(createMemoryHistory); // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| }, [enabled, independent]); | ||
| const [history] = React.useState(_createMemoryHistory.default); | ||
| // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo` | ||
| // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect | ||
| const enabledRef = React.useRef(enabled); | ||
| const configRef = React.useRef(config); | ||
| const getStateFromPathRef = React.useRef(getStateFromPath); | ||
| const getPathFromStateRef = React.useRef(getPathFromState); | ||
| const getActionFromStateRef = React.useRef(getActionFromState); | ||
| const getPathFromStateRef = React.useRef(getPathFromState); | ||
| React.useEffect(() => { | ||
@@ -331,4 +104,4 @@ enabledRef.current = enabled; | ||
| getStateFromPathRef.current = getStateFromPath; | ||
| getPathFromStateRef.current = getPathFromState; | ||
| getActionFromStateRef.current = getActionFromState; | ||
| getPathFromStateRef.current = getPathFromState; | ||
| }); | ||
@@ -338,9 +111,5 @@ const server = React.useContext(_ServerContext.default); | ||
| let value; | ||
| if (enabledRef.current) { | ||
| var _server$location; | ||
| const location = (_server$location = server === null || server === void 0 ? void 0 : server.location) !== null && _server$location !== void 0 ? _server$location : typeof window !== 'undefined' ? window.location : undefined; | ||
| const location = (server === null || server === void 0 ? void 0 : server.location) ?? (typeof window !== 'undefined' ? window.location : undefined); | ||
| const path = location ? location.pathname + location.search : undefined; | ||
| if (path) { | ||
@@ -350,3 +119,2 @@ value = getStateFromPathRef.current(path, configRef.current); | ||
| } | ||
| const thenable = { | ||
@@ -356,9 +124,8 @@ then(onfulfilled) { | ||
| }, | ||
| catch() { | ||
| return thenable; | ||
| } | ||
| }; | ||
| return thenable; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| return thenable; | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
@@ -371,20 +138,16 @@ const previousIndexRef = React.useRef(undefined); | ||
| return history.listen(() => { | ||
| var _previousIndexRef$cur; | ||
| const navigation = ref.current; | ||
| if (!navigation || !enabled) { | ||
| return; | ||
| } | ||
| const path = location.pathname + location.search; | ||
| const index = history.index; | ||
| const previousIndex = (_previousIndexRef$cur = previousIndexRef.current) !== null && _previousIndexRef$cur !== void 0 ? _previousIndexRef$cur : 0; | ||
| const previousIndex = previousIndexRef.current ?? 0; | ||
| previousIndexRef.current = index; | ||
| pendingPopStatePathRef.current = path; // When browser back/forward is clicked, we first need to check if state object for this index exists | ||
| pendingPopStatePathRef.current = path; | ||
| // When browser back/forward is clicked, we first need to check if state object for this index exists | ||
| // If it does we'll reset to that state object | ||
| // Otherwise, we'll handle it like a regular deep link | ||
| const record = history.get(index); | ||
| if ((record === null || record === void 0 ? void 0 : record.path) === path && record !== null && record !== void 0 && record.state) { | ||
@@ -394,6 +157,6 @@ navigation.resetRoot(record.state); | ||
| } | ||
| const state = getStateFromPathRef.current(path, configRef.current); | ||
| const state = getStateFromPathRef.current(path, configRef.current); // We should only dispatch an action when going forward | ||
| // We should only dispatch an action when going forward | ||
| // Otherwise the action will likely add items to history, which would mess things up | ||
| if (state) { | ||
@@ -403,11 +166,8 @@ // Make sure that the routes in the state exist in the root navigator | ||
| const rootState = navigation.getRootState(); | ||
| if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) { | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration."); | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."); | ||
| return; | ||
| } | ||
| if (index > previousIndex) { | ||
| const action = getActionFromStateRef.current(state, configRef.current); | ||
| if (action !== undefined) { | ||
@@ -419,3 +179,3 @@ try { | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn("An error occurred when trying to handle the link '".concat(path, "': ").concat(e.message)); | ||
| console.warn(`An error occurred when trying to handle the link '${path}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`); | ||
| } | ||
@@ -436,7 +196,19 @@ } else { | ||
| var _ref$current; | ||
| if (!enabled) { | ||
| return; | ||
| } | ||
| const getPathForRoute = (route, state) => { | ||
| // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match | ||
| // This makes sure that we preserve the original URL for wildcard routes | ||
| if (route !== null && route !== void 0 && route.path) { | ||
| const stateForPath = getStateFromPathRef.current(route.path, configRef.current); | ||
| if (stateForPath) { | ||
| const focusedRoute = (0, _core.findFocusedRoute)(stateForPath); | ||
| if (focusedRoute && focusedRoute.name === route.name && (0, _fastDeepEqual.default)(focusedRoute.params, route.params)) { | ||
| return route.path; | ||
| } | ||
| } | ||
| } | ||
| return getPathFromStateRef.current(state, configRef.current); | ||
| }; | ||
| if (ref.current) { | ||
@@ -446,10 +218,8 @@ // We need to record the current metadata on the first render if they aren't set | ||
| const state = ref.current.getRootState(); | ||
| if (state) { | ||
| const path = getPathFromStateRef.current(state, configRef.current); | ||
| const route = (0, _core.findFocusedRoute)(state); | ||
| const path = getPathForRoute(route, state); | ||
| if (previousStateRef.current === undefined) { | ||
| previousStateRef.current = state; | ||
| } | ||
| history.replace({ | ||
@@ -461,27 +231,30 @@ path, | ||
| } | ||
| const onStateChange = async () => { | ||
| const navigation = ref.current; | ||
| if (!navigation || !enabled) { | ||
| return; | ||
| } | ||
| const previousState = previousStateRef.current; | ||
| const state = navigation.getRootState(); | ||
| // root state may not available, for example when root navigators switch inside the container | ||
| if (!state) { | ||
| return; | ||
| } | ||
| const pendingPath = pendingPopStatePathRef.current; | ||
| const path = getPathFromStateRef.current(state, configRef.current); | ||
| const route = (0, _core.findFocusedRoute)(state); | ||
| const path = getPathForRoute(route, state); | ||
| previousStateRef.current = state; | ||
| pendingPopStatePathRef.current = undefined; // To detect the kind of state change, we need to: | ||
| pendingPopStatePathRef.current = undefined; | ||
| // To detect the kind of state change, we need to: | ||
| // - Find the common focused navigation state in previous and current state | ||
| // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace | ||
| // - If no common focused navigation state found, it's a replace | ||
| const [previousFocusedState, focusedState] = findMatchingState(previousState, state); | ||
| if (previousFocusedState && focusedState && // We should only handle push/pop if path changed from what was in last `popstate` | ||
| if (previousFocusedState && focusedState && | ||
| // We should only handle push/pop if path changed from what was in last `popstate` | ||
| // Otherwise it's likely a change triggered by `popstate` | ||
| path !== pendingPath) { | ||
| const historyDelta = (focusedState.history ? focusedState.history.length : focusedState.routes.length) - (previousFocusedState.history ? previousFocusedState.history.length : previousFocusedState.routes.length); | ||
| if (historyDelta > 0) { | ||
@@ -496,2 +269,3 @@ // If history length is increased, we should pushState | ||
| // If history length is decreased, i.e. entries were removed, we want to go back | ||
| const nextIndex = history.backIndex({ | ||
@@ -501,3 +275,2 @@ path | ||
| const currentIndex = history.index; | ||
| try { | ||
@@ -512,5 +285,5 @@ if (nextIndex !== -1 && nextIndex < currentIndex) { | ||
| await history.go(historyDelta); | ||
| } // Store the updated state as well as fix the path if incorrect | ||
| } | ||
| // Store the updated state as well as fix the path if incorrect | ||
| history.replace({ | ||
@@ -520,3 +293,4 @@ path, | ||
| }); | ||
| } catch (e) {// The navigation was interrupted | ||
| } catch (e) { | ||
| // The navigation was interrupted | ||
| } | ||
@@ -538,9 +312,9 @@ } else { | ||
| } | ||
| }; // We debounce onStateChange coz we don't want multiple state changes to be handled at one time | ||
| }; | ||
| // We debounce onStateChange coz we don't want multiple state changes to be handled at one time | ||
| // This could happen since `history.go(n)` is asynchronous | ||
| // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up | ||
| return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.addListener('state', series(onStateChange)); | ||
| }); | ||
| }, [enabled, history, ref]); | ||
| return { | ||
@@ -547,0 +321,0 @@ getInitialState |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinking.tsx"],"names":["createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","replaceState","go","n","Math","min","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","last","pop","removeEventListener","addEventListener","listen","listener","findMatchingState","a","b","undefined","key","aHistoryLength","routes","bHistoryLength","aRoute","bRoute","aChildState","bChildState","series","handling","queue","callback","unshift","isUsingLinking","useLinking","enabled","config","getStateFromPath","getStateFromPathDefault","getPathFromState","getPathFromStateDefault","getActionFromState","getActionFromStateDefault","React","useEffect","join","trim","useState","enabledRef","useRef","configRef","getStateFromPathRef","getActionFromStateRef","getPathFromStateRef","current","server","useContext","ServerContext","getInitialState","useCallback","value","location","pathname","search","thenable","then","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","navigation","previousIndex","record","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","console","warn","action","dispatch","e","message","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","currentIndex","addListener"],"mappings":";;;;;;;AAAA;;AACA;;AAOA;;AACA;;;;;;;;AAcA,MAAMA,mBAAmB,GAAG,MAAM;AAChC,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAsB,GAAG,EAA7B,CAFgC,CAIhC;AACA;;AACA,QAAMC,OAAgE,GAAG,EAAzE;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 'react';\nimport {\n getStateFromPath as getStateFromPathDefault,\n getPathFromState as getPathFromStateDefault,\n getActionFromState as getActionFromStateDefault,\n NavigationContainerRef,\n NavigationState,\n} from '@react-navigation/core';\nimport { nanoid } from 'nanoid/non-secure';\nimport ServerContext from './ServerContext';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\ntype HistoryRecord = {\n // Unique identifier for this record to match it with window.history.state\n id: string;\n // Navigation state object for the history entry\n state: NavigationState;\n // Path of the history entry\n path: string;\n};\n\nconst createMemoryHistory = () => {\n let index = 0;\n let items: HistoryRecord[] = [];\n\n // Pending callbacks for `history.go(n)`\n // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n const interrupt = () => {\n // If another history operation was performed we need to interrupt existing ones\n // This makes sure that calls such as `history.replace` after `history.go` don't happen\n // Since otherwise it won't be correct if something else has changed\n pending.forEach((it) => {\n const cb = it.cb;\n it.cb = () => cb(true);\n });\n };\n\n const history = {\n get index(): number {\n // We store an id in the state instead of an index\n // Index could get out of sync with in-memory values if page reloads\n const id = window.history.state?.id;\n\n if (id) {\n const index = items.findIndex((item) => item.id === id);\n\n return index > -1 ? index : 0;\n }\n\n return 0;\n },\n\n get(index: number) {\n return items[index];\n },\n\n backIndex({ path }: { path: string }) {\n // We need to find the index from the element before current to get closest path to go back to\n for (let i = index - 1; i >= 0; i--) {\n const item = items[i];\n\n if (item.path === path) {\n return i;\n }\n }\n\n return -1;\n },\n\n push({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = nanoid();\n\n // When a new entry is pushed, all the existing entries after index will be inaccessible\n // So we remove any existing entries after the current index to clean them up\n items = items.slice(0, index + 1);\n\n items.push({ path, state, id });\n index = items.length - 1;\n\n // We pass empty string for title because it's ignored in all browsers except safari\n // We don't store state object in history.state because:\n // - browsers have limits on how big it can be, and we don't control the size\n // - while not recommended, there could be non-serializable data in state\n window.history.pushState({ id }, '', path);\n },\n\n replace({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = window.history.state?.id ?? nanoid();\n\n if (items.length) {\n items[index] = { path, state, id };\n } else {\n // This is the first time any state modifications are done\n // So we need to push the entry as there's nothing to replace\n items.push({ path, state, id });\n }\n\n window.history.replaceState({ id }, '', path);\n },\n\n // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n go(n: number) {\n interrupt();\n\n if (n > 0) {\n // We shouldn't go forward more than available index\n n = Math.min(n, items.length - 1);\n } else if (n < 0) {\n // We shouldn't go back more than the 0 index\n // Otherwise we'll exit the page\n n = index + n < 0 ? -index : n;\n }\n\n if (n === 0) {\n return;\n }\n\n index += n;\n\n // When we call `history.go`, `popstate` will fire when there's history to go back to\n // So we need to somehow handle following cases:\n // - There's history to go back, `history.go` is called, and `popstate` fires\n // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n // - No history to go back, but `history.go` was called, browser has no API to detect it\n return new Promise<void>((resolve, reject) => {\n const done = (interrupted?: boolean) => {\n clearTimeout(timer);\n\n if (interrupted) {\n reject(new Error('History was changed during navigation.'));\n return;\n }\n\n // There seems to be a bug in Chrome regarding updating the title\n // If we set a title just before calling `history.go`, the title gets lost\n // However the value of `document.title` is still what we set it to\n // It's just not displayed in the tab bar\n // To update the tab bar, we need to reset the title to something else first (e.g. '')\n // And set the title to what it was before so it gets applied\n // It won't work without setting it to empty string coz otherwise title isn't changing\n // Which means that the browser won't do anything after setting the title\n const { title } = window.document;\n\n window.document.title = '';\n window.document.title = title;\n\n resolve();\n };\n\n pending.push({ ref: done, cb: done });\n\n // If navigation didn't happen within 100ms, assume that it won't happen\n // This may not be accurate, but hopefully it won't take so much time\n // In Chrome, navigation seems to happen instantly in next microtask\n // But on Firefox, it seems to take much longer, around 50ms from our testing\n // We're using a hacky timeout since there doesn't seem to be way to know for sure\n const timer = setTimeout(() => {\n const index = pending.findIndex((it) => it.ref === done);\n\n if (index > -1) {\n pending[index].cb();\n pending.splice(index, 1);\n }\n }, 100);\n\n const onPopState = () => {\n const last = pending.pop();\n\n window.removeEventListener('popstate', onPopState);\n last?.cb();\n };\n\n window.addEventListener('popstate', onPopState);\n window.history.go(n);\n });\n },\n\n // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n listen(listener: () => void) {\n const onPopState = () => {\n if (pending.length) {\n // This was triggered by `history.go(n)`, we shouldn't call the listener\n return;\n }\n\n listener();\n };\n\n window.addEventListener('popstate', onPopState);\n\n return () => window.removeEventListener('popstate', onPopState);\n },\n };\n\n return history;\n};\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nconst series = (cb: () => Promise<void>) => {\n // Whether we're currently handling a callback\n let handling = false;\n let queue: (() => Promise<void>)[] = [];\n\n const callback = async () => {\n try {\n if (handling) {\n // If we're currently handling a previous event, wait before handling this one\n // Add the callback to the beginning of the queue\n queue.unshift(callback);\n return;\n }\n\n handling = true;\n\n await cb();\n } finally {\n handling = false;\n\n if (queue.length) {\n // If we have queued items, handle the last one\n const last = queue.pop();\n\n last?.();\n }\n }\n };\n\n return callback;\n};\n\nlet isUsingLinking = false;\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef>,\n {\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: LinkingOptions\n) {\n React.useEffect(() => {\n if (enabled !== false && isUsingLinking) {\n throw new Error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since URL integration should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You are not using both 'linking' prop and 'useLinking'\",\n \"- You don't have 'useLinking' in multiple components\",\n ]\n .join('\\n')\n .trim()\n );\n } else {\n isUsingLinking = enabled !== false;\n }\n\n return () => {\n isUsingLinking = false;\n };\n });\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getActionFromStateRef = React.useRef(getActionFromState);\n const getPathFromStateRef = React.useRef(getPathFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getActionFromStateRef.current = getActionFromState;\n getPathFromStateRef.current = getPathFromState;\n });\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ??\n (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const path = location.pathname + location.search;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n if (index > previousIndex) {\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${e.message}`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, ref]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const path = getPathFromStateRef.current(state, configRef.current);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n const pendingPath = pendingPopStatePathRef.current;\n const path = getPathFromStateRef.current(state, configRef.current);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(\n previousState,\n state\n );\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history\n ? focusedState.history.length\n : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (nextIndex !== -1 && nextIndex < currentIndex) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch (e) {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n });\n\n return {\n getInitialState,\n };\n}\n"]} | ||
| {"version":3,"names":["findMatchingState","a","b","undefined","key","aHistoryLength","history","length","routes","bHistoryLength","aRoute","index","bRoute","aChildState","state","bChildState","series","cb","queue","Promise","resolve","callback","then","linkingHandlers","useLinking","ref","independent","enabled","config","getStateFromPath","getStateFromPathDefault","getPathFromState","getPathFromStateDefault","getActionFromState","getActionFromStateDefault","React","useEffect","process","env","NODE_ENV","console","error","join","trim","handler","Symbol","push","indexOf","splice","useState","createMemoryHistory","enabledRef","useRef","configRef","getStateFromPathRef","getPathFromStateRef","getActionFromStateRef","current","server","useContext","ServerContext","getInitialState","useCallback","value","location","window","path","pathname","search","thenable","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","listen","navigation","previousIndex","record","get","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","warn","action","dispatch","e","message","getPathForRoute","route","stateForPath","focusedRoute","findFocusedRoute","isEqual","params","replace","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","backIndex","currentIndex","go","addListener"],"sourceRoot":"../../src","sources":["useLinking.tsx"],"mappings":";;;;;;;AAAA;AASA;AACA;AAEA;AACA;AAA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SAAS,KAAK,CAAC,CAAC,IAAIA,SAAS,GAAGE,YAAY,EAAE;cAChD;cACA,MAAMvG,OAAO,CAACwG,EAAE,CAACH,SAAS,GAAGE,YAAY,CAAC;YAC5C,CAAC,MAAM;cACL;cACA;cACA;cACA,MAAMvG,OAAO,CAACwG,EAAE,CAACJ,YAAY,CAAC;YAChC;;YAEA;YACApG,OAAO,CAAC8F,OAAO,CAAC;cAAElC,IAAI;cAAEpD;YAAM,CAAC,CAAC;UAClC,CAAC,CAAC,OAAO6E,CAAC,EAAE;YACV;UAAA;QAEJ,CAAC,MAAM;UACL;UACArF,OAAO,CAAC8F,OAAO,CAAC;YAAElC,IAAI;YAAEpD;UAAM,CAAC,CAAC;QAClC;MACF,CAAC,MAAM;QACL;QACA;QACAR,OAAO,CAAC8F,OAAO,CAAC;UAAElC,IAAI;UAAEpD;QAAM,CAAC,CAAC;MAClC;IACF,CAAC;;IAED;IACA;IACA;IACA,uBAAOW,GAAG,CAACgC,OAAO,iDAAX,aAAasD,WAAW,CAAC,OAAO,EAAE/F,MAAM,CAACqF,aAAa,CAAC,CAAC;EACjE,CAAC,EAAE,CAAC1E,OAAO,EAAErB,OAAO,EAAEmB,GAAG,CAAC,CAAC;EAE3B,OAAO;IACLoC;EACF,CAAC;AACH"} |
@@ -7,61 +7,74 @@ "use strict"; | ||
| exports.default = useLinking; | ||
| var _core = require("@react-navigation/core"); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _reactNative = require("react-native"); | ||
| var _core = require("@react-navigation/core"); | ||
| var _extractPathFromURL = _interopRequireDefault(require("./extractPathFromURL")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| 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; } | ||
| let linkingHandlers = []; | ||
| function useLinking(ref, _ref) { | ||
| let { | ||
| independent, | ||
| enabled = true, | ||
| prefixes, | ||
| filter, | ||
| config, | ||
| getInitialURL = () => Promise.race([_reactNative.Linking.getInitialURL(), new Promise(resolve => | ||
| // Timeout in 150ms if `getInitialState` doesn't resolve | ||
| // Workaround for https://github.com/facebook/react-native/issues/25675 | ||
| setTimeout(resolve, 150))]), | ||
| subscribe = listener => { | ||
| var _Linking$removeEventL; | ||
| const callback = _ref2 => { | ||
| let { | ||
| url | ||
| } = _ref2; | ||
| return listener(url); | ||
| }; | ||
| const subscription = _reactNative.Linking.addEventListener('url', callback); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; } | ||
| let isUsingLinking = false; | ||
| function useLinking(ref, { | ||
| enabled = true, | ||
| prefixes, | ||
| config, | ||
| getInitialURL = () => Promise.race([_reactNative.Linking.getInitialURL(), new Promise(resolve => // Timeout in 150ms if `getInitialState` doesn't resolve | ||
| // Workaround for https://github.com/facebook/react-native/issues/25675 | ||
| setTimeout(resolve, 150))]), | ||
| subscribe = listener => { | ||
| const callback = ({ | ||
| url | ||
| }) => listener(url); | ||
| const subscription = _reactNative.Linking.addEventListener('url', callback); | ||
| // Storing this in a local variable stops Jest from complaining about import after teardown | ||
| // @ts-expect-error: removeEventListener is not present in newer RN versions | ||
| const removeEventListener = (_Linking$removeEventL = _reactNative.Linking.removeEventListener) === null || _Linking$removeEventL === void 0 ? void 0 : _Linking$removeEventL.bind(_reactNative.Linking); | ||
| return () => { | ||
| // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7 | ||
| if (subscription !== null && subscription !== void 0 && subscription.remove) { | ||
| subscription.remove(); | ||
| } else { | ||
| removeEventListener === null || removeEventListener === void 0 ? void 0 : removeEventListener('url', callback); | ||
| } | ||
| }; | ||
| }, | ||
| getStateFromPath = _core.getStateFromPath, | ||
| getActionFromState = _core.getActionFromState | ||
| } = _ref; | ||
| React.useEffect(() => { | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return undefined; | ||
| } | ||
| if (independent) { | ||
| return undefined; | ||
| } | ||
| if (enabled !== false && linkingHandlers.length) { | ||
| console.error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", '- Only a single instance of the root component is rendered', _reactNative.Platform.OS === 'android' ? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances" : ''].join('\n').trim()); | ||
| } | ||
| const handler = Symbol(); | ||
| if (enabled !== false) { | ||
| linkingHandlers.push(handler); | ||
| } | ||
| return () => { | ||
| // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7 | ||
| if (subscription !== null && subscription !== void 0 && subscription.remove) { | ||
| subscription.remove(); | ||
| } else { | ||
| _reactNative.Linking.removeEventListener('url', callback); | ||
| const index = linkingHandlers.indexOf(handler); | ||
| if (index > -1) { | ||
| linkingHandlers.splice(index, 1); | ||
| } | ||
| }; | ||
| }, | ||
| getStateFromPath = _core.getStateFromPath, | ||
| getActionFromState = _core.getActionFromState | ||
| }) { | ||
| React.useEffect(() => { | ||
| if (enabled !== false && isUsingLinking) { | ||
| throw new Error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You are not using both 'linking' prop and 'useLinking'", "- You don't have 'useLinking' in multiple components", _reactNative.Platform.OS === 'android' ? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances" : ''].join('\n').trim()); | ||
| } else { | ||
| isUsingLinking = enabled !== false; | ||
| } | ||
| }, [enabled, independent]); | ||
| return () => { | ||
| isUsingLinking = false; | ||
| }; | ||
| }); // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo` | ||
| // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect | ||
| const enabledRef = React.useRef(enabled); | ||
| const prefixesRef = React.useRef(prefixes); | ||
| const filterRef = React.useRef(filter); | ||
| const configRef = React.useRef(config); | ||
@@ -74,2 +87,3 @@ const getInitialURLRef = React.useRef(getInitialURL); | ||
| prefixesRef.current = prefixes; | ||
| filterRef.current = filter; | ||
| configRef.current = config; | ||
@@ -80,19 +94,21 @@ getInitialURLRef.current = getInitialURL; | ||
| }); | ||
| const getStateFromURL = React.useCallback(url => { | ||
| if (!url || filterRef.current && !filterRef.current(url)) { | ||
| return undefined; | ||
| } | ||
| const path = (0, _extractPathFromURL.default)(prefixesRef.current, url); | ||
| return path !== undefined ? getStateFromPathRef.current(path, configRef.current) : undefined; | ||
| }, []); | ||
| const getInitialState = React.useCallback(() => { | ||
| let state; | ||
| if (enabledRef.current) { | ||
| const url = getInitialURLRef.current(); | ||
| if (url != null && typeof url !== 'string') { | ||
| return url.then(url => { | ||
| const path = url ? (0, _extractPathFromURL.default)(prefixesRef.current, url) : null; | ||
| return path ? getStateFromPathRef.current(path, configRef.current) : undefined; | ||
| const state = getStateFromURL(url); | ||
| return state; | ||
| }); | ||
| } | ||
| const path = url ? (0, _extractPathFromURL.default)(prefixesRef.current, url) : null; | ||
| state = path ? getStateFromPathRef.current(path, configRef.current) : undefined; | ||
| state = getStateFromURL(url); | ||
| } | ||
| const thenable = { | ||
@@ -102,10 +118,8 @@ then(onfulfilled) { | ||
| }, | ||
| catch() { | ||
| return thenable; | ||
| } | ||
| }; | ||
| return thenable; | ||
| }, []); | ||
| }, [getStateFromURL]); | ||
| React.useEffect(() => { | ||
@@ -116,38 +130,28 @@ const listener = url => { | ||
| } | ||
| const path = (0, _extractPathFromURL.default)(prefixesRef.current, url); | ||
| const navigation = ref.current; | ||
| if (navigation && path) { | ||
| const state = getStateFromPathRef.current(path, configRef.current); | ||
| if (state) { | ||
| // Make sure that the routes in the state exist in the root navigator | ||
| // Otherwise there's an error in the linking configuration | ||
| const rootState = navigation.getRootState(); | ||
| if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) { | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration."); | ||
| return; | ||
| const state = navigation ? getStateFromURL(url) : undefined; | ||
| if (navigation && state) { | ||
| // Make sure that the routes in the state exist in the root navigator | ||
| // Otherwise there's an error in the linking configuration | ||
| const rootState = navigation.getRootState(); | ||
| if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) { | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."); | ||
| return; | ||
| } | ||
| const action = getActionFromStateRef.current(state, configRef.current); | ||
| if (action !== undefined) { | ||
| try { | ||
| navigation.dispatch(action); | ||
| } catch (e) { | ||
| // Ignore any errors from deep linking. | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn(`An error occurred when trying to handle the link '${url}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`); | ||
| } | ||
| const action = getActionFromStateRef.current(state, configRef.current); | ||
| if (action !== undefined) { | ||
| try { | ||
| navigation.dispatch(action); | ||
| } catch (e) { | ||
| // Ignore any errors from deep linking. | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn("An error occurred when trying to handle the link '".concat(path, "': ").concat(e.message)); | ||
| } | ||
| } else { | ||
| navigation.resetRoot(state); | ||
| } | ||
| } else { | ||
| navigation.resetRoot(state); | ||
| } | ||
| } | ||
| }; | ||
| return subscribe(listener); | ||
| }, [enabled, ref, subscribe]); | ||
| }, [enabled, getStateFromURL, ref, subscribe]); | ||
| return { | ||
@@ -154,0 +158,0 @@ getInitialState |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinking.native.tsx"],"names":["isUsingLinking","useLinking","ref","enabled","prefixes","config","getInitialURL","Promise","race","Linking","resolve","setTimeout","subscribe","listener","callback","url","subscription","addEventListener","remove","removeEventListener","getStateFromPath","getStateFromPathDefault","getActionFromState","getActionFromStateDefault","React","useEffect","Error","Platform","OS","join","trim","enabledRef","useRef","prefixesRef","configRef","getInitialURLRef","getStateFromPathRef","getActionFromStateRef","current","getInitialState","useCallback","state","then","path","undefined","thenable","onfulfilled","catch","navigation","rootState","getRootState","routes","some","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AMQ,SAAS,GAAGD,UAAU,CAACE,YAAX,EAAlB;;AAEA,cACET,KAAK,CAACU,MAAN,CAAaC,IAAb,CAAmBC,CAAD,IAAO,EAACJ,SAAD,aAACA,SAAD,eAACA,SAAS,CAAEK,UAAX,CAAsBC,QAAtB,CAA+BF,CAAC,CAACG,IAAjC,CAAD,CAAzB,CADF,EAEE;AACAC,YAAAA,OAAO,CAACC,IAAR,CACE,8SADF;AAGA;AACD;;AAED,gBAAMC,MAAM,GAAGtB,qBAAqB,CAACC,OAAtB,CACbG,KADa,EAEbP,SAAS,CAACI,OAFG,CAAf;;AAKA,cAAIqB,MAAM,KAAKf,SAAf,EAA0B;AACxB,gBAAI;AACFI,cAAAA,UAAU,CAACY,QAAX,CAAoBD,MAApB;AACD,aAFD,CAEE,OAAOE,CAAP,EAAU;AACV;AACA;AACAJ,cAAAA,OAAO,CAACC,IAAR,6DACuDf,IADvD,gBACiEkB,CAAC,CAACC,OADnE;AAGD;AACF,WAVD,MAUO;AACLd,YAAAA,UAAU,CAACe,SAAX,CAAqBtB,KAArB;AACD;AACF;AACF;AACF,KA7CD;;AA+CA,WAAO7B,SAAS,CAACC,QAAD,CAAhB;AACD,GAjDD,EAiDG,CAACV,OAAD,EAAUD,GAAV,EAAeU,SAAf,CAjDH;AAmDA,SAAO;AACL2B,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import * as React from 'react';\nimport { Linking, Platform } from 'react-native';\nimport {\n getActionFromState as getActionFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n} from '@react-navigation/core';\nimport extractPathFromURL from './extractPathFromURL';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\nlet isUsingLinking = false;\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef>,\n {\n enabled = true,\n prefixes,\n config,\n getInitialURL = () =>\n Promise.race([\n Linking.getInitialURL(),\n new Promise<undefined>((resolve) =>\n // Timeout in 150ms if `getInitialState` doesn't resolve\n // Workaround for https://github.com/facebook/react-native/issues/25675\n setTimeout(resolve, 150)\n ),\n ]),\n subscribe = (listener) => {\n const callback = ({ url }: { url: string }) => listener(url);\n\n const subscription = Linking.addEventListener('url', callback) as\n | { remove(): void }\n | undefined;\n\n return () => {\n // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7\n if (subscription?.remove) {\n subscription.remove();\n } else {\n Linking.removeEventListener('url', callback);\n }\n };\n },\n getStateFromPath = getStateFromPathDefault,\n getActionFromState = getActionFromStateDefault,\n }: LinkingOptions\n) {\n React.useEffect(() => {\n if (enabled !== false && isUsingLinking) {\n throw new Error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You are not using both 'linking' prop and 'useLinking'\",\n \"- You don't have 'useLinking' in multiple components\",\n Platform.OS === 'android'\n ? \"- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances\"\n : '',\n ]\n .join('\\n')\n .trim()\n );\n } else {\n isUsingLinking = enabled !== false;\n }\n\n return () => {\n isUsingLinking = false;\n };\n });\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const prefixesRef = React.useRef(prefixes);\n const configRef = React.useRef(config);\n const getInitialURLRef = React.useRef(getInitialURL);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n prefixesRef.current = prefixes;\n configRef.current = config;\n getInitialURLRef.current = getInitialURL;\n getStateFromPathRef.current = getStateFromPath;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const getInitialState = React.useCallback(() => {\n let state: ResultState | undefined;\n\n if (enabledRef.current) {\n const url = getInitialURLRef.current();\n\n if (url != null && typeof url !== 'string') {\n return url.then((url) => {\n const path = url\n ? extractPathFromURL(prefixesRef.current, url)\n : null;\n\n return path\n ? getStateFromPathRef.current(path, configRef.current)\n : undefined;\n });\n }\n\n const path = url ? extractPathFromURL(prefixesRef.current, url) : null;\n\n state = path\n ? getStateFromPathRef.current(path, configRef.current)\n : undefined;\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(state) : state);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n }, []);\n\n React.useEffect(() => {\n const listener = (url: string) => {\n if (!enabled) {\n return;\n }\n\n const path = extractPathFromURL(prefixesRef.current, url);\n const navigation = ref.current;\n\n if (navigation && path) {\n const state = getStateFromPathRef.current(path, configRef.current);\n\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (\n state.routes.some((r) => !rootState?.routeNames.includes(r.name))\n ) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${e.message}`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n }\n }\n };\n\n return subscribe(listener);\n }, [enabled, ref, subscribe]);\n\n return {\n getInitialState,\n };\n}\n"]} | ||
| {"version":3,"names":["linkingHandlers","useLinking","ref","independent","enabled","prefixes","filter","config","getInitialURL","Promise","race","Linking","resolve","setTimeout","subscribe","listener","callback","url","subscription","addEventListener","removeEventListener","bind","remove","getStateFromPath","getStateFromPathDefault","getActionFromState","getActionFromStateDefault","React","useEffect","process","env","NODE_ENV","undefined","length","console","error","Platform","OS","join","trim","handler","Symbol","push","index","indexOf","splice","enabledRef","useRef","prefixesRef","filterRef","configRef","getInitialURLRef","getStateFromPathRef","getActionFromStateRef","current","getStateFromURL","useCallback","path","extractPathFromURL","getInitialState","state","then","thenable","onfulfilled","catch","navigation","rootState","getRootState","routes","some","r","routeNames","includes","name","warn","action","dispatch","e","message","resetRoot"],"sourceRoot":"../../src","sources":["useLinking.native.tsx"],"mappings":";;;;;;AAAA;AAMA;AACA;AAEA;AAAsD;AAAA;AAAA;AAStD,IAAIA,eAAyB,GAAG,EAAE;AAEnB,SAASC,UAAU,CAChCC,GAA2D,QAuC3D;EAAA,IAtCA;IACEC,WAAW;IACXC,OAAO,GAAG,IAAI;IACdC,QAAQ;IACRC,MAAM;IACNC,MAAM;IACNC,aAAa,GAAG,MACdC,OAAO,CAACC,IAAI,CAAC,CACXC,oBAAO,CAACH,aAAa,EAAE,EACvB,IAAIC,OAAO,CAAaG,OAAO;IAC7B;IACA;IACAC,UAAU,CAACD,OAAO,EAAE,GAAG,CAAC,CACzB,CACF,CAAC;IACJE,SAAS,GAAIC,QAAQ,IAAK;MAAA;MACxB,MAAMC,QAAQ,GAAG;QAAA,IAAC;UAAEC;QAAqB,CAAC;QAAA,OAAKF,QAAQ,CAACE,GAAG,CAAC;MAAA;MAE5D,MAAMC,YAAY,GAAGP,oBAAO,CAACQ,gBAAgB,CAAC,KAAK,EAAEH,QAAQ,CAEhD;;MAEb;MACA;MACA,MAAMI,mBAAmB,4BAAGT,oBAAO,CAACS,mBAAmB,0DAA3B,sBAA6BC,IAAI,CAACV,oBAAO,CAAC;MAEtE,OAAO,MAAM;QACX;QACA,IAAIO,YAAY,aAAZA,YAAY,eAAZA,YAAY,CAAEI,MAAM,EAAE;UACxBJ,YAAY,CAACI,MAAM,EAAE;QACvB,CAAC,MAAM;UACLF,mBAAmB,aAAnBA,mBAAmB,uBAAnBA,mBA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AAM,KAAK3C,SAAS,EAAE;UACxB,IAAI;YACFiC,UAAU,CAACW,QAAQ,CAACD,MAAM,CAAC;UAC7B,CAAC,CAAC,OAAOE,CAAC,EAAE;YACV;YACA;YACA3C,OAAO,CAACwC,IAAI,CACT,qDAAoDzD,GAAI,MACvD,OAAO4D,CAAC,KAAK,QAAQ,IAAIA,CAAC,IAAI,IAAI,IAAI,SAAS,IAAIA,CAAC,GAChDA,CAAC,CAACC,OAAO,GACTD,CACL,EAAC,CACH;UACH;QACF,CAAC,MAAM;UACLZ,UAAU,CAACc,SAAS,CAACnB,KAAK,CAAC;QAC7B;MACF;IACF,CAAC;IAED,OAAO9C,SAAS,CAACC,QAAQ,CAAC;EAC5B,CAAC,EAAE,CAACX,OAAO,EAAEmD,eAAe,EAAErD,GAAG,EAAEY,SAAS,CAAC,CAAC;EAE9C,OAAO;IACL6C;EACF,CAAC;AACH"} |
@@ -7,17 +7,27 @@ "use strict"; | ||
| exports.default = useLinkProps; | ||
| var _core = require("@react-navigation/core"); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _reactNative = require("react-native"); | ||
| var _core = require("@react-navigation/core"); | ||
| var _LinkingContext = _interopRequireDefault(require("./LinkingContext")); | ||
| var _useLinkTo = _interopRequireDefault(require("./useLinkTo")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| 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; } | ||
| const getStateFromParams = params => { | ||
| if (params !== null && params !== void 0 && params.state) { | ||
| return params.state; | ||
| } | ||
| if (params !== null && params !== void 0 && params.screen) { | ||
| return { | ||
| routes: [{ | ||
| name: params.screen, | ||
| params: params.params, | ||
| // @ts-expect-error | ||
| state: params.screen ? getStateFromParams(params.params) : undefined | ||
| }] | ||
| }; | ||
| } | ||
| return undefined; | ||
| }; | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; } | ||
| /** | ||
@@ -29,28 +39,32 @@ * Hook to get props for an anchor tag so it can work with in page navigation. | ||
| */ | ||
| function useLinkProps({ | ||
| to, | ||
| action | ||
| }) { | ||
| function useLinkProps(_ref) { | ||
| let { | ||
| to, | ||
| action | ||
| } = _ref; | ||
| const root = React.useContext(_core.NavigationContainerRefContext); | ||
| const navigation = React.useContext(_core.NavigationHelpersContext); | ||
| const { | ||
| options | ||
| } = React.useContext(_LinkingContext.default); | ||
| const linkTo = (0, _useLinkTo.default)(); | ||
| const onPress = e => { | ||
| var _e$currentTarget; | ||
| let shouldHandle = false; | ||
| if (_reactNative.Platform.OS !== 'web' || !e) { | ||
| shouldHandle = e ? !e.defaultPrevented : true; | ||
| } else if (!e.defaultPrevented && // onPress prevented default | ||
| } else if (!e.defaultPrevented && | ||
| // onPress prevented default | ||
| // @ts-expect-error: these properties exist on web, but not in React Native | ||
| !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && ( // ignore clicks with modifier keys | ||
| !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && ( | ||
| // ignore clicks with modifier keys | ||
| // @ts-expect-error: these properties exist on web, but not in React Native | ||
| e.button == null || e.button === 0) && // ignore everything but left clicks | ||
| e.button == null || e.button === 0) && | ||
| // ignore everything but left clicks | ||
| // @ts-expect-error: these properties exist on web, but not in React Native | ||
| [undefined, null, '', 'self'].includes((_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : _e$currentTarget.target) // let browser handle "target=_blank" etc. | ||
| ) { | ||
| e.preventDefault(); | ||
| shouldHandle = true; | ||
| } | ||
| e.preventDefault(); | ||
| shouldHandle = true; | ||
| } | ||
| if (shouldHandle) { | ||
@@ -60,10 +74,8 @@ if (action) { | ||
| navigation.dispatch(action); | ||
| } else if (root) { | ||
| root.dispatch(action); | ||
| } else { | ||
| throw new Error("Couldn't find a navigation object."); | ||
| throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?"); | ||
| } | ||
| } else { | ||
| if (typeof to !== 'string') { | ||
| throw new Error("To 'to' option is invalid (found '".concat(String(to), "'. It must be a valid string for navigation.")); | ||
| } | ||
| linkTo(to); | ||
@@ -73,5 +85,14 @@ } | ||
| }; | ||
| const getPathFromStateHelper = (options === null || options === void 0 ? void 0 : options.getPathFromState) ?? _core.getPathFromState; | ||
| const href = typeof to === 'string' ? to : getPathFromStateHelper({ | ||
| routes: [{ | ||
| name: to.screen, | ||
| // @ts-expect-error | ||
| params: to.params, | ||
| // @ts-expect-error | ||
| state: getStateFromParams(to.params) | ||
| }] | ||
| }, options === null || options === void 0 ? void 0 : options.config); | ||
| return { | ||
| href: to, | ||
| href, | ||
| accessibilityRole: 'link', | ||
@@ -78,0 +99,0 @@ onPress |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinkProps.tsx"],"names":["useLinkProps","to","action","navigation","React","useContext","NavigationHelpersContext","linkTo","onPress","e","shouldHandle","Platform","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","undefined","includes","currentTarget","target","preventDefault","dispatch","Error","String","href","accessibilityRole"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAIA;;;;;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAsB;AAAEC,EAAAA,EAAF;AAAMC,EAAAA;AAAN,CAAtB,EAA6C;AAC1D,QAAMC,UAAU,GAAGC,KAAK,CAACC,UAAN,CAAiBC,8BAAjB,CAAnB;AACA,QAAMC,MAAM,GAAG,yBAAf;;AAEA,QAAMC,OAAO,GACXC,CADc,IAEX;AAAA;;AACH,QAAIC,YAAY,GAAG,KAAnB;;AAEA,QAAIC,sBAASC,EAAT,KAAgB,KAAhB,IAAyB,CAACH,CAA9B,EAAiC;AAC/BC,MAAAA,YAAY,GAAGD,CAAC,GAAG,CAACA,CAAC,CAACI,gBAAN,GAAyB,IAAzC;AACD,KAFD,MAEO,IACL,CAACJ,CAAC,CAACI,gBAAH,IAAuB;AACvB;AACA,MAAEJ,CAAC,CAACK,OAAF,IAAaL,CAAC,CAACM,MAAf,IAAyBN,CAAC,CAACO,OAA3B,IAAsCP,CAAC,CAACQ,QAA1C,CAFA,MAEuD;AACvD;AACCR,IAAAA,CAAC,CAACS,MAAF,IAAY,IAAZ,IAAoBT,CAAC,CAACS,MAAF,KAAa,CAJlC,KAIwC;AACxC;AACA,KAACC,SAAD,EAAY,IAAZ,EAAkB,EAAlB,EAAsB,MAAtB,EAA8BC,QAA9B,qBAAuCX,CAAC,CAACY,aAAzC,qDAAuC,iBAAiBC,MAAxD,CAPK,CAO2D;AAP3D,MAQL;AACAb,QAAAA,CAAC,CAACc,cAAF;AACAb,QAAAA,YAAY,GAAG,IAAf;AACD;;AAED,QAAIA,YAAJ,EAAkB;AAChB,UAAIR,MAAJ,EAAY;AACV,YAAIC,UAAJ,EAAgB;AACdA,UAAAA,UAAU,CAACqB,QAAX,CAAoBtB,MAApB;AACD,SAFD,MAEO;AACL,gBAAM,IAAIuB,KAAJ,CAAU,oCAAV,CAAN;AACD;AACF,OAND,MAMO;AACL,YAAI,OAAOxB,EAAP,KAAc,QAAlB,EAA4B;AAC1B,gBAAM,IAAIwB,KAAJ,6CACiCC,MAAM,CACzCzB,EADyC,CADvC,kDAAN;AAKD;;AAEDM,QAAAA,MAAM,CAACN,EAAD,CAAN;AACD;AACF;AACF,GAvCD;;AAyCA,SAAO;AACL0B,IAAAA,IAAI,EAAE1B,EADD;AAEL2B,IAAAA,iBAAiB,EAAE,MAFd;AAGLpB,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["import * as React from 'react';\nimport { Platform, GestureResponderEvent } from 'react-native';\nimport {\n NavigationAction,\n NavigationHelpersContext,\n} from '@react-navigation/core';\nimport useLinkTo from './useLinkTo';\n\ntype Props = {\n to: string;\n action?: NavigationAction;\n};\n\n/**\n * Hook to get props for an anchor tag so it can work with in page navigation.\n *\n * @param props.to Absolute path to screen (e.g. `/feeds/hot`).\n * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.\n */\nexport default function useLinkProps({ to, action }: Props) {\n const navigation = React.useContext(NavigationHelpersContext);\n const linkTo = useLinkTo();\n\n const onPress = (\n e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => {\n let shouldHandle = false;\n\n if (Platform.OS !== 'web' || !e) {\n shouldHandle = e ? !e.defaultPrevented : true;\n } else if (\n !e.defaultPrevented && // onPress prevented default\n // @ts-expect-error: these properties exist on web, but not in React Native\n !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys\n // @ts-expect-error: these properties exist on web, but not in React Native\n (e.button == null || e.button === 0) && // ignore everything but left clicks\n // @ts-expect-error: these properties exist on web, but not in React Native\n [undefined, null, '', 'self'].includes(e.currentTarget?.target) // let browser handle \"target=_blank\" etc.\n ) {\n e.preventDefault();\n shouldHandle = true;\n }\n\n if (shouldHandle) {\n if (action) {\n if (navigation) {\n navigation.dispatch(action);\n } else {\n throw new Error(\"Couldn't find a navigation object.\");\n }\n } else {\n if (typeof to !== 'string') {\n throw new Error(\n `To 'to' option is invalid (found '${String(\n to\n )}'. It must be a valid string for navigation.`\n );\n }\n\n linkTo(to);\n }\n }\n };\n\n return {\n href: to,\n accessibilityRole: 'link' as const,\n onPress,\n };\n}\n"]} | ||
| {"version":3,"names":["getStateFromParams","params","state","screen","routes","name","undefined","useLinkProps","to","action","root","React","useContext","NavigationContainerRefContext","navigation","NavigationHelpersContext","options","LinkingContext","linkTo","useLinkTo","onPress","e","shouldHandle","Platform","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","includes","currentTarget","target","preventDefault","dispatch","Error","getPathFromStateHelper","getPathFromState","href","config","accessibilityRole"],"sourceRoot":"../../src","sources":["useLinkProps.tsx"],"mappings":";;;;;;AAAA;AASA;AACA;AAEA;AACA;AAA4C;AAAA;AAAA;AAO5C,MAAMA,kBAAkB,GACtBC,MAAyE,IACT;EAChE,IAAIA,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEC,KAAK,EAAE;IACjB,OAAOD,MAAM,CAACC,KAAK;EACrB;EAEA,IAAID,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEE,MAAM,EAAE;IAClB,OAAO;MACLC,MAAM,EAAE,CACN;QACEC,IAAI,EAAEJ,MAAM,CAACE,MAAM;QACnBF,MAAM,EAAEA,MAAM,CAACA,MAAM;QACrB;QACAC,KAAK,EAAED,MAAM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M,EAAE;QACV,IAAIK,UAAU,EAAE;UACdA,UAAU,CAACqB,QAAQ,CAAC1B,MAAM,CAAC;QAC7B,CAAC,MAAM,IAAIC,IAAI,EAAE;UACfA,IAAI,CAACyB,QAAQ,CAAC1B,MAAM,CAAC;QACvB,CAAC,MAAM;UACL,MAAM,IAAI2B,KAAK,CACb,kFAAkF,CACnF;QACH;MACF,CAAC,MAAM;QACLlB,MAAM,CAACV,EAAE,CAAC;MACZ;IACF;EACF,CAAC;EAED,MAAM6B,sBAAsB,GAAG,CAAArB,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEsB,gBAAgB,KAAIA,sBAAgB;EAE5E,MAAMC,IAAI,GACR,OAAO/B,EAAE,KAAK,QAAQ,GAClBA,EAAE,GACF6B,sBAAsB,CACpB;IACEjC,MAAM,EAAE,CACN;MACEC,IAAI,EAAEG,EAAE,CAACL,MAAM;MACf;MACAF,MAAM,EAAEO,EAAE,CAACP,MAAM;MACjB;MACAC,KAAK,EAAEF,kBAAkB,CAACQ,EAAE,CAACP,MAAM;IACrC,CAAC;EAEL,CAAC,EACDe,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEwB,MAAM,CAChB;EAEP,OAAO;IACLD,IAAI;IACJE,iBAAiB,EAAE,MAAe;IAClCrB;EACF,CAAC;AACH"} |
@@ -7,46 +7,33 @@ "use strict"; | ||
| exports.default = useLinkTo; | ||
| var _core = require("@react-navigation/core"); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _core = require("@react-navigation/core"); | ||
| var _LinkingContext = _interopRequireDefault(require("./LinkingContext")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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 useLinkTo() { | ||
| const navigation = React.useContext(_core.NavigationContext); | ||
| const navigation = React.useContext(_core.NavigationContainerRefContext); | ||
| const linking = React.useContext(_LinkingContext.default); | ||
| const linkTo = React.useCallback(path => { | ||
| if (!path.startsWith('/')) { | ||
| throw new Error("The path must start with '/' (".concat(path, ").")); | ||
| } | ||
| const linkTo = React.useCallback(to => { | ||
| if (navigation === undefined) { | ||
| throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?"); | ||
| throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?"); | ||
| } | ||
| if (typeof to !== 'string') { | ||
| // @ts-expect-error: This is fine | ||
| navigation.navigate(to.screen, to.params); | ||
| return; | ||
| } | ||
| if (!to.startsWith('/')) { | ||
| throw new Error(`The path must start with '/' (${to}).`); | ||
| } | ||
| const { | ||
| options | ||
| } = linking; | ||
| const state = options !== null && options !== void 0 && options.getStateFromPath ? options.getStateFromPath(path, options.config) : (0, _core.getStateFromPath)(path, options === null || options === void 0 ? void 0 : options.config); | ||
| const state = options !== null && options !== void 0 && options.getStateFromPath ? options.getStateFromPath(to, options.config) : (0, _core.getStateFromPath)(to, options === null || options === void 0 ? void 0 : options.config); | ||
| if (state) { | ||
| let root = navigation; | ||
| let current; // Traverse up to get the root navigation | ||
| while (current = root.getParent()) { | ||
| root = current; | ||
| } | ||
| const action = (0, _core.getActionFromState)(state, options === null || options === void 0 ? void 0 : options.config); | ||
| if (action !== undefined) { | ||
| root.dispatch(action); | ||
| navigation.dispatch(action); | ||
| } else { | ||
| root.reset(state); | ||
| navigation.reset(state); | ||
| } | ||
@@ -53,0 +40,0 @@ } else { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinkTo.tsx"],"names":["useLinkTo","navigation","React","useContext","NavigationContext","linking","LinkingContext","linkTo","useCallback","path","startsWith","Error","undefined","options","state","getStateFromPath","config","root","current","getParent","action","dispatch","reset"],"mappings":";;;;;;;AAAA;;AACA;;AAKA;;;;;;;;AAEe,SAASA,SAAT,GAAqB;AAClC,QAAMC,UAAU,GAAGC,KAAK,CAACC,UAAN,CAAiBC,uBAAjB,CAAnB;AACA,QAAMC,OAAO,GAAGH,KAAK,CAACC,UAAN,CAAiBG,uBAAjB,CAAhB;AAEA,QAAMC,MAAM,GAAGL,KAAK,CAACM,WAAN,CACZC,IAAD,IAAkB;AAChB,QAAI,CAACA,IAAI,CAACC,UAAL,CAAgB,GAAhB,CAAL,EAA2B;AACzB,YAAM,IAAIC,KAAJ,yCAA2CF,IAA3C,QAAN;AACD;;AAED,QAAIR,UAAU,KAAKW,SAAnB,EAA8B;AAC5B,YAAM,IAAID,KAAJ,CACJ,sFADI,CAAN;AAGD;;AAED,UAAM;AAAEE,MAAAA;AAAF,QAAcR,OAApB;AAEA,UAAMS,KAAK,GAAGD,OAAO,SAAP,IAAAA,OAAO,WAAP,IAAAA,OAAO,CAAEE,gBAAT,GACVF,OAAO,CAACE,gBAAR,CAAyBN,IAAzB,EAA+BI,OAAO,CAACG,MAAvC,CADU,GAEV,4BAAiBP,IAAjB,EAAuBI,OAAvB,aAAuBA,OAAvB,uBAAuBA,OAAO,CAAEG,MAAhC,CAFJ;;AAIA,QAAIF,KAAJ,EAAW;AACT,UAAIG,IAAI,GAAGhB,UAAX;AACA,UAAIiB,OAAJ,CAFS,CAIT;;AACA,aAAQA,OAAO,GAAGD,IAAI,CAACE,SAAL,EAAlB,EAAqC;AACnCF,QAAAA,IAAI,GAAGC,OAAP;AACD;;AAED,YAAME,MAAM,GAAG,8BAAmBN,KAAnB,EAA0BD,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAEG,MAAnC,CAAf;;AAEA,UAAII,MAAM,KAAKR,SAAf,EAA0B;AACxBK,QAAAA,IAAI,CAACI,QAAL,CAAcD,MAAd;AACD,OAFD,MAEO;AACLH,QAAAA,IAAI,CAACK,KAAL,CAAWR,KAAX;AACD;AACF,KAhBD,MAgBO;AACL,YAAM,IAAIH,KAAJ,CAAU,iDAAV,CAAN;AACD;AACF,GArCY,EAsCb,CAACN,OAAD,EAAUJ,UAAV,CAtCa,CAAf;AAyCA,SAAOM,MAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {\n getStateFromPath,\n getActionFromState,\n NavigationContext,\n} from '@react-navigation/core';\nimport LinkingContext from './LinkingContext';\n\nexport default function useLinkTo() {\n const navigation = React.useContext(NavigationContext);\n const linking = React.useContext(LinkingContext);\n\n const linkTo = React.useCallback(\n (path: string) => {\n if (!path.startsWith('/')) {\n throw new Error(`The path must start with '/' (${path}).`);\n }\n\n if (navigation === undefined) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside a screen in a navigator?\"\n );\n }\n\n const { options } = linking;\n\n const state = options?.getStateFromPath\n ? options.getStateFromPath(path, options.config)\n : getStateFromPath(path, options?.config);\n\n if (state) {\n let root = navigation;\n let current;\n\n // Traverse up to get the root navigation\n while ((current = root.getParent())) {\n root = current;\n }\n\n const action = getActionFromState(state, options?.config);\n\n if (action !== undefined) {\n root.dispatch(action);\n } else {\n root.reset(state);\n }\n } else {\n throw new Error('Failed to parse the path to a navigation state.');\n }\n },\n [linking, navigation]\n );\n\n return linkTo;\n}\n"]} | ||
| {"version":3,"names":["useLinkTo","navigation","React","useContext","NavigationContainerRefContext","linking","LinkingContext","linkTo","useCallback","to","undefined","Error","navigate","screen","params","startsWith","options","state","getStateFromPath","config","action","getActionFromState","dispatch","reset"],"sourceRoot":"../../src","sources":["useLinkTo.tsx"],"mappings":";;;;;;AAAA;AAKA;AAEA;AAA8C;AAAA;AAAA;AAiB/B,SAASA,SAAS,GAE7B;EACF,MAAMC,UAAU,GAAGC,KAAK,CAACC,UAAU,CAACC,mCAA6B,CAAC;EAClE,MAAMC,OAAO,GAAGH,KAAK,CAACC,UAAU,CAACG,uBAAc,CAAC;EAEhD,MAAMC,MAAM,GAAGL,KAAK,CAACM,WAAW,CAC7BC,EAAiB,IAAK;IACrB,IAAIR,UAAU,KAAKS,SAAS,EAAE;MAC5B,MAAM,IAAIC,KAAK,CACb,kFAAkF,CACnF;IACH;IAEA,IAAI,OAAOF,EAAE,KAAK,QAAQ,EAAE;MAC1B;MACAR,UAAU,CAACW,QAAQ,CAACH,EAAE,CAACI,MAAM,EAAEJ,EAAE,CAACK,MAAM,CAAC;MACzC;IACF;IAEA,IAAI,CAACL,EAAE,CAACM,UAAU,CAAC,GAAG,CAAC,EAAE;MACvB,MAAM,IAAIJ,KAAK,CAAE,iCAAgCF,EAAG,IAAG,CAAC;IAC1D;IAEA,MAAM;MAAEO;IAAQ,CAAC,GAAGX,OAAO;IAE3B,MAAMY,KAAK,GAAGD,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEE,gBAAgB,GACnCF,OAAO,CAACE,gBAAgB,CAACT,EAAE,EAAEO,OAAO,CAACG,MAAM,CAAC,GAC5C,IAAAD,sBAAgB,EAACT,EAAE,EAAEO,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEG,MAAM,CAAC;IAEzC,IAAIF,KAAK,EAAE;MACT,MAAMG,MAAM,GAAG,IAAAC,wBAAkB,EAACJ,KAAK,EAAED,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEG,MAAM,CAAC;MAEzD,IAAIC,MAAM,KAAKV,SAAS,EAAE;QACxBT,UAAU,CAACqB,QAAQ,CAACF,MAAM,CAAC;MAC7B,CAAC,MAAM;QACLnB,UAAU,CAACsB,KAAK,CAACN,KAAK,CAAC;MACzB;IACF,CAAC,MAAM;MACL,MAAM,IAAIN,KAAK,CAAC,iDAAiD,CAAC;IACpE;EACF,CAAC,EACD,CAACN,OAAO,EAAEJ,UAAU,CAAC,CACtB;EAED,OAAOM,MAAM;AACf"} |
@@ -7,11 +7,6 @@ "use strict"; | ||
| exports.default = useScrollToTop; | ||
| var _core = require("@react-navigation/core"); | ||
| var React = _interopRequireWildcard(require("react")); | ||
| var _core = require("@react-navigation/core"); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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 getScrollableNode(ref) { | ||
@@ -21,3 +16,2 @@ if (ref.current == null) { | ||
| } | ||
| if ('scrollToTop' in ref.current || 'scrollTo' in ref.current || 'scrollToOffset' in ref.current || 'scrollResponderScrollTo' in ref.current) { | ||
@@ -40,3 +34,2 @@ // This is already a scrollable node. | ||
| } | ||
| function useScrollToTop(ref) { | ||
@@ -46,52 +39,61 @@ const navigation = (0, _core.useNavigation)(); | ||
| React.useEffect(() => { | ||
| let current = navigation; // The screen might be inside another navigator such as stack nested in tabs | ||
| // We need to find the closest tab navigator and add the listener there | ||
| let tabNavigations = []; | ||
| let currentNavigation = navigation; | ||
| while (current && current.getState().type !== 'tab') { | ||
| current = current.getParent(); | ||
| // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them | ||
| // So we need to find all the parent tab navigators and add the listeners there | ||
| while (currentNavigation) { | ||
| if (currentNavigation.getState().type === 'tab') { | ||
| tabNavigations.push(currentNavigation); | ||
| } | ||
| currentNavigation = currentNavigation.getParent(); | ||
| } | ||
| if (!current) { | ||
| if (tabNavigations.length === 0) { | ||
| return; | ||
| } | ||
| const unsubscribers = tabNavigations.map(tab => { | ||
| return tab.addListener( | ||
| // We don't wanna import tab types here to avoid extra deps | ||
| // in addition, there are multiple tab implementations | ||
| // @ts-expect-error | ||
| 'tabPress', e => { | ||
| // We should scroll to top only when the screen is focused | ||
| const isFocused = navigation.isFocused(); | ||
| const unsubscribe = current.addListener( // We don't wanna import tab types here to avoid extra deps | ||
| // in addition, there are multiple tab implementations | ||
| // @ts-expect-error | ||
| 'tabPress', e => { | ||
| // We should scroll to top only when the screen is focused | ||
| const isFocused = navigation.isFocused(); // In a nested stack navigator, tab press resets the stack to first screen | ||
| // So we should scroll to top only when we are on first screen | ||
| // In a nested stack navigator, tab press resets the stack to first screen | ||
| // So we should scroll to top only when we are on first screen | ||
| const isFirst = tabNavigations.includes(navigation) || navigation.getState().routes[0].key === route.key; | ||
| const isFirst = navigation === current || navigation.getState().routes[0].key === route.key; // Run the operation in the next frame so we're sure all listeners have been run | ||
| // This is necessary to know if preventDefault() has been called | ||
| requestAnimationFrame(() => { | ||
| const scrollable = getScrollableNode(ref); | ||
| if (isFocused && isFirst && scrollable && !e.defaultPrevented) { | ||
| if ('scrollToTop' in scrollable) { | ||
| scrollable.scrollToTop(); | ||
| } else if ('scrollTo' in scrollable) { | ||
| scrollable.scrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollToOffset' in scrollable) { | ||
| scrollable.scrollToOffset({ | ||
| offset: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollResponderScrollTo' in scrollable) { | ||
| scrollable.scrollResponderScrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| // Run the operation in the next frame so we're sure all listeners have been run | ||
| // This is necessary to know if preventDefault() has been called | ||
| requestAnimationFrame(() => { | ||
| const scrollable = getScrollableNode(ref); | ||
| if (isFocused && isFirst && scrollable && !e.defaultPrevented) { | ||
| if ('scrollToTop' in scrollable) { | ||
| scrollable.scrollToTop(); | ||
| } else if ('scrollTo' in scrollable) { | ||
| scrollable.scrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollToOffset' in scrollable) { | ||
| scrollable.scrollToOffset({ | ||
| offset: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollResponderScrollTo' in scrollable) { | ||
| scrollable.scrollResponderScrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| return unsubscribe; | ||
| return () => { | ||
| unsubscribers.forEach(unsubscribe => unsubscribe()); | ||
| }; | ||
| }, [navigation, ref, route.key]); | ||
| } | ||
| //# sourceMappingURL=useScrollToTop.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useScrollToTop.tsx"],"names":["getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","route","React","useEffect","getState","type","getParent","unsubscribe","addListener","e","isFocused","isFirst","routes","key","requestAnimationFrame","scrollable","defaultPrevented","scrollToTop","scrollTo","y","animated","scrollToOffset","offset","scrollResponderScrollTo"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAeA,SAASA,iBAAT,CAA2BC,GAA3B,EAAoE;AAClE,MAAIA,GAAG,CAACC,OAAJ,IAAe,IAAnB,EAAyB;AACvB,WAAO,IAAP;AACD;;AAED,MACE,iBAAiBD,GAAG,CAACC,OAArB,IACA,cAAcD,GAAG,CAACC,OADlB,IAEA,oBAAoBD,GAAG,CAACC,OAFxB,IAGA,6BAA6BD,GAAG,CAACC,OAJnC,EAKE;AACA;AACA,WAAOD,GAAG,CAACC,OAAX;AACD,GARD,MAQO,IAAI,wBAAwBD,GAAG,CAACC,OAAhC,EAAyC;AAC9C;AACA;AACA,WAAOD,GAAG,CAAC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AA,UAAU,CAACG,QAAX,CAAoB;AAAEC,cAAAA,CAAC,EAAE,CAAL;AAAQC,cAAAA,QAAQ,EAAE;AAAlB,aAApB;AACD,WAFM,MAEA,IAAI,oBAAoBL,UAAxB,EAAoC;AACzCA,YAAAA,UAAU,CAACM,cAAX,CAA0B;AAAEC,cAAAA,MAAM,EAAE,CAAV;AAAaF,cAAAA,QAAQ,EAAE;AAAvB,aAA1B;AACD,WAFM,MAEA,IAAI,6BAA6BL,UAAjC,EAA6C;AAClDA,YAAAA,UAAU,CAACQ,uBAAX,CAAmC;AAAEJ,cAAAA,CAAC,EAAE,CAAL;AAAQC,cAAAA,QAAQ,EAAE;AAAlB,aAAnC;AACD;AACF;AACF,OAdoB,CAArB;AAeD,KAhCiB,CAApB;AAmCA,WAAOb,WAAP;AACD,GAjDD,EAiDG,CAACP,UAAD,EAAaL,GAAb,EAAkBM,KAAK,CAACY,GAAxB,CAjDH;AAkDD","sourcesContent":["import * as React from 'react';\nimport { useNavigation, useRoute, EventArg } from '@react-navigation/core';\n\ntype ScrollOptions = { y?: number; animated?: boolean };\n\ntype ScrollableView =\n | { scrollToTop(): void }\n | { scrollTo(options: ScrollOptions): void }\n | { scrollToOffset(options: { offset?: number; animated?: boolean }): void }\n | { scrollResponderScrollTo(options: ScrollOptions): void };\n\ntype ScrollableWrapper =\n | { getScrollResponder(): React.ReactNode }\n | { getNode(): ScrollableView }\n | ScrollableView;\n\nfunction getScrollableNode(ref: React.RefObject<ScrollableWrapper>) {\n if (ref.current == null) {\n return null;\n }\n\n if (\n 'scrollToTop' in ref.current ||\n 'scrollTo' in ref.current ||\n 'scrollToOffset' in ref.current ||\n 'scrollResponderScrollTo' in ref.current\n ) {\n // This is already a scrollable node.\n return ref.current;\n } else if ('getScrollResponder' in ref.current) {\n // If the view is a wrapper like FlatList, SectionList etc.\n // We need to use `getScrollResponder` to get access to the scroll responder\n return ref.current.getScrollResponder();\n } else if ('getNode' in ref.current) {\n // When a `ScrollView` is wraped in `Animated.createAnimatedComponent`\n // we need to use `getNode` to get the ref to the actual scrollview.\n // Note that `getNode` is deprecated in newer versions of react-native\n // this is why we check if we already have a scrollable node above.\n return ref.current.getNode();\n } else {\n return ref.current;\n }\n}\n\nexport default function useScrollToTop(\n ref: React.RefObject<ScrollableWrapper>\n) {\n const navigation = useNavigation();\n const route = useRoute();\n\n React.useEffect(() => {\n let current = navigation;\n\n // The screen might be inside another navigator such as stack nested in tabs\n // We need to find the closest tab navigator and add the listener there\n while (current && current.getState().type !== 'tab') {\n current = current.getParent();\n }\n\n if (!current) {\n return;\n }\n\n const unsubscribe = current.addListener(\n // We don't wanna import tab types here to avoid extra deps\n // in addition, there are multiple tab implementations\n // @ts-expect-error\n 'tabPress',\n (e: EventArg<'tabPress', true>) => {\n // We should scroll to top only when the screen is focused\n const isFocused = navigation.isFocused();\n\n // In a nested stack navigator, tab press resets the stack to first screen\n // So we should scroll to top only when we are on first screen\n const isFirst =\n navigation === current ||\n navigation.getState().routes[0].key === route.key;\n\n // Run the operation in the next frame so we're sure all listeners have been run\n // This is necessary to know if preventDefault() has been called\n requestAnimationFrame(() => {\n const scrollable = getScrollableNode(ref) as ScrollableWrapper;\n\n if (isFocused && isFirst && scrollable && !e.defaultPrevented) {\n if ('scrollToTop' in scrollable) {\n scrollable.scrollToTop();\n } else if ('scrollTo' in scrollable) {\n scrollable.scrollTo({ y: 0, animated: true });\n } else if ('scrollToOffset' in scrollable) {\n scrollable.scrollToOffset({ offset: 0, animated: true });\n } else if ('scrollResponderScrollTo' in scrollable) {\n scrollable.scrollResponderScrollTo({ y: 0, animated: true });\n }\n }\n });\n }\n );\n\n return unsubscribe;\n }, [navigation, ref, route.key]);\n}\n"]} | ||
| {"version":3,"names":["getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","useNavigation","route","useRoute","React","useEffect","tabNavigations","currentNavigation","getState","type","push","getParent","length","unsubscribers","map","tab","addListener","e","isFocused","isFirst","includes","routes","key","requestAnimationFrame","scrollable","defaultPrevented","scrollToTop","scrollTo","y","animated","scrollToOffset","offset","scrollResponderScrollTo","forEach","unsubscribe"],"sourceRoot":"../../src","sources":["useScrollToTop.tsx"],"mappings":";;;;;;AAAA;AAMA;AAA+B;AAAA;AAgB/B,SAASA,iBAAiB,CAACC,GAAuC,EAAE;EAClE,IAAIA,GAAG,CAACC,OAAO,IAAI,IAAI,EAAE;IACvB,OAAO,IAAI;EACb;EAEA,IACE,aAAa,IAAID,GAAG,CAACC,OAAO,IAC5B,UAAU,IAAID,GAAG,CAACC,OAAO,IACzB,gBAAgB,IAAID,GAAG,CAACC,OAAO,IAC/B,yBAAyB,IAAID,GAAG,CAACC,OAAO,EACxC;IACA;IACA,OAAOD,GAAG,CAACC,OAAO;EACpB,CAAC,MAAM,IAAI,oBAAoB,IAAID,GAAG,CAACC,OAAO,EAAE;IAC9C;IACA;IACA,OAAOD,GAAG,CAACC,OAAO,CAACC,kBAAkB,EAAE;EACzC,CAAC,MAAM,IAAI,SAAS,IAAIF,GAAG,CAACC,OAAO,EAAE;IACnC;IACA;IACA;IACA;IACA,OAAOD,GAAG,CAACC,OAAO,CAACE,OAAO,EAAE;EAC9B,CAAC,MAAM;IACL,OAAOH,GAAG,CAACC,OAAO;EACpB;AACF;AAEe,SAASG,cAAc,CACpCJ,GAAuC,EACvC;EACA,MAAMK,UAAU,GAAG,IAAAC,mBAAa,GAAE;EAClC,MAAMC,KAAK,GAAG,IAAAC,cAAQ,GAAE;EAExBC,KAAK,CAACC,SAAS,CAAC,MAAM;IACpB,IAAIC,cAA+D,GAAG,EAAE;IACxE,IAAIC,iBAAiB,GAAGP,UAAU;;IAElC;IACA;IACA,OAAOO,iBAAiB,EAAE;MACxB,IAAIA,iBAAiB,CAACC,QAAQ,EAAE,CAACC,IAAI,KAAK,KAAK,EAAE;QAC/CH,cAAc,CAACI,IAAI,CAACH,iBAAiB,CAAC;MACxC;MAEAA,iBAAiB,GAAGA,iBAAiB,CAACI,SAAS,EAAE;IACnD;IAE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aAAa,CAACoB,OAAO,CAAEC,WAAW,IAAKA,WAAW,EAAE,CAAC;IACvD,CAAC;EACH,CAAC,EAAE,CAAClC,UAAU,EAAEL,GAAG,EAAEO,KAAK,CAACoB,GAAG,CAAC,CAAC;AAClC"} |
@@ -7,13 +7,10 @@ "use strict"; | ||
| exports.default = useThenable; | ||
| var React = _interopRequireWildcard(require("react")); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _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 useThenable(create) { | ||
| const [promise] = React.useState(create); | ||
| let initialState = [false, undefined]; // Check if our thenable is synchronous | ||
| let initialState = [false, undefined]; | ||
| // Check if our thenable is synchronous | ||
| promise.then(result => { | ||
@@ -26,6 +23,4 @@ initialState = [true, result]; | ||
| let cancelled = false; | ||
| const resolve = async () => { | ||
| let result; | ||
| try { | ||
@@ -39,7 +34,5 @@ result = await promise; | ||
| }; | ||
| if (!resolved) { | ||
| resolve(); | ||
| } | ||
| return () => { | ||
@@ -46,0 +39,0 @@ cancelled = true; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useThenable.tsx"],"names":["useThenable","create","promise","React","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"mappings":";;;;;;;AAAA;;;;;;AAEe,SAASA,WAAT,CAAwBC,MAAxB,EAAsD;AACnE,QAAM,CAACC,OAAD,IAAYC,KAAK,CAACC,QAAN,CAAeH,MAAf,CAAlB;AAEA,MAAII,YAAsC,GAAG,CAAC,KAAD,EAAQC,SAAR,CAA7C,CAHmE,CAKnE;;AACAJ,EAAAA,OAAO,CAACK,IAAR,CAAcC,MAAD,IAAY;AACvBH,IAAAA,YAAY,GAAG,CAAC,IAAD,EAAOG,MAAP,CAAf;AACD,GAFD;AAIA,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBP,KAAK,CAACC,QAAN,CAAeC,YAAf,CAA1B;AACA,QAAM,CAACM,QAAD,IAAaF,KAAnB;AAEAN,EAAAA,KAAK,CAACS,SAAN,CAAgB,MAAM;AACpB,QAAIC,SAAS,GAAG,KAAhB;;AAEA,UAAMC,OAAO,GAAG,YAAY;AAC1B,UAAIN,MAAJ;;AAEA,UAAI;AACFA,QAAAA,MAAM,GAAG,MAAMN,OAAf;AACD,OAFD,SAEU;AACR,YAAI,CAACW,SAAL,EAAgB;AACdH,UAAAA,QAAQ,CAAC,CAAC,IAAD,EAAOF,MAAP,CAAD,CAAR;AACD;AACF;AACF,KAVD;;AAYA,QAAI,CAACG,QAAL,EAAe;AACbG,MAAAA,OAAO;AACR;;AAED,WAAO,MAAM;AACXD,MAAAA,SAAS,GAAG,IAAZ;AACD,KAFD;AAGD,GAtBD,EAsBG,CAACX,OAAD,EAAUS,QAAV,CAtBH;AAwBA,SAAOF,KAAP;AACD","sourcesContent":["import * as React from 'react';\n\nexport default function useThenable<T>(create: () => PromiseLike<T>) {\n const [promise] = React.useState(create);\n\n let initialState: [boolean, T | undefined] = [false, undefined];\n\n // Check if our thenable is synchronous\n promise.then((result) => {\n initialState = [true, result];\n });\n\n const [state, setState] = React.useState(initialState);\n const [resolved] = state;\n\n React.useEffect(() => {\n let cancelled = false;\n\n const resolve = async () => {\n let result;\n\n try {\n result = await promise;\n } finally {\n if (!cancelled) {\n setState([true, result]);\n }\n }\n };\n\n if (!resolved) {\n resolve();\n }\n\n return () => {\n cancelled = true;\n };\n }, [promise, resolved]);\n\n return state;\n}\n"]} | ||
| {"version":3,"names":["useThenable","create","promise","React","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"sourceRoot":"../../src","sources":["useThenable.tsx"],"mappings":";;;;;;AAAA;AAA+B;AAAA;AAEhB,SAASA,WAAW,CAAIC,MAA4B,EAAE;EACnE,MAAM,CAACC,OAAO,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAACH,MAAM,CAAC;EAExC,IAAII,YAAsC,GAAG,CAAC,KAAK,EAAEC,SAAS,CAAC;;EAE/D;EACAJ,OAAO,CAACK,IAAI,CAAEC,MAAM,IAAK;IACvBH,YAAY,GAAG,CAAC,IAAI,EAAEG,MAAM,CAAC;EAC/B,CAAC,CAAC;EAEF,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACC,QAAQ,CAACC,YAAY,CAAC;EACtD,MAAM,CAACM,QAAQ,CAAC,GAAGF,KAAK;EAExBN,KAAK,CAACS,SAAS,CAAC,MAAM;IACpB,IAAIC,SAAS,GAAG,KAAK;IAErB,MAAMC,OAAO,GAAG,YAAY;MAC1B,IAAIN,MAAM;MAEV,IAAI;QACFA,MAAM,GAAG,MAAMN,OAAO;MACxB,CAAC,SAAS;QACR,IAAI,CAACW,SAAS,EAAE;UACdH,QAAQ,CAAC,CAAC,IAAI,EAAEF,MAAM,CAAC,CAAC;QAC1B;MACF;IACF,CAAC;IAED,IAAI,CAACG,QAAQ,EAAE;MACbG,OAAO,EAAE;IACX;IAEA,OAAO,MAAM;MACXD,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CAACX,OAAO,EAAES,QAAQ,CAAC,CAAC;EAEvB,OAAOF,KAAK;AACd"} |
| import escapeStringRegexp from 'escape-string-regexp'; | ||
| export default function extractPathFromURL(prefixes, url) { | ||
| for (const prefix of prefixes) { | ||
| var _prefix$match$, _prefix$match; | ||
| const protocol = (_prefix$match$ = (_prefix$match = prefix.match(/^[^:]+:/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[0]) !== null && _prefix$match$ !== void 0 ? _prefix$match$ : ''; | ||
| const host = prefix.replace(new RegExp("^".concat(escapeStringRegexp(protocol))), '').replace(/\/+/g, '/') // Replace multiple slash (//) with single ones | ||
| var _prefix$match; | ||
| const protocol = ((_prefix$match = prefix.match(/^[^:]+:/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[0]) ?? ''; | ||
| const host = prefix.replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '').replace(/\/+/g, '/') // Replace multiple slash (//) with single ones | ||
| .replace(/^\//, ''); // Remove extra leading slash | ||
| const prefixRegex = new RegExp("^".concat(escapeStringRegexp(protocol), "(/)*").concat(host.split('.').map(it => it === '*' ? '[^/]+' : escapeStringRegexp(it)).join('\\.'))); | ||
| const normalizedURL = url.replace(/\/+/g, '/'); | ||
| const prefixRegex = new RegExp(`^${escapeStringRegexp(protocol)}(/)*${host.split('.').map(it => it === '*' ? '[^/]+' : escapeStringRegexp(it)).join('\\.')}`); | ||
| const [originAndPath, searchParams] = url.split('?'); | ||
| const normalizedURL = originAndPath.replace(/\/+/g, '/').concat(searchParams ? `?${searchParams}` : ''); | ||
| if (prefixRegex.test(normalizedURL)) { | ||
@@ -17,5 +16,4 @@ return normalizedURL.replace(prefixRegex, ''); | ||
| } | ||
| return undefined; | ||
| } | ||
| //# sourceMappingURL=extractPathFromURL.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["extractPathFromURL.tsx"],"names":["escapeStringRegexp","extractPathFromURL","prefixes","url","prefix","protocol","match","host","replace","RegExp","prefixRegex","split","map","it","join","normalizedURL","test","undefined"],"mappings":"AAAA,OAAOA,kBAAP,MAA+B,sBAA/B;AAEA,eAAe,SAASC,kBAAT,CAA4BC,QAA5B,EAAgDC,GAAhD,EAA6D;AAC1E,OAAK,MAAMC,MAAX,IAAqBF,QAArB,EAA+B;AAAA;;AAC7B,UAAMG,QAAQ,sCAAGD,MAAM,CAACE,KAAP,CAAa,SAAb,CAAH,kDAAG,cAA0B,CAA1B,CAAH,2DAAmC,EAAjD;AACA,UAAMC,IAAI,GAAGH,MAAM,CAChBI,OADU,CACF,IAAIC,MAAJ,YAAeT,kBAAkB,CAACK,QAAD,CAAjC,EADE,EAC8C,EAD9C,EAEVG,OAFU,CAEF,MAFE,EAEM,GAFN,EAEW;AAFX,KAGVA,OAHU,CAGF,KAHE,EAGK,EAHL,CAAb,CAF6B,CAKN;;AAEvB,UAAME,WAAW,GAAG,IAAID,MAAJ,YACdT,kBAAkB,CAACK,QAAD,CADJ,iBACqBE,IAAI,CACxCI,KADoC,CAC9B,GAD8B,EAEpCC,GAFoC,CAE/BC,EAAD,IAASA,EAAE,KAAK,GAAP,GAAa,OAAb,GAAuBb,kBAAkB,CAACa,EAAD,CAFlB,EAGpCC,IAHoC,CAG/B,KAH+B,CADrB,EAApB;AAOA,UAAMC,aAAa,GAAGZ,GAAG,CAACK,OAAJ,CAAY,MAAZ,EAAoB,GAApB,CAAtB;;AAEA,QAAIE,WAAW,CAACM,IAAZ,CAAiBD,aAAjB,CAAJ,EAAqC;AACnC,aAAOA,aAAa,CAACP,OAAd,CAAsBE,WAAtB,EAAmC,EAAnC,CAAP;AACD;AACF;;AAED,SAAOO,SAAP;AACD","sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nexport default function extractPathFromURL(prefixes: string[], url: string) {\n for (const prefix of prefixes) {\n const protocol = prefix.match(/^[^:]+:/)?.[0] ?? '';\n const host = prefix\n .replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '')\n .replace(/\\/+/g, '/') // Replace multiple slash (//) with single ones\n .replace(/^\\//, ''); // Remove extra leading slash\n\n const prefixRegex = new RegExp(\n `^${escapeStringRegexp(protocol)}(/)*${host\n .split('.')\n .map((it) => (it === '*' ? '[^/]+' : escapeStringRegexp(it)))\n .join('\\\\.')}`\n );\n\n const normalizedURL = url.replace(/\\/+/g, '/');\n\n if (prefixRegex.test(normalizedURL)) {\n return normalizedURL.replace(prefixRegex, '');\n }\n }\n\n return undefined;\n}\n"]} | ||
| {"version":3,"names":["escapeStringRegexp","extractPathFromURL","prefixes","url","prefix","protocol","match","host","replace","RegExp","prefixRegex","split","map","it","join","originAndPath","searchParams","normalizedURL","concat","test","undefined"],"sourceRoot":"../../src","sources":["extractPathFromURL.tsx"],"mappings":"AAAA,OAAOA,kBAAkB,MAAM,sBAAsB;AAErD,eAAe,SAASC,kBAAkB,CAACC,QAAkB,EAAEC,GAAW,EAAE;EAC1E,KAAK,MAAMC,MAAM,IAAIF,QAAQ,EAAE;IAAA;IAC7B,MAAMG,QAAQ,GAAG,kBAAAD,MAAM,CAACE,KAAK,CAAC,SAAS,CAAC,kDAAvB,cAA0B,CAAC,CAAC,KAAI,EAAE;IACnD,MAAMC,IAAI,GAAGH,MAAM,CAChBI,OAAO,CAAC,IAAIC,MAAM,CAAE,IAAGT,kBAAkB,CAACK,QAAQ,CAAE,EAAC,CAAC,EAAE,EAAE,CAAC,CAC3DG,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAA,CACrBA,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;;IAEvB,MAAME,WAAW,GAAG,IAAID,MAAM,CAC3B,IAAGT,kBAAkB,CAACK,QAAQ,CAAE,OAAME,IAAI,CACxCI,KAAK,CAAC,GAAG,CAAC,CACVC,GAAG,CAAEC,EAAE,IAAMA,EAAE,KAAK,GAAG,GAAG,OAAO,GAAGb,kBAAkB,CAACa,EAAE,CAAE,CAAC,CAC5DC,IAAI,CAAC,KAAK,CAAE,EAAC,CACjB;IAED,MAAM,CAACC,aAAa,EAAEC,YAAY,CAAC,GAAGb,GAAG,CAACQ,KAAK,CAAC,GAAG,CAAC;IACpD,MAAMM,aAAa,GAAGF,aAAa,CAChCP,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CACpBU,MAAM,CAACF,YAAY,GAAI,IAAGA,YAAa,EAAC,GAAG,EAAE,CAAC;IAEjD,IAAIN,WAAW,CAACS,IAAI,CAACF,aAAa,CAAC,EAAE;MACnC,OAAOA,aAAa,CAACT,OAAO,CAACE,WAAW,EAAE,EAAE,CAAC;IAC/C;EACF;EAEA,OAAOU,SAAS;AAClB"} |
+9
-10
@@ -1,16 +0,15 @@ | ||
| export * from '@react-navigation/core'; | ||
| export { default as Link } from './Link'; | ||
| export { default as LinkingContext } from './LinkingContext'; | ||
| export { default as NavigationContainer } from './NavigationContainer'; | ||
| export { default as useBackButton } from './useBackButton'; | ||
| export { default as useScrollToTop } from './useScrollToTop'; | ||
| export { default as ServerContainer } from './ServerContainer'; | ||
| export { default as DarkTheme } from './theming/DarkTheme'; | ||
| export { default as DefaultTheme } from './theming/DefaultTheme'; | ||
| export { default as DarkTheme } from './theming/DarkTheme'; | ||
| export { default as ThemeProvider } from './theming/ThemeProvider'; | ||
| export { default as useTheme } from './theming/useTheme'; | ||
| export { default as Link } from './Link'; | ||
| export { default as useLinking } from './useLinking'; | ||
| export * from './types'; | ||
| export { default as useLinkBuilder } from './useLinkBuilder'; | ||
| export { default as useLinkProps } from './useLinkProps'; | ||
| export { default as useLinkTo } from './useLinkTo'; | ||
| export { default as useLinkProps } from './useLinkProps'; | ||
| export { default as useLinkBuilder } from './useLinkBuilder'; | ||
| export { default as ServerContainer } from './ServerContainer'; | ||
| export * from './types'; | ||
| export { default as useScrollToTop } from './useScrollToTop'; | ||
| export * from '@react-navigation/core'; | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["index.tsx"],"names":["default","NavigationContainer","useBackButton","useScrollToTop","DefaultTheme","DarkTheme","ThemeProvider","useTheme","Link","useLinking","useLinkTo","useLinkProps","useLinkBuilder","ServerContainer"],"mappings":"AAAA,cAAc,wBAAd;AAEA,SAASA,OAAO,IAAIC,mBAApB,QAA+C,uBAA/C;AAEA,SAASD,OAAO,IAAIE,aAApB,QAAyC,iBAAzC;AACA,SAASF,OAAO,IAAIG,cAApB,QAA0C,kBAA1C;AAEA,SAASH,OAAO,IAAII,YAApB,QAAwC,wBAAxC;AACA,SAASJ,OAAO,IAAIK,SAApB,QAAqC,qBAArC;AACA,SAASL,OAAO,IAAIM,aAApB,QAAyC,yBAAzC;AACA,SAASN,OAAO,IAAIO,QAApB,QAAoC,oBAApC;AAEA,SAASP,OAAO,IAAIQ,IAApB,QAAgC,QAAhC;AACA,SAASR,OAAO,IAAIS,UAApB,QAAsC,cAAtC;AACA,SAAST,OAAO,IAAIU,SAApB,QAAqC,aAArC;AACA,SAASV,OAAO,IAAIW,YAApB,QAAwC,gBAAxC;AACA,SAASX,OAAO,IAAIY,cAApB,QAA0C,kBAA1C;AAEA,SAASZ,OAAO,IAAIa,eAApB,QAA2C,mBAA3C;AAEA,cAAc,SAAd","sourcesContent":["export * from '@react-navigation/core';\n\nexport { default as NavigationContainer } from './NavigationContainer';\n\nexport { default as useBackButton } from './useBackButton';\nexport { default as useScrollToTop } from './useScrollToTop';\n\nexport { default as DefaultTheme } from './theming/DefaultTheme';\nexport { default as DarkTheme } from './theming/DarkTheme';\nexport { default as ThemeProvider } from './theming/ThemeProvider';\nexport { default as useTheme } from './theming/useTheme';\n\nexport { default as Link } from './Link';\nexport { default as useLinking } from './useLinking';\nexport { default as useLinkTo } from './useLinkTo';\nexport { default as useLinkProps } from './useLinkProps';\nexport { default as useLinkBuilder } from './useLinkBuilder';\n\nexport { default as ServerContainer } from './ServerContainer';\n\nexport * from './types';\n"]} | ||
| {"version":3,"names":["default","Link","LinkingContext","NavigationContainer","ServerContainer","DarkTheme","DefaultTheme","ThemeProvider","useTheme","useLinkBuilder","useLinkProps","useLinkTo","useScrollToTop"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,OAAO,IAAIC,IAAI,QAAQ,QAAQ;AACxC,SAASD,OAAO,IAAIE,cAAc,QAAQ,kBAAkB;AAC5D,SAASF,OAAO,IAAIG,mBAAmB,QAAQ,uBAAuB;AACtE,SAASH,OAAO,IAAII,eAAe,QAAQ,mBAAmB;AAC9D,SAASJ,OAAO,IAAIK,SAAS,QAAQ,qBAAqB;AAC1D,SAASL,OAAO,IAAIM,YAAY,QAAQ,wBAAwB;AAChE,SAASN,OAAO,IAAIO,aAAa,QAAQ,yBAAyB;AAClE,SAASP,OAAO,IAAIQ,QAAQ,QAAQ,oBAAoB;AACxD,cAAc,SAAS;AACvB,SAASR,OAAO,IAAIS,cAAc,QAAQ,kBAAkB;AAC5D,SAAST,OAAO,IAAIU,YAAY,QAAQ,gBAAgB;AACxD,SAASV,OAAO,IAAIW,SAAS,QAAQ,aAAa;AAClD,SAASX,OAAO,IAAIY,cAAc,QAAQ,kBAAkB;AAC5D,cAAc,wBAAwB"} |
+9
-12
| import * as React from 'react'; | ||
| import { Text, Platform } from 'react-native'; | ||
| import { Platform, Text } from 'react-native'; | ||
| import useLinkProps from './useLinkProps'; | ||
| /** | ||
@@ -13,7 +12,8 @@ * Component to render link to another screen using a path. | ||
| */ | ||
| export default function Link({ | ||
| to, | ||
| action, | ||
| ...rest | ||
| }) { | ||
| export default function Link(_ref) { | ||
| let { | ||
| to, | ||
| action, | ||
| ...rest | ||
| } = _ref; | ||
| const props = useLinkProps({ | ||
@@ -23,14 +23,11 @@ to, | ||
| }); | ||
| const onPress = e => { | ||
| if ('onPress' in rest) { | ||
| var _rest$onPress; | ||
| (_rest$onPress = rest.onPress) === null || _rest$onPress === void 0 ? void 0 : _rest$onPress.call(rest, e); | ||
| } | ||
| props.onPress(e); | ||
| }; | ||
| return /*#__PURE__*/React.createElement(Text, { ...props, | ||
| return /*#__PURE__*/React.createElement(Text, { | ||
| ...props, | ||
| ...rest, | ||
@@ -37,0 +34,0 @@ ...Platform.select({ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["Link.tsx"],"names":["React","Text","Platform","useLinkProps","Link","to","action","rest","props","onPress","e","createElement","select","web","onClick","default"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,IAAT,EAAiDC,QAAjD,QAAiE,cAAjE;AAEA,OAAOC,YAAP,MAAyB,gBAAzB;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,IAAT,CAAc;AAAEC,EAAAA,EAAF;AAAMC,EAAAA,MAAN;AAAc,KAAGC;AAAjB,CAAd,EAA8C;AAC3D,QAAMC,KAAK,GAAGL,YAAY,CAAC;AAAEE,IAAAA,EAAF;AAAMC,IAAAA;AAAN,GAAD,CAA1B;;AAEA,QAAMG,OAAO,GACXC,CADc,IAEX;AACH,QAAI,aAAaH,IAAjB,EAAuB;AAAA;;AACrB,uBAAAA,IAAI,CAACE,OAAL,qEAAAF,IAAI,EAAWG,CAAX,CAAJ;AACD;;AAEDF,IAAAA,KAAK,CAACC,OAAN,CAAcC,CAAd;AACD,GARD;;AAUA,sBAAOV,KAAK,CAACW,aAAN,CAAoBV,IAApB,EAA0B,EAC/B,GAAGO,KAD4B;AAE/B,OAAGD,IAF4B;AAG/B,OAAGL,QAAQ,CAACU,MAAT,CAAgB;AACjBC,MAAAA,GAAG,EAAE;AAAEC,QAAAA,OAAO,EAAEL;AAAX,OADY;AAEjBM,MAAAA,OAAO,EAAE;AAAEN,QAAAA;AAAF;AAFQ,KAAhB;AAH4B,GAA1B,CAAP;AAQD","sourcesContent":["import * as React from 'react';\nimport { Text, TextProps, GestureResponderEvent, Platform } from 'react-native';\nimport type { NavigationAction } from '@react-navigation/core';\nimport useLinkProps from './useLinkProps';\n\ntype Props = {\n to: string;\n action?: NavigationAction;\n target?: string;\n onPress?: (\n e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => void;\n} & (TextProps & { children: React.ReactNode });\n\n/**\n * Component to render link to another screen using a path.\n * Uses an anchor tag on the web.\n *\n * @param props.to Absolute path to screen (e.g. `/feeds/hot`).\n * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.\n * @param props.children Child elements to render the content.\n */\nexport default function Link({ to, action, ...rest }: Props) {\n const props = useLinkProps({ to, action });\n\n const onPress = (\n e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => {\n if ('onPress' in rest) {\n rest.onPress?.(e);\n }\n\n props.onPress(e);\n };\n\n return React.createElement(Text, {\n ...props,\n ...rest,\n ...Platform.select({\n web: { onClick: onPress } as any,\n default: { onPress },\n }),\n });\n}\n"]} | ||
| {"version":3,"names":["React","Platform","Text","useLinkProps","Link","to","action","rest","props","onPress","e","createElement","select","web","onClick","default"],"sourceRoot":"../../src","sources":["Link.tsx"],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAgCC,QAAQ,EAAEC,IAAI,QAAmB,cAAc;AAE/E,OAAOC,YAAY,MAAM,gBAAgB;AAezC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,IAAI,OAIP;EAAA,IAJyD;IAC5EC,EAAE;IACFC,MAAM;IACN,GAAGC;EACa,CAAC;EACjB,MAAMC,KAAK,GAAGL,YAAY,CAAY;IAAEE,EAAE;IAAEC;EAAO,CAAC,CAAC;EAErD,MAAMG,OAAO,GACXC,CAA0E,IACvE;IACH,IAAI,SAAS,IAAIH,IAAI,EAAE;MAAA;MACrB,iBAAAA,IAAI,CAACE,OAAO,kDAAZ,mBAAAF,IAAI,EAAWG,CAAC,CAAC;IACnB;IAEAF,KAAK,CAACC,OAAO,CAACC,CAAC,CAAC;EAClB,CAAC;EAED,oBAAOV,KAAK,CAACW,aAAa,CAACT,IAAI,EAAE;IAC/B,GAAGM,KAAK;IACR,GAAGD,IAAI;IACP,GAAGN,QAAQ,CAACW,MAAM,CAAC;MACjBC,GAAG,EAAE;QAAEC,OAAO,EAAEL;MAAQ,CAAQ;MAChCM,OAAO,EAAE;QAAEN;MAAQ;IACrB,CAAC;EACH,CAAC,CAAC;AACJ"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["LinkingContext.tsx"],"names":["React","LinkingContext","createContext","options","undefined","displayName"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAGA,MAAMC,cAAc,gBAAGD,KAAK,CAACE,aAAN,CAEpB;AAAEC,EAAAA,OAAO,EAAEC;AAAX,CAFoB,CAAvB;AAIAH,cAAc,CAACI,WAAf,GAA6B,gBAA7B;AAEA,eAAeJ,cAAf","sourcesContent":["import * as React from 'react';\nimport type { LinkingOptions } from './types';\n\nconst LinkingContext = React.createContext<{\n options: LinkingOptions | undefined;\n}>({ options: undefined });\n\nLinkingContext.displayName = 'LinkingContext';\n\nexport default LinkingContext;\n"]} | ||
| {"version":3,"names":["React","LinkingContext","createContext","options","undefined","displayName"],"sourceRoot":"../../src","sources":["LinkingContext.tsx"],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAI9B,MAAMC,cAAc,gBAAGD,KAAK,CAACE,aAAa,CAEvC;EAAEC,OAAO,EAAEC;AAAU,CAAC,CAAC;AAE1BH,cAAc,CAACI,WAAW,GAAG,gBAAgB;AAE7C,eAAeJ,cAAc"} |
@@ -1,13 +0,12 @@ | ||
| function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
| function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
| import { BaseNavigationContainer, getActionFromState, getPathFromState, getStateFromPath, validatePathConfig } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { BaseNavigationContainer } from '@react-navigation/core'; | ||
| import LinkingContext from './LinkingContext'; | ||
| import DefaultTheme from './theming/DefaultTheme'; | ||
| import ThemeProvider from './theming/ThemeProvider'; | ||
| import DefaultTheme from './theming/DefaultTheme'; | ||
| import LinkingContext from './LinkingContext'; | ||
| import useBackButton from './useBackButton'; | ||
| import useDocumentTitle from './useDocumentTitle'; | ||
| import useLinking from './useLinking'; | ||
| import useThenable from './useThenable'; | ||
| import useLinking from './useLinking'; | ||
| import useDocumentTitle from './useDocumentTitle'; | ||
| import useBackButton from './useBackButton'; | ||
| global.REACT_NAVIGATION_DEVTOOLS = new WeakMap(); | ||
| /** | ||
@@ -27,11 +26,15 @@ * Container component which holds the navigation state designed for React Native apps. | ||
| */ | ||
| const NavigationContainer = /*#__PURE__*/React.forwardRef(function NavigationContainer({ | ||
| theme = DefaultTheme, | ||
| linking, | ||
| fallback = null, | ||
| documentTitle, | ||
| onReady, | ||
| ...rest | ||
| }, ref) { | ||
| function NavigationContainerInner(_ref, ref) { | ||
| let { | ||
| theme = DefaultTheme, | ||
| linking, | ||
| fallback = null, | ||
| documentTitle, | ||
| onReady, | ||
| ...rest | ||
| } = _ref; | ||
| const isLinkingEnabled = linking ? linking.enabled !== false : false; | ||
| if (linking !== null && linking !== void 0 && linking.config) { | ||
| validatePathConfig(linking.config); | ||
| } | ||
| const refContainer = React.useRef(null); | ||
@@ -43,2 +46,3 @@ useBackButton(refContainer); | ||
| } = useLinking(refContainer, { | ||
| independent: rest.independent, | ||
| enabled: isLinkingEnabled, | ||
@@ -48,2 +52,21 @@ prefixes: [], | ||
| }); | ||
| // Add additional linking related info to the ref | ||
| // This will be used by the devtools | ||
| React.useEffect(() => { | ||
| if (refContainer.current) { | ||
| REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, { | ||
| get linking() { | ||
| return { | ||
| ...linking, | ||
| enabled: isLinkingEnabled, | ||
| prefixes: (linking === null || linking === void 0 ? void 0 : linking.prefixes) ?? [], | ||
| getStateFromPath: (linking === null || linking === void 0 ? void 0 : linking.getStateFromPath) ?? getStateFromPath, | ||
| getPathFromState: (linking === null || linking === void 0 ? void 0 : linking.getPathFromState) ?? getPathFromState, | ||
| getActionFromState: (linking === null || linking === void 0 ? void 0 : linking.getActionFromState) ?? getActionFromState | ||
| }; | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| const [isResolved, initialState] = useThenable(getInitialState); | ||
@@ -62,7 +85,5 @@ React.useImperativeHandle(ref, () => refContainer.current); | ||
| var _onReadyRef$current; | ||
| (_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 ? void 0 : _onReadyRef$current.call(onReadyRef); | ||
| } | ||
| }, [isReady]); | ||
| if (!isReady) { | ||
@@ -73,3 +94,2 @@ // This is temporary until we have Suspense for data-fetching | ||
| } | ||
| return /*#__PURE__*/React.createElement(LinkingContext.Provider, { | ||
@@ -83,4 +103,5 @@ value: linkingContext | ||
| })))); | ||
| }); | ||
| } | ||
| const NavigationContainer = /*#__PURE__*/React.forwardRef(NavigationContainerInner); | ||
| export default NavigationContainer; | ||
| //# sourceMappingURL=NavigationContainer.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["NavigationContainer.tsx"],"names":["React","BaseNavigationContainer","ThemeProvider","DefaultTheme","LinkingContext","useThenable","useLinking","useDocumentTitle","useBackButton","NavigationContainer","forwardRef","theme","linking","fallback","documentTitle","onReady","rest","ref","isLinkingEnabled","enabled","refContainer","useRef","getInitialState","prefixes","isResolved","initialState","useImperativeHandle","current","linkingContext","useMemo","options","isReady","onReadyRef","useEffect"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,uBADF,QAIO,wBAJP;AAKA,OAAOC,aAAP,MAA0B,yBAA1B;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AACA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,gBAAGT,KAAK,CAACU,UAAN,CAAiB,SAASD,mBAAT,CAC3C;AACEE,EAAAA,KAAK,GAAGR,YADV;AAEES,EAAAA,OAFF;AAGEC,EAAAA,QAAQ,GAAG,IAHb;AAIEC,EAAAA,aAJF;AAKEC,EAAAA,OALF;AAME,KAAGC;AANL,CAD2C,EAS3CC,GAT2C,EAU3C;AACA,QAAMC,gBAAgB,GAAGN,OAAO,GAAGA,OAAO,CAACO,OAAR,KAAoB,KAAvB,GAA+B,KAA/D;AAEA,QAAMC,YAAY,GAAGpB,KAAK,CAACqB,MAAN,CAAqC,IAArC,CAArB;AAEAb,EAAAA,aAAa,CAACY,YAAD,CAAb;AACAb,EAAAA,gBAAgB,CAACa,YAAD,EAAeN,aAAf,CAAhB;AAEA,QAAM;AAAEQ,IAAAA;AAAF,MAAsBhB,UAAU,CAACc,YAAD,EAAe;AACnDD,I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AeX,mBAAf","sourcesContent":["import * as React from 'react';\nimport {\n BaseNavigationContainer,\n NavigationContainerProps,\n NavigationContainerRef,\n} from '@react-navigation/core';\nimport ThemeProvider from './theming/ThemeProvider';\nimport DefaultTheme from './theming/DefaultTheme';\nimport LinkingContext from './LinkingContext';\nimport useThenable from './useThenable';\nimport useLinking from './useLinking';\nimport useDocumentTitle from './useDocumentTitle';\nimport useBackButton from './useBackButton';\nimport type { Theme, LinkingOptions, DocumentTitleOptions } from './types';\n\ntype Props = NavigationContainerProps & {\n theme?: Theme;\n linking?: LinkingOptions;\n fallback?: React.ReactNode;\n documentTitle?: DocumentTitleOptions;\n onReady?: () => void;\n};\n\n/**\n * Container component which holds the navigation state designed for React Native apps.\n * This should be rendered at the root wrapping the whole app.\n *\n * @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).\n * @param props.onReady Callback which is called after the navigation tree mounts.\n * @param props.onStateChange Callback which is called with the latest navigation state when it changes.\n * @param props.theme Theme object for the navigators.\n * @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.\n * @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.\n * @param props.documentTitle Options to configure the document title on Web. Updating document title is handled by default unless `documentTitle.enabled` is `false`.\n * @param props.children Child elements to render the content.\n * @param props.ref Ref object which refers to the navigation object containing helper methods.\n */\nconst NavigationContainer = React.forwardRef(function NavigationContainer(\n {\n theme = DefaultTheme,\n linking,\n fallback = null,\n documentTitle,\n onReady,\n ...rest\n }: Props,\n ref?: React.Ref<NavigationContainerRef | null>\n) {\n const isLinkingEnabled = linking ? linking.enabled !== false : false;\n\n const refContainer = React.useRef<NavigationContainerRef>(null);\n\n useBackButton(refContainer);\n useDocumentTitle(refContainer, documentTitle);\n\n const { getInitialState } = useLinking(refContainer, {\n enabled: isLinkingEnabled,\n prefixes: [],\n ...linking,\n });\n\n const [isResolved, initialState] = useThenable(getInitialState);\n\n React.useImperativeHandle(ref, () => refContainer.current);\n\n const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);\n\n const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;\n\n const onReadyRef = React.useRef(onReady);\n\n React.useEffect(() => {\n onReadyRef.current = onReady;\n });\n\n React.useEffect(() => {\n if (isReady) {\n onReadyRef.current?.();\n }\n }, [isReady]);\n\n if (!isReady) {\n // This is temporary until we have Suspense for data-fetching\n // Then the fallback will be handled by a parent `Suspense` component\n return fallback as React.ReactElement;\n }\n\n return (\n <LinkingContext.Provider value={linkingContext}>\n <ThemeProvider value={theme}>\n <BaseNavigationContainer\n {...rest}\n initialState={\n rest.initialState == null ? initialState : rest.initialState\n }\n ref={refContainer}\n />\n </ThemeProvider>\n </LinkingContext.Provider>\n );\n});\n\nexport default NavigationContainer;\n"]} | ||
| {"version":3,"names":["BaseNavigationContainer","getActionFromState","getPathFromState","getStateFromPath","validatePathConfig","React","LinkingContext","DefaultTheme","ThemeProvider","useBackButton","useDocumentTitle","useLinking","useThenable","global","REACT_NAVIGATION_DEVTOOLS","WeakMap","NavigationContainerInner","ref","theme","linking","fallback","documentTitle","onReady","rest","isLinkingEnabled","enabled","config","refContainer","useRef","getInitialState","independent","prefixes","useEffect","current","set","isResolved","initialState","useImperativeHandle","linkingContext","useMemo","options","isReady","onReadyRef","NavigationContainer","forwardRef"],"sourceRoot":"../../src","sources":["NavigationContainer.tsx"],"mappings":";AAAA,SACEA,uBAAuB,EACvBC,kBAAkB,EAClBC,gBAAgB,EAChBC,gBAAgB,EAIhBC,kBAAkB,QACb,wBAAwB;AAC/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,YAAY,MAAM,wBAAwB;AACjD,OAAOC,aAAa,MAAM,yBAAyB;AAEnD,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,gBAAgB,MAAM,oBAAo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AAM,gBAC1B,oBAAC,uBAAuB,eAClBK,IAAI;IACR,YAAY,EACVA,IAAI,CAACa,YAAY,IAAI,IAAI,GAAGA,YAAY,GAAGb,IAAI,CAACa,YACjD;IACD,GAAG,EAAET;EAAa,GAClB,CACY,CACQ;AAE9B;AAEA,MAAMgB,mBAAmB,gBAAGtC,KAAK,CAACuC,UAAU,CAAC5B,wBAAwB,CAM9C;AAEvB,eAAe2B,mBAAmB"} |
@@ -0,5 +1,4 @@ | ||
| import { CurrentRenderContext } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { CurrentRenderContext } from '@react-navigation/core'; | ||
| import ServerContext from './ServerContext'; | ||
| /** | ||
@@ -12,6 +11,7 @@ * Container component for server rendering. | ||
| */ | ||
| export default /*#__PURE__*/React.forwardRef(function ServerContainer({ | ||
| children, | ||
| location | ||
| }, ref) { | ||
| export default /*#__PURE__*/React.forwardRef(function ServerContainer(_ref, ref) { | ||
| let { | ||
| children, | ||
| location | ||
| } = _ref; | ||
| React.useEffect(() => { | ||
@@ -21,3 +21,2 @@ console.error("'ServerContainer' should only be used on the server with 'react-dom/server' for SSR."); | ||
| const current = {}; | ||
| if (ref) { | ||
@@ -28,8 +27,8 @@ const value = { | ||
| } | ||
| }; | ||
| }; // We write to the `ref` during render instead of `React.useImperativeHandle` | ||
| // We write to the `ref` during render instead of `React.useImperativeHandle` | ||
| // This is because `useImperativeHandle` will update the ref after 'commit', | ||
| // and there's no 'commit' phase during SSR. | ||
| // Mutating ref during render is unsafe in concurrent mode, but we don't care about it for SSR. | ||
| if (typeof ref === 'function') { | ||
@@ -42,3 +41,2 @@ ref(value); | ||
| } | ||
| return /*#__PURE__*/React.createElement(ServerContext.Provider, { | ||
@@ -45,0 +43,0 @@ value: { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ServerContainer.tsx"],"names":["React","CurrentRenderContext","ServerContext","forwardRef","ServerContainer","children","location","ref","useEffect","console","error","current","value","getCurrentOptions","options"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,oBAAT,QAAqC,wBAArC;AACA,OAAOC,aAAP,MAAiD,iBAAjD;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAAeF,KAAK,CAACG,UAAN,CAAiB,SAASC,eAAT,CAC9B;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAD8B,EAE9BC,GAF8B,EAG9B;AACAP,EAAAA,KAAK,CAACQ,SAAN,CAAgB,MAAM;AACpBC,IAAAA,OAAO,CAACC,KAAR,CACE,sFADF;AAGD,GAJD,EAIG,EAJH;AAMA,QAAMC,OAA6B,GAAG,EAAtC;;AAEA,MAAIJ,GAAJ,EAAS;AACP,UAAMK,KAAK,GAAG;AACZC,MAAAA,iBAAiB,GAAG;AAClB,eAAOF,OAAO,CAACG,OAAf;AACD;;AAHW,KAAd,CADO,CAOP;AACA;AACA;AACA;;AACA,QAAI,OAAOP,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,MAAAA,GAAG,CAACK,KAAD,CAAH;AACD,KAFD,MAEO;AACL;AACAL,MAAAA,GAAG,CAACI,OAAJ,GAAcC,KAAd;AACD;AACF;;AAED,sBACE,oBAAC,aAAD,CAAe,QAAf;AAAwB,IAAA,KAAK,EAAE;AAAEN,MAAAA;AAAF;AAA/B,kBACE,oBAAC,oBAAD,CAAsB,QAAtB;AAA+B,IAAA,KAAK,EAAEK;AAAtC,KACGN,QADH,CADF,CADF;AAOD,CAtCc,CAAf","sourcesContent":["import * as React from 'react';\nimport { CurrentRenderContext } from '@react-navigation/core';\nimport ServerContext, { ServerContextType } from './ServerContext';\nimport type { ServerContainerRef } from './types';\n\ntype Props = ServerContextType & {\n children: React.ReactNode;\n};\n\n/**\n * Container component for server rendering.\n *\n * @param props.location Location object to base the initial URL for SSR.\n * @param props.children Child elements to render the content.\n * @param props.ref Ref object which contains helper methods.\n */\nexport default React.forwardRef(function ServerContainer(\n { children, location }: Props,\n ref: React.Ref<ServerContainerRef>\n) {\n React.useEffect(() => {\n console.error(\n \"'ServerContainer' should only be used on the server with 'react-dom/server' for SSR.\"\n );\n }, []);\n\n const current: { options?: object } = {};\n\n if (ref) {\n const value = {\n getCurrentOptions() {\n return current.options;\n },\n };\n\n // We write to the `ref` during render instead of `React.useImperativeHandle`\n // This is because `useImperativeHandle` will update the ref after 'commit',\n // and there's no 'commit' phase during SSR.\n // Mutating ref during render is unsafe in concurrent mode, but we don't care about it for SSR.\n if (typeof ref === 'function') {\n ref(value);\n } else {\n // @ts-expect-error: the TS types are incorrect and say that ref.current is readonly\n ref.current = value;\n }\n }\n\n return (\n <ServerContext.Provider value={{ location }}>\n <CurrentRenderContext.Provider value={current}>\n {children}\n </CurrentRenderContext.Provider>\n </ServerContext.Provider>\n );\n});\n"]} | ||
| {"version":3,"names":["CurrentRenderContext","React","ServerContext","forwardRef","ServerContainer","ref","children","location","useEffect","console","error","current","value","getCurrentOptions","options"],"sourceRoot":"../../src","sources":["ServerContainer.tsx"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,wBAAwB;AAC7D,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,OAAOC,aAAa,MAA6B,iBAAiB;AAOlE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAAeD,KAAK,CAACE,UAAU,CAAC,SAASC,eAAe,OAEtDC,GAAkC,EAClC;EAAA,IAFA;IAAEC,QAAQ;IAAEC;EAAgB,CAAC;EAG7BN,KAAK,CAACO,SAAS,CAAC,MAAM;IACpBC,OAAO,CAACC,KAAK,CACX,sFAAsF,CACvF;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,OAA6B,GAAG,CAAC,CAAC;EAExC,IAAIN,GAAG,EAAE;IACP,MAAMO,KAAK,GAAG;MACZC,iBAAiB,GAAG;QAClB,OAAOF,OAAO,CAACG,OAAO;MACxB;IACF,CAAC;;IAED;IACA;IACA;IACA;IACA,IAAI,OAAOT,GAAG,KAAK,UAAU,EAAE;MAC7BA,GAAG,CAACO,KAAK,CAAC;IACZ,CAAC,MAAM;MACL;MACAP,GAAG,CAACM,OAAO,GAAGC,KAAK;IACrB;EACF;EAEA,oBACE,oBAAC,aAAa,CAAC,QAAQ;IAAC,KAAK,EAAE;MAAEL;IAAS;EAAE,gBAC1C,oBAAC,oBAAoB,CAAC,QAAQ;IAAC,KAAK,EAAEI;EAAQ,GAC3CL,QAAQ,CACqB,CACT;AAE7B,CAAC,CAAC"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ServerContext.tsx"],"names":["React","ServerContext","createContext","undefined"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AASA,MAAMC,aAAa,gBAAGD,KAAK,CAACE,aAAN,CACpBC,SADoB,CAAtB;AAIA,eAAeF,aAAf","sourcesContent":["import * as React from 'react';\n\nexport type ServerContextType = {\n location?: {\n pathname: string;\n search: string;\n };\n};\n\nconst ServerContext = React.createContext<ServerContextType | undefined>(\n undefined\n);\n\nexport default ServerContext;\n"]} | ||
| {"version":3,"names":["React","ServerContext","createContext","undefined"],"sourceRoot":"../../src","sources":["ServerContext.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAS9B,MAAMC,aAAa,gBAAGD,KAAK,CAACE,aAAa,CACvCC,SAAS,CACV;AAED,eAAeF,aAAa"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["DarkTheme.tsx"],"names":["DarkTheme","dark","colors","primary","background","card","text","border","notification"],"mappings":"AAEA,MAAMA,SAAgB,GAAG;AACvBC,EAAAA,IAAI,EAAE,IADiB;AAEvBC,EAAAA,MAAM,EAAE;AACNC,IAAAA,OAAO,EAAE,mBADH;AAENC,IAAAA,UAAU,EAAE,cAFN;AAGNC,IAAAA,IAAI,EAAE,iBAHA;AAINC,IAAAA,IAAI,EAAE,oBAJA;AAKNC,IAAAA,MAAM,EAAE,iBALF;AAMNC,IAAAA,YAAY,EAAE;AANR;AAFe,CAAzB;AAYA,eAAeR,SAAf","sourcesContent":["import type { Theme } from '../types';\n\nconst DarkTheme: Theme = {\n dark: true,\n colors: {\n primary: 'rgb(10, 132, 255)',\n background: 'rgb(1, 1, 1)',\n card: 'rgb(18, 18, 18)',\n text: 'rgb(229, 229, 231)',\n border: 'rgb(39, 39, 41)',\n notification: 'rgb(255, 69, 58)',\n },\n};\n\nexport default DarkTheme;\n"]} | ||
| {"version":3,"names":["DarkTheme","dark","colors","primary","background","card","text","border","notification"],"sourceRoot":"../../../src","sources":["theming/DarkTheme.tsx"],"mappings":"AAEA,MAAMA,SAAgB,GAAG;EACvBC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE;IACNC,OAAO,EAAE,mBAAmB;IAC5BC,UAAU,EAAE,cAAc;IAC1BC,IAAI,EAAE,iBAAiB;IACvBC,IAAI,EAAE,oBAAoB;IAC1BC,MAAM,EAAE,iBAAiB;IACzBC,YAAY,EAAE;EAChB;AACF,CAAC;AAED,eAAeR,SAAS"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["DefaultTheme.tsx"],"names":["DefaultTheme","dark","colors","primary","background","card","text","border","notification"],"mappings":"AAEA,MAAMA,YAAmB,GAAG;AAC1BC,EAAAA,IAAI,EAAE,KADoB;AAE1BC,EAAAA,MAAM,EAAE;AACNC,IAAAA,OAAO,EAAE,kBADH;AAENC,IAAAA,UAAU,EAAE,oBAFN;AAGNC,IAAAA,IAAI,EAAE,oBAHA;AAINC,IAAAA,IAAI,EAAE,iBAJA;AAKNC,IAAAA,MAAM,EAAE,oBALF;AAMNC,IAAAA,YAAY,EAAE;AANR;AAFkB,CAA5B;AAYA,eAAeR,YAAf","sourcesContent":["import type { Theme } from '../types';\n\nconst DefaultTheme: Theme = {\n dark: false,\n colors: {\n primary: 'rgb(0, 122, 255)',\n background: 'rgb(242, 242, 242)',\n card: 'rgb(255, 255, 255)',\n text: 'rgb(28, 28, 30)',\n border: 'rgb(216, 216, 216)',\n notification: 'rgb(255, 59, 48)',\n },\n};\n\nexport default DefaultTheme;\n"]} | ||
| {"version":3,"names":["DefaultTheme","dark","colors","primary","background","card","text","border","notification"],"sourceRoot":"../../../src","sources":["theming/DefaultTheme.tsx"],"mappings":"AAEA,MAAMA,YAAmB,GAAG;EAC1BC,IAAI,EAAE,KAAK;EACXC,MAAM,EAAE;IACNC,OAAO,EAAE,kBAAkB;IAC3BC,UAAU,EAAE,oBAAoB;IAChCC,IAAI,EAAE,oBAAoB;IAC1BC,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAE,oBAAoB;IAC5BC,YAAY,EAAE;EAChB;AACF,CAAC;AAED,eAAeR,YAAY"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ThemeContext.tsx"],"names":["React","DefaultTheme","ThemeContext","createContext","displayName"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAGA,MAAMC,YAAY,gBAAGF,KAAK,CAACG,aAAN,CAA2BF,YAA3B,CAArB;AAEAC,YAAY,CAACE,WAAb,GAA2B,cAA3B;AAEA,eAAeF,YAAf","sourcesContent":["import * as React from 'react';\nimport DefaultTheme from './DefaultTheme';\nimport type { Theme } from '../types';\n\nconst ThemeContext = React.createContext<Theme>(DefaultTheme);\n\nThemeContext.displayName = 'ThemeContext';\n\nexport default ThemeContext;\n"]} | ||
| {"version":3,"names":["React","DefaultTheme","ThemeContext","createContext","displayName"],"sourceRoot":"../../../src","sources":["theming/ThemeContext.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B,OAAOC,YAAY,MAAM,gBAAgB;AAEzC,MAAMC,YAAY,gBAAGF,KAAK,CAACG,aAAa,CAAQF,YAAY,CAAC;AAE7DC,YAAY,CAACE,WAAW,GAAG,cAAc;AAEzC,eAAeF,YAAY"} |
| import * as React from 'react'; | ||
| import ThemeContext from './ThemeContext'; | ||
| export default function ThemeProvider({ | ||
| value, | ||
| children | ||
| }) { | ||
| export default function ThemeProvider(_ref) { | ||
| let { | ||
| value, | ||
| children | ||
| } = _ref; | ||
| return /*#__PURE__*/React.createElement(ThemeContext.Provider, { | ||
@@ -8,0 +9,0 @@ value: value |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["ThemeProvider.tsx"],"names":["React","ThemeContext","ThemeProvider","value","children"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAQA,eAAe,SAASC,aAAT,CAAuB;AAAEC,EAAAA,KAAF;AAASC,EAAAA;AAAT,CAAvB,EAAmD;AAChE,sBACE,oBAAC,YAAD,CAAc,QAAd;AAAuB,IAAA,KAAK,EAAED;AAA9B,KAAsCC,QAAtC,CADF;AAGD","sourcesContent":["import * as React from 'react';\nimport ThemeContext from './ThemeContext';\nimport type { Theme } from '../types';\n\ntype Props = {\n value: Theme;\n children: React.ReactNode;\n};\n\nexport default function ThemeProvider({ value, children }: Props) {\n return (\n <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>\n );\n}\n"]} | ||
| {"version":3,"names":["React","ThemeContext","ThemeProvider","value","children"],"sourceRoot":"../../../src","sources":["theming/ThemeProvider.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B,OAAOC,YAAY,MAAM,gBAAgB;AAOzC,eAAe,SAASC,aAAa,OAA6B;EAAA,IAA5B;IAAEC,KAAK;IAAEC;EAAgB,CAAC;EAC9D,oBACE,oBAAC,YAAY,CAAC,QAAQ;IAAC,KAAK,EAAED;EAAM,GAAEC,QAAQ,CAAyB;AAE3E"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useTheme.tsx"],"names":["React","ThemeContext","useTheme","theme","useContext"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAEA,eAAe,SAASC,QAAT,GAAoB;AACjC,QAAMC,KAAK,GAAGH,KAAK,CAACI,UAAN,CAAiBH,YAAjB,CAAd;AAEA,SAAOE,KAAP;AACD","sourcesContent":["import * as React from 'react';\nimport ThemeContext from './ThemeContext';\n\nexport default function useTheme() {\n const theme = React.useContext(ThemeContext);\n\n return theme;\n}\n"]} | ||
| {"version":3,"names":["React","ThemeContext","useTheme","theme","useContext"],"sourceRoot":"../../../src","sources":["theming/useTheme.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,OAAOC,YAAY,MAAM,gBAAgB;AAEzC,eAAe,SAASC,QAAQ,GAAG;EACjC,MAAMC,KAAK,GAAGH,KAAK,CAACI,UAAU,CAACH,YAAY,CAAC;EAE5C,OAAOE,KAAK;AACd"} |
@@ -1,2 +0,2 @@ | ||
| export {}; | ||
| //# sourceMappingURL=types.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]} | ||
| {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.tsx"],"mappings":""} |
@@ -1,22 +0,5 @@ | ||
| import * as React from 'react'; | ||
| import { BackHandler } from 'react-native'; | ||
| export default function useBackButton(ref) { | ||
| React.useEffect(() => { | ||
| const subscription = BackHandler.addEventListener('hardwareBackPress', () => { | ||
| const navigation = ref.current; | ||
| if (navigation == null) { | ||
| return false; | ||
| } | ||
| if (navigation.canGoBack()) { | ||
| navigation.goBack(); | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| return () => subscription.remove(); | ||
| }, [ref]); | ||
| export default function useBackButton(_) { | ||
| // No-op | ||
| // BackHandler is not available on web | ||
| } | ||
| //# sourceMappingURL=useBackButton.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useBackButton.tsx"],"names":["React","BackHandler","useBackButton","ref","useEffect","subscription","addEventListener","navigation","current","canGoBack","goBack","remove"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,WAAT,QAA4B,cAA5B;AAGA,eAAe,SAASC,aAAT,CACbC,GADa,EAEb;AACAH,EAAAA,KAAK,CAACI,SAAN,CAAgB,MAAM;AACpB,UAAMC,YAAY,GAAGJ,WAAW,CAACK,gBAAZ,CACnB,mBADmB,EAEnB,MAAM;AACJ,YAAMC,UAAU,GAAGJ,GAAG,CAACK,OAAvB;;AAEA,UAAID,UAAU,IAAI,IAAlB,EAAwB;AACtB,eAAO,KAAP;AACD;;AAED,UAAIA,UAAU,CAACE,SAAX,EAAJ,EAA4B;AAC1BF,QAAAA,UAAU,CAACG,MAAX;AAEA,eAAO,IAAP;AACD;;AAED,aAAO,KAAP;AACD,KAhBkB,CAArB;AAmBA,WAAO,MAAML,YAAY,CAACM,MAAb,EAAb;AACD,GArBD,EAqBG,CAACR,GAAD,CArBH;AAsBD","sourcesContent":["import * as React from 'react';\nimport { BackHandler } from 'react-native';\nimport type { NavigationContainerRef } from '@react-navigation/core';\n\nexport default function useBackButton(\n ref: React.RefObject<NavigationContainerRef>\n) {\n React.useEffect(() => {\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n () => {\n const navigation = ref.current;\n\n if (navigation == null) {\n return false;\n }\n\n if (navigation.canGoBack()) {\n navigation.goBack();\n\n return true;\n }\n\n return false;\n }\n );\n\n return () => subscription.remove();\n }, [ref]);\n}\n"]} | ||
| {"version":3,"names":["useBackButton","_"],"sourceRoot":"../../src","sources":["useBackButton.tsx"],"mappings":"AAKA,eAAe,SAASA,aAAa,CACnCC,CAAyD,EACzD;EACA;EACA;AAAA"} |
| import * as React from 'react'; | ||
| /** | ||
| * Set the document title for the active screen | ||
| */ | ||
| export default function useDocumentTitle(ref, { | ||
| enabled = true, | ||
| formatter = (options, route) => { | ||
| var _options$title; | ||
| return (_options$title = options === null || options === void 0 ? void 0 : options.title) !== null && _options$title !== void 0 ? _options$title : route === null || route === void 0 ? void 0 : route.name; | ||
| } | ||
| } = {}) { | ||
| export default function useDocumentTitle(ref) { | ||
| let { | ||
| enabled = true, | ||
| formatter = (options, route) => (options === null || options === void 0 ? void 0 : options.title) ?? (route === null || route === void 0 ? void 0 : route.name) | ||
| } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
| React.useEffect(() => { | ||
@@ -18,5 +14,3 @@ if (!enabled) { | ||
| } | ||
| const navigation = ref.current; | ||
| if (navigation) { | ||
@@ -26,3 +20,2 @@ const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute()); | ||
| } | ||
| return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', e => { | ||
@@ -29,0 +22,0 @@ const title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute()); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useDocumentTitle.tsx"],"names":["React","useDocumentTitle","ref","enabled","formatter","options","route","title","name","useEffect","navigation","current","getCurrentOptions","getCurrentRoute","document","addListener","e","data"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAIA;AACA;AACA;AACA,eAAe,SAASC,gBAAT,CACbC,GADa,EAEb;AACEC,EAAAA,OAAO,GAAG,IADZ;AAEEC,EAAAA,SAAS,GAAG,CAACC,OAAD,EAAUC,KAAV;AAAA;;AAAA,6BAAoBD,OAApB,aAAoBA,OAApB,uBAAoBA,OAAO,CAAEE,KAA7B,2DAAsCD,KAAtC,aAAsCA,KAAtC,uBAAsCA,KAAK,CAAEE,IAA7C;AAAA;AAFd,IAG0B,EALb,EAMb;AACAR,EAAAA,KAAK,CAACS,SAAN,CAAgB,MAAM;AACpB,QAAI,CAACN,OAAL,EAAc;AACZ;AACD;;AAED,UAAMO,UAAU,GAAGR,GAAG,CAACS,OAAvB;;AAEA,QAAID,UAAJ,EAAgB;AACd,YAAMH,KAAK,GAAGH,SAAS,CACrBM,UAAU,CAACE,iBAAX,EADqB,EAErBF,UAAU,CAACG,eAAX,EAFqB,CAAvB;AAKAC,MAAAA,QAAQ,CAACP,KAAT,GAAiBA,KAAjB;AACD;;AAED,WAAOG,UAAP,aAAOA,UAAP,uBAAOA,UAAU,CAAEK,WAAZ,CAAwB,SAAxB,EAAoCC,CAAD,IAAO;AAC/C,YAAMT,KAAK,GAAGH,SAAS,CAACY,CAAC,CAACC,IAAF,CAAOZ,OAAR,EAAiBK,UAAjB,aAAiBA,UAAjB,uBAAiBA,UAAU,CAAEG,eAAZ,EAAjB,CAAvB;AAEAC,MAAAA,QAAQ,CAACP,KAAT,GAAiBA,KAAjB;AACD,KAJM,CAAP;AAKD,GArBD;AAsBD","sourcesContent":["import * as React from 'react';\nimport type { NavigationContainerRef } from '@react-navigation/core';\nimport type { DocumentTitleOptions } from './types';\n\n/**\n * Set the document title for the active screen\n */\nexport default function useDocumentTitle(\n ref: React.RefObject<NavigationContainerRef>,\n {\n enabled = true,\n formatter = (options, route) => options?.title ?? route?.name,\n }: DocumentTitleOptions = {}\n) {\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const navigation = ref.current;\n\n if (navigation) {\n const title = formatter(\n navigation.getCurrentOptions(),\n navigation.getCurrentRoute()\n );\n\n document.title = title;\n }\n\n return navigation?.addListener('options', (e) => {\n const title = formatter(e.data.options, navigation?.getCurrentRoute());\n\n document.title = title;\n });\n });\n}\n"]} | ||
| {"version":3,"names":["React","useDocumentTitle","ref","enabled","formatter","options","route","title","name","useEffect","navigation","current","getCurrentOptions","getCurrentRoute","document","addListener","e","data"],"sourceRoot":"../../src","sources":["useDocumentTitle.tsx"],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAI9B;AACA;AACA;AACA,eAAe,SAASC,gBAAgB,CACtCC,GAA2D,EAK3D;EAAA,IAJA;IACEC,OAAO,GAAG,IAAI;IACdC,SAAS,GAAG,CAACC,OAAO,EAAEC,KAAK,KAAK,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,KAAK,MAAID,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEE,IAAI;EACzC,CAAC,uEAAG,CAAC,CAAC;EAE5BR,KAAK,CAACS,SAAS,CAAC,MAAM;IACpB,IAAI,CAACN,OAAO,EAAE;MACZ;IACF;IAEA,MAAMO,UAAU,GAAGR,GAAG,CAACS,OAAO;IAE9B,IAAID,UAAU,EAAE;MACd,MAAMH,KAAK,GAAGH,SAAS,CACrBM,UAAU,CAACE,iBAAiB,EAAE,EAC9BF,UAAU,CAACG,eAAe,EAAE,CAC7B;MAEDC,QAAQ,CAACP,KAAK,GAAGA,KAAK;IACxB;IAEA,OAAOG,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,WAAW,CAAC,SAAS,EAAGC,CAAC,IAAK;MAC/C,MAAMT,KAAK,GAAGH,SAAS,CAACY,CAAC,CAACC,IAAI,CAACZ,OAAO,EAAEK,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEG,eAAe,EAAE,CAAC;MAEtEC,QAAQ,CAACP,KAAK,GAAGA,KAAK;IACxB,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ"} |
@@ -1,3 +0,4 @@ | ||
| export default function useDocumentTitle() {// Noop for React Native | ||
| export default function useDocumentTitle() { | ||
| // Noop for React Native | ||
| } | ||
| //# sourceMappingURL=useDocumentTitle.native.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useDocumentTitle.native.tsx"],"names":["useDocumentTitle"],"mappings":"AAAA,eAAe,SAASA,gBAAT,GAA4B,CACzC;AACD","sourcesContent":["export default function useDocumentTitle() {\n // Noop for React Native\n}\n"]} | ||
| {"version":3,"names":["useDocumentTitle"],"sourceRoot":"../../src","sources":["useDocumentTitle.native.tsx"],"mappings":"AAAA,eAAe,SAASA,gBAAgB,GAAG;EACzC;AAAA"} |
@@ -0,8 +1,6 @@ | ||
| import { getPathFromState, NavigationHelpersContext } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { NavigationHelpersContext, getPathFromState } from '@react-navigation/core'; | ||
| import LinkingContext from './LinkingContext'; | ||
| const getRootStateForNavigate = (navigation, state) => { | ||
| const parent = navigation.getParent(); | ||
| if (parent) { | ||
@@ -12,3 +10,4 @@ const parentState = parent.getState(); | ||
| index: 0, | ||
| routes: [{ ...parentState.routes[parentState.index], | ||
| routes: [{ | ||
| ...parentState.routes[parentState.index], | ||
| state: state | ||
@@ -18,5 +17,5 @@ }] | ||
| } | ||
| return state; | ||
| }; | ||
| /** | ||
@@ -26,4 +25,2 @@ * Build destination link for a navigate action. | ||
| */ | ||
| export default function useLinkBuilder() { | ||
@@ -36,7 +33,5 @@ const navigation = React.useContext(NavigationHelpersContext); | ||
| } = linking; | ||
| if ((options === null || options === void 0 ? void 0 : options.enabled) === false) { | ||
| return undefined; | ||
| } | ||
| const state = navigation ? getRootStateForNavigate(navigation, { | ||
@@ -48,3 +43,4 @@ index: 0, | ||
| }] | ||
| }) : // If we couldn't find a navigation object in context, we're at root | ||
| }) : | ||
| // If we couldn't find a navigation object in context, we're at root | ||
| // So we'll construct a basic state object to use | ||
@@ -51,0 +47,0 @@ { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinkBuilder.tsx"],"names":["React","NavigationHelpersContext","getPathFromState","LinkingContext","getRootStateForNavigate","navigation","state","parent","getParent","parentState","getState","index","routes","useLinkBuilder","useContext","linking","buildLink","useCallback","name","params","options","enabled","undefined","path","config"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAEEC,wBAFF,EAKEC,gBALF,QAMO,wBANP;AAOA,OAAOC,cAAP,MAA2B,kBAA3B;;AAWA,MAAMC,uBAAuB,GAAG,CAC9BC,UAD8B,EAE9BC,KAF8B,KAGb;AACjB,QAAMC,MAAM,GAAGF,UAAU,CAACG,SAAX,EAAf;;AAEA,MAAID,MAAJ,EAAY;AACV,UAAME,WAAW,GAAGF,MAAM,CAACG,QAAP,EAApB;AAEA,WAAON,uBAAuB,CAACG,MAAD,EAAS;AACrCI,MAAAA,KAAK,EAAE,CAD8B;AAErCC,MAAAA,MAAM,EAAE,CACN,EACE,G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IAAP;AACD,GAzBe,EA0BhB,CAACR,OAAD,EAAUV,UAAV,CA1BgB,CAAlB;AA6BA,SAAOW,SAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {\n NavigationHelpers,\n NavigationHelpersContext,\n NavigationProp,\n ParamListBase,\n getPathFromState,\n} from '@react-navigation/core';\nimport LinkingContext from './LinkingContext';\n\ntype NavigationObject =\n | NavigationHelpers<ParamListBase>\n | NavigationProp<ParamListBase>;\n\ntype MinimalState = {\n index: number;\n routes: { name: string; params?: object; state?: MinimalState }[];\n};\n\nconst getRootStateForNavigate = (\n navigation: NavigationObject,\n state: MinimalState\n): MinimalState => {\n const parent = navigation.getParent();\n\n if (parent) {\n const parentState = parent.getState();\n\n return getRootStateForNavigate(parent, {\n index: 0,\n routes: [\n {\n ...parentState.routes[parentState.index],\n state: state,\n },\n ],\n });\n }\n\n return state;\n};\n\n/**\n * Build destination link for a navigate action.\n * Useful for showing anchor tags on the web for buttons that perform navigation.\n */\nexport default function useLinkBuilder() {\n const navigation = React.useContext(NavigationHelpersContext);\n const linking = React.useContext(LinkingContext);\n\n const buildLink = React.useCallback(\n (name: string, params?: object) => {\n const { options } = linking;\n\n if (options?.enabled === false) {\n return undefined;\n }\n\n const state = navigation\n ? getRootStateForNavigate(navigation, {\n index: 0,\n routes: [{ name, params }],\n })\n : // If we couldn't find a navigation object in context, we're at root\n // So we'll construct a basic state object to use\n {\n index: 0,\n routes: [{ name, params }],\n };\n\n const path = options?.getPathFromState\n ? options.getPathFromState(state, options?.config)\n : getPathFromState(state, options?.config);\n\n return path;\n },\n [linking, navigation]\n );\n\n return buildLink;\n}\n"]} | ||
| {"version":3,"names":["getPathFromState","NavigationHelpersContext","React","LinkingContext","getRootStateForNavigate","navigation","state","parent","getParent","parentState","getState","index","routes","useLinkBuilder","useContext","linking","buildLink","useCallback","name","params","options","enabled","undefined","path","config"],"sourceRoot":"../../src","sources":["useLinkBuilder.tsx"],"mappings":"AAAA,SACEA,gBAAgB,EAEhBC,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GAAGH,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEpB,gBAAgB,GAClCoB,OAAO,CAACpB,gBAAgB,CAACM,KAAK,EAAEc,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,MAAM,CAAC,GAChDxB,gBAAgB,CAACM,KAAK,EAAEc,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,MAAM,CAAC;IAE5C,OAAOD,IAAI;EACb,CAAC,EACD,CAACR,OAAO,EAAEV,UAAU,CAAC,CACtB;EAED,OAAOW,SAAS;AAClB"} |
+93
-313
@@ -0,214 +1,6 @@ | ||
| import { findFocusedRoute, getActionFromState as getActionFromStateDefault, getPathFromState as getPathFromStateDefault, getStateFromPath as getStateFromPathDefault } from '@react-navigation/core'; | ||
| import isEqual from 'fast-deep-equal'; | ||
| import * as React from 'react'; | ||
| import { getStateFromPath as getStateFromPathDefault, getPathFromState as getPathFromStateDefault, getActionFromState as getActionFromStateDefault } from '@react-navigation/core'; | ||
| import { nanoid } from 'nanoid/non-secure'; | ||
| import createMemoryHistory from './createMemoryHistory'; | ||
| import ServerContext from './ServerContext'; | ||
| const createMemoryHistory = () => { | ||
| let index = 0; | ||
| let items = []; // Pending callbacks for `history.go(n)` | ||
| // We might modify the callback stored if it was interrupted, so we have a ref to identify it | ||
| const pending = []; | ||
| const interrupt = () => { | ||
| // If another history operation was performed we need to interrupt existing ones | ||
| // This makes sure that calls such as `history.replace` after `history.go` don't happen | ||
| // Since otherwise it won't be correct if something else has changed | ||
| pending.forEach(it => { | ||
| const cb = it.cb; | ||
| it.cb = () => cb(true); | ||
| }); | ||
| }; | ||
| const history = { | ||
| get index() { | ||
| var _window$history$state; | ||
| // We store an id in the state instead of an index | ||
| // Index could get out of sync with in-memory values if page reloads | ||
| const id = (_window$history$state = window.history.state) === null || _window$history$state === void 0 ? void 0 : _window$history$state.id; | ||
| if (id) { | ||
| const index = items.findIndex(item => item.id === id); | ||
| return index > -1 ? index : 0; | ||
| } | ||
| return 0; | ||
| }, | ||
| get(index) { | ||
| return items[index]; | ||
| }, | ||
| backIndex({ | ||
| path | ||
| }) { | ||
| // We need to find the index from the element before current to get closest path to go back to | ||
| for (let i = index - 1; i >= 0; i--) { | ||
| const item = items[i]; | ||
| if (item.path === path) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }, | ||
| push({ | ||
| path, | ||
| state | ||
| }) { | ||
| interrupt(); | ||
| const id = nanoid(); // When a new entry is pushed, all the existing entries after index will be inaccessible | ||
| // So we remove any existing entries after the current index to clean them up | ||
| items = items.slice(0, index + 1); | ||
| items.push({ | ||
| path, | ||
| state, | ||
| id | ||
| }); | ||
| index = items.length - 1; // We pass empty string for title because it's ignored in all browsers except safari | ||
| // We don't store state object in history.state because: | ||
| // - browsers have limits on how big it can be, and we don't control the size | ||
| // - while not recommended, there could be non-serializable data in state | ||
| window.history.pushState({ | ||
| id | ||
| }, '', path); | ||
| }, | ||
| replace({ | ||
| path, | ||
| state | ||
| }) { | ||
| var _window$history$state2, _window$history$state3; | ||
| interrupt(); | ||
| const id = (_window$history$state2 = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id) !== null && _window$history$state2 !== void 0 ? _window$history$state2 : nanoid(); | ||
| if (items.length) { | ||
| items[index] = { | ||
| path, | ||
| state, | ||
| id | ||
| }; | ||
| } else { | ||
| // This is the first time any state modifications are done | ||
| // So we need to push the entry as there's nothing to replace | ||
| items.push({ | ||
| path, | ||
| state, | ||
| id | ||
| }); | ||
| } | ||
| window.history.replaceState({ | ||
| id | ||
| }, '', path); | ||
| }, | ||
| // `history.go(n)` is asynchronous, there are couple of things to keep in mind: | ||
| // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire. | ||
| // - each `history.go(n)` call will trigger a separate `popstate` event with correct location. | ||
| // - the `popstate` event fires before the next frame after calling `history.go(n)`. | ||
| // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can. | ||
| go(n) { | ||
| interrupt(); | ||
| if (n > 0) { | ||
| // We shouldn't go forward more than available index | ||
| n = Math.min(n, items.length - 1); | ||
| } else if (n < 0) { | ||
| // We shouldn't go back more than the 0 index | ||
| // Otherwise we'll exit the page | ||
| n = index + n < 0 ? -index : n; | ||
| } | ||
| if (n === 0) { | ||
| return; | ||
| } | ||
| index += n; // When we call `history.go`, `popstate` will fire when there's history to go back to | ||
| // So we need to somehow handle following cases: | ||
| // - There's history to go back, `history.go` is called, and `popstate` fires | ||
| // - `history.go` is called multiple times, we need to resolve on respective `popstate` | ||
| // - No history to go back, but `history.go` was called, browser has no API to detect it | ||
| return new Promise((resolve, reject) => { | ||
| const done = interrupted => { | ||
| clearTimeout(timer); | ||
| if (interrupted) { | ||
| reject(new Error('History was changed during navigation.')); | ||
| return; | ||
| } // There seems to be a bug in Chrome regarding updating the title | ||
| // If we set a title just before calling `history.go`, the title gets lost | ||
| // However the value of `document.title` is still what we set it to | ||
| // It's just not displayed in the tab bar | ||
| // To update the tab bar, we need to reset the title to something else first (e.g. '') | ||
| // And set the title to what it was before so it gets applied | ||
| // It won't work without setting it to empty string coz otherwise title isn't changing | ||
| // Which means that the browser won't do anything after setting the title | ||
| const { | ||
| title | ||
| } = window.document; | ||
| window.document.title = ''; | ||
| window.document.title = title; | ||
| resolve(); | ||
| }; | ||
| pending.push({ | ||
| ref: done, | ||
| cb: done | ||
| }); // If navigation didn't happen within 100ms, assume that it won't happen | ||
| // This may not be accurate, but hopefully it won't take so much time | ||
| // In Chrome, navigation seems to happen instantly in next microtask | ||
| // But on Firefox, it seems to take much longer, around 50ms from our testing | ||
| // We're using a hacky timeout since there doesn't seem to be way to know for sure | ||
| const timer = setTimeout(() => { | ||
| const index = pending.findIndex(it => it.ref === done); | ||
| if (index > -1) { | ||
| pending[index].cb(); | ||
| pending.splice(index, 1); | ||
| } | ||
| }, 100); | ||
| const onPopState = () => { | ||
| const last = pending.pop(); | ||
| window.removeEventListener('popstate', onPopState); | ||
| last === null || last === void 0 ? void 0 : last.cb(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| window.history.go(n); | ||
| }); | ||
| }, | ||
| // The `popstate` event is triggered when history changes, except `pushState` and `replaceState` | ||
| // If we call `history.go(n)` ourselves, we don't want it to trigger the listener | ||
| // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener | ||
| listen(listener) { | ||
| const onPopState = () => { | ||
| if (pending.length) { | ||
| // This was triggered by `history.go(n)`, we shouldn't call the listener | ||
| return; | ||
| } | ||
| listener(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| return () => window.removeEventListener('popstate', onPopState); | ||
| } | ||
| }; | ||
| return history; | ||
| }; | ||
| /** | ||
@@ -218,10 +10,8 @@ * Find the matching navigation state that changed between 2 navigation states | ||
| */ | ||
| const findMatchingState = (a, b) => { | ||
| if (a === undefined || b === undefined || a.key !== b.key) { | ||
| return [undefined, undefined]; | ||
| } // Tab and drawer will have `history` property, but stack will have history in `routes` | ||
| } | ||
| // Tab and drawer will have `history` property, but stack will have history in `routes` | ||
| const aHistoryLength = a.history ? a.history.length : a.routes.length; | ||
@@ -232,3 +22,5 @@ const bHistoryLength = b.history ? b.history.length : b.routes.length; | ||
| const aChildState = aRoute.state; | ||
| const bChildState = bRoute.state; // Stop here if this is the state object that changed: | ||
| const bChildState = bRoute.state; | ||
| // Stop here if this is the state object that changed: | ||
| // - history length is different | ||
@@ -238,72 +30,59 @@ // - focused routes are different | ||
| // - child state keys are different | ||
| if (aHistoryLength !== bHistoryLength || aRoute.key !== bRoute.key || aChildState === undefined || bChildState === undefined || aChildState.key !== bChildState.key) { | ||
| return [a, b]; | ||
| } | ||
| return findMatchingState(aChildState, bChildState); | ||
| }; | ||
| /** | ||
| * Run async function in series as it's called. | ||
| */ | ||
| const series = cb => { | ||
| // Whether we're currently handling a callback | ||
| let handling = false; | ||
| let queue = []; | ||
| const callback = async () => { | ||
| try { | ||
| if (handling) { | ||
| // If we're currently handling a previous event, wait before handling this one | ||
| // Add the callback to the beginning of the queue | ||
| queue.unshift(callback); | ||
| return; | ||
| } | ||
| handling = true; | ||
| await cb(); | ||
| } finally { | ||
| handling = false; | ||
| if (queue.length) { | ||
| // If we have queued items, handle the last one | ||
| const last = queue.pop(); | ||
| last === null || last === void 0 ? void 0 : last(); | ||
| } | ||
| } | ||
| export const series = cb => { | ||
| let queue = Promise.resolve(); | ||
| const callback = () => { | ||
| queue = queue.then(cb); | ||
| }; | ||
| return callback; | ||
| }; | ||
| let isUsingLinking = false; | ||
| export default function useLinking(ref, { | ||
| enabled = true, | ||
| config, | ||
| getStateFromPath = getStateFromPathDefault, | ||
| getPathFromState = getPathFromStateDefault, | ||
| getActionFromState = getActionFromStateDefault | ||
| }) { | ||
| let linkingHandlers = []; | ||
| export default function useLinking(ref, _ref) { | ||
| let { | ||
| independent, | ||
| enabled = true, | ||
| config, | ||
| getStateFromPath = getStateFromPathDefault, | ||
| getPathFromState = getPathFromStateDefault, | ||
| getActionFromState = getActionFromStateDefault | ||
| } = _ref; | ||
| React.useEffect(() => { | ||
| if (enabled !== false && isUsingLinking) { | ||
| throw new Error(['Looks like you have configured linking in multiple places. This is likely an error since URL integration should only be handled in one place to avoid conflicts. Make sure that:', "- You are not using both 'linking' prop and 'useLinking'", "- You don't have 'useLinking' in multiple components"].join('\n').trim()); | ||
| } else { | ||
| isUsingLinking = enabled !== false; | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return undefined; | ||
| } | ||
| if (independent) { | ||
| return undefined; | ||
| } | ||
| if (enabled !== false && linkingHandlers.length) { | ||
| console.error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", '- Only a single instance of the root component is rendered'].join('\n').trim()); | ||
| } | ||
| const handler = Symbol(); | ||
| if (enabled !== false) { | ||
| linkingHandlers.push(handler); | ||
| } | ||
| return () => { | ||
| isUsingLinking = false; | ||
| const index = linkingHandlers.indexOf(handler); | ||
| if (index > -1) { | ||
| linkingHandlers.splice(index, 1); | ||
| } | ||
| }; | ||
| }); | ||
| const [history] = React.useState(createMemoryHistory); // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| }, [enabled, independent]); | ||
| const [history] = React.useState(createMemoryHistory); | ||
| // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo` | ||
| // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect | ||
| const enabledRef = React.useRef(enabled); | ||
| const configRef = React.useRef(config); | ||
| const getStateFromPathRef = React.useRef(getStateFromPath); | ||
| const getPathFromStateRef = React.useRef(getPathFromState); | ||
| const getActionFromStateRef = React.useRef(getActionFromState); | ||
| const getPathFromStateRef = React.useRef(getPathFromState); | ||
| React.useEffect(() => { | ||
@@ -313,4 +92,4 @@ enabledRef.current = enabled; | ||
| getStateFromPathRef.current = getStateFromPath; | ||
| getPathFromStateRef.current = getPathFromState; | ||
| getActionFromStateRef.current = getActionFromState; | ||
| getPathFromStateRef.current = getPathFromState; | ||
| }); | ||
@@ -320,9 +99,5 @@ const server = React.useContext(ServerContext); | ||
| let value; | ||
| if (enabledRef.current) { | ||
| var _server$location; | ||
| const location = (_server$location = server === null || server === void 0 ? void 0 : server.location) !== null && _server$location !== void 0 ? _server$location : typeof window !== 'undefined' ? window.location : undefined; | ||
| const location = (server === null || server === void 0 ? void 0 : server.location) ?? (typeof window !== 'undefined' ? window.location : undefined); | ||
| const path = location ? location.pathname + location.search : undefined; | ||
| if (path) { | ||
@@ -332,3 +107,2 @@ value = getStateFromPathRef.current(path, configRef.current); | ||
| } | ||
| const thenable = { | ||
@@ -338,9 +112,8 @@ then(onfulfilled) { | ||
| }, | ||
| catch() { | ||
| return thenable; | ||
| } | ||
| }; | ||
| return thenable; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| return thenable; | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
@@ -353,20 +126,16 @@ const previousIndexRef = React.useRef(undefined); | ||
| return history.listen(() => { | ||
| var _previousIndexRef$cur; | ||
| const navigation = ref.current; | ||
| if (!navigation || !enabled) { | ||
| return; | ||
| } | ||
| const path = location.pathname + location.search; | ||
| const index = history.index; | ||
| const previousIndex = (_previousIndexRef$cur = previousIndexRef.current) !== null && _previousIndexRef$cur !== void 0 ? _previousIndexRef$cur : 0; | ||
| const previousIndex = previousIndexRef.current ?? 0; | ||
| previousIndexRef.current = index; | ||
| pendingPopStatePathRef.current = path; // When browser back/forward is clicked, we first need to check if state object for this index exists | ||
| pendingPopStatePathRef.current = path; | ||
| // When browser back/forward is clicked, we first need to check if state object for this index exists | ||
| // If it does we'll reset to that state object | ||
| // Otherwise, we'll handle it like a regular deep link | ||
| const record = history.get(index); | ||
| if ((record === null || record === void 0 ? void 0 : record.path) === path && record !== null && record !== void 0 && record.state) { | ||
@@ -376,6 +145,6 @@ navigation.resetRoot(record.state); | ||
| } | ||
| const state = getStateFromPathRef.current(path, configRef.current); | ||
| const state = getStateFromPathRef.current(path, configRef.current); // We should only dispatch an action when going forward | ||
| // We should only dispatch an action when going forward | ||
| // Otherwise the action will likely add items to history, which would mess things up | ||
| if (state) { | ||
@@ -385,11 +154,8 @@ // Make sure that the routes in the state exist in the root navigator | ||
| const rootState = navigation.getRootState(); | ||
| if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) { | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration."); | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."); | ||
| return; | ||
| } | ||
| if (index > previousIndex) { | ||
| const action = getActionFromStateRef.current(state, configRef.current); | ||
| if (action !== undefined) { | ||
@@ -401,3 +167,3 @@ try { | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn("An error occurred when trying to handle the link '".concat(path, "': ").concat(e.message)); | ||
| console.warn(`An error occurred when trying to handle the link '${path}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`); | ||
| } | ||
@@ -418,7 +184,19 @@ } else { | ||
| var _ref$current; | ||
| if (!enabled) { | ||
| return; | ||
| } | ||
| const getPathForRoute = (route, state) => { | ||
| // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match | ||
| // This makes sure that we preserve the original URL for wildcard routes | ||
| if (route !== null && route !== void 0 && route.path) { | ||
| const stateForPath = getStateFromPathRef.current(route.path, configRef.current); | ||
| if (stateForPath) { | ||
| const focusedRoute = findFocusedRoute(stateForPath); | ||
| if (focusedRoute && focusedRoute.name === route.name && isEqual(focusedRoute.params, route.params)) { | ||
| return route.path; | ||
| } | ||
| } | ||
| } | ||
| return getPathFromStateRef.current(state, configRef.current); | ||
| }; | ||
| if (ref.current) { | ||
@@ -428,10 +206,8 @@ // We need to record the current metadata on the first render if they aren't set | ||
| const state = ref.current.getRootState(); | ||
| if (state) { | ||
| const path = getPathFromStateRef.current(state, configRef.current); | ||
| const route = findFocusedRoute(state); | ||
| const path = getPathForRoute(route, state); | ||
| if (previousStateRef.current === undefined) { | ||
| previousStateRef.current = state; | ||
| } | ||
| history.replace({ | ||
@@ -443,27 +219,30 @@ path, | ||
| } | ||
| const onStateChange = async () => { | ||
| const navigation = ref.current; | ||
| if (!navigation || !enabled) { | ||
| return; | ||
| } | ||
| const previousState = previousStateRef.current; | ||
| const state = navigation.getRootState(); | ||
| // root state may not available, for example when root navigators switch inside the container | ||
| if (!state) { | ||
| return; | ||
| } | ||
| const pendingPath = pendingPopStatePathRef.current; | ||
| const path = getPathFromStateRef.current(state, configRef.current); | ||
| const route = findFocusedRoute(state); | ||
| const path = getPathForRoute(route, state); | ||
| previousStateRef.current = state; | ||
| pendingPopStatePathRef.current = undefined; // To detect the kind of state change, we need to: | ||
| pendingPopStatePathRef.current = undefined; | ||
| // To detect the kind of state change, we need to: | ||
| // - Find the common focused navigation state in previous and current state | ||
| // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace | ||
| // - If no common focused navigation state found, it's a replace | ||
| const [previousFocusedState, focusedState] = findMatchingState(previousState, state); | ||
| if (previousFocusedState && focusedState && // We should only handle push/pop if path changed from what was in last `popstate` | ||
| if (previousFocusedState && focusedState && | ||
| // We should only handle push/pop if path changed from what was in last `popstate` | ||
| // Otherwise it's likely a change triggered by `popstate` | ||
| path !== pendingPath) { | ||
| const historyDelta = (focusedState.history ? focusedState.history.length : focusedState.routes.length) - (previousFocusedState.history ? previousFocusedState.history.length : previousFocusedState.routes.length); | ||
| if (historyDelta > 0) { | ||
@@ -478,2 +257,3 @@ // If history length is increased, we should pushState | ||
| // If history length is decreased, i.e. entries were removed, we want to go back | ||
| const nextIndex = history.backIndex({ | ||
@@ -483,3 +263,2 @@ path | ||
| const currentIndex = history.index; | ||
| try { | ||
@@ -494,5 +273,5 @@ if (nextIndex !== -1 && nextIndex < currentIndex) { | ||
| await history.go(historyDelta); | ||
| } // Store the updated state as well as fix the path if incorrect | ||
| } | ||
| // Store the updated state as well as fix the path if incorrect | ||
| history.replace({ | ||
@@ -502,3 +281,4 @@ path, | ||
| }); | ||
| } catch (e) {// The navigation was interrupted | ||
| } catch (e) { | ||
| // The navigation was interrupted | ||
| } | ||
@@ -520,9 +300,9 @@ } else { | ||
| } | ||
| }; // We debounce onStateChange coz we don't want multiple state changes to be handled at one time | ||
| }; | ||
| // We debounce onStateChange coz we don't want multiple state changes to be handled at one time | ||
| // This could happen since `history.go(n)` is asynchronous | ||
| // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up | ||
| return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.addListener('state', series(onStateChange)); | ||
| }); | ||
| }, [enabled, history, ref]); | ||
| return { | ||
@@ -529,0 +309,0 @@ getInitialState |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinking.tsx"],"names":["React","getStateFromPath","getStateFromPathDefault","getPathFromState","getPathFromStateDefault","getActionFromState","getActionFromStateDefault","nanoid","ServerContext","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","replaceState","go","n","Math","min","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","last","pop","removeEventListener","addEventListener","listen","listener","findMatchingState","a","b","undefined","key","aHistoryLength","routes","bHistoryLength","aRoute","bRoute","aChildState","bChildState","series","handling","queue","callback","unshift","isUsingLinking","useLinking","enabled","config","useEffect","join","trim","useState","enabledRef","useRef","configRef","getStateFromPathRef","getActionFromStateRef","getPathFromStateRef","current","server","useContext","getInitialState","useCallback","value","location","pathname","search","thenable","then","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","navigation","previousIndex","record","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","console","warn","action","dispatch","e","message","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","currentIndex","addListener"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,gBAAgB,IAAIC,uBADtB,EAEEC,gBAAgB,IAAIC,uBAFtB,EAGEC,kBAAkB,IAAIC,yBAHxB,QAMO,wBANP;AAOA,SAASC,MAAT,QAAuB,mBAAvB;AACA,OAAOC,aAAP,MAA0B,iBAA1B;;AAcA,MAAMC,mBAAmB,GAAG,MAAM;AAChC,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAsB,GAAG,EAA7B,CAFgC,CAIhC;AACA;;AACA,QAAMC,OAAgE,GAAG,EAAzE;;AAEA,QAAMC,SAAS,GAAG,MAAM;AACtB;AACA;AACA;AACAD,IAAAA,OAAO,CAACE,OAAR,CAAiBC,EAAD,IAAQ;AACtB,YAAMC,EAAE,GAAGD,EAAE,CAACC,EAAd;;AAC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ACpB;AACA;AACA7G,UAAAA,OAAO,CAACU,IAAR,CAAa;AAAEF,YAAAA,IAAF;AAAQL,YAAAA;AAAR,WAAb;AACD,SAJD,MAIO,IAAI0G,YAAY,GAAG,CAAnB,EAAsB;AAC3B;AAEA,gBAAMC,SAAS,GAAG9G,OAAO,CAACO,SAAR,CAAkB;AAAEC,YAAAA;AAAF,WAAlB,CAAlB;AACA,gBAAMuG,YAAY,GAAG/G,OAAO,CAACP,KAA7B;;AAEA,cAAI;AACF,gBAAIqH,SAAS,KAAK,CAAC,CAAf,IAAoBA,SAAS,GAAGC,YAApC,EAAkD;AAChD;AACA,oBAAM/G,OAAO,CAACgB,EAAR,CAAW8F,SAAS,GAAGC,YAAvB,CAAN;AACD,aAHD,MAGO;AACL;AACA;AACA;AACA,oBAAM/G,OAAO,CAACgB,EAAR,CAAW6F,YAAX,CAAN;AACD,aATC,CAWF;;;AACA7G,YAAAA,OAAO,CAACc,OAAR,CAAgB;AAAEN,cAAAA,IAAF;AAAQL,cAAAA;AAAR,aAAhB;AACD,WAbD,CAaE,OAAOmG,CAAP,EAAU,CACV;AACD;AACF,SAtBM,MAsBA;AACL;AACAtG,UAAAA,OAAO,CAACc,OAAR,CAAgB;AAAEN,YAAAA,IAAF;AAAQL,YAAAA;AAAR,WAAhB;AACD;AACF,OA7CD,MA6CO;AACL;AACA;AACAH,QAAAA,OAAO,CAACc,OAAR,CAAgB;AAAEN,UAAAA,IAAF;AAAQL,UAAAA;AAAR,SAAhB;AACD;AACF,KA3ED,CArBoB,CAkGpB;AACA;AACA;;;AACA,2BAAO2B,GAAG,CAACyC,OAAX,iDAAO,aAAayC,WAAb,CAAyB,OAAzB,EAAkC5D,MAAM,CAACoD,aAAD,CAAxC,CAAP;AACD,GAtGD;AAwGA,SAAO;AACL9B,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import * as React from 'react';\nimport {\n getStateFromPath as getStateFromPathDefault,\n getPathFromState as getPathFromStateDefault,\n getActionFromState as getActionFromStateDefault,\n NavigationContainerRef,\n NavigationState,\n} from '@react-navigation/core';\nimport { nanoid } from 'nanoid/non-secure';\nimport ServerContext from './ServerContext';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\ntype HistoryRecord = {\n // Unique identifier for this record to match it with window.history.state\n id: string;\n // Navigation state object for the history entry\n state: NavigationState;\n // Path of the history entry\n path: string;\n};\n\nconst createMemoryHistory = () => {\n let index = 0;\n let items: HistoryRecord[] = [];\n\n // Pending callbacks for `history.go(n)`\n // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n const interrupt = () => {\n // If another history operation was performed we need to interrupt existing ones\n // This makes sure that calls such as `history.replace` after `history.go` don't happen\n // Since otherwise it won't be correct if something else has changed\n pending.forEach((it) => {\n const cb = it.cb;\n it.cb = () => cb(true);\n });\n };\n\n const history = {\n get index(): number {\n // We store an id in the state instead of an index\n // Index could get out of sync with in-memory values if page reloads\n const id = window.history.state?.id;\n\n if (id) {\n const index = items.findIndex((item) => item.id === id);\n\n return index > -1 ? index : 0;\n }\n\n return 0;\n },\n\n get(index: number) {\n return items[index];\n },\n\n backIndex({ path }: { path: string }) {\n // We need to find the index from the element before current to get closest path to go back to\n for (let i = index - 1; i >= 0; i--) {\n const item = items[i];\n\n if (item.path === path) {\n return i;\n }\n }\n\n return -1;\n },\n\n push({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = nanoid();\n\n // When a new entry is pushed, all the existing entries after index will be inaccessible\n // So we remove any existing entries after the current index to clean them up\n items = items.slice(0, index + 1);\n\n items.push({ path, state, id });\n index = items.length - 1;\n\n // We pass empty string for title because it's ignored in all browsers except safari\n // We don't store state object in history.state because:\n // - browsers have limits on how big it can be, and we don't control the size\n // - while not recommended, there could be non-serializable data in state\n window.history.pushState({ id }, '', path);\n },\n\n replace({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = window.history.state?.id ?? nanoid();\n\n if (items.length) {\n items[index] = { path, state, id };\n } else {\n // This is the first time any state modifications are done\n // So we need to push the entry as there's nothing to replace\n items.push({ path, state, id });\n }\n\n window.history.replaceState({ id }, '', path);\n },\n\n // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n go(n: number) {\n interrupt();\n\n if (n > 0) {\n // We shouldn't go forward more than available index\n n = Math.min(n, items.length - 1);\n } else if (n < 0) {\n // We shouldn't go back more than the 0 index\n // Otherwise we'll exit the page\n n = index + n < 0 ? -index : n;\n }\n\n if (n === 0) {\n return;\n }\n\n index += n;\n\n // When we call `history.go`, `popstate` will fire when there's history to go back to\n // So we need to somehow handle following cases:\n // - There's history to go back, `history.go` is called, and `popstate` fires\n // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n // - No history to go back, but `history.go` was called, browser has no API to detect it\n return new Promise<void>((resolve, reject) => {\n const done = (interrupted?: boolean) => {\n clearTimeout(timer);\n\n if (interrupted) {\n reject(new Error('History was changed during navigation.'));\n return;\n }\n\n // There seems to be a bug in Chrome regarding updating the title\n // If we set a title just before calling `history.go`, the title gets lost\n // However the value of `document.title` is still what we set it to\n // It's just not displayed in the tab bar\n // To update the tab bar, we need to reset the title to something else first (e.g. '')\n // And set the title to what it was before so it gets applied\n // It won't work without setting it to empty string coz otherwise title isn't changing\n // Which means that the browser won't do anything after setting the title\n const { title } = window.document;\n\n window.document.title = '';\n window.document.title = title;\n\n resolve();\n };\n\n pending.push({ ref: done, cb: done });\n\n // If navigation didn't happen within 100ms, assume that it won't happen\n // This may not be accurate, but hopefully it won't take so much time\n // In Chrome, navigation seems to happen instantly in next microtask\n // But on Firefox, it seems to take much longer, around 50ms from our testing\n // We're using a hacky timeout since there doesn't seem to be way to know for sure\n const timer = setTimeout(() => {\n const index = pending.findIndex((it) => it.ref === done);\n\n if (index > -1) {\n pending[index].cb();\n pending.splice(index, 1);\n }\n }, 100);\n\n const onPopState = () => {\n const last = pending.pop();\n\n window.removeEventListener('popstate', onPopState);\n last?.cb();\n };\n\n window.addEventListener('popstate', onPopState);\n window.history.go(n);\n });\n },\n\n // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n listen(listener: () => void) {\n const onPopState = () => {\n if (pending.length) {\n // This was triggered by `history.go(n)`, we shouldn't call the listener\n return;\n }\n\n listener();\n };\n\n window.addEventListener('popstate', onPopState);\n\n return () => window.removeEventListener('popstate', onPopState);\n },\n };\n\n return history;\n};\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nconst series = (cb: () => Promise<void>) => {\n // Whether we're currently handling a callback\n let handling = false;\n let queue: (() => Promise<void>)[] = [];\n\n const callback = async () => {\n try {\n if (handling) {\n // If we're currently handling a previous event, wait before handling this one\n // Add the callback to the beginning of the queue\n queue.unshift(callback);\n return;\n }\n\n handling = true;\n\n await cb();\n } finally {\n handling = false;\n\n if (queue.length) {\n // If we have queued items, handle the last one\n const last = queue.pop();\n\n last?.();\n }\n }\n };\n\n return callback;\n};\n\nlet isUsingLinking = false;\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef>,\n {\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: LinkingOptions\n) {\n React.useEffect(() => {\n if (enabled !== false && isUsingLinking) {\n throw new Error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since URL integration should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You are not using both 'linking' prop and 'useLinking'\",\n \"- You don't have 'useLinking' in multiple components\",\n ]\n .join('\\n')\n .trim()\n );\n } else {\n isUsingLinking = enabled !== false;\n }\n\n return () => {\n isUsingLinking = false;\n };\n });\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getActionFromStateRef = React.useRef(getActionFromState);\n const getPathFromStateRef = React.useRef(getPathFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getActionFromStateRef.current = getActionFromState;\n getPathFromStateRef.current = getPathFromState;\n });\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ??\n (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const path = location.pathname + location.search;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n if (index > previousIndex) {\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${e.message}`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, ref]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const path = getPathFromStateRef.current(state, configRef.current);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n const pendingPath = pendingPopStatePathRef.current;\n const path = getPathFromStateRef.current(state, configRef.current);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(\n previousState,\n state\n );\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history\n ? focusedState.history.length\n : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (nextIndex !== -1 && nextIndex < currentIndex) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch (e) {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n });\n\n return {\n getInitialState,\n };\n}\n"]} | ||
| {"version":3,"names":["findFocusedRoute","getActionFromState","getActionFromStateDefault","getPathFromState","getPathFromStateDefault","getStateFromPath","getStateFromPathDefault","isEqual","React","createMemoryHistory","ServerContext","findMatchingState","a","b","undefined","key","aHistoryLength","history","length","routes","bHistoryLength","aRoute","index","bRoute","aChildState","state","bChildState","series","cb","queue","Promise","resolve","callback","then","linkingHandlers","useLinking","ref","independent","enabled","config","useEffect","process","env","NODE_ENV","console","error","join","trim","handler","Symbol","push","indexOf","splice","useState","enabledRef","useRef","configRef","getStateFromPathRef","getPathFromStateRef","getActionFromStateRef","current","server","useContext","getInitialState","useCallback","value","location","window","path","pathname","search","thenable","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","listen","navigation","previousIndex","record","get","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","warn","action","dispatch","e","message","getPathForRoute","route","stateForPath","focusedRoute","params","replace","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","backIndex","currentIndex","go","addListener"],"sourceRoot":"../../src","sources":["useLinking.tsx"],"mappings":"AAAA,SACEA,gBAAgB,EAChBC,kBAAkB,IAAIC,yBAAyB,EAC/CC,gBAAgB,IAAIC,uBAAuB,EAC3CC,gBAAgB,IAAIC,uBAAuB,QA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AEA,MAAMC,SAAS,GAAG1F,OAAO,CAAC2F,SAAS,CAAC;YAAExC;UAAK,CAAC,CAAC;UAC7C,MAAMyC,YAAY,GAAG5F,OAAO,CAACK,KAAK;UAElC,IAAI;YACF,IAAIqF,SAAS,KAAK,CAAC,CAAC,IAAIA,SAAS,GAAGE,YAAY,EAAE;cAChD;cACA,MAAM5F,OAAO,CAAC6F,EAAE,CAACH,SAAS,GAAGE,YAAY,CAAC;YAC5C,CAAC,MAAM;cACL;cACA;cACA;cACA,MAAM5F,OAAO,CAAC6F,EAAE,CAACJ,YAAY,CAAC;YAChC;;YAEA;YACAzF,OAAO,CAACmF,OAAO,CAAC;cAAEhC,IAAI;cAAE3C;YAAM,CAAC,CAAC;UAClC,CAAC,CAAC,OAAOoE,CAAC,EAAE;YACV;UAAA;QAEJ,CAAC,MAAM;UACL;UACA5E,OAAO,CAACmF,OAAO,CAAC;YAAEhC,IAAI;YAAE3C;UAAM,CAAC,CAAC;QAClC;MACF,CAAC,MAAM;QACL;QACA;QACAR,OAAO,CAACmF,OAAO,CAAC;UAAEhC,IAAI;UAAE3C;QAAM,CAAC,CAAC;MAClC;IACF,CAAC;;IAED;IACA;IACA;IACA,uBAAOW,GAAG,CAACwB,OAAO,iDAAX,aAAamD,WAAW,CAAC,OAAO,EAAEpF,MAAM,CAAC0E,aAAa,CAAC,CAAC;EACjE,CAAC,EAAE,CAAC/D,OAAO,EAAErB,OAAO,EAAEmB,GAAG,CAAC,CAAC;EAE3B,OAAO;IACL2B;EACF,CAAC;AACH"} |
@@ -0,47 +1,70 @@ | ||
| import { getActionFromState as getActionFromStateDefault, getStateFromPath as getStateFromPathDefault } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { Linking, Platform } from 'react-native'; | ||
| import { getActionFromState as getActionFromStateDefault, getStateFromPath as getStateFromPathDefault } from '@react-navigation/core'; | ||
| import extractPathFromURL from './extractPathFromURL'; | ||
| let isUsingLinking = false; | ||
| export default function useLinking(ref, { | ||
| enabled = true, | ||
| prefixes, | ||
| config, | ||
| getInitialURL = () => Promise.race([Linking.getInitialURL(), new Promise(resolve => // Timeout in 150ms if `getInitialState` doesn't resolve | ||
| // Workaround for https://github.com/facebook/react-native/issues/25675 | ||
| setTimeout(resolve, 150))]), | ||
| subscribe = listener => { | ||
| const callback = ({ | ||
| url | ||
| }) => listener(url); | ||
| let linkingHandlers = []; | ||
| export default function useLinking(ref, _ref) { | ||
| let { | ||
| independent, | ||
| enabled = true, | ||
| prefixes, | ||
| filter, | ||
| config, | ||
| getInitialURL = () => Promise.race([Linking.getInitialURL(), new Promise(resolve => | ||
| // Timeout in 150ms if `getInitialState` doesn't resolve | ||
| // Workaround for https://github.com/facebook/react-native/issues/25675 | ||
| setTimeout(resolve, 150))]), | ||
| subscribe = listener => { | ||
| var _Linking$removeEventL; | ||
| const callback = _ref2 => { | ||
| let { | ||
| url | ||
| } = _ref2; | ||
| return listener(url); | ||
| }; | ||
| const subscription = Linking.addEventListener('url', callback); | ||
| const subscription = Linking.addEventListener('url', callback); | ||
| // Storing this in a local variable stops Jest from complaining about import after teardown | ||
| // @ts-expect-error: removeEventListener is not present in newer RN versions | ||
| const removeEventListener = (_Linking$removeEventL = Linking.removeEventListener) === null || _Linking$removeEventL === void 0 ? void 0 : _Linking$removeEventL.bind(Linking); | ||
| return () => { | ||
| // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7 | ||
| if (subscription !== null && subscription !== void 0 && subscription.remove) { | ||
| subscription.remove(); | ||
| } else { | ||
| removeEventListener === null || removeEventListener === void 0 ? void 0 : removeEventListener('url', callback); | ||
| } | ||
| }; | ||
| }, | ||
| getStateFromPath = getStateFromPathDefault, | ||
| getActionFromState = getActionFromStateDefault | ||
| } = _ref; | ||
| React.useEffect(() => { | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return undefined; | ||
| } | ||
| if (independent) { | ||
| return undefined; | ||
| } | ||
| if (enabled !== false && linkingHandlers.length) { | ||
| console.error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", '- Only a single instance of the root component is rendered', Platform.OS === 'android' ? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances" : ''].join('\n').trim()); | ||
| } | ||
| const handler = Symbol(); | ||
| if (enabled !== false) { | ||
| linkingHandlers.push(handler); | ||
| } | ||
| return () => { | ||
| // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7 | ||
| if (subscription !== null && subscription !== void 0 && subscription.remove) { | ||
| subscription.remove(); | ||
| } else { | ||
| Linking.removeEventListener('url', callback); | ||
| const index = linkingHandlers.indexOf(handler); | ||
| if (index > -1) { | ||
| linkingHandlers.splice(index, 1); | ||
| } | ||
| }; | ||
| }, | ||
| getStateFromPath = getStateFromPathDefault, | ||
| getActionFromState = getActionFromStateDefault | ||
| }) { | ||
| React.useEffect(() => { | ||
| if (enabled !== false && isUsingLinking) { | ||
| throw new Error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You are not using both 'linking' prop and 'useLinking'", "- You don't have 'useLinking' in multiple components", Platform.OS === 'android' ? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances" : ''].join('\n').trim()); | ||
| } else { | ||
| isUsingLinking = enabled !== false; | ||
| } | ||
| }, [enabled, independent]); | ||
| return () => { | ||
| isUsingLinking = false; | ||
| }; | ||
| }); // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo` | ||
| // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect | ||
| const enabledRef = React.useRef(enabled); | ||
| const prefixesRef = React.useRef(prefixes); | ||
| const filterRef = React.useRef(filter); | ||
| const configRef = React.useRef(config); | ||
@@ -54,2 +77,3 @@ const getInitialURLRef = React.useRef(getInitialURL); | ||
| prefixesRef.current = prefixes; | ||
| filterRef.current = filter; | ||
| configRef.current = config; | ||
@@ -60,19 +84,21 @@ getInitialURLRef.current = getInitialURL; | ||
| }); | ||
| const getStateFromURL = React.useCallback(url => { | ||
| if (!url || filterRef.current && !filterRef.current(url)) { | ||
| return undefined; | ||
| } | ||
| const path = extractPathFromURL(prefixesRef.current, url); | ||
| return path !== undefined ? getStateFromPathRef.current(path, configRef.current) : undefined; | ||
| }, []); | ||
| const getInitialState = React.useCallback(() => { | ||
| let state; | ||
| if (enabledRef.current) { | ||
| const url = getInitialURLRef.current(); | ||
| if (url != null && typeof url !== 'string') { | ||
| return url.then(url => { | ||
| const path = url ? extractPathFromURL(prefixesRef.current, url) : null; | ||
| return path ? getStateFromPathRef.current(path, configRef.current) : undefined; | ||
| const state = getStateFromURL(url); | ||
| return state; | ||
| }); | ||
| } | ||
| const path = url ? extractPathFromURL(prefixesRef.current, url) : null; | ||
| state = path ? getStateFromPathRef.current(path, configRef.current) : undefined; | ||
| state = getStateFromURL(url); | ||
| } | ||
| const thenable = { | ||
@@ -82,10 +108,8 @@ then(onfulfilled) { | ||
| }, | ||
| catch() { | ||
| return thenable; | ||
| } | ||
| }; | ||
| return thenable; | ||
| }, []); | ||
| }, [getStateFromURL]); | ||
| React.useEffect(() => { | ||
@@ -96,38 +120,28 @@ const listener = url => { | ||
| } | ||
| const path = extractPathFromURL(prefixesRef.current, url); | ||
| const navigation = ref.current; | ||
| if (navigation && path) { | ||
| const state = getStateFromPathRef.current(path, configRef.current); | ||
| if (state) { | ||
| // Make sure that the routes in the state exist in the root navigator | ||
| // Otherwise there's an error in the linking configuration | ||
| const rootState = navigation.getRootState(); | ||
| if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) { | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration."); | ||
| return; | ||
| const state = navigation ? getStateFromURL(url) : undefined; | ||
| if (navigation && state) { | ||
| // Make sure that the routes in the state exist in the root navigator | ||
| // Otherwise there's an error in the linking configuration | ||
| const rootState = navigation.getRootState(); | ||
| if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) { | ||
| console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."); | ||
| return; | ||
| } | ||
| const action = getActionFromStateRef.current(state, configRef.current); | ||
| if (action !== undefined) { | ||
| try { | ||
| navigation.dispatch(action); | ||
| } catch (e) { | ||
| // Ignore any errors from deep linking. | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn(`An error occurred when trying to handle the link '${url}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`); | ||
| } | ||
| const action = getActionFromStateRef.current(state, configRef.current); | ||
| if (action !== undefined) { | ||
| try { | ||
| navigation.dispatch(action); | ||
| } catch (e) { | ||
| // Ignore any errors from deep linking. | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn("An error occurred when trying to handle the link '".concat(path, "': ").concat(e.message)); | ||
| } | ||
| } else { | ||
| navigation.resetRoot(state); | ||
| } | ||
| } else { | ||
| navigation.resetRoot(state); | ||
| } | ||
| } | ||
| }; | ||
| return subscribe(listener); | ||
| }, [enabled, ref, subscribe]); | ||
| }, [enabled, getStateFromURL, ref, subscribe]); | ||
| return { | ||
@@ -134,0 +148,0 @@ getInitialState |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinking.native.tsx"],"names":["React","Linking","Platform","getActionFromState","getActionFromStateDefault","getStateFromPath","getStateFromPathDefault","extractPathFromURL","isUsingLinking","useLinking","ref","enabled","prefixes","config","getInitialURL","Promise","race","resolve","setTimeout","subscribe","listener","callback","url","subscription","addEventListener","remove","removeEventListener","useEffect","Error","OS","join","trim","enabledRef","useRef","prefixesRef","configRef","getInitialURLRef","getStateFromPathRef","getActionFromStateRef","current","getInitialState","useCallback","state","then","path","undefined","thenable","onfulfilled","catch","navigation","rootState","getRootState","routes","some","r","routeNames","includes","name","console","warn","action","dispatch","e","message","resetRoot"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,OAAT,EAAkBC,QAAlB,QAAkC,cAAlC;AACA,SACEC,kBAAkB,IAAIC,yBADxB,EAEEC,gBAAgB,IAAIC,uBAFtB,QAIO,wBAJP;AAKA,OAAOC,kBAAP,MAA+B,sBAA/B;AAKA,IAAIC,cAAc,GAAG,KAArB;AAEA,eAAe,SAASC,UAAT,CACbC,GADa,EAEb;AACEC,EAAAA,OAAO,GAAG,IADZ;AAEEC,EAAAA,QAFF;AAGEC,EAAAA,MAHF;AAIEC,EAAAA,aAAa,GAAG,MACdC,OAAO,CAACC,IAAR,CAAa,CACXf,OAAO,CAACa,aAAR,EADW,EAEX,IAAIC,OAAJ,CAAwBE,OAAD,IACrB;AACA;AACAC,EAAAA,UAAU,CAACD,OAAD,EAAU,GAAV,CAHZ,CAFW,CAAb,CALJ;AAaEE,EAAAA,SAAS,GAAIC,QAAD,IAAc;AACxB,UAAMC,QAAQ,GAAG,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAA8BF,QAAQ,CAACE,GAAD,CAAvD;;AAEA,UAAMC,YAAY,GAAGtB,OAAO,CAACuB,gBAAR,CAAyB,KAAzB,EAAgCH,QAAhC,CAArB;AAIA,WAAO,MAAM;AACX;AACA,UAAIE,YAAJ,aAAIA,YAAJ,eAAIA,YAAY,CAAEE,MAAlB,EAA0B;AACxBF,QAAAA,YAAY,CAACE,MAAb;AACD,OAFD,MAEO;AACLxB,QAAAA,OAAO,CAACyB,mBAAR,CAA4B,KAA5B,EAAmCL,QAAnC;AACD;AACF,KAPD;AAQD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ACLqB,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import * as React from 'react';\nimport { Linking, Platform } from 'react-native';\nimport {\n getActionFromState as getActionFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n} from '@react-navigation/core';\nimport extractPathFromURL from './extractPathFromURL';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\nlet isUsingLinking = false;\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef>,\n {\n enabled = true,\n prefixes,\n config,\n getInitialURL = () =>\n Promise.race([\n Linking.getInitialURL(),\n new Promise<undefined>((resolve) =>\n // Timeout in 150ms if `getInitialState` doesn't resolve\n // Workaround for https://github.com/facebook/react-native/issues/25675\n setTimeout(resolve, 150)\n ),\n ]),\n subscribe = (listener) => {\n const callback = ({ url }: { url: string }) => listener(url);\n\n const subscription = Linking.addEventListener('url', callback) as\n | { remove(): void }\n | undefined;\n\n return () => {\n // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7\n if (subscription?.remove) {\n subscription.remove();\n } else {\n Linking.removeEventListener('url', callback);\n }\n };\n },\n getStateFromPath = getStateFromPathDefault,\n getActionFromState = getActionFromStateDefault,\n }: LinkingOptions\n) {\n React.useEffect(() => {\n if (enabled !== false && isUsingLinking) {\n throw new Error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You are not using both 'linking' prop and 'useLinking'\",\n \"- You don't have 'useLinking' in multiple components\",\n Platform.OS === 'android'\n ? \"- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances\"\n : '',\n ]\n .join('\\n')\n .trim()\n );\n } else {\n isUsingLinking = enabled !== false;\n }\n\n return () => {\n isUsingLinking = false;\n };\n });\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const prefixesRef = React.useRef(prefixes);\n const configRef = React.useRef(config);\n const getInitialURLRef = React.useRef(getInitialURL);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n prefixesRef.current = prefixes;\n configRef.current = config;\n getInitialURLRef.current = getInitialURL;\n getStateFromPathRef.current = getStateFromPath;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const getInitialState = React.useCallback(() => {\n let state: ResultState | undefined;\n\n if (enabledRef.current) {\n const url = getInitialURLRef.current();\n\n if (url != null && typeof url !== 'string') {\n return url.then((url) => {\n const path = url\n ? extractPathFromURL(prefixesRef.current, url)\n : null;\n\n return path\n ? getStateFromPathRef.current(path, configRef.current)\n : undefined;\n });\n }\n\n const path = url ? extractPathFromURL(prefixesRef.current, url) : null;\n\n state = path\n ? getStateFromPathRef.current(path, configRef.current)\n : undefined;\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(state) : state);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n }, []);\n\n React.useEffect(() => {\n const listener = (url: string) => {\n if (!enabled) {\n return;\n }\n\n const path = extractPathFromURL(prefixesRef.current, url);\n const navigation = ref.current;\n\n if (navigation && path) {\n const state = getStateFromPathRef.current(path, configRef.current);\n\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (\n state.routes.some((r) => !rootState?.routeNames.includes(r.name))\n ) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${e.message}`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n }\n }\n };\n\n return subscribe(listener);\n }, [enabled, ref, subscribe]);\n\n return {\n getInitialState,\n };\n}\n"]} | ||
| {"version":3,"names":["getActionFromState","getActionFromStateDefault","getStateFromPath","getStateFromPathDefault","React","Linking","Platform","extractPathFromURL","linkingHandlers","useLinking","ref","independent","enabled","prefixes","filter","config","getInitialURL","Promise","race","resolve","setTimeout","subscribe","listener","callback","url","subscription","addEventListener","removeEventListener","bind","remove","useEffect","process","env","NODE_ENV","undefined","length","console","error","OS","join","trim","handler","Symbol","push","index","indexOf","splice","enabledRef","useRef","prefixesRef","filterRef","configRef","getInitialURLRef","getStateFromPathRef","getActionFromStateRef","current","getStateFromURL","useCallback","path","getInitialState","state","then","thenable","onfulfilled","catch","navigation","rootState","getRootState","routes","some","r","routeNames","includes","name","warn","action","dispatch","e","message","resetRoot"],"sourceRoot":"../../src","sources":["useLinking.native.tsx"],"mappings":"AAAA,SACEA,kBAAkB,IAAIC,yBAAyB,EAC/CC,gBAAgB,IAAIC,uBAAuB,QAGtC,wBAAwB;AAC/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,OAAO,EAAEC,QAAQ,QAAQ,cAAc;AAEhD,OAAOC,kBAAkB,MAAM,sBAAsB;AASrD,IAAIC,eAAyB,GAAG,EAAE;AAElC,eAAe,SAASC,UAAU,CAChCC,GAA2D,QAuC3D;EAAA,IAtCA;IACEC,WAAW;IACXC,OAAO,GAAG,IAAI;IACdC,QAAQ;IACRC,MAAM;IACNC,MAAM;IACNC,aAAa,GAAG,MACdC,OAAO,CAACC,IAAI,CAAC,CACXb,OAAO,CAACW,aAAa,EAAE,EACvB,IAAIC,OAAO,CAAaE,OAAO;IA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IAAI,CAACZ,OAAO,EAAE;QACZ;MACF;MAEA,MAAMqD,UAAU,GAAGvD,GAAG,CAAC6C,OAAO;MAC9B,MAAMK,KAAK,GAAGK,UAAU,GAAGT,eAAe,CAAChC,GAAG,CAAC,GAAGU,SAAS;MAE3D,IAAI+B,UAAU,IAAIL,KAAK,EAAE;QACvB;QACA;QACA,MAAMM,SAAS,GAAGD,UAAU,CAACE,YAAY,EAAE;QAE3C,IAAIP,KAAK,CAACQ,MAAM,CAACC,IAAI,CAAEC,CAAC,IAAK,EAACJ,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEK,UAAU,CAACC,QAAQ,CAACF,CAAC,CAACG,IAAI,CAAC,EAAC,EAAE;UACrErC,OAAO,CAACsC,IAAI,CACV,0SAA0S,CAC3S;UACD;QACF;QAEA,MAAMC,MAAM,GAAGrB,qBAAqB,CAACC,OAAO,CAACK,KAAK,EAAET,SAAS,CAACI,OAAO,CAAC;QAEtE,IAAIoB,MAAM,KAAKzC,SAAS,EAAE;UACxB,IAAI;YACF+B,UAAU,CAACW,QAAQ,CAACD,MAAM,CAAC;UAC7B,CAAC,CAAC,OAAOE,CAAC,EAAE;YACV;YACA;YACAzC,OAAO,CAACsC,IAAI,CACT,qDAAoDlD,GAAI,MACvD,OAAOqD,CAAC,KAAK,QAAQ,IAAIA,CAAC,IAAI,IAAI,IAAI,SAAS,IAAIA,CAAC,GAChDA,CAAC,CAACC,OAAO,GACTD,CACL,EAAC,CACH;UACH;QACF,CAAC,MAAM;UACLZ,UAAU,CAACc,SAAS,CAACnB,KAAK,CAAC;QAC7B;MACF;IACF,CAAC;IAED,OAAOvC,SAAS,CAACC,QAAQ,CAAC;EAC5B,CAAC,EAAE,CAACV,OAAO,EAAE4C,eAAe,EAAE9C,GAAG,EAAEW,SAAS,CAAC,CAAC;EAE9C,OAAO;IACLsC;EACF,CAAC;AACH"} |
@@ -0,5 +1,22 @@ | ||
| import { getPathFromState, NavigationContainerRefContext, NavigationHelpersContext } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { Platform } from 'react-native'; | ||
| import { NavigationHelpersContext } from '@react-navigation/core'; | ||
| import LinkingContext from './LinkingContext'; | ||
| import useLinkTo from './useLinkTo'; | ||
| const getStateFromParams = params => { | ||
| if (params !== null && params !== void 0 && params.state) { | ||
| return params.state; | ||
| } | ||
| if (params !== null && params !== void 0 && params.screen) { | ||
| return { | ||
| routes: [{ | ||
| name: params.screen, | ||
| params: params.params, | ||
| // @ts-expect-error | ||
| state: params.screen ? getStateFromParams(params.params) : undefined | ||
| }] | ||
| }; | ||
| } | ||
| return undefined; | ||
| }; | ||
@@ -12,28 +29,32 @@ /** | ||
| */ | ||
| export default function useLinkProps({ | ||
| to, | ||
| action | ||
| }) { | ||
| export default function useLinkProps(_ref) { | ||
| let { | ||
| to, | ||
| action | ||
| } = _ref; | ||
| const root = React.useContext(NavigationContainerRefContext); | ||
| const navigation = React.useContext(NavigationHelpersContext); | ||
| const { | ||
| options | ||
| } = React.useContext(LinkingContext); | ||
| const linkTo = useLinkTo(); | ||
| const onPress = e => { | ||
| var _e$currentTarget; | ||
| let shouldHandle = false; | ||
| if (Platform.OS !== 'web' || !e) { | ||
| shouldHandle = e ? !e.defaultPrevented : true; | ||
| } else if (!e.defaultPrevented && // onPress prevented default | ||
| } else if (!e.defaultPrevented && | ||
| // onPress prevented default | ||
| // @ts-expect-error: these properties exist on web, but not in React Native | ||
| !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && ( // ignore clicks with modifier keys | ||
| !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && ( | ||
| // ignore clicks with modifier keys | ||
| // @ts-expect-error: these properties exist on web, but not in React Native | ||
| e.button == null || e.button === 0) && // ignore everything but left clicks | ||
| e.button == null || e.button === 0) && | ||
| // ignore everything but left clicks | ||
| // @ts-expect-error: these properties exist on web, but not in React Native | ||
| [undefined, null, '', 'self'].includes((_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : _e$currentTarget.target) // let browser handle "target=_blank" etc. | ||
| ) { | ||
| e.preventDefault(); | ||
| shouldHandle = true; | ||
| } | ||
| e.preventDefault(); | ||
| shouldHandle = true; | ||
| } | ||
| if (shouldHandle) { | ||
@@ -43,10 +64,8 @@ if (action) { | ||
| navigation.dispatch(action); | ||
| } else if (root) { | ||
| root.dispatch(action); | ||
| } else { | ||
| throw new Error("Couldn't find a navigation object."); | ||
| throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?"); | ||
| } | ||
| } else { | ||
| if (typeof to !== 'string') { | ||
| throw new Error("To 'to' option is invalid (found '".concat(String(to), "'. It must be a valid string for navigation.")); | ||
| } | ||
| linkTo(to); | ||
@@ -56,5 +75,14 @@ } | ||
| }; | ||
| const getPathFromStateHelper = (options === null || options === void 0 ? void 0 : options.getPathFromState) ?? getPathFromState; | ||
| const href = typeof to === 'string' ? to : getPathFromStateHelper({ | ||
| routes: [{ | ||
| name: to.screen, | ||
| // @ts-expect-error | ||
| params: to.params, | ||
| // @ts-expect-error | ||
| state: getStateFromParams(to.params) | ||
| }] | ||
| }, options === null || options === void 0 ? void 0 : options.config); | ||
| return { | ||
| href: to, | ||
| href, | ||
| accessibilityRole: 'link', | ||
@@ -61,0 +89,0 @@ onPress |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinkProps.tsx"],"names":["React","Platform","NavigationHelpersContext","useLinkTo","useLinkProps","to","action","navigation","useContext","linkTo","onPress","e","shouldHandle","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","undefined","includes","currentTarget","target","preventDefault","dispatch","Error","String","href","accessibilityRole"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,QAAgD,cAAhD;AACA,SAEEC,wBAFF,QAGO,wBAHP;AAIA,OAAOC,SAAP,MAAsB,aAAtB;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,YAAT,CAAsB;AAAEC,EAAAA,EAAF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AAEDI,QAAAA,MAAM,CAACJ,EAAD,CAAN;AACD;AACF;AACF,GAvCD;;AAyCA,SAAO;AACLuB,IAAAA,IAAI,EAAEvB,EADD;AAELwB,IAAAA,iBAAiB,EAAE,MAFd;AAGLnB,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["import * as React from 'react';\nimport { Platform, GestureResponderEvent } from 'react-native';\nimport {\n NavigationAction,\n NavigationHelpersContext,\n} from '@react-navigation/core';\nimport useLinkTo from './useLinkTo';\n\ntype Props = {\n to: string;\n action?: NavigationAction;\n};\n\n/**\n * Hook to get props for an anchor tag so it can work with in page navigation.\n *\n * @param props.to Absolute path to screen (e.g. `/feeds/hot`).\n * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.\n */\nexport default function useLinkProps({ to, action }: Props) {\n const navigation = React.useContext(NavigationHelpersContext);\n const linkTo = useLinkTo();\n\n const onPress = (\n e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => {\n let shouldHandle = false;\n\n if (Platform.OS !== 'web' || !e) {\n shouldHandle = e ? !e.defaultPrevented : true;\n } else if (\n !e.defaultPrevented && // onPress prevented default\n // @ts-expect-error: these properties exist on web, but not in React Native\n !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys\n // @ts-expect-error: these properties exist on web, but not in React Native\n (e.button == null || e.button === 0) && // ignore everything but left clicks\n // @ts-expect-error: these properties exist on web, but not in React Native\n [undefined, null, '', 'self'].includes(e.currentTarget?.target) // let browser handle \"target=_blank\" etc.\n ) {\n e.preventDefault();\n shouldHandle = true;\n }\n\n if (shouldHandle) {\n if (action) {\n if (navigation) {\n navigation.dispatch(action);\n } else {\n throw new Error(\"Couldn't find a navigation object.\");\n }\n } else {\n if (typeof to !== 'string') {\n throw new Error(\n `To 'to' option is invalid (found '${String(\n to\n )}'. It must be a valid string for navigation.`\n );\n }\n\n linkTo(to);\n }\n }\n };\n\n return {\n href: to,\n accessibilityRole: 'link' as const,\n onPress,\n };\n}\n"]} | ||
| {"version":3,"names":["getPathFromState","NavigationContainerRefContext","NavigationHelpersContext","React","Platform","LinkingContext","useLinkTo","getStateFromParams","params","state","screen","routes","name","undefined","useLinkProps","to","action","root","useContext","navigation","options","linkTo","onPress","e","shouldHandle","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","includes","currentTarget","target","preventDefault","dispatch","Error","getPathFromStateHelper","href","config","accessibilityRole"],"sourceRoot":"../../src","sources":["useLinkProps.tsx"],"mappings":"AAAA,SACEA,gBAAgB,EAEhBC,6BAA6B,EAC7BC,wBAAwB,QAGnB,wBAAwB;AAE/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAAgCC,QAAQ,QAAQ,cAAc;AAE9D,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,SAAS,MAAc,aAAa;AAO3C,MAAMC,kBAAkB,GACtBC,MAAyE,IACT;EAChE,IAAIA,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEC,KAAK,EAAE;IACjB,OAAOD,MAAM,CAACC,KAAK;EACrB;EAEA,IAAID,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEE,MAAM,EAAE;IAClB,OAAO;MACLC,MAAM,EAAE,CACN;QACEC,IAAI,EAAEJ,MAAM,CAACE,MAAM;QACnBF,MAAM,EAAEA,MAAM,CAACA,MAAM;QACrB;QACAC,KAAK,EAAED,MAAM,CAACE,MAAM,GAChBH,kBAAkB,CAChBC,MAAM,CAACA,MAAM,CAGd,GACDK;MACN,CAAC;IAEL,CAAC;EACH;EAEA,OAAOA,SAAS;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,YAAY,OAEA;EAAA,IAAlC;IAAEC,EAAE;IAAEC;EAAyB,CAAC;EAChC,MAAMC,IAAI,GAAGd,KAAK,CAACe,UAAU,CAACjB,6BAA6B,CAAC;EAC5D,MAAMkB,UAAU,GAAGhB,KAAK,CAACe,UAAU,CAACh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APA,OAAO,uBAAPA,OAAO,CAAEpB,gBAAgB,KAAIA,gBAAgB;EAE5E,MAAMuC,IAAI,GACR,OAAOxB,EAAE,KAAK,QAAQ,GAClBA,EAAE,GACFuB,sBAAsB,CACpB;IACE3B,MAAM,EAAE,CACN;MACEC,IAAI,EAAEG,EAAE,CAACL,MAAM;MACf;MACAF,MAAM,EAAEO,EAAE,CAACP,MAAM;MACjB;MACAC,KAAK,EAAEF,kBAAkB,CAACQ,EAAE,CAACP,MAAM;IACrC,CAAC;EAEL,CAAC,EACDY,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEoB,MAAM,CAChB;EAEP,OAAO;IACLD,IAAI;IACJE,iBAAiB,EAAE,MAAe;IAClCnB;EACF,CAAC;AACH"} |
+15
-21
@@ -0,35 +1,29 @@ | ||
| import { getActionFromState, getStateFromPath, NavigationContainerRefContext } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { getStateFromPath, getActionFromState, NavigationContext } from '@react-navigation/core'; | ||
| import LinkingContext from './LinkingContext'; | ||
| export default function useLinkTo() { | ||
| const navigation = React.useContext(NavigationContext); | ||
| const navigation = React.useContext(NavigationContainerRefContext); | ||
| const linking = React.useContext(LinkingContext); | ||
| const linkTo = React.useCallback(path => { | ||
| if (!path.startsWith('/')) { | ||
| throw new Error("The path must start with '/' (".concat(path, ").")); | ||
| } | ||
| const linkTo = React.useCallback(to => { | ||
| if (navigation === undefined) { | ||
| throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?"); | ||
| throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?"); | ||
| } | ||
| if (typeof to !== 'string') { | ||
| // @ts-expect-error: This is fine | ||
| navigation.navigate(to.screen, to.params); | ||
| return; | ||
| } | ||
| if (!to.startsWith('/')) { | ||
| throw new Error(`The path must start with '/' (${to}).`); | ||
| } | ||
| const { | ||
| options | ||
| } = linking; | ||
| const state = options !== null && options !== void 0 && options.getStateFromPath ? options.getStateFromPath(path, options.config) : getStateFromPath(path, options === null || options === void 0 ? void 0 : options.config); | ||
| const state = options !== null && options !== void 0 && options.getStateFromPath ? options.getStateFromPath(to, options.config) : getStateFromPath(to, options === null || options === void 0 ? void 0 : options.config); | ||
| if (state) { | ||
| let root = navigation; | ||
| let current; // Traverse up to get the root navigation | ||
| while (current = root.getParent()) { | ||
| root = current; | ||
| } | ||
| const action = getActionFromState(state, options === null || options === void 0 ? void 0 : options.config); | ||
| if (action !== undefined) { | ||
| root.dispatch(action); | ||
| navigation.dispatch(action); | ||
| } else { | ||
| root.reset(state); | ||
| navigation.reset(state); | ||
| } | ||
@@ -36,0 +30,0 @@ } else { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useLinkTo.tsx"],"names":["React","getStateFromPath","getActionFromState","NavigationContext","LinkingContext","useLinkTo","navigation","useContext","linking","linkTo","useCallback","path","startsWith","Error","undefined","options","state","config","root","current","getParent","action","dispatch","reset"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,gBADF,EAEEC,kBAFF,EAGEC,iBAHF,QAIO,wBAJP;AAKA,OAAOC,cAAP,MAA2B,kBAA3B;AAEA,eAAe,SAASC,SAAT,GAAqB;AAClC,QAAMC,UAAU,GAAGN,KAAK,CAACO,UAAN,CAAiBJ,iBAAjB,CAAnB;AACA,QAAMK,OAAO,GAAGR,KAAK,CAACO,UAAN,CAAiBH,cAAjB,CAAhB;AAEA,QAAMK,MAAM,GAAGT,KAAK,CAACU,WAAN,CACZC,IAAD,IAAkB;AAChB,QAAI,CAACA,IAAI,CAACC,UAAL,CAAgB,GAAhB,CAAL,EAA2B;AACzB,YAAM,IAAIC,KAAJ,yCAA2CF,IAA3C,QAAN;AACD;;AAED,QAAIL,UAAU,KAAKQ,SAAnB,EAA8B;AAC5B,YAAM,IAAID,KAAJ,CACJ,sFADI,CAAN;AAGD;;AAED,UAAM;AAAEE,MAAAA;AAAF,QAAcP,OAApB;AAEA,UAAMQ,KAAK,GAAGD,OAAO,SAAP,IAAAA,OAAO,WAAP,IAAAA,OAAO,CAAEd,gBAAT,GACVc,OAAO,CAACd,gBAAR,CAAyBU,IAAzB,EAA+BI,OAAO,CAACE,MAAvC,CADU,GAEVhB,gBAAgB,CAACU,IAAD,EAAOI,OAAP,aAAOA,OAAP,uBAAOA,OAAO,CAAEE,MAAhB,CAFpB;;AAIA,QAAID,KAAJ,EAAW;AACT,UAAIE,IAAI,GAAGZ,UAAX;AACA,UAAIa,OAAJ,CAFS,CAIT;;AACA,aAAQA,OAAO,GAAGD,IAAI,CAACE,SAAL,EAAlB,EAAqC;AACnCF,QAAAA,IAAI,GAAGC,OAAP;AACD;;AAED,YAAME,MAAM,GAAGnB,kBAAkB,CAACc,KAAD,EAAQD,OAAR,aAAQA,OAAR,uBAAQA,OAAO,CAAEE,MAAjB,CAAjC;;AAEA,UAAII,MAAM,KAAKP,SAAf,EAA0B;AACxBI,QAAAA,IAAI,CAACI,QAAL,CAAcD,MAAd;AACD,OAFD,MAEO;AACLH,QAAAA,IAAI,CAACK,KAAL,CAAWP,KAAX;AACD;AACF,KAhBD,MAgBO;AACL,YAAM,IAAIH,KAAJ,CAAU,iDAAV,CAAN;AACD;AACF,GArCY,EAsCb,CAACL,OAAD,EAAUF,UAAV,CAtCa,CAAf;AAyCA,SAAOG,MAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {\n getStateFromPath,\n getActionFromState,\n NavigationContext,\n} from '@react-navigation/core';\nimport LinkingContext from './LinkingContext';\n\nexport default function useLinkTo() {\n const navigation = React.useContext(NavigationContext);\n const linking = React.useContext(LinkingContext);\n\n const linkTo = React.useCallback(\n (path: string) => {\n if (!path.startsWith('/')) {\n throw new Error(`The path must start with '/' (${path}).`);\n }\n\n if (navigation === undefined) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside a screen in a navigator?\"\n );\n }\n\n const { options } = linking;\n\n const state = options?.getStateFromPath\n ? options.getStateFromPath(path, options.config)\n : getStateFromPath(path, options?.config);\n\n if (state) {\n let root = navigation;\n let current;\n\n // Traverse up to get the root navigation\n while ((current = root.getParent())) {\n root = current;\n }\n\n const action = getActionFromState(state, options?.config);\n\n if (action !== undefined) {\n root.dispatch(action);\n } else {\n root.reset(state);\n }\n } else {\n throw new Error('Failed to parse the path to a navigation state.');\n }\n },\n [linking, navigation]\n );\n\n return linkTo;\n}\n"]} | ||
| {"version":3,"names":["getActionFromState","getStateFromPath","NavigationContainerRefContext","React","LinkingContext","useLinkTo","navigation","useContext","linking","linkTo","useCallback","to","undefined","Error","navigate","screen","params","startsWith","options","state","config","action","dispatch","reset"],"sourceRoot":"../../src","sources":["useLinkTo.tsx"],"mappings":"AAAA,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,6BAA6B,QACxB,wBAAwB;AAC/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,OAAOC,cAAc,MAAM,kBAAkB;AAiB7C,eAAe,SAASC,SAAS,GAE7B;EACF,MAAMC,UAAU,GAAGH,KAAK,CAACI,UAAU,CAACL,6BAA6B,CAAC;EAClE,MAAMM,OAAO,GAAGL,KAAK,CAACI,UAAU,CAACH,cAAc,CAAC;EAEhD,MAAMK,MAAM,GAAGN,KAAK,CAACO,WAAW,CAC7BC,EAAiB,IAAK;IACrB,IAAIL,UAAU,KAAKM,SAAS,EAAE;MAC5B,MAAM,IAAIC,KAAK,CACb,kFAAkF,CACnF;IACH;IAEA,IAAI,OAAOF,EAAE,KAAK,QAAQ,EAAE;MAC1B;MACAL,UAAU,CAACQ,QAAQ,CAACH,EAAE,CAACI,MAAM,EAAEJ,EAAE,CAACK,MAAM,CAAC;MACzC;IACF;IAEA,IAAI,CAACL,EAAE,CAACM,UAAU,CAAC,GAAG,CAAC,EAAE;MACvB,MAAM,IAAIJ,KAAK,CAAE,iCAAgCF,EAAG,IAAG,CAAC;IAC1D;IAEA,MAAM;MAAEO;IAAQ,CAAC,GAAGV,OAAO;IAE3B,MAAMW,KAAK,GAAGD,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEjB,gBAAgB,GACnCiB,OAAO,CAACjB,gBAAgB,CAACU,EAAE,EAAEO,OAAO,CAACE,MAAM,CAAC,GAC5CnB,gBAAgB,CAACU,EAAE,EAAEO,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,MAAM,CAAC;IAEzC,IAAID,KAAK,EAAE;MACT,MAAME,MAAM,GAAGrB,kBAAkB,CAACmB,KAAK,EAAED,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,MAAM,CAAC;MAEzD,IAAIC,MAAM,KAAKT,SAAS,EAAE;QACxBN,UAAU,CAACgB,QAAQ,CAACD,MAAM,CAAC;MAC7B,CAAC,MAAM;QACLf,UAAU,CAACiB,KAAK,CAACJ,KAAK,CAAC;MACzB;IACF,CAAC,MAAM;MACL,MAAM,IAAIN,KAAK,CAAC,iDAAiD,CAAC;IACpE;EACF,CAAC,EACD,CAACL,OAAO,EAAEF,UAAU,CAAC,CACtB;EAED,OAAOG,MAAM;AACf"} |
@@ -0,4 +1,3 @@ | ||
| import { useNavigation, useRoute } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { useNavigation, useRoute } from '@react-navigation/core'; | ||
| function getScrollableNode(ref) { | ||
@@ -8,3 +7,2 @@ if (ref.current == null) { | ||
| } | ||
| if ('scrollToTop' in ref.current || 'scrollTo' in ref.current || 'scrollToOffset' in ref.current || 'scrollResponderScrollTo' in ref.current) { | ||
@@ -27,3 +25,2 @@ // This is already a scrollable node. | ||
| } | ||
| export default function useScrollToTop(ref) { | ||
@@ -33,52 +30,61 @@ const navigation = useNavigation(); | ||
| React.useEffect(() => { | ||
| let current = navigation; // The screen might be inside another navigator such as stack nested in tabs | ||
| // We need to find the closest tab navigator and add the listener there | ||
| let tabNavigations = []; | ||
| let currentNavigation = navigation; | ||
| while (current && current.getState().type !== 'tab') { | ||
| current = current.getParent(); | ||
| // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them | ||
| // So we need to find all the parent tab navigators and add the listeners there | ||
| while (currentNavigation) { | ||
| if (currentNavigation.getState().type === 'tab') { | ||
| tabNavigations.push(currentNavigation); | ||
| } | ||
| currentNavigation = currentNavigation.getParent(); | ||
| } | ||
| if (!current) { | ||
| if (tabNavigations.length === 0) { | ||
| return; | ||
| } | ||
| const unsubscribers = tabNavigations.map(tab => { | ||
| return tab.addListener( | ||
| // We don't wanna import tab types here to avoid extra deps | ||
| // in addition, there are multiple tab implementations | ||
| // @ts-expect-error | ||
| 'tabPress', e => { | ||
| // We should scroll to top only when the screen is focused | ||
| const isFocused = navigation.isFocused(); | ||
| const unsubscribe = current.addListener( // We don't wanna import tab types here to avoid extra deps | ||
| // in addition, there are multiple tab implementations | ||
| // @ts-expect-error | ||
| 'tabPress', e => { | ||
| // We should scroll to top only when the screen is focused | ||
| const isFocused = navigation.isFocused(); // In a nested stack navigator, tab press resets the stack to first screen | ||
| // So we should scroll to top only when we are on first screen | ||
| // In a nested stack navigator, tab press resets the stack to first screen | ||
| // So we should scroll to top only when we are on first screen | ||
| const isFirst = tabNavigations.includes(navigation) || navigation.getState().routes[0].key === route.key; | ||
| const isFirst = navigation === current || navigation.getState().routes[0].key === route.key; // Run the operation in the next frame so we're sure all listeners have been run | ||
| // This is necessary to know if preventDefault() has been called | ||
| requestAnimationFrame(() => { | ||
| const scrollable = getScrollableNode(ref); | ||
| if (isFocused && isFirst && scrollable && !e.defaultPrevented) { | ||
| if ('scrollToTop' in scrollable) { | ||
| scrollable.scrollToTop(); | ||
| } else if ('scrollTo' in scrollable) { | ||
| scrollable.scrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollToOffset' in scrollable) { | ||
| scrollable.scrollToOffset({ | ||
| offset: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollResponderScrollTo' in scrollable) { | ||
| scrollable.scrollResponderScrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| // Run the operation in the next frame so we're sure all listeners have been run | ||
| // This is necessary to know if preventDefault() has been called | ||
| requestAnimationFrame(() => { | ||
| const scrollable = getScrollableNode(ref); | ||
| if (isFocused && isFirst && scrollable && !e.defaultPrevented) { | ||
| if ('scrollToTop' in scrollable) { | ||
| scrollable.scrollToTop(); | ||
| } else if ('scrollTo' in scrollable) { | ||
| scrollable.scrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollToOffset' in scrollable) { | ||
| scrollable.scrollToOffset({ | ||
| offset: 0, | ||
| animated: true | ||
| }); | ||
| } else if ('scrollResponderScrollTo' in scrollable) { | ||
| scrollable.scrollResponderScrollTo({ | ||
| y: 0, | ||
| animated: true | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| return unsubscribe; | ||
| return () => { | ||
| unsubscribers.forEach(unsubscribe => unsubscribe()); | ||
| }; | ||
| }, [navigation, ref, route.key]); | ||
| } | ||
| //# sourceMappingURL=useScrollToTop.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useScrollToTop.tsx"],"names":["React","useNavigation","useRoute","getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","route","useEffect","getState","type","getParent","unsubscribe","addListener","e","isFocused","isFirst","routes","key","requestAnimationFrame","scrollable","defaultPrevented","scrollToTop","scrollTo","y","animated","scrollToOffset","offset","scrollResponderScrollTo"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,aAAT,EAAwBC,QAAxB,QAAkD,wBAAlD;;AAeA,SAASC,iBAAT,CAA2BC,GAA3B,EAAoE;AAClE,MAAIA,GAAG,CAACC,OAAJ,IAAe,IAAnB,EAAyB;AACvB,WAAO,IAAP;AACD;;AAED,MACE,iBAAiBD,GAAG,CAACC,OAArB,IACA,cAAcD,GAAG,CAACC,OADlB,IAEA,oBAAoBD,GAAG,CAACC,OAFxB,IAGA,6BAA6BD,GAAG,CAACC,OAJnC,EAKE;AACA;AACA,WAAOD,GAAG,CAACC,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I,iBAAiBD,UAArB,EAAiC;AAC/BA,YAAAA,UAAU,CAACE,WAAX;AACD,WAFD,MAEO,IAAI,cAAcF,UAAlB,EAA8B;AACnCA,YAAAA,UAAU,CAACG,QAAX,CAAoB;AAAEC,cAAAA,CAAC,EAAE,CAAL;AAAQC,cAAAA,QAAQ,EAAE;AAAlB,aAApB;AACD,WAFM,MAEA,IAAI,oBAAoBL,UAAxB,EAAoC;AACzCA,YAAAA,UAAU,CAACM,cAAX,CAA0B;AAAEC,cAAAA,MAAM,EAAE,CAAV;AAAaF,cAAAA,QAAQ,EAAE;AAAvB,aAA1B;AACD,WAFM,MAEA,IAAI,6BAA6BL,UAAjC,EAA6C;AAClDA,YAAAA,UAAU,CAACQ,uBAAX,CAAmC;AAAEJ,cAAAA,CAAC,EAAE,CAAL;AAAQC,cAAAA,QAAQ,EAAE;AAAlB,aAAnC;AACD;AACF;AACF,OAdoB,CAArB;AAeD,KAhCiB,CAApB;AAmCA,WAAOb,WAAP;AACD,GAjDD,EAiDG,CAACN,UAAD,EAAaL,GAAb,EAAkBM,KAAK,CAACW,GAAxB,CAjDH;AAkDD","sourcesContent":["import * as React from 'react';\nimport { useNavigation, useRoute, EventArg } from '@react-navigation/core';\n\ntype ScrollOptions = { y?: number; animated?: boolean };\n\ntype ScrollableView =\n | { scrollToTop(): void }\n | { scrollTo(options: ScrollOptions): void }\n | { scrollToOffset(options: { offset?: number; animated?: boolean }): void }\n | { scrollResponderScrollTo(options: ScrollOptions): void };\n\ntype ScrollableWrapper =\n | { getScrollResponder(): React.ReactNode }\n | { getNode(): ScrollableView }\n | ScrollableView;\n\nfunction getScrollableNode(ref: React.RefObject<ScrollableWrapper>) {\n if (ref.current == null) {\n return null;\n }\n\n if (\n 'scrollToTop' in ref.current ||\n 'scrollTo' in ref.current ||\n 'scrollToOffset' in ref.current ||\n 'scrollResponderScrollTo' in ref.current\n ) {\n // This is already a scrollable node.\n return ref.current;\n } else if ('getScrollResponder' in ref.current) {\n // If the view is a wrapper like FlatList, SectionList etc.\n // We need to use `getScrollResponder` to get access to the scroll responder\n return ref.current.getScrollResponder();\n } else if ('getNode' in ref.current) {\n // When a `ScrollView` is wraped in `Animated.createAnimatedComponent`\n // we need to use `getNode` to get the ref to the actual scrollview.\n // Note that `getNode` is deprecated in newer versions of react-native\n // this is why we check if we already have a scrollable node above.\n return ref.current.getNode();\n } else {\n return ref.current;\n }\n}\n\nexport default function useScrollToTop(\n ref: React.RefObject<ScrollableWrapper>\n) {\n const navigation = useNavigation();\n const route = useRoute();\n\n React.useEffect(() => {\n let current = navigation;\n\n // The screen might be inside another navigator such as stack nested in tabs\n // We need to find the closest tab navigator and add the listener there\n while (current && current.getState().type !== 'tab') {\n current = current.getParent();\n }\n\n if (!current) {\n return;\n }\n\n const unsubscribe = current.addListener(\n // We don't wanna import tab types here to avoid extra deps\n // in addition, there are multiple tab implementations\n // @ts-expect-error\n 'tabPress',\n (e: EventArg<'tabPress', true>) => {\n // We should scroll to top only when the screen is focused\n const isFocused = navigation.isFocused();\n\n // In a nested stack navigator, tab press resets the stack to first screen\n // So we should scroll to top only when we are on first screen\n const isFirst =\n navigation === current ||\n navigation.getState().routes[0].key === route.key;\n\n // Run the operation in the next frame so we're sure all listeners have been run\n // This is necessary to know if preventDefault() has been called\n requestAnimationFrame(() => {\n const scrollable = getScrollableNode(ref) as ScrollableWrapper;\n\n if (isFocused && isFirst && scrollable && !e.defaultPrevented) {\n if ('scrollToTop' in scrollable) {\n scrollable.scrollToTop();\n } else if ('scrollTo' in scrollable) {\n scrollable.scrollTo({ y: 0, animated: true });\n } else if ('scrollToOffset' in scrollable) {\n scrollable.scrollToOffset({ offset: 0, animated: true });\n } else if ('scrollResponderScrollTo' in scrollable) {\n scrollable.scrollResponderScrollTo({ y: 0, animated: true });\n }\n }\n });\n }\n );\n\n return unsubscribe;\n }, [navigation, ref, route.key]);\n}\n"]} | ||
| {"version":3,"names":["useNavigation","useRoute","React","getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","route","useEffect","tabNavigations","currentNavigation","getState","type","push","getParent","length","unsubscribers","map","tab","addListener","e","isFocused","isFirst","includes","routes","key","requestAnimationFrame","scrollable","defaultPrevented","scrollToTop","scrollTo","y","animated","scrollToOffset","offset","scrollResponderScrollTo","forEach","unsubscribe"],"sourceRoot":"../../src","sources":["useScrollToTop.tsx"],"mappings":"AAAA,SAGEA,aAAa,EACbC,QAAQ,QACH,wBAAwB;AAC/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAgB9B,SAASC,iBAAiB,CAACC,GAAuC,EAAE;EAClE,IAAIA,GAAG,CAACC,OAAO,IAAI,IAAI,EAAE;IACvB,OAAO,IAAI;EACb;EAEA,IACE,aAAa,IAAID,GAAG,CAACC,OAAO,IAC5B,UAAU,IAAID,GAAG,CAACC,OAAO,IACzB,gBAAgB,IAAID,GAAG,CAACC,OAAO,IAC/B,yBAAyB,IAAID,GAAG,CAACC,OAAO,EACxC;IACA;IACA,OAAOD,GAAG,CAACC,OAAO;EACpB,CAAC,MAAM,IAAI,oBAAoB,IAAID,GAAG,CAACC,OAAO,EAAE;IAC9C;IACA;IACA,OAAOD,GAAG,CAACC,OAAO,CAACC,kBAAkB,EAAE;EACzC,CAAC,MAAM,IAAI,SAAS,IAAIF,GAAG,CAACC,OAAO,EAAE;IACnC;IACA;IACA;IACA;IACA,OAAOD,GAAG,CAACC,OAAO,CAACE,OAAO,EAAE;EAC9B,CAAC,MAAM;IACL,OAAOH,GAAG,CAACC,OAAO;EACpB;AACF;AAEA,eAAe,SAASG,cAAc,CACpCJ,GAAuC,EACvC;EACA,MAAMK,UAAU,GAAGT,aAAa,EAAE;EAClC,MAAMU,KAAK,GAAGT,QAAQ,EAAE;EAExBC,KAAK,CAACS,SAAS,CAAC,MAAM;IACpB,IAAIC,cAA+D,GAAG,EAAE;IACxE,IAAIC,iBAAiB,GAAGJ,UAAU;;IAElC;IACA;IACA,OAAOI,iBAAiB,EAAE;MACxB,IAAIA,iBAAiB,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C;gBAAEJ,CAAC,EAAE,CAAC;gBAAEC,QAAQ,EAAE;cAAK,CAAC,CAAC;YAC9D;UACF;QACF,CAAC,CAAC;MACJ,CAAC,CACF;IACH,CAAC,CAAC;IAEF,OAAO,MAAM;MACXhB,aAAa,CAACoB,OAAO,CAAEC,WAAW,IAAKA,WAAW,EAAE,CAAC;IACvD,CAAC;EACH,CAAC,EAAE,CAAC/B,UAAU,EAAEL,GAAG,EAAEM,KAAK,CAACkB,GAAG,CAAC,CAAC;AAClC"} |
| import * as React from 'react'; | ||
| export default function useThenable(create) { | ||
| const [promise] = React.useState(create); | ||
| let initialState = [false, undefined]; // Check if our thenable is synchronous | ||
| let initialState = [false, undefined]; | ||
| // Check if our thenable is synchronous | ||
| promise.then(result => { | ||
@@ -13,6 +14,4 @@ initialState = [true, result]; | ||
| let cancelled = false; | ||
| const resolve = async () => { | ||
| let result; | ||
| try { | ||
@@ -26,7 +25,5 @@ result = await promise; | ||
| }; | ||
| if (!resolved) { | ||
| resolve(); | ||
| } | ||
| return () => { | ||
@@ -33,0 +30,0 @@ cancelled = true; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["useThenable.tsx"],"names":["React","useThenable","create","promise","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,eAAe,SAASC,WAAT,CAAwBC,MAAxB,EAAsD;AACnE,QAAM,CAACC,OAAD,IAAYH,KAAK,CAACI,QAAN,CAAeF,MAAf,CAAlB;AAEA,MAAIG,YAAsC,GAAG,CAAC,KAAD,EAAQC,SAAR,CAA7C,CAHmE,CAKnE;;AACAH,EAAAA,OAAO,CAACI,IAAR,CAAcC,MAAD,IAAY;AACvBH,IAAAA,YAAY,GAAG,CAAC,IAAD,EAAOG,MAAP,CAAf;AACD,GAFD;AAIA,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBV,KAAK,CAACI,QAAN,CAAeC,YAAf,CAA1B;AACA,QAAM,CAACM,QAAD,IAAaF,KAAnB;AAEAT,EAAAA,KAAK,CAACY,SAAN,CAAgB,MAAM;AACpB,QAAIC,SAAS,GAAG,KAAhB;;AAEA,UAAMC,OAAO,GAAG,YAAY;AAC1B,UAAIN,MAAJ;;AAEA,UAAI;AACFA,QAAAA,MAAM,GAAG,MAAML,OAAf;AACD,OAFD,SAEU;AACR,YAAI,CAACU,SAAL,EAAgB;AACdH,UAAAA,QAAQ,CAAC,CAAC,IAAD,EAAOF,MAAP,CAAD,CAAR;AACD;AACF;AACF,KAVD;;AAYA,QAAI,CAACG,QAAL,EAAe;AACbG,MAAAA,OAAO;AACR;;AAED,WAAO,MAAM;AACXD,MAAAA,SAAS,GAAG,IAAZ;AACD,KAFD;AAGD,GAtBD,EAsBG,CAACV,OAAD,EAAUQ,QAAV,CAtBH;AAwBA,SAAOF,KAAP;AACD","sourcesContent":["import * as React from 'react';\n\nexport default function useThenable<T>(create: () => PromiseLike<T>) {\n const [promise] = React.useState(create);\n\n let initialState: [boolean, T | undefined] = [false, undefined];\n\n // Check if our thenable is synchronous\n promise.then((result) => {\n initialState = [true, result];\n });\n\n const [state, setState] = React.useState(initialState);\n const [resolved] = state;\n\n React.useEffect(() => {\n let cancelled = false;\n\n const resolve = async () => {\n let result;\n\n try {\n result = await promise;\n } finally {\n if (!cancelled) {\n setState([true, result]);\n }\n }\n };\n\n if (!resolved) {\n resolve();\n }\n\n return () => {\n cancelled = true;\n };\n }, [promise, resolved]);\n\n return state;\n}\n"]} | ||
| {"version":3,"names":["React","useThenable","create","promise","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"sourceRoot":"../../src","sources":["useThenable.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,eAAe,SAASC,WAAW,CAAIC,MAA4B,EAAE;EACnE,MAAM,CAACC,OAAO,CAAC,GAAGH,KAAK,CAACI,QAAQ,CAACF,MAAM,CAAC;EAExC,IAAIG,YAAsC,GAAG,CAAC,KAAK,EAAEC,SAAS,CAAC;;EAE/D;EACAH,OAAO,CAACI,IAAI,CAAEC,MAAM,IAAK;IACvBH,YAAY,GAAG,CAAC,IAAI,EAAEG,MAAM,CAAC;EAC/B,CAAC,CAAC;EAEF,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGV,KAAK,CAACI,QAAQ,CAACC,YAAY,CAAC;EACtD,MAAM,CAACM,QAAQ,CAAC,GAAGF,KAAK;EAExBT,KAAK,CAACY,SAAS,CAAC,MAAM;IACpB,IAAIC,SAAS,GAAG,KAAK;IAErB,MAAMC,OAAO,GAAG,YAAY;MAC1B,IAAIN,MAAM;MAEV,IAAI;QACFA,MAAM,GAAG,MAAML,OAAO;MACxB,CAAC,SAAS;QACR,IAAI,CAACU,SAAS,EAAE;UACdH,QAAQ,CAAC,CAAC,IAAI,EAAEF,MAAM,CAAC,CAAC;QAC1B;MACF;IACF,CAAC;IAED,IAAI,CAACG,QAAQ,EAAE;MACbG,OAAO,EAAE;IACX;IAEA,OAAO,MAAM;MACXD,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CAACV,OAAO,EAAEQ,QAAQ,CAAC,CAAC;EAEvB,OAAOF,KAAK;AACd"} |
@@ -1,2 +0,2 @@ | ||
| declare const _default: { | ||
| declare const window: { | ||
| document: { | ||
@@ -14,5 +14,7 @@ title: string; | ||
| }; | ||
| addEventListener: (type: "popstate", listener: () => void) => void; | ||
| removeEventListener: (type: "popstate", listener: () => void) => void; | ||
| addEventListener: (type: 'popstate', listener: () => void) => void; | ||
| removeEventListener: (type: 'popstate', listener: () => void) => void; | ||
| readonly window: any; | ||
| }; | ||
| export default _default; | ||
| export default window; | ||
| //# sourceMappingURL=window.d.ts.map |
| export default function extractPathFromURL(prefixes: string[], url: string): string | undefined; | ||
| //# sourceMappingURL=extractPathFromURL.d.ts.map |
@@ -1,15 +0,15 @@ | ||
| export * from '@react-navigation/core'; | ||
| export { default as Link } from './Link'; | ||
| export { default as LinkingContext } from './LinkingContext'; | ||
| export { default as NavigationContainer } from './NavigationContainer'; | ||
| export { default as useBackButton } from './useBackButton'; | ||
| export { default as useScrollToTop } from './useScrollToTop'; | ||
| export { default as ServerContainer } from './ServerContainer'; | ||
| export { default as DarkTheme } from './theming/DarkTheme'; | ||
| export { default as DefaultTheme } from './theming/DefaultTheme'; | ||
| export { default as DarkTheme } from './theming/DarkTheme'; | ||
| export { default as ThemeProvider } from './theming/ThemeProvider'; | ||
| export { default as useTheme } from './theming/useTheme'; | ||
| export { default as Link } from './Link'; | ||
| export { default as useLinking } from './useLinking'; | ||
| export * from './types'; | ||
| export { default as useLinkBuilder } from './useLinkBuilder'; | ||
| export { default as useLinkProps } from './useLinkProps'; | ||
| export { default as useLinkTo } from './useLinkTo'; | ||
| export { default as useLinkProps } from './useLinkProps'; | ||
| export { default as useLinkBuilder } from './useLinkBuilder'; | ||
| export { default as ServerContainer } from './ServerContainer'; | ||
| export * from './types'; | ||
| export { default as useScrollToTop } from './useScrollToTop'; | ||
| export * from '@react-navigation/core'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -0,10 +1,12 @@ | ||
| import type { NavigationAction } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { Text, TextProps, GestureResponderEvent } from 'react-native'; | ||
| import type { NavigationAction } from '@react-navigation/core'; | ||
| declare type Props = { | ||
| to: string; | ||
| import { GestureResponderEvent, Text, TextProps } from 'react-native'; | ||
| import type { To } from './useLinkTo'; | ||
| type Props<ParamList extends ReactNavigation.RootParamList> = { | ||
| to: To<ParamList>; | ||
| action?: NavigationAction; | ||
| target?: string; | ||
| onPress?: (e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent) => void; | ||
| } & (TextProps & { | ||
| } & (Omit<TextProps, 'disabled'> & { | ||
| disabled?: boolean | null; | ||
| children: React.ReactNode; | ||
@@ -20,3 +22,4 @@ }); | ||
| */ | ||
| export default function Link({ to, action, ...rest }: Props): React.CElement<TextProps, Text>; | ||
| export default function Link<ParamList extends ReactNavigation.RootParamList>({ to, action, ...rest }: Props<ParamList>): React.CElement<TextProps, Text>; | ||
| export {}; | ||
| //# sourceMappingURL=Link.d.ts.map |
@@ -0,6 +1,8 @@ | ||
| import type { ParamListBase } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import type { LinkingOptions } from './types'; | ||
| declare const LinkingContext: React.Context<{ | ||
| options: LinkingOptions | undefined; | ||
| options: LinkingOptions<ParamListBase> | undefined; | ||
| }>; | ||
| export default LinkingContext; | ||
| //# sourceMappingURL=LinkingContext.d.ts.map |
@@ -0,25 +1,26 @@ | ||
| import { NavigationContainerProps, NavigationContainerRef } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { NavigationContainerProps, NavigationContainerRef } from '@react-navigation/core'; | ||
| import type { Theme, LinkingOptions, DocumentTitleOptions } from './types'; | ||
| /** | ||
| * Container component which holds the navigation state designed for React Native apps. | ||
| * This should be rendered at the root wrapping the whole app. | ||
| * | ||
| * @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`). | ||
| * @param props.onReady Callback which is called after the navigation tree mounts. | ||
| * @param props.onStateChange Callback which is called with the latest navigation state when it changes. | ||
| * @param props.theme Theme object for the navigators. | ||
| * @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`. | ||
| * @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`. | ||
| * @param props.documentTitle Options to configure the document title on Web. Updating document title is handled by default unless `documentTitle.enabled` is `false`. | ||
| * @param props.children Child elements to render the content. | ||
| * @param props.ref Ref object which refers to the navigation object containing helper methods. | ||
| */ | ||
| declare const NavigationContainer: React.ForwardRefExoticComponent<NavigationContainerProps & { | ||
| import type { DocumentTitleOptions, LinkingOptions, Theme } from './types'; | ||
| declare global { | ||
| var REACT_NAVIGATION_DEVTOOLS: WeakMap<NavigationContainerRef<any>, { | ||
| readonly linking: LinkingOptions<any>; | ||
| }>; | ||
| } | ||
| type Props<ParamList extends {}> = NavigationContainerProps & { | ||
| theme?: Theme; | ||
| linking?: LinkingOptions<ParamList>; | ||
| fallback?: React.ReactNode; | ||
| documentTitle?: DocumentTitleOptions; | ||
| onReady?: () => void; | ||
| }; | ||
| declare const NavigationContainer: <RootParamList extends {} = ReactNavigation.RootParamList>(props: NavigationContainerProps & { | ||
| theme?: Theme | undefined; | ||
| linking?: LinkingOptions | undefined; | ||
| linking?: LinkingOptions<RootParamList> | undefined; | ||
| fallback?: React.ReactNode; | ||
| documentTitle?: DocumentTitleOptions | undefined; | ||
| onReady?: (() => void) | undefined; | ||
| } & React.RefAttributes<NavigationContainerRef>>; | ||
| } & { | ||
| ref?: React.Ref<NavigationContainerRef<RootParamList>> | undefined; | ||
| }) => React.ReactElement; | ||
| export default NavigationContainer; | ||
| //# sourceMappingURL=NavigationContainer.d.ts.map |
| import * as React from 'react'; | ||
| import { ServerContextType } from './ServerContext'; | ||
| import type { ServerContainerRef } from './types'; | ||
| declare const _default: React.ForwardRefExoticComponent<ServerContextType & { | ||
| children: React.ReactNode; | ||
| } & React.RefAttributes<ServerContainerRef>>; | ||
| /** | ||
@@ -14,2 +11,6 @@ * Container component for server rendering. | ||
| */ | ||
| declare const _default: React.ForwardRefExoticComponent<ServerContextType & { | ||
| children: React.ReactNode; | ||
| } & React.RefAttributes<ServerContainerRef>>; | ||
| export default _default; | ||
| //# sourceMappingURL=ServerContainer.d.ts.map |
| import * as React from 'react'; | ||
| export declare type ServerContextType = { | ||
| export type ServerContextType = { | ||
| location?: { | ||
@@ -10,1 +10,2 @@ pathname: string; | ||
| export default ServerContext; | ||
| //# sourceMappingURL=ServerContext.d.ts.map |
| import type { Theme } from '../types'; | ||
| declare const DarkTheme: Theme; | ||
| export default DarkTheme; | ||
| //# sourceMappingURL=DarkTheme.d.ts.map |
| import type { Theme } from '../types'; | ||
| declare const DefaultTheme: Theme; | ||
| export default DefaultTheme; | ||
| //# sourceMappingURL=DefaultTheme.d.ts.map |
@@ -5,1 +5,2 @@ import * as React from 'react'; | ||
| export default ThemeContext; | ||
| //# sourceMappingURL=ThemeContext.d.ts.map |
| import * as React from 'react'; | ||
| import type { Theme } from '../types'; | ||
| declare type Props = { | ||
| type Props = { | ||
| value: Theme; | ||
@@ -9,1 +9,2 @@ children: React.ReactNode; | ||
| export {}; | ||
| //# sourceMappingURL=ThemeProvider.d.ts.map |
| export default function useTheme(): import("..").Theme; | ||
| //# sourceMappingURL=useTheme.d.ts.map |
@@ -1,3 +0,3 @@ | ||
| import type { getStateFromPath as getStateFromPathDefault, getPathFromState as getPathFromStateDefault, getActionFromState as getActionFromStateDefault, PathConfigMap, Route } from '@react-navigation/core'; | ||
| export declare type Theme = { | ||
| import type { getActionFromState as getActionFromStateDefault, getPathFromState as getPathFromStateDefault, getStateFromPath as getStateFromPathDefault, PathConfigMap, Route } from '@react-navigation/core'; | ||
| export type Theme = { | ||
| dark: boolean; | ||
@@ -13,3 +13,3 @@ colors: { | ||
| }; | ||
| export declare type LinkingOptions = { | ||
| export type LinkingOptions<ParamList extends {}> = { | ||
| /** | ||
@@ -23,4 +23,5 @@ * Whether deep link handling should be enabled. | ||
| * Usually they are the `scheme` + `host` (e.g. `myapp://chat?user=jane`) | ||
| * Only applicable on Android and iOS. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
@@ -39,2 +40,20 @@ * ```js | ||
| /** | ||
| * Optional function which takes an incoming URL returns a boolean | ||
| * indicating whether React Navigation should handle it. | ||
| * | ||
| * This can be used to disable deep linking for specific URLs. | ||
| * e.g. URLs used for authentication, and not for deep linking to screens. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
| * ```js | ||
| * { | ||
| * // Filter out URLs used by expo-auth-session | ||
| * filter: (url) => !url.includes('+expo-auth-session') | ||
| * } | ||
| * ``` | ||
| */ | ||
| filter?: (url: string) => boolean; | ||
| /** | ||
| * Config to fine-tune how to parse the path. | ||
@@ -53,4 +72,4 @@ * | ||
| config?: { | ||
| initialRouteName?: string; | ||
| screens: PathConfigMap; | ||
| initialRouteName?: keyof ParamList; | ||
| screens: PathConfigMap<ParamList>; | ||
| }; | ||
@@ -60,4 +79,5 @@ /** | ||
| * Uses `Linking.getInitialURL()` by default. | ||
| * Not supported on Web. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
@@ -74,4 +94,5 @@ * ```js | ||
| * Uses `Linking.addEventListener('url', callback)` by default. | ||
| * Not supported on Web. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
@@ -93,23 +114,21 @@ * ```js | ||
| * Custom function to parse the URL to a valid navigation state (advanced). | ||
| * This state object will be passed as `initialState` for initial URL, | ||
| * and converted to an action object to `dispatch` for subsequent URLs. | ||
| */ | ||
| getStateFromPath?: typeof getStateFromPathDefault; | ||
| /** | ||
| * Custom function to convert the state object to an action to dispatch (advanced). | ||
| * By default, the state is converted to a `NAVIGATE` action. | ||
| * Custom function to convert the state object to a valid URL (advanced). | ||
| * Only applicable on Web. | ||
| */ | ||
| getActionFromState?: typeof getActionFromStateDefault; | ||
| getPathFromState?: typeof getPathFromStateDefault; | ||
| /** | ||
| * Custom function to convert the state object to a valid URL (advanced). | ||
| * Used for creating links for navigation, primarily useful on Web. | ||
| * Custom function to convert the state object to a valid action (advanced). | ||
| */ | ||
| getPathFromState?: typeof getPathFromStateDefault; | ||
| getActionFromState?: typeof getActionFromStateDefault; | ||
| }; | ||
| export declare type DocumentTitleOptions = { | ||
| export type DocumentTitleOptions = { | ||
| enabled?: boolean; | ||
| formatter?: (options: Record<string, any> | undefined, route: Route<string> | undefined) => string; | ||
| }; | ||
| export declare type ServerContainerRef = { | ||
| export type ServerContainerRef = { | ||
| getCurrentOptions(): Record<string, any> | undefined; | ||
| }; | ||
| //# sourceMappingURL=types.d.ts.map |
@@ -1,3 +0,4 @@ | ||
| import * as React from 'react'; | ||
| import type { NavigationContainerRef } from '@react-navigation/core'; | ||
| export default function useBackButton(ref: React.RefObject<NavigationContainerRef>): void; | ||
| /// <reference types="react" /> | ||
| import type { NavigationContainerRef, ParamListBase } from '@react-navigation/core'; | ||
| export default function useBackButton(_: React.RefObject<NavigationContainerRef<ParamListBase>>): void; | ||
| //# sourceMappingURL=useBackButton.d.ts.map |
@@ -0,3 +1,3 @@ | ||
| import type { NavigationContainerRef, ParamListBase } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import type { NavigationContainerRef } from '@react-navigation/core'; | ||
| import type { DocumentTitleOptions } from './types'; | ||
@@ -7,2 +7,3 @@ /** | ||
| */ | ||
| export default function useDocumentTitle(ref: React.RefObject<NavigationContainerRef>, { enabled, formatter, }?: DocumentTitleOptions): void; | ||
| export default function useDocumentTitle(ref: React.RefObject<NavigationContainerRef<ParamListBase>>, { enabled, formatter, }?: DocumentTitleOptions): void; | ||
| //# sourceMappingURL=useDocumentTitle.d.ts.map |
| export default function useDocumentTitle(): void; | ||
| //# sourceMappingURL=useDocumentTitle.native.d.ts.map |
@@ -5,2 +5,3 @@ /** | ||
| */ | ||
| export default function useLinkBuilder(): (name: string, params?: object | undefined) => string | undefined; | ||
| export default function useLinkBuilder(): (name: string, params?: object) => string | undefined; | ||
| //# sourceMappingURL=useLinkBuilder.d.ts.map |
@@ -0,6 +1,13 @@ | ||
| import { NavigationContainerRef, ParamListBase } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { NavigationContainerRef } from '@react-navigation/core'; | ||
| import type { LinkingOptions } from './types'; | ||
| export default function useLinking(ref: React.RefObject<NavigationContainerRef>, { enabled, config, getStateFromPath, getPathFromState, getActionFromState, }: LinkingOptions): { | ||
| getInitialState: () => PromiseLike<(Partial<Pick<Readonly<{ | ||
| /** | ||
| * Run async function in series as it's called. | ||
| */ | ||
| export declare const series: (cb: () => Promise<void>) => () => void; | ||
| type Options = LinkingOptions<ParamListBase> & { | ||
| independent?: boolean; | ||
| }; | ||
| export default function useLinking(ref: React.RefObject<NavigationContainerRef<ParamListBase>>, { independent, enabled, config, getStateFromPath, getPathFromState, getActionFromState, }: Options): { | ||
| getInitialState: () => PromiseLike<(Partial<Omit<Readonly<{ | ||
| key: string; | ||
@@ -13,4 +20,5 @@ index: number; | ||
| name: string; | ||
| path?: string | undefined; | ||
| }> & Readonly<{ | ||
| params?: object | undefined; | ||
| params?: Readonly<object | undefined>; | ||
| }> & { | ||
@@ -21,7 +29,7 @@ state?: Readonly<any> | import("@react-navigation/core").PartialState<Readonly<any>> | undefined; | ||
| stale: false; | ||
| }>, "key" | "index" | "routeNames" | "history" | "type">> & Readonly<{ | ||
| }>, "stale" | "routes">> & Readonly<{ | ||
| stale?: true | undefined; | ||
| routes: import("@react-navigation/core").PartialRoute<import("@react-navigation/core").Route<string, object | undefined>>[]; | ||
| }> & { | ||
| state?: (Partial<Pick<Readonly<{ | ||
| state?: (Partial<Omit<Readonly<{ | ||
| key: string; | ||
@@ -34,4 +42,5 @@ index: number; | ||
| name: string; | ||
| path?: string | undefined; | ||
| }> & Readonly<{ | ||
| params?: object | undefined; | ||
| params?: Readonly<object | undefined>; | ||
| }> & { | ||
@@ -42,3 +51,3 @@ state?: Readonly<any> | import("@react-navigation/core").PartialState<Readonly<any>> | undefined; | ||
| stale: false; | ||
| }>, "key" | "index" | "routeNames" | "history" | "type">> & Readonly<{ | ||
| }>, "stale" | "routes">> & Readonly<{ | ||
| stale?: true | undefined; | ||
@@ -49,1 +58,3 @@ routes: import("@react-navigation/core").PartialRoute<import("@react-navigation/core").Route<string, object | undefined>>[]; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=useLinking.d.ts.map |
@@ -0,6 +1,9 @@ | ||
| import { NavigationContainerRef, ParamListBase } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { NavigationContainerRef } from '@react-navigation/core'; | ||
| import type { LinkingOptions } from './types'; | ||
| export default function useLinking(ref: React.RefObject<NavigationContainerRef>, { enabled, prefixes, config, getInitialURL, subscribe, getStateFromPath, getActionFromState, }: LinkingOptions): { | ||
| getInitialState: () => PromiseLike<(Partial<Pick<Readonly<{ | ||
| type Options = LinkingOptions<ParamListBase> & { | ||
| independent?: boolean; | ||
| }; | ||
| export default function useLinking(ref: React.RefObject<NavigationContainerRef<ParamListBase>>, { independent, enabled, prefixes, filter, config, getInitialURL, subscribe, getStateFromPath, getActionFromState, }: Options): { | ||
| getInitialState: () => PromiseLike<(Partial<Omit<Readonly<{ | ||
| key: string; | ||
@@ -13,4 +16,5 @@ index: number; | ||
| name: string; | ||
| path?: string | undefined; | ||
| }> & Readonly<{ | ||
| params?: object | undefined; | ||
| params?: Readonly<object | undefined>; | ||
| }> & { | ||
@@ -21,7 +25,7 @@ state?: Readonly<any> | import("@react-navigation/core").PartialState<Readonly<any>> | undefined; | ||
| stale: false; | ||
| }>, "key" | "index" | "routeNames" | "history" | "type">> & Readonly<{ | ||
| }>, "stale" | "routes">> & Readonly<{ | ||
| stale?: true | undefined; | ||
| routes: import("@react-navigation/core").PartialRoute<import("@react-navigation/core").Route<string, object | undefined>>[]; | ||
| }> & { | ||
| state?: (Partial<Pick<Readonly<{ | ||
| state?: (Partial<Omit<Readonly<{ | ||
| key: string; | ||
@@ -34,4 +38,5 @@ index: number; | ||
| name: string; | ||
| path?: string | undefined; | ||
| }> & Readonly<{ | ||
| params?: object | undefined; | ||
| params?: Readonly<object | undefined>; | ||
| }> & { | ||
@@ -42,3 +47,3 @@ state?: Readonly<any> | import("@react-navigation/core").PartialState<Readonly<any>> | undefined; | ||
| stale: false; | ||
| }>, "key" | "index" | "routeNames" | "history" | "type">> & Readonly<{ | ||
| }>, "stale" | "routes">> & Readonly<{ | ||
| stale?: true | undefined; | ||
@@ -49,1 +54,3 @@ routes: import("@react-navigation/core").PartialRoute<import("@react-navigation/core").Route<string, object | undefined>>[]; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=useLinking.native.d.ts.map |
@@ -0,6 +1,7 @@ | ||
| import { NavigationAction } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { GestureResponderEvent } from 'react-native'; | ||
| import { NavigationAction } from '@react-navigation/core'; | ||
| declare type Props = { | ||
| to: string; | ||
| import { To } from './useLinkTo'; | ||
| type Props<ParamList extends ReactNavigation.RootParamList> = { | ||
| to: To<ParamList>; | ||
| action?: NavigationAction; | ||
@@ -14,7 +15,8 @@ }; | ||
| */ | ||
| export default function useLinkProps({ to, action }: Props): { | ||
| export default function useLinkProps<ParamList extends ReactNavigation.RootParamList>({ to, action }: Props<ParamList>): { | ||
| href: string; | ||
| accessibilityRole: "link"; | ||
| onPress: (e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent | undefined) => void; | ||
| onPress: (e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent) => void; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=useLinkProps.d.ts.map |
@@ -1,1 +0,9 @@ | ||
| export default function useLinkTo(): (path: string) => void; | ||
| export type To<ParamList extends ReactNavigation.RootParamList = ReactNavigation.RootParamList, RouteName extends keyof ParamList = keyof ParamList> = string | (undefined extends ParamList[RouteName] ? { | ||
| screen: Extract<RouteName, string>; | ||
| params?: ParamList[RouteName]; | ||
| } : { | ||
| screen: Extract<RouteName, string>; | ||
| params: ParamList[RouteName]; | ||
| }); | ||
| export default function useLinkTo<ParamList extends ReactNavigation.RootParamList>(): (to: To<ParamList>) => void; | ||
| //# sourceMappingURL=useLinkTo.d.ts.map |
| import * as React from 'react'; | ||
| declare type ScrollOptions = { | ||
| import type { ScrollView } from 'react-native'; | ||
| type ScrollOptions = { | ||
| x?: number; | ||
| y?: number; | ||
| animated?: boolean; | ||
| }; | ||
| declare type ScrollableView = { | ||
| type ScrollableView = { | ||
| scrollToTop(): void; | ||
@@ -18,4 +20,4 @@ } | { | ||
| }; | ||
| declare type ScrollableWrapper = { | ||
| getScrollResponder(): React.ReactNode; | ||
| type ScrollableWrapper = { | ||
| getScrollResponder(): React.ReactNode | ScrollView; | ||
| } | { | ||
@@ -26,1 +28,2 @@ getNode(): ScrollableView; | ||
| export {}; | ||
| //# sourceMappingURL=useScrollToTop.d.ts.map |
| export default function useThenable<T>(create: () => PromiseLike<T>): [boolean, T | undefined]; | ||
| //# sourceMappingURL=useThenable.d.ts.map |
+16
-15
| { | ||
| "name": "@react-navigation/native", | ||
| "description": "React Native integration for React Navigation", | ||
| "version": "5.9.8", | ||
| "version": "6.1.9", | ||
| "keywords": [ | ||
@@ -36,21 +36,22 @@ "react-native", | ||
| "scripts": { | ||
| "prepare": "bob build", | ||
| "prepack": "bob build", | ||
| "clean": "del lib" | ||
| }, | ||
| "dependencies": { | ||
| "@react-navigation/core": "^5.16.1", | ||
| "@react-navigation/core": "^6.4.10", | ||
| "escape-string-regexp": "^4.0.0", | ||
| "nanoid": "^3.1.15" | ||
| "fast-deep-equal": "^3.1.3", | ||
| "nanoid": "^3.1.23" | ||
| }, | ||
| "devDependencies": { | ||
| "@testing-library/react-native": "^7.1.0", | ||
| "@types/react": "^16.9.53", | ||
| "@types/react-dom": "^16.9.8", | ||
| "@types/react-native": "^0.63.30", | ||
| "del-cli": "^3.0.1", | ||
| "react": "~16.13.1", | ||
| "react-dom": "^16.13.1", | ||
| "react-native": "~0.63.2", | ||
| "react-native-builder-bob": "^0.17.0", | ||
| "typescript": "^4.0.3" | ||
| "@testing-library/react-native": "^11.5.0", | ||
| "@types/react": "~18.0.27", | ||
| "@types/react-dom": "~18.0.10", | ||
| "@types/react-native": "~0.71.3", | ||
| "del-cli": "^5.0.0", | ||
| "react": "18.2.0", | ||
| "react-dom": "18.2.0", | ||
| "react-native": "0.71.8", | ||
| "react-native-builder-bob": "^0.20.4", | ||
| "typescript": "^4.9.4" | ||
| }, | ||
@@ -75,3 +76,3 @@ "peerDependencies": { | ||
| }, | ||
| "gitHead": "5d9807ff4d7df74a4e91f43fe8271b2f150c7ba0" | ||
| "gitHead": "f632ec3ecb5a6401b904222c75267dadba1c4b61" | ||
| } |
+1
-1
@@ -5,2 +5,2 @@ # `@react-navigation/native` | ||
| Installation instructions and documentation can be found on the [React Navigation website](https://reactnavigation.org/docs/5.x/getting-started/). | ||
| Installation instructions and documentation can be found on the [React Navigation website](https://reactnavigation.org/docs/getting-started/). |
@@ -37,4 +37,6 @@ const location = new URL('', 'http://example.com'); | ||
| index += n; | ||
| Object.assign(location, new URL(entries[index].href)); | ||
| listeners.forEach((cb) => cb); | ||
| const entry = entries[index]; | ||
| Object.assign(location, new URL(entry.href)); | ||
| currentState = entry.state; | ||
| listeners.forEach((cb) => cb()); | ||
| } | ||
@@ -65,3 +67,3 @@ }, 0); | ||
| export default { | ||
| const window = { | ||
| document: { title: '' }, | ||
@@ -72,2 +74,7 @@ location, | ||
| removeEventListener, | ||
| get window() { | ||
| return window; | ||
| }, | ||
| }; | ||
| export default window; |
@@ -18,3 +18,6 @@ import escapeStringRegexp from 'escape-string-regexp'; | ||
| const normalizedURL = url.replace(/\/+/g, '/'); | ||
| const [originAndPath, searchParams] = url.split('?'); | ||
| const normalizedURL = originAndPath | ||
| .replace(/\/+/g, '/') | ||
| .concat(searchParams ? `?${searchParams}` : ''); | ||
@@ -21,0 +24,0 @@ if (prefixRegex.test(normalizedURL)) { |
+9
-16
@@ -1,21 +0,14 @@ | ||
| export * from '@react-navigation/core'; | ||
| export { default as Link } from './Link'; | ||
| export { default as LinkingContext } from './LinkingContext'; | ||
| export { default as NavigationContainer } from './NavigationContainer'; | ||
| export { default as useBackButton } from './useBackButton'; | ||
| export { default as useScrollToTop } from './useScrollToTop'; | ||
| export { default as ServerContainer } from './ServerContainer'; | ||
| export { default as DarkTheme } from './theming/DarkTheme'; | ||
| export { default as DefaultTheme } from './theming/DefaultTheme'; | ||
| export { default as DarkTheme } from './theming/DarkTheme'; | ||
| export { default as ThemeProvider } from './theming/ThemeProvider'; | ||
| export { default as useTheme } from './theming/useTheme'; | ||
| export { default as Link } from './Link'; | ||
| export { default as useLinking } from './useLinking'; | ||
| export * from './types'; | ||
| export { default as useLinkBuilder } from './useLinkBuilder'; | ||
| export { default as useLinkProps } from './useLinkProps'; | ||
| export { default as useLinkTo } from './useLinkTo'; | ||
| export { default as useLinkProps } from './useLinkProps'; | ||
| export { default as useLinkBuilder } from './useLinkBuilder'; | ||
| export { default as ServerContainer } from './ServerContainer'; | ||
| export * from './types'; | ||
| export { default as useScrollToTop } from './useScrollToTop'; | ||
| export * from '@react-navigation/core'; |
+16
-7
@@ -0,8 +1,10 @@ | ||
| import type { NavigationAction } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { Text, TextProps, GestureResponderEvent, Platform } from 'react-native'; | ||
| import type { NavigationAction } from '@react-navigation/core'; | ||
| import { GestureResponderEvent, Platform, Text, TextProps } from 'react-native'; | ||
| import useLinkProps from './useLinkProps'; | ||
| import type { To } from './useLinkTo'; | ||
| type Props = { | ||
| to: string; | ||
| type Props<ParamList extends ReactNavigation.RootParamList> = { | ||
| to: To<ParamList>; | ||
| action?: NavigationAction; | ||
@@ -13,3 +15,6 @@ target?: string; | ||
| ) => void; | ||
| } & (TextProps & { children: React.ReactNode }); | ||
| } & (Omit<TextProps, 'disabled'> & { | ||
| disabled?: boolean | null; | ||
| children: React.ReactNode; | ||
| }); | ||
@@ -24,4 +29,8 @@ /** | ||
| */ | ||
| export default function Link({ to, action, ...rest }: Props) { | ||
| const props = useLinkProps({ to, action }); | ||
| export default function Link<ParamList extends ReactNavigation.RootParamList>({ | ||
| to, | ||
| action, | ||
| ...rest | ||
| }: Props<ParamList>) { | ||
| const props = useLinkProps<ParamList>({ to, action }); | ||
@@ -28,0 +37,0 @@ const onPress = ( |
@@ -0,6 +1,8 @@ | ||
| import type { ParamListBase } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import type { LinkingOptions } from './types'; | ||
| const LinkingContext = React.createContext<{ | ||
| options: LinkingOptions | undefined; | ||
| options: LinkingOptions<ParamListBase> | undefined; | ||
| }>({ options: undefined }); | ||
@@ -7,0 +9,0 @@ |
@@ -1,19 +0,34 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| BaseNavigationContainer, | ||
| getActionFromState, | ||
| getPathFromState, | ||
| getStateFromPath, | ||
| NavigationContainerProps, | ||
| NavigationContainerRef, | ||
| ParamListBase, | ||
| validatePathConfig, | ||
| } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import LinkingContext from './LinkingContext'; | ||
| import DefaultTheme from './theming/DefaultTheme'; | ||
| import ThemeProvider from './theming/ThemeProvider'; | ||
| import DefaultTheme from './theming/DefaultTheme'; | ||
| import LinkingContext from './LinkingContext'; | ||
| import type { DocumentTitleOptions, LinkingOptions, Theme } from './types'; | ||
| import useBackButton from './useBackButton'; | ||
| import useDocumentTitle from './useDocumentTitle'; | ||
| import useLinking from './useLinking'; | ||
| import useThenable from './useThenable'; | ||
| import useLinking from './useLinking'; | ||
| import useDocumentTitle from './useDocumentTitle'; | ||
| import useBackButton from './useBackButton'; | ||
| import type { Theme, LinkingOptions, DocumentTitleOptions } from './types'; | ||
| type Props = NavigationContainerProps & { | ||
| declare global { | ||
| var REACT_NAVIGATION_DEVTOOLS: WeakMap< | ||
| NavigationContainerRef<any>, | ||
| { readonly linking: LinkingOptions<any> } | ||
| >; | ||
| } | ||
| global.REACT_NAVIGATION_DEVTOOLS = new WeakMap(); | ||
| type Props<ParamList extends {}> = NavigationContainerProps & { | ||
| theme?: Theme; | ||
| linking?: LinkingOptions; | ||
| linking?: LinkingOptions<ParamList>; | ||
| fallback?: React.ReactNode; | ||
@@ -38,3 +53,3 @@ documentTitle?: DocumentTitleOptions; | ||
| */ | ||
| const NavigationContainer = React.forwardRef(function NavigationContainer( | ||
| function NavigationContainerInner( | ||
| { | ||
@@ -47,9 +62,14 @@ theme = DefaultTheme, | ||
| ...rest | ||
| }: Props, | ||
| ref?: React.Ref<NavigationContainerRef | null> | ||
| }: Props<ParamListBase>, | ||
| ref?: React.Ref<NavigationContainerRef<ParamListBase> | null> | ||
| ) { | ||
| const isLinkingEnabled = linking ? linking.enabled !== false : false; | ||
| const refContainer = React.useRef<NavigationContainerRef>(null); | ||
| if (linking?.config) { | ||
| validatePathConfig(linking.config); | ||
| } | ||
| const refContainer = | ||
| React.useRef<NavigationContainerRef<ParamListBase>>(null); | ||
| useBackButton(refContainer); | ||
@@ -59,2 +79,3 @@ useDocumentTitle(refContainer, documentTitle); | ||
| const { getInitialState } = useLinking(refContainer, { | ||
| independent: rest.independent, | ||
| enabled: isLinkingEnabled, | ||
@@ -65,2 +86,22 @@ prefixes: [], | ||
| // Add additional linking related info to the ref | ||
| // This will be used by the devtools | ||
| React.useEffect(() => { | ||
| if (refContainer.current) { | ||
| REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, { | ||
| get linking() { | ||
| return { | ||
| ...linking, | ||
| enabled: isLinkingEnabled, | ||
| prefixes: linking?.prefixes ?? [], | ||
| getStateFromPath: linking?.getStateFromPath ?? getStateFromPath, | ||
| getPathFromState: linking?.getPathFromState ?? getPathFromState, | ||
| getActionFromState: | ||
| linking?.getActionFromState ?? getActionFromState, | ||
| }; | ||
| }, | ||
| }); | ||
| } | ||
| }); | ||
| const [isResolved, initialState] = useThenable(getInitialState); | ||
@@ -105,4 +146,12 @@ | ||
| ); | ||
| }); | ||
| } | ||
| const NavigationContainer = React.forwardRef(NavigationContainerInner) as < | ||
| RootParamList extends {} = ReactNavigation.RootParamList | ||
| >( | ||
| props: Props<RootParamList> & { | ||
| ref?: React.Ref<NavigationContainerRef<RootParamList>>; | ||
| } | ||
| ) => React.ReactElement; | ||
| export default NavigationContainer; |
@@ -0,3 +1,4 @@ | ||
| import { CurrentRenderContext } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { CurrentRenderContext } from '@react-navigation/core'; | ||
| import ServerContext, { ServerContextType } from './ServerContext'; | ||
@@ -4,0 +5,0 @@ import type { ServerContainerRef } from './types'; |
| import * as React from 'react'; | ||
| import type { Theme } from '../types'; | ||
| import DefaultTheme from './DefaultTheme'; | ||
| import type { Theme } from '../types'; | ||
@@ -5,0 +6,0 @@ const ThemeContext = React.createContext<Theme>(DefaultTheme); |
| import * as React from 'react'; | ||
| import type { Theme } from '../types'; | ||
| import ThemeContext from './ThemeContext'; | ||
| import type { Theme } from '../types'; | ||
@@ -5,0 +6,0 @@ type Props = { |
| import * as React from 'react'; | ||
| import ThemeContext from './ThemeContext'; | ||
@@ -3,0 +4,0 @@ |
+36
-15
| import type { | ||
| getActionFromState as getActionFromStateDefault, | ||
| getPathFromState as getPathFromStateDefault, | ||
| getStateFromPath as getStateFromPathDefault, | ||
| getPathFromState as getPathFromStateDefault, | ||
| getActionFromState as getActionFromStateDefault, | ||
| PathConfigMap, | ||
@@ -21,3 +21,3 @@ Route, | ||
| export type LinkingOptions = { | ||
| export type LinkingOptions<ParamList extends {}> = { | ||
| /** | ||
@@ -31,4 +31,5 @@ * Whether deep link handling should be enabled. | ||
| * Usually they are the `scheme` + `host` (e.g. `myapp://chat?user=jane`) | ||
| * Only applicable on Android and iOS. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
@@ -47,2 +48,20 @@ * ```js | ||
| /** | ||
| * Optional function which takes an incoming URL returns a boolean | ||
| * indicating whether React Navigation should handle it. | ||
| * | ||
| * This can be used to disable deep linking for specific URLs. | ||
| * e.g. URLs used for authentication, and not for deep linking to screens. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
| * ```js | ||
| * { | ||
| * // Filter out URLs used by expo-auth-session | ||
| * filter: (url) => !url.includes('+expo-auth-session') | ||
| * } | ||
| * ``` | ||
| */ | ||
| filter?: (url: string) => boolean; | ||
| /** | ||
| * Config to fine-tune how to parse the path. | ||
@@ -60,8 +79,12 @@ * | ||
| */ | ||
| config?: { initialRouteName?: string; screens: PathConfigMap }; | ||
| config?: { | ||
| initialRouteName?: keyof ParamList; | ||
| screens: PathConfigMap<ParamList>; | ||
| }; | ||
| /** | ||
| * Custom function to get the initial URL used for linking. | ||
| * Uses `Linking.getInitialURL()` by default. | ||
| * Not supported on Web. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
@@ -82,4 +105,5 @@ * ```js | ||
| * Uses `Linking.addEventListener('url', callback)` by default. | ||
| * Not supported on Web. | ||
| * | ||
| * This is not supported on Web. | ||
| * | ||
| * @example | ||
@@ -103,16 +127,13 @@ * ```js | ||
| * Custom function to parse the URL to a valid navigation state (advanced). | ||
| * This state object will be passed as `initialState` for initial URL, | ||
| * and converted to an action object to `dispatch` for subsequent URLs. | ||
| */ | ||
| getStateFromPath?: typeof getStateFromPathDefault; | ||
| /** | ||
| * Custom function to convert the state object to an action to dispatch (advanced). | ||
| * By default, the state is converted to a `NAVIGATE` action. | ||
| * Custom function to convert the state object to a valid URL (advanced). | ||
| * Only applicable on Web. | ||
| */ | ||
| getActionFromState?: typeof getActionFromStateDefault; | ||
| getPathFromState?: typeof getPathFromStateDefault; | ||
| /** | ||
| * Custom function to convert the state object to a valid URL (advanced). | ||
| * Used for creating links for navigation, primarily useful on Web. | ||
| * Custom function to convert the state object to a valid action (advanced). | ||
| */ | ||
| getPathFromState?: typeof getPathFromStateDefault; | ||
| getActionFromState?: typeof getActionFromStateDefault; | ||
| }; | ||
@@ -119,0 +140,0 @@ |
@@ -1,30 +0,11 @@ | ||
| import * as React from 'react'; | ||
| import { BackHandler } from 'react-native'; | ||
| import type { NavigationContainerRef } from '@react-navigation/core'; | ||
| import type { | ||
| NavigationContainerRef, | ||
| ParamListBase, | ||
| } from '@react-navigation/core'; | ||
| export default function useBackButton( | ||
| ref: React.RefObject<NavigationContainerRef> | ||
| _: React.RefObject<NavigationContainerRef<ParamListBase>> | ||
| ) { | ||
| React.useEffect(() => { | ||
| const subscription = BackHandler.addEventListener( | ||
| 'hardwareBackPress', | ||
| () => { | ||
| const navigation = ref.current; | ||
| if (navigation == null) { | ||
| return false; | ||
| } | ||
| if (navigation.canGoBack()) { | ||
| navigation.goBack(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| ); | ||
| return () => subscription.remove(); | ||
| }, [ref]); | ||
| // No-op | ||
| // BackHandler is not available on web | ||
| } |
@@ -0,3 +1,7 @@ | ||
| import type { | ||
| NavigationContainerRef, | ||
| ParamListBase, | ||
| } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import type { NavigationContainerRef } from '@react-navigation/core'; | ||
| import type { DocumentTitleOptions } from './types'; | ||
@@ -9,3 +13,3 @@ | ||
| export default function useDocumentTitle( | ||
| ref: React.RefObject<NavigationContainerRef>, | ||
| ref: React.RefObject<NavigationContainerRef<ParamListBase>>, | ||
| { | ||
@@ -12,0 +16,0 @@ enabled = true, |
@@ -1,3 +0,3 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| getPathFromState, | ||
| NavigationHelpers, | ||
@@ -7,4 +7,5 @@ NavigationHelpersContext, | ||
| ParamListBase, | ||
| getPathFromState, | ||
| } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import LinkingContext from './LinkingContext'; | ||
@@ -11,0 +12,0 @@ |
@@ -1,3 +0,1 @@ | ||
| import * as React from 'react'; | ||
| import { Linking, Platform } from 'react-native'; | ||
| import { | ||
@@ -7,3 +5,7 @@ getActionFromState as getActionFromStateDefault, | ||
| NavigationContainerRef, | ||
| ParamListBase, | ||
| } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { Linking, Platform } from 'react-native'; | ||
| import extractPathFromURL from './extractPathFromURL'; | ||
@@ -14,9 +16,15 @@ import type { LinkingOptions } from './types'; | ||
| let isUsingLinking = false; | ||
| type Options = LinkingOptions<ParamListBase> & { | ||
| independent?: boolean; | ||
| }; | ||
| let linkingHandlers: Symbol[] = []; | ||
| export default function useLinking( | ||
| ref: React.RefObject<NavigationContainerRef>, | ||
| ref: React.RefObject<NavigationContainerRef<ParamListBase>>, | ||
| { | ||
| independent, | ||
| enabled = true, | ||
| prefixes, | ||
| filter, | ||
| config, | ||
@@ -39,2 +47,6 @@ getInitialURL = () => | ||
| // Storing this in a local variable stops Jest from complaining about import after teardown | ||
| // @ts-expect-error: removeEventListener is not present in newer RN versions | ||
| const removeEventListener = Linking.removeEventListener?.bind(Linking); | ||
| return () => { | ||
@@ -45,3 +57,3 @@ // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7 | ||
| } else { | ||
| Linking.removeEventListener('url', callback); | ||
| removeEventListener?.('url', callback); | ||
| } | ||
@@ -52,11 +64,19 @@ }; | ||
| getActionFromState = getActionFromStateDefault, | ||
| }: LinkingOptions | ||
| }: Options | ||
| ) { | ||
| React.useEffect(() => { | ||
| if (enabled !== false && isUsingLinking) { | ||
| throw new Error( | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return undefined; | ||
| } | ||
| if (independent) { | ||
| return undefined; | ||
| } | ||
| if (enabled !== false && linkingHandlers.length) { | ||
| console.error( | ||
| [ | ||
| 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', | ||
| "- You are not using both 'linking' prop and 'useLinking'", | ||
| "- You don't have 'useLinking' in multiple components", | ||
| "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", | ||
| '- Only a single instance of the root component is rendered', | ||
| Platform.OS === 'android' | ||
@@ -69,10 +89,18 @@ ? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances" | ||
| ); | ||
| } else { | ||
| isUsingLinking = enabled !== false; | ||
| } | ||
| const handler = Symbol(); | ||
| if (enabled !== false) { | ||
| linkingHandlers.push(handler); | ||
| } | ||
| return () => { | ||
| isUsingLinking = false; | ||
| const index = linkingHandlers.indexOf(handler); | ||
| if (index > -1) { | ||
| linkingHandlers.splice(index, 1); | ||
| } | ||
| }; | ||
| }); | ||
| }, [enabled, independent]); | ||
@@ -84,2 +112,3 @@ // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners | ||
| const prefixesRef = React.useRef(prefixes); | ||
| const filterRef = React.useRef(filter); | ||
| const configRef = React.useRef(config); | ||
@@ -93,2 +122,3 @@ const getInitialURLRef = React.useRef(getInitialURL); | ||
| prefixesRef.current = prefixes; | ||
| filterRef.current = filter; | ||
| configRef.current = config; | ||
@@ -100,2 +130,17 @@ getInitialURLRef.current = getInitialURL; | ||
| const getStateFromURL = React.useCallback( | ||
| (url: string | null | undefined) => { | ||
| if (!url || (filterRef.current && !filterRef.current(url))) { | ||
| return undefined; | ||
| } | ||
| const path = extractPathFromURL(prefixesRef.current, url); | ||
| return path !== undefined | ||
| ? getStateFromPathRef.current(path, configRef.current) | ||
| : undefined; | ||
| }, | ||
| [] | ||
| ); | ||
| const getInitialState = React.useCallback(() => { | ||
@@ -109,17 +154,9 @@ let state: ResultState | undefined; | ||
| return url.then((url) => { | ||
| const path = url | ||
| ? extractPathFromURL(prefixesRef.current, url) | ||
| : null; | ||
| const state = getStateFromURL(url); | ||
| return path | ||
| ? getStateFromPathRef.current(path, configRef.current) | ||
| : undefined; | ||
| return state; | ||
| }); | ||
| } | ||
| const path = url ? extractPathFromURL(prefixesRef.current, url) : null; | ||
| state = path | ||
| ? getStateFromPathRef.current(path, configRef.current) | ||
| : undefined; | ||
| state = getStateFromURL(url); | ||
| } | ||
@@ -137,3 +174,3 @@ | ||
| return thenable as PromiseLike<ResultState | undefined>; | ||
| }, []); | ||
| }, [getStateFromURL]); | ||
@@ -146,40 +183,35 @@ React.useEffect(() => { | ||
| const path = extractPathFromURL(prefixesRef.current, url); | ||
| const navigation = ref.current; | ||
| const state = navigation ? getStateFromURL(url) : undefined; | ||
| if (navigation && path) { | ||
| const state = getStateFromPathRef.current(path, configRef.current); | ||
| if (navigation && state) { | ||
| // Make sure that the routes in the state exist in the root navigator | ||
| // Otherwise there's an error in the linking configuration | ||
| const rootState = navigation.getRootState(); | ||
| if (state) { | ||
| // Make sure that the routes in the state exist in the root navigator | ||
| // Otherwise there's an error in the linking configuration | ||
| const rootState = navigation.getRootState(); | ||
| if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) { | ||
| console.warn( | ||
| "The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration." | ||
| ); | ||
| return; | ||
| } | ||
| if ( | ||
| state.routes.some((r) => !rootState?.routeNames.includes(r.name)) | ||
| ) { | ||
| const action = getActionFromStateRef.current(state, configRef.current); | ||
| if (action !== undefined) { | ||
| try { | ||
| navigation.dispatch(action); | ||
| } catch (e) { | ||
| // Ignore any errors from deep linking. | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn( | ||
| "The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration." | ||
| `An error occurred when trying to handle the link '${url}': ${ | ||
| typeof e === 'object' && e != null && 'message' in e | ||
| ? e.message | ||
| : e | ||
| }` | ||
| ); | ||
| return; | ||
| } | ||
| const action = getActionFromStateRef.current( | ||
| state, | ||
| configRef.current | ||
| ); | ||
| if (action !== undefined) { | ||
| try { | ||
| navigation.dispatch(action); | ||
| } catch (e) { | ||
| // Ignore any errors from deep linking. | ||
| // This could happen in case of malformed links, navigation object not being initialized etc. | ||
| console.warn( | ||
| `An error occurred when trying to handle the link '${path}': ${e.message}` | ||
| ); | ||
| } | ||
| } else { | ||
| navigation.resetRoot(state); | ||
| } | ||
| } else { | ||
| navigation.resetRoot(state); | ||
| } | ||
@@ -190,3 +222,3 @@ } | ||
| return subscribe(listener); | ||
| }, [enabled, ref, subscribe]); | ||
| }, [enabled, getStateFromURL, ref, subscribe]); | ||
@@ -193,0 +225,0 @@ return { |
+91
-248
@@ -1,10 +0,14 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| findFocusedRoute, | ||
| getActionFromState as getActionFromStateDefault, | ||
| getPathFromState as getPathFromStateDefault, | ||
| getStateFromPath as getStateFromPathDefault, | ||
| getPathFromState as getPathFromStateDefault, | ||
| getActionFromState as getActionFromStateDefault, | ||
| NavigationContainerRef, | ||
| NavigationState, | ||
| ParamListBase, | ||
| } from '@react-navigation/core'; | ||
| import { nanoid } from 'nanoid/non-secure'; | ||
| import isEqual from 'fast-deep-equal'; | ||
| import * as React from 'react'; | ||
| import createMemoryHistory from './createMemoryHistory'; | ||
| import ServerContext from './ServerContext'; | ||
@@ -15,199 +19,2 @@ import type { LinkingOptions } from './types'; | ||
| type HistoryRecord = { | ||
| // Unique identifier for this record to match it with window.history.state | ||
| id: string; | ||
| // Navigation state object for the history entry | ||
| state: NavigationState; | ||
| // Path of the history entry | ||
| path: string; | ||
| }; | ||
| const createMemoryHistory = () => { | ||
| let index = 0; | ||
| let items: HistoryRecord[] = []; | ||
| // Pending callbacks for `history.go(n)` | ||
| // We might modify the callback stored if it was interrupted, so we have a ref to identify it | ||
| const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = []; | ||
| const interrupt = () => { | ||
| // If another history operation was performed we need to interrupt existing ones | ||
| // This makes sure that calls such as `history.replace` after `history.go` don't happen | ||
| // Since otherwise it won't be correct if something else has changed | ||
| pending.forEach((it) => { | ||
| const cb = it.cb; | ||
| it.cb = () => cb(true); | ||
| }); | ||
| }; | ||
| const history = { | ||
| get index(): number { | ||
| // We store an id in the state instead of an index | ||
| // Index could get out of sync with in-memory values if page reloads | ||
| const id = window.history.state?.id; | ||
| if (id) { | ||
| const index = items.findIndex((item) => item.id === id); | ||
| return index > -1 ? index : 0; | ||
| } | ||
| return 0; | ||
| }, | ||
| get(index: number) { | ||
| return items[index]; | ||
| }, | ||
| backIndex({ path }: { path: string }) { | ||
| // We need to find the index from the element before current to get closest path to go back to | ||
| for (let i = index - 1; i >= 0; i--) { | ||
| const item = items[i]; | ||
| if (item.path === path) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }, | ||
| push({ path, state }: { path: string; state: NavigationState }) { | ||
| interrupt(); | ||
| const id = nanoid(); | ||
| // When a new entry is pushed, all the existing entries after index will be inaccessible | ||
| // So we remove any existing entries after the current index to clean them up | ||
| items = items.slice(0, index + 1); | ||
| items.push({ path, state, id }); | ||
| index = items.length - 1; | ||
| // We pass empty string for title because it's ignored in all browsers except safari | ||
| // We don't store state object in history.state because: | ||
| // - browsers have limits on how big it can be, and we don't control the size | ||
| // - while not recommended, there could be non-serializable data in state | ||
| window.history.pushState({ id }, '', path); | ||
| }, | ||
| replace({ path, state }: { path: string; state: NavigationState }) { | ||
| interrupt(); | ||
| const id = window.history.state?.id ?? nanoid(); | ||
| if (items.length) { | ||
| items[index] = { path, state, id }; | ||
| } else { | ||
| // This is the first time any state modifications are done | ||
| // So we need to push the entry as there's nothing to replace | ||
| items.push({ path, state, id }); | ||
| } | ||
| window.history.replaceState({ id }, '', path); | ||
| }, | ||
| // `history.go(n)` is asynchronous, there are couple of things to keep in mind: | ||
| // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire. | ||
| // - each `history.go(n)` call will trigger a separate `popstate` event with correct location. | ||
| // - the `popstate` event fires before the next frame after calling `history.go(n)`. | ||
| // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can. | ||
| go(n: number) { | ||
| interrupt(); | ||
| if (n > 0) { | ||
| // We shouldn't go forward more than available index | ||
| n = Math.min(n, items.length - 1); | ||
| } else if (n < 0) { | ||
| // We shouldn't go back more than the 0 index | ||
| // Otherwise we'll exit the page | ||
| n = index + n < 0 ? -index : n; | ||
| } | ||
| if (n === 0) { | ||
| return; | ||
| } | ||
| index += n; | ||
| // When we call `history.go`, `popstate` will fire when there's history to go back to | ||
| // So we need to somehow handle following cases: | ||
| // - There's history to go back, `history.go` is called, and `popstate` fires | ||
| // - `history.go` is called multiple times, we need to resolve on respective `popstate` | ||
| // - No history to go back, but `history.go` was called, browser has no API to detect it | ||
| return new Promise<void>((resolve, reject) => { | ||
| const done = (interrupted?: boolean) => { | ||
| clearTimeout(timer); | ||
| if (interrupted) { | ||
| reject(new Error('History was changed during navigation.')); | ||
| return; | ||
| } | ||
| // There seems to be a bug in Chrome regarding updating the title | ||
| // If we set a title just before calling `history.go`, the title gets lost | ||
| // However the value of `document.title` is still what we set it to | ||
| // It's just not displayed in the tab bar | ||
| // To update the tab bar, we need to reset the title to something else first (e.g. '') | ||
| // And set the title to what it was before so it gets applied | ||
| // It won't work without setting it to empty string coz otherwise title isn't changing | ||
| // Which means that the browser won't do anything after setting the title | ||
| const { title } = window.document; | ||
| window.document.title = ''; | ||
| window.document.title = title; | ||
| resolve(); | ||
| }; | ||
| pending.push({ ref: done, cb: done }); | ||
| // If navigation didn't happen within 100ms, assume that it won't happen | ||
| // This may not be accurate, but hopefully it won't take so much time | ||
| // In Chrome, navigation seems to happen instantly in next microtask | ||
| // But on Firefox, it seems to take much longer, around 50ms from our testing | ||
| // We're using a hacky timeout since there doesn't seem to be way to know for sure | ||
| const timer = setTimeout(() => { | ||
| const index = pending.findIndex((it) => it.ref === done); | ||
| if (index > -1) { | ||
| pending[index].cb(); | ||
| pending.splice(index, 1); | ||
| } | ||
| }, 100); | ||
| const onPopState = () => { | ||
| const last = pending.pop(); | ||
| window.removeEventListener('popstate', onPopState); | ||
| last?.cb(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| window.history.go(n); | ||
| }); | ||
| }, | ||
| // The `popstate` event is triggered when history changes, except `pushState` and `replaceState` | ||
| // If we call `history.go(n)` ourselves, we don't want it to trigger the listener | ||
| // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener | ||
| listen(listener: () => void) { | ||
| const onPopState = () => { | ||
| if (pending.length) { | ||
| // This was triggered by `history.go(n)`, we shouldn't call the listener | ||
| return; | ||
| } | ||
| listener(); | ||
| }; | ||
| window.addEventListener('popstate', onPopState); | ||
| return () => window.removeEventListener('popstate', onPopState); | ||
| }, | ||
| }; | ||
| return history; | ||
| }; | ||
| /** | ||
@@ -256,39 +63,20 @@ * Find the matching navigation state that changed between 2 navigation states | ||
| */ | ||
| const series = (cb: () => Promise<void>) => { | ||
| // Whether we're currently handling a callback | ||
| let handling = false; | ||
| let queue: (() => Promise<void>)[] = []; | ||
| const callback = async () => { | ||
| try { | ||
| if (handling) { | ||
| // If we're currently handling a previous event, wait before handling this one | ||
| // Add the callback to the beginning of the queue | ||
| queue.unshift(callback); | ||
| return; | ||
| } | ||
| handling = true; | ||
| await cb(); | ||
| } finally { | ||
| handling = false; | ||
| if (queue.length) { | ||
| // If we have queued items, handle the last one | ||
| const last = queue.pop(); | ||
| last?.(); | ||
| } | ||
| } | ||
| export const series = (cb: () => Promise<void>) => { | ||
| let queue = Promise.resolve(); | ||
| const callback = () => { | ||
| queue = queue.then(cb); | ||
| }; | ||
| return callback; | ||
| }; | ||
| let isUsingLinking = false; | ||
| let linkingHandlers: Symbol[] = []; | ||
| type Options = LinkingOptions<ParamListBase> & { | ||
| independent?: boolean; | ||
| }; | ||
| export default function useLinking( | ||
| ref: React.RefObject<NavigationContainerRef>, | ||
| ref: React.RefObject<NavigationContainerRef<ParamListBase>>, | ||
| { | ||
| independent, | ||
| enabled = true, | ||
@@ -299,11 +87,19 @@ config, | ||
| getActionFromState = getActionFromStateDefault, | ||
| }: LinkingOptions | ||
| }: Options | ||
| ) { | ||
| React.useEffect(() => { | ||
| if (enabled !== false && isUsingLinking) { | ||
| throw new Error( | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return undefined; | ||
| } | ||
| if (independent) { | ||
| return undefined; | ||
| } | ||
| if (enabled !== false && linkingHandlers.length) { | ||
| console.error( | ||
| [ | ||
| 'Looks like you have configured linking in multiple places. This is likely an error since URL integration should only be handled in one place to avoid conflicts. Make sure that:', | ||
| "- You are not using both 'linking' prop and 'useLinking'", | ||
| "- You don't have 'useLinking' in multiple components", | ||
| 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', | ||
| "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", | ||
| '- Only a single instance of the root component is rendered', | ||
| ] | ||
@@ -313,10 +109,18 @@ .join('\n') | ||
| ); | ||
| } else { | ||
| isUsingLinking = enabled !== false; | ||
| } | ||
| const handler = Symbol(); | ||
| if (enabled !== false) { | ||
| linkingHandlers.push(handler); | ||
| } | ||
| return () => { | ||
| isUsingLinking = false; | ||
| const index = linkingHandlers.indexOf(handler); | ||
| if (index > -1) { | ||
| linkingHandlers.splice(index, 1); | ||
| } | ||
| }; | ||
| }); | ||
| }, [enabled, independent]); | ||
@@ -331,4 +135,4 @@ const [history] = React.useState(createMemoryHistory); | ||
| const getStateFromPathRef = React.useRef(getStateFromPath); | ||
| const getPathFromStateRef = React.useRef(getPathFromState); | ||
| const getActionFromStateRef = React.useRef(getActionFromState); | ||
| const getPathFromStateRef = React.useRef(getPathFromState); | ||
@@ -339,4 +143,4 @@ React.useEffect(() => { | ||
| getStateFromPathRef.current = getStateFromPath; | ||
| getPathFromStateRef.current = getPathFromState; | ||
| getActionFromStateRef.current = getActionFromState; | ||
| getPathFromStateRef.current = getPathFromState; | ||
| }); | ||
@@ -417,3 +221,3 @@ | ||
| console.warn( | ||
| "The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/5.x/configuring-links for more details on how to specify a linking configuration." | ||
| "The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration." | ||
| ); | ||
@@ -436,3 +240,7 @@ return; | ||
| console.warn( | ||
| `An error occurred when trying to handle the link '${path}': ${e.message}` | ||
| `An error occurred when trying to handle the link '${path}': ${ | ||
| typeof e === 'object' && e != null && 'message' in e | ||
| ? e.message | ||
| : e | ||
| }` | ||
| ); | ||
@@ -458,2 +266,30 @@ } | ||
| const getPathForRoute = ( | ||
| route: ReturnType<typeof findFocusedRoute>, | ||
| state: NavigationState | ||
| ): string => { | ||
| // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match | ||
| // This makes sure that we preserve the original URL for wildcard routes | ||
| if (route?.path) { | ||
| const stateForPath = getStateFromPathRef.current( | ||
| route.path, | ||
| configRef.current | ||
| ); | ||
| if (stateForPath) { | ||
| const focusedRoute = findFocusedRoute(stateForPath); | ||
| if ( | ||
| focusedRoute && | ||
| focusedRoute.name === route.name && | ||
| isEqual(focusedRoute.params, route.params) | ||
| ) { | ||
| return route.path; | ||
| } | ||
| } | ||
| } | ||
| return getPathFromStateRef.current(state, configRef.current); | ||
| }; | ||
| if (ref.current) { | ||
@@ -465,3 +301,4 @@ // We need to record the current metadata on the first render if they aren't set | ||
| if (state) { | ||
| const path = getPathFromStateRef.current(state, configRef.current); | ||
| const route = findFocusedRoute(state); | ||
| const path = getPathForRoute(route, state); | ||
@@ -486,4 +323,10 @@ if (previousStateRef.current === undefined) { | ||
| // root state may not available, for example when root navigators switch inside the container | ||
| if (!state) { | ||
| return; | ||
| } | ||
| const pendingPath = pendingPopStatePathRef.current; | ||
| const path = getPathFromStateRef.current(state, configRef.current); | ||
| const route = findFocusedRoute(state); | ||
| const path = getPathForRoute(route, state); | ||
@@ -558,3 +401,3 @@ previousStateRef.current = state; | ||
| return ref.current?.addListener('state', series(onStateChange)); | ||
| }); | ||
| }, [enabled, history, ref]); | ||
@@ -561,0 +404,0 @@ return { |
+72
-16
@@ -1,14 +0,50 @@ | ||
| import * as React from 'react'; | ||
| import { Platform, GestureResponderEvent } from 'react-native'; | ||
| import { | ||
| getPathFromState, | ||
| NavigationAction, | ||
| NavigationContainerRefContext, | ||
| NavigationHelpersContext, | ||
| NavigatorScreenParams, | ||
| ParamListBase, | ||
| } from '@react-navigation/core'; | ||
| import useLinkTo from './useLinkTo'; | ||
| import type { NavigationState, PartialState } from '@react-navigation/routers'; | ||
| import * as React from 'react'; | ||
| import { GestureResponderEvent, Platform } from 'react-native'; | ||
| type Props = { | ||
| to: string; | ||
| import LinkingContext from './LinkingContext'; | ||
| import useLinkTo, { To } from './useLinkTo'; | ||
| type Props<ParamList extends ReactNavigation.RootParamList> = { | ||
| to: To<ParamList>; | ||
| action?: NavigationAction; | ||
| }; | ||
| const getStateFromParams = ( | ||
| params: NavigatorScreenParams<ParamListBase, NavigationState> | undefined | ||
| ): PartialState<NavigationState> | NavigationState | undefined => { | ||
| if (params?.state) { | ||
| return params.state; | ||
| } | ||
| if (params?.screen) { | ||
| return { | ||
| routes: [ | ||
| { | ||
| name: params.screen, | ||
| params: params.params, | ||
| // @ts-expect-error | ||
| state: params.screen | ||
| ? getStateFromParams( | ||
| params.params as | ||
| | NavigatorScreenParams<ParamListBase, NavigationState> | ||
| | undefined | ||
| ) | ||
| : undefined, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| return undefined; | ||
| }; | ||
| /** | ||
@@ -20,5 +56,9 @@ * Hook to get props for an anchor tag so it can work with in page navigation. | ||
| */ | ||
| export default function useLinkProps({ to, action }: Props) { | ||
| export default function useLinkProps< | ||
| ParamList extends ReactNavigation.RootParamList | ||
| >({ to, action }: Props<ParamList>) { | ||
| const root = React.useContext(NavigationContainerRefContext); | ||
| const navigation = React.useContext(NavigationHelpersContext); | ||
| const linkTo = useLinkTo(); | ||
| const { options } = React.useContext(LinkingContext); | ||
| const linkTo = useLinkTo<ParamList>(); | ||
@@ -49,14 +89,10 @@ const onPress = ( | ||
| navigation.dispatch(action); | ||
| } else if (root) { | ||
| root.dispatch(action); | ||
| } else { | ||
| throw new Error("Couldn't find a navigation object."); | ||
| } | ||
| } else { | ||
| if (typeof to !== 'string') { | ||
| throw new Error( | ||
| `To 'to' option is invalid (found '${String( | ||
| to | ||
| )}'. It must be a valid string for navigation.` | ||
| "Couldn't find a navigation object. Is your component inside NavigationContainer?" | ||
| ); | ||
| } | ||
| } else { | ||
| linkTo(to); | ||
@@ -67,4 +103,24 @@ } | ||
| const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState; | ||
| const href = | ||
| typeof to === 'string' | ||
| ? to | ||
| : getPathFromStateHelper( | ||
| { | ||
| routes: [ | ||
| { | ||
| name: to.screen, | ||
| // @ts-expect-error | ||
| params: to.params, | ||
| // @ts-expect-error | ||
| state: getStateFromParams(to.params), | ||
| }, | ||
| ], | ||
| }, | ||
| options?.config | ||
| ); | ||
| return { | ||
| href: to, | ||
| href, | ||
| accessibilityRole: 'link' as const, | ||
@@ -71,0 +127,0 @@ onPress, |
+39
-23
@@ -1,46 +0,62 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| getActionFromState, | ||
| getStateFromPath, | ||
| getActionFromState, | ||
| NavigationContext, | ||
| NavigationContainerRefContext, | ||
| } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import LinkingContext from './LinkingContext'; | ||
| export default function useLinkTo() { | ||
| const navigation = React.useContext(NavigationContext); | ||
| export type To< | ||
| ParamList extends ReactNavigation.RootParamList = ReactNavigation.RootParamList, | ||
| RouteName extends keyof ParamList = keyof ParamList | ||
| > = | ||
| | string | ||
| | (undefined extends ParamList[RouteName] | ||
| ? { | ||
| screen: Extract<RouteName, string>; | ||
| params?: ParamList[RouteName]; | ||
| } | ||
| : { | ||
| screen: Extract<RouteName, string>; | ||
| params: ParamList[RouteName]; | ||
| }); | ||
| export default function useLinkTo< | ||
| ParamList extends ReactNavigation.RootParamList | ||
| >() { | ||
| const navigation = React.useContext(NavigationContainerRefContext); | ||
| const linking = React.useContext(LinkingContext); | ||
| const linkTo = React.useCallback( | ||
| (path: string) => { | ||
| if (!path.startsWith('/')) { | ||
| throw new Error(`The path must start with '/' (${path}).`); | ||
| } | ||
| (to: To<ParamList>) => { | ||
| if (navigation === undefined) { | ||
| throw new Error( | ||
| "Couldn't find a navigation object. Is your component inside a screen in a navigator?" | ||
| "Couldn't find a navigation object. Is your component inside NavigationContainer?" | ||
| ); | ||
| } | ||
| if (typeof to !== 'string') { | ||
| // @ts-expect-error: This is fine | ||
| navigation.navigate(to.screen, to.params); | ||
| return; | ||
| } | ||
| if (!to.startsWith('/')) { | ||
| throw new Error(`The path must start with '/' (${to}).`); | ||
| } | ||
| const { options } = linking; | ||
| const state = options?.getStateFromPath | ||
| ? options.getStateFromPath(path, options.config) | ||
| : getStateFromPath(path, options?.config); | ||
| ? options.getStateFromPath(to, options.config) | ||
| : getStateFromPath(to, options?.config); | ||
| if (state) { | ||
| let root = navigation; | ||
| let current; | ||
| // Traverse up to get the root navigation | ||
| while ((current = root.getParent())) { | ||
| root = current; | ||
| } | ||
| const action = getActionFromState(state, options?.config); | ||
| if (action !== undefined) { | ||
| root.dispatch(action); | ||
| navigation.dispatch(action); | ||
| } else { | ||
| root.reset(state); | ||
| navigation.reset(state); | ||
| } | ||
@@ -47,0 +63,0 @@ } else { |
+55
-40
@@ -0,5 +1,11 @@ | ||
| import { | ||
| EventArg, | ||
| NavigationProp, | ||
| useNavigation, | ||
| useRoute, | ||
| } from '@react-navigation/core'; | ||
| import * as React from 'react'; | ||
| import { useNavigation, useRoute, EventArg } from '@react-navigation/core'; | ||
| import type { ScrollView } from 'react-native'; | ||
| type ScrollOptions = { y?: number; animated?: boolean }; | ||
| type ScrollOptions = { x?: number; y?: number; animated?: boolean }; | ||
@@ -13,3 +19,3 @@ type ScrollableView = | ||
| type ScrollableWrapper = | ||
| | { getScrollResponder(): React.ReactNode } | ||
| | { getScrollResponder(): React.ReactNode | ScrollView } | ||
| | { getNode(): ScrollableView } | ||
@@ -53,51 +59,60 @@ | ScrollableView; | ||
| React.useEffect(() => { | ||
| let current = navigation; | ||
| let tabNavigations: NavigationProp<ReactNavigation.RootParamList>[] = []; | ||
| let currentNavigation = navigation; | ||
| // The screen might be inside another navigator such as stack nested in tabs | ||
| // We need to find the closest tab navigator and add the listener there | ||
| while (current && current.getState().type !== 'tab') { | ||
| current = current.getParent(); | ||
| // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them | ||
| // So we need to find all the parent tab navigators and add the listeners there | ||
| while (currentNavigation) { | ||
| if (currentNavigation.getState().type === 'tab') { | ||
| tabNavigations.push(currentNavigation); | ||
| } | ||
| currentNavigation = currentNavigation.getParent(); | ||
| } | ||
| if (!current) { | ||
| if (tabNavigations.length === 0) { | ||
| return; | ||
| } | ||
| const unsubscribe = current.addListener( | ||
| // We don't wanna import tab types here to avoid extra deps | ||
| // in addition, there are multiple tab implementations | ||
| // @ts-expect-error | ||
| 'tabPress', | ||
| (e: EventArg<'tabPress', true>) => { | ||
| // We should scroll to top only when the screen is focused | ||
| const isFocused = navigation.isFocused(); | ||
| const unsubscribers = tabNavigations.map((tab) => { | ||
| return tab.addListener( | ||
| // We don't wanna import tab types here to avoid extra deps | ||
| // in addition, there are multiple tab implementations | ||
| // @ts-expect-error | ||
| 'tabPress', | ||
| (e: EventArg<'tabPress', true>) => { | ||
| // We should scroll to top only when the screen is focused | ||
| const isFocused = navigation.isFocused(); | ||
| // In a nested stack navigator, tab press resets the stack to first screen | ||
| // So we should scroll to top only when we are on first screen | ||
| const isFirst = | ||
| navigation === current || | ||
| navigation.getState().routes[0].key === route.key; | ||
| // In a nested stack navigator, tab press resets the stack to first screen | ||
| // So we should scroll to top only when we are on first screen | ||
| const isFirst = | ||
| tabNavigations.includes(navigation) || | ||
| navigation.getState().routes[0].key === route.key; | ||
| // Run the operation in the next frame so we're sure all listeners have been run | ||
| // This is necessary to know if preventDefault() has been called | ||
| requestAnimationFrame(() => { | ||
| const scrollable = getScrollableNode(ref) as ScrollableWrapper; | ||
| // Run the operation in the next frame so we're sure all listeners have been run | ||
| // This is necessary to know if preventDefault() has been called | ||
| requestAnimationFrame(() => { | ||
| const scrollable = getScrollableNode(ref) as ScrollableWrapper; | ||
| if (isFocused && isFirst && scrollable && !e.defaultPrevented) { | ||
| if ('scrollToTop' in scrollable) { | ||
| scrollable.scrollToTop(); | ||
| } else if ('scrollTo' in scrollable) { | ||
| scrollable.scrollTo({ y: 0, animated: true }); | ||
| } else if ('scrollToOffset' in scrollable) { | ||
| scrollable.scrollToOffset({ offset: 0, animated: true }); | ||
| } else if ('scrollResponderScrollTo' in scrollable) { | ||
| scrollable.scrollResponderScrollTo({ y: 0, animated: true }); | ||
| if (isFocused && isFirst && scrollable && !e.defaultPrevented) { | ||
| if ('scrollToTop' in scrollable) { | ||
| scrollable.scrollToTop(); | ||
| } else if ('scrollTo' in scrollable) { | ||
| scrollable.scrollTo({ y: 0, animated: true }); | ||
| } else if ('scrollToOffset' in scrollable) { | ||
| scrollable.scrollToOffset({ offset: 0, animated: true }); | ||
| } else if ('scrollResponderScrollTo' in scrollable) { | ||
| scrollable.scrollResponderScrollTo({ y: 0, animated: true }); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
| return unsubscribe; | ||
| return () => { | ||
| unsubscribers.forEach((unsubscribe) => unsubscribe()); | ||
| }; | ||
| }, [navigation, ref, route.key]); | ||
| } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
181
26.57%4963
16.34%309400
-13.6%6
20%17
70%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated