feat(smart-app): implement complete mobile app MVP

- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
This commit is contained in:
Eric FELIXINE
2026-06-01 18:00:35 -04:00
parent 08ca495bde
commit e30ae8ed09
35578 changed files with 3703534 additions and 43 deletions

View File

@@ -0,0 +1,42 @@
import * as React from 'react';
import { Platform, Text } from 'react-native';
import useLinkProps from './useLinkProps';
/**
* Component to render link to another screen using a path.
* Uses an anchor tag on the web.
*
* @param props.to Absolute path to screen (e.g. `/feeds/hot`).
* @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
* @param props.children Child elements to render the content.
*/
export default function Link(_ref) {
let {
to,
action,
...rest
} = _ref;
const props = useLinkProps({
to,
action
});
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,
...rest,
...Platform.select({
web: {
onClick: onPress
},
default: {
onPress
}
})
});
}
//# sourceMappingURL=Link.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,7 @@
import * as React from 'react';
const LinkingContext = /*#__PURE__*/React.createContext({
options: undefined
});
LinkingContext.displayName = 'LinkingContext';
export default LinkingContext;
//# sourceMappingURL=LinkingContext.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,101 @@
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 LinkingContext from './LinkingContext';
import DefaultTheme from './theming/DefaultTheme';
import ThemeProvider from './theming/ThemeProvider';
import useBackButton from './useBackButton';
import useDocumentTitle from './useDocumentTitle';
import useLinking from './useLinking';
import useThenable from './useThenable';
global.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
/**
* 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.
*/
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);
useBackButton(refContainer);
useDocumentTitle(refContainer, documentTitle);
const {
getInitialState
} = useLinking(refContainer, {
independent: rest.independent,
enabled: isLinkingEnabled,
prefixes: [],
...linking
});
// 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);
React.useImperativeHandle(ref, () => refContainer.current);
const linkingContext = React.useMemo(() => ({
options: linking
}), [linking]);
const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
const onReadyRef = React.useRef(onReady);
React.useEffect(() => {
onReadyRef.current = onReady;
});
React.useEffect(() => {
if (isReady) {
var _onReadyRef$current;
(_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 ? void 0 : _onReadyRef$current.call(onReadyRef);
}
}, [isReady]);
if (!isReady) {
// This is temporary until we have Suspense for data-fetching
// Then the fallback will be handled by a parent `Suspense` component
return fallback;
}
return /*#__PURE__*/React.createElement(LinkingContext.Provider, {
value: linkingContext
}, /*#__PURE__*/React.createElement(ThemeProvider, {
value: theme
}, /*#__PURE__*/React.createElement(BaseNavigationContainer, _extends({}, rest, {
initialState: rest.initialState == null ? initialState : rest.initialState,
ref: refContainer
}))));
}
const NavigationContainer = /*#__PURE__*/React.forwardRef(NavigationContainerInner);
export default NavigationContainer;
//# sourceMappingURL=NavigationContainer.js.map

View File

@@ -0,0 +1 @@
{"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,oBAAoB;AACjD,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,WAAW,MAAM,eAAe;AASvCC,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,GAAGX,YAAY;IACpBY,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;IACnBtB,kBAAkB,CAACe,OAAO,CAACO,MAAM,CAAC;EACpC;EAEA,MAAMC,YAAY,GAChBtB,KAAK,CAACuB,MAAM,CAAwC,IAAI,CAAC;EAE3DnB,aAAa,C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AAGlB,IAAI,CAACa,YAAY,IAAI,IAAI,IAAI,CAACZ,gBAAgB,IAAIW,UAAU;EAE5E,MAAMO,UAAU,GAAGrC,KAAK,CAACuB,MAAM,CAACN,OAAO,CAAC;EAExCjB,KAAK,CAAC2B,SAAS,CAAC,MAAM;IACpBU,UAAU,CAACT,OAAO,GAAGX,OAAO;EAC9B,CAAC,CAAC;EAEFjB,KAAK,CAAC2B,SAAS,CAAC,MAAM;IACpB,IAAIS,OAAO,EAAE;MAAA;MACX,uBAAAC,UAAU,CAACT,OAAO,wDAAlB,yBAAAS,UAAU,CAAY;IACxB;EACF,CAAC,EAAE,CAACD,OAAO,CAAC,CAAC;EAEb,IAAI,CAACA,OAAO,EAAE;IACZ;IACA;IACA,OAAOrB,QAAQ;EACjB;EAEA,oBACE,oBAAC,cAAc,CAAC,QAAQ;IAAC,KAAK,EAAEkB;EAAe,gBAC7C,oBAAC,aAAa;IAAC,KAAK,EAAEpB;EAAM,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"}

View File

@@ -0,0 +1,46 @@
import { CurrentRenderContext } from '@react-navigation/core';
import * as React from 'react';
import ServerContext from './ServerContext';
/**
* Container component for server rendering.
*
* @param props.location Location object to base the initial URL for SSR.
* @param props.children Child elements to render the content.
* @param props.ref Ref object which contains helper methods.
*/
export default /*#__PURE__*/React.forwardRef(function ServerContainer(_ref, ref) {
let {
children,
location
} = _ref;
React.useEffect(() => {
console.error("'ServerContainer' should only be used on the server with 'react-dom/server' for SSR.");
}, []);
const current = {};
if (ref) {
const value = {
getCurrentOptions() {
return current.options;
}
};
// 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') {
ref(value);
} else {
// @ts-expect-error: the TS types are incorrect and say that ref.current is readonly
ref.current = value;
}
}
return /*#__PURE__*/React.createElement(ServerContext.Provider, {
value: {
location
}
}, /*#__PURE__*/React.createElement(CurrentRenderContext.Provider, {
value: current
}, children));
});
//# sourceMappingURL=ServerContainer.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,4 @@
import * as React from 'react';
const ServerContext = /*#__PURE__*/React.createContext(undefined);
export default ServerContext;
//# sourceMappingURL=ServerContext.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,217 @@
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

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
import escapeStringRegexp from 'escape-string-regexp';
export default function extractPathFromURL(prefixes, url) {
for (const prefix of prefixes) {
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(`^${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)) {
return normalizedURL.replace(prefixRegex, '');
}
}
return undefined;
}
//# sourceMappingURL=extractPathFromURL.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,15 @@
export { default as Link } from './Link';
export { default as LinkingContext } from './LinkingContext';
export { default as NavigationContainer } from './NavigationContainer';
export { default as ServerContainer } from './ServerContainer';
export { default as DarkTheme } from './theming/DarkTheme';
export { default as DefaultTheme } from './theming/DefaultTheme';
export { default as ThemeProvider } from './theming/ThemeProvider';
export { default as useTheme } from './theming/useTheme';
export * from './types';
export { default as useLinkBuilder } from './useLinkBuilder';
export { default as useLinkProps } from './useLinkProps';
export { default as useLinkTo } from './useLinkTo';
export { default as useScrollToTop } from './useScrollToTop';
export * from '@react-navigation/core';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,13 @@
const DarkTheme = {
dark: true,
colors: {
primary: 'rgb(10, 132, 255)',
background: 'rgb(1, 1, 1)',
card: 'rgb(18, 18, 18)',
text: 'rgb(229, 229, 231)',
border: 'rgb(39, 39, 41)',
notification: 'rgb(255, 69, 58)'
}
};
export default DarkTheme;
//# sourceMappingURL=DarkTheme.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,13 @@
const DefaultTheme = {
dark: false,
colors: {
primary: 'rgb(0, 122, 255)',
background: 'rgb(242, 242, 242)',
card: 'rgb(255, 255, 255)',
text: 'rgb(28, 28, 30)',
border: 'rgb(216, 216, 216)',
notification: 'rgb(255, 59, 48)'
}
};
export default DefaultTheme;
//# sourceMappingURL=DefaultTheme.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,6 @@
import * as React from 'react';
import DefaultTheme from './DefaultTheme';
const ThemeContext = /*#__PURE__*/React.createContext(DefaultTheme);
ThemeContext.displayName = 'ThemeContext';
export default ThemeContext;
//# sourceMappingURL=ThemeContext.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,12 @@
import * as React from 'react';
import ThemeContext from './ThemeContext';
export default function ThemeProvider(_ref) {
let {
value,
children
} = _ref;
return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
value: value
}, children);
}
//# sourceMappingURL=ThemeProvider.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,7 @@
import * as React from 'react';
import ThemeContext from './ThemeContext';
export default function useTheme() {
const theme = React.useContext(ThemeContext);
return theme;
}
//# sourceMappingURL=useTheme.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.tsx"],"mappings":""}

View File

@@ -0,0 +1,5 @@
export default function useBackButton(_) {
// No-op
// BackHandler is not available on web
}
//# sourceMappingURL=useBackButton.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useBackButton","_"],"sourceRoot":"../../src","sources":["useBackButton.tsx"],"mappings":"AAKA,eAAe,SAASA,aAAa,CACnCC,CAAyD,EACzD;EACA;EACA;AAAA"}

View File

@@ -0,0 +1,19 @@
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

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,25 @@
import * as React from 'react';
/**
* Set the document title for the active screen
*/
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(() => {
if (!enabled) {
return;
}
const navigation = ref.current;
if (navigation) {
const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute());
document.title = title;
}
return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', e => {
const title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute());
document.title = title;
});
});
}
//# sourceMappingURL=useDocumentTitle.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,4 @@
export default function useDocumentTitle() {
// Noop for React Native
}
//# sourceMappingURL=useDocumentTitle.native.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useDocumentTitle"],"sourceRoot":"../../src","sources":["useDocumentTitle.native.tsx"],"mappings":"AAAA,eAAe,SAASA,gBAAgB,GAAG;EACzC;AAAA"}

View File

@@ -0,0 +1,54 @@
import { getPathFromState, NavigationHelpersContext } from '@react-navigation/core';
import * as React from 'react';
import LinkingContext from './LinkingContext';
const getRootStateForNavigate = (navigation, state) => {
const parent = navigation.getParent();
if (parent) {
const parentState = parent.getState();
return getRootStateForNavigate(parent, {
index: 0,
routes: [{
...parentState.routes[parentState.index],
state: state
}]
});
}
return state;
};
/**
* Build destination link for a navigate action.
* Useful for showing anchor tags on the web for buttons that perform navigation.
*/
export default function useLinkBuilder() {
const navigation = React.useContext(NavigationHelpersContext);
const linking = React.useContext(LinkingContext);
const buildLink = React.useCallback((name, params) => {
const {
options
} = linking;
if ((options === null || options === void 0 ? void 0 : options.enabled) === false) {
return undefined;
}
const state = navigation ? getRootStateForNavigate(navigation, {
index: 0,
routes: [{
name,
params
}]
}) :
// If we couldn't find a navigation object in context, we're at root
// So we'll construct a basic state object to use
{
index: 0,
routes: [{
name,
params
}]
};
const path = options !== null && options !== void 0 && options.getPathFromState ? options.getPathFromState(state, options === null || options === void 0 ? void 0 : options.config) : getPathFromState(state, options === null || options === void 0 ? void 0 : options.config);
return path;
}, [linking, navigation]);
return buildLink;
}
//# sourceMappingURL=useLinkBuilder.js.map

View File

@@ -0,0 +1 @@
{"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,wBAAwB,QAGnB,wBAAwB;AAC/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,OAAOC,cAAc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AgB,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"}

View File

@@ -0,0 +1,89 @@
import { getPathFromState, NavigationContainerRefContext, NavigationHelpersContext } from '@react-navigation/core';
import * as React from 'react';
import { Platform } from 'react-native';
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;
};
/**
* Hook to get props for an anchor tag so it can work with in page navigation.
*
* @param props.to Absolute path to screen (e.g. `/feeds/hot`).
* @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
*/
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
// @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
// @ts-expect-error: these properties exist on web, but not in React Native
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;
}
if (shouldHandle) {
if (action) {
if (navigation) {
navigation.dispatch(action);
} else if (root) {
root.dispatch(action);
} else {
throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
}
} else {
linkTo(to);
}
}
};
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,
accessibilityRole: 'link',
onPress
};
}
//# sourceMappingURL=useLinkProps.js.map

View File

@@ -0,0 +1 @@
{"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;QAC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ClBX,YAAY,GAAG,IAAI;IACrB;IAEA,IAAIA,YAAY,EAAE;MAChB,IAAIR,MAAM,EAAE;QACV,IAAIG,UAAU,EAAE;UACdA,UAAU,CAACiB,QAAQ,CAACpB,MAAM,CAAC;QAC7B,CAAC,MAAM,IAAIC,IAAI,EAAE;UACfA,IAAI,CAACmB,QAAQ,CAACpB,MAAM,CAAC;QACvB,CAAC,MAAM;UACL,MAAM,IAAIqB,KAAK,CACb,kFAAkF,CACnF;QACH;MACF,CAAC,MAAM;QACLhB,MAAM,CAACN,EAAE,CAAC;MACZ;IACF;EACF,CAAC;EAED,MAAMuB,sBAAsB,GAAG,CAAAlB,OAAO,aAAPA,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"}

View File

@@ -0,0 +1,36 @@
import { getActionFromState, getStateFromPath, NavigationContainerRefContext } from '@react-navigation/core';
import * as React from 'react';
import LinkingContext from './LinkingContext';
export default function useLinkTo() {
const navigation = React.useContext(NavigationContainerRefContext);
const linking = React.useContext(LinkingContext);
const linkTo = React.useCallback(to => {
if (navigation === undefined) {
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(to, options.config) : getStateFromPath(to, options === null || options === void 0 ? void 0 : options.config);
if (state) {
const action = getActionFromState(state, options === null || options === void 0 ? void 0 : options.config);
if (action !== undefined) {
navigation.dispatch(action);
} else {
navigation.reset(state);
}
} else {
throw new Error('Failed to parse the path to a navigation state.');
}
}, [linking, navigation]);
return linkTo;
}
//# sourceMappingURL=useLinkTo.js.map

View File

@@ -0,0 +1 @@
{"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"}

View File

@@ -0,0 +1,298 @@
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 createMemoryHistory from './createMemoryHistory';
import ServerContext from './ServerContext';
/**
* Find the matching navigation state that changed between 2 navigation states
* e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state
*/
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`
const aHistoryLength = a.history ? a.history.length : a.routes.length;
const bHistoryLength = b.history ? b.history.length : b.routes.length;
const aRoute = a.routes[a.index];
const bRoute = b.routes[b.index];
const aChildState = aRoute.state;
const bChildState = bRoute.state;
// Stop here if this is the state object that changed:
// - history length is different
// - focused routes are different
// - one of them doesn't have child state
// - 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.
*/
export const series = cb => {
let queue = Promise.resolve();
const callback = () => {
queue = queue.then(cb);
};
return callback;
};
let linkingHandlers = [];
export default function useLinking(ref, _ref) {
let {
independent,
enabled = true,
config,
getStateFromPath = getStateFromPathDefault,
getPathFromState = getPathFromStateDefault,
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'].join('\n').trim());
}
const handler = Symbol();
if (enabled !== false) {
linkingHandlers.push(handler);
}
return () => {
const index = linkingHandlers.indexOf(handler);
if (index > -1) {
linkingHandlers.splice(index, 1);
}
};
}, [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);
React.useEffect(() => {
enabledRef.current = enabled;
configRef.current = config;
getStateFromPathRef.current = getStateFromPath;
getPathFromStateRef.current = getPathFromState;
getActionFromStateRef.current = getActionFromState;
});
const server = React.useContext(ServerContext);
const getInitialState = React.useCallback(() => {
let value;
if (enabledRef.current) {
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) {
value = getStateFromPathRef.current(path, configRef.current);
}
}
const thenable = {
then(onfulfilled) {
return Promise.resolve(onfulfilled ? onfulfilled(value) : value);
},
catch() {
return thenable;
}
};
return thenable;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const previousIndexRef = React.useRef(undefined);
const previousStateRef = React.useRef(undefined);
const pendingPopStatePathRef = React.useRef(undefined);
React.useEffect(() => {
previousIndexRef.current = history.index;
return history.listen(() => {
const navigation = ref.current;
if (!navigation || !enabled) {
return;
}
const {
location
} = window;
const path = location.pathname + location.search;
const index = history.index;
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
// 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) {
navigation.resetRoot(record.state);
return;
}
const state = getStateFromPathRef.current(path, configRef.current);
// 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) {
// 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;
}
if (index > previousIndex) {
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}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`);
}
} else {
navigation.resetRoot(state);
}
} else {
navigation.resetRoot(state);
}
} else {
// if current path didn't return any state, we should revert to initial state
navigation.resetRoot(state);
}
});
}, [enabled, history, ref]);
React.useEffect(() => {
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) {
// We need to record the current metadata on the first render if they aren't set
// This will allow the initial state to be in the history entry
const state = ref.current.getRootState();
if (state) {
const route = findFocusedRoute(state);
const path = getPathForRoute(route, state);
if (previousStateRef.current === undefined) {
previousStateRef.current = state;
}
history.replace({
path,
state
});
}
}
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 route = findFocusedRoute(state);
const path = getPathForRoute(route, state);
previousStateRef.current = state;
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`
// 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) {
// If history length is increased, we should pushState
// Note that path might not actually change here, for example, drawer open should pushState
history.push({
path,
state
});
} else if (historyDelta < 0) {
// If history length is decreased, i.e. entries were removed, we want to go back
const nextIndex = history.backIndex({
path
});
const currentIndex = history.index;
try {
if (nextIndex !== -1 && nextIndex < currentIndex &&
// We should only go back if the entry exists and it's less than current index
history.get(nextIndex - currentIndex)) {
// An existing entry for this path exists and it's less than current index, go back to that
await history.go(nextIndex - currentIndex);
} else {
// We couldn't find an existing entry to go back to, so we'll go back by the delta
// This won't be correct if multiple routes were pushed in one go before
// Usually this shouldn't happen and this is a fallback for that
await history.go(historyDelta);
}
// Store the updated state as well as fix the path if incorrect
history.replace({
path,
state
});
} catch (e) {
// The navigation was interrupted
}
} else {
// If history length is unchanged, we want to replaceState
history.replace({
path,
state
});
}
} else {
// If no common navigation state was found, assume it's a replace
// This would happen if the user did a reset/conditionally changed navigators
history.replace({
path,
state
});
}
};
// 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 {
getInitialState
};
}
//# sourceMappingURL=useLinking.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,147 @@
import { getActionFromState as getActionFromStateDefault, getStateFromPath as getStateFromPathDefault } from '@react-navigation/core';
import * as React from 'react';
import { Linking, Platform } from 'react-native';
import extractPathFromURL from './extractPathFromURL';
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);
// 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 () => {
const index = linkingHandlers.indexOf(handler);
if (index > -1) {
linkingHandlers.splice(index, 1);
}
};
}, [enabled, independent]);
// 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);
const getInitialURLRef = React.useRef(getInitialURL);
const getStateFromPathRef = React.useRef(getStateFromPath);
const getActionFromStateRef = React.useRef(getActionFromState);
React.useEffect(() => {
enabledRef.current = enabled;
prefixesRef.current = prefixes;
filterRef.current = filter;
configRef.current = config;
getInitialURLRef.current = getInitialURL;
getStateFromPathRef.current = getStateFromPath;
getActionFromStateRef.current = getActionFromState;
});
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 state = getStateFromURL(url);
return state;
});
}
state = getStateFromURL(url);
}
const thenable = {
then(onfulfilled) {
return Promise.resolve(onfulfilled ? onfulfilled(state) : state);
},
catch() {
return thenable;
}
};
return thenable;
}, [getStateFromURL]);
React.useEffect(() => {
const listener = url => {
if (!enabled) {
return;
}
const navigation = ref.current;
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}`);
}
} else {
navigation.resetRoot(state);
}
}
};
return subscribe(listener);
}, [enabled, getStateFromURL, ref, subscribe]);
return {
getInitialState
};
}
//# sourceMappingURL=useLinking.native.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,89 @@
import { NavigationContext, useRoute } from '@react-navigation/core';
import * as React from 'react';
function getScrollableNode(ref) {
if (ref.current == null) {
return null;
}
if ('scrollToTop' in ref.current || 'scrollTo' in ref.current || 'scrollToOffset' in ref.current || 'scrollResponderScrollTo' in ref.current) {
// This is already a scrollable node.
return ref.current;
} else if ('getScrollResponder' in ref.current) {
// If the view is a wrapper like FlatList, SectionList etc.
// We need to use `getScrollResponder` to get access to the scroll responder
return ref.current.getScrollResponder();
} else if ('getNode' in ref.current) {
// When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
// we need to use `getNode` to get the ref to the actual scrollview.
// Note that `getNode` is deprecated in newer versions of react-native
// this is why we check if we already have a scrollable node above.
return ref.current.getNode();
} else {
return ref.current;
}
}
export default function useScrollToTop(ref) {
const navigation = React.useContext(NavigationContext);
const route = useRoute();
if (navigation === undefined) {
throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
}
React.useEffect(() => {
const tabNavigations = [];
let currentNavigation = navigation;
// 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 (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();
// 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);
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 () => {
unsubscribers.forEach(unsubscribe => unsubscribe());
};
}, [navigation, ref, route.key]);
}
//# sourceMappingURL=useScrollToTop.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["NavigationContext","useRoute","React","getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","useContext","route","undefined","Error","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,SAEEA,iBAAiB,EAGjBC,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,GAAGP,KAAK,CAACQ,UAAU,CAACV,iBAAiB,CAAC;EACtD,MAAMW,KAAK,GAAGV,QAAQ,EAAE;EAExB,IAAIQ,UAAU,KAAKG,SAAS,EAAE;IAC5B,MAAM,IA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,IAAIL,UAAU,EAAE;cACzCA,UAAU,CAACM,cAAc,CAAC;gBAAEC,MAAM,EAAE,CAAC;gBAAEF,QAAQ,EAAE;cAAK,CAAC,CAAC;YAC1D,CAAC,MAAM,IAAI,yBAAyB,IAAIL,UAAU,EAAE;cAClDA,UAAU,CAACQ,uBAAuB,CAAC;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,CAAClC,UAAU,EAAEL,GAAG,EAAEO,KAAK,CAACoB,GAAG,CAAC,CAAC;AAClC"}

View File

@@ -0,0 +1,33 @@
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
promise.then(result => {
initialState = [true, result];
});
const [state, setState] = React.useState(initialState);
const [resolved] = state;
React.useEffect(() => {
let cancelled = false;
const resolve = async () => {
let result;
try {
result = await promise;
} finally {
if (!cancelled) {
setState([true, result]);
}
}
};
if (!resolved) {
resolve();
}
return () => {
cancelled = true;
};
}, [promise, resolved]);
return state;
}
//# sourceMappingURL=useThenable.js.map

View File

@@ -0,0 +1 @@
{"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"}