mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-07 00:52:04 +08:00
chore: fix crash due to asyncstorage on web
This commit is contained in:
@@ -8,6 +8,7 @@ it('loads the article page', async () => {
|
||||
expect(await page.evaluate(() => location.pathname + location.search)).toBe(
|
||||
'/link-component/article/gandalf'
|
||||
);
|
||||
|
||||
expect(
|
||||
((await page.accessibility.snapshot()) as any)?.children?.find(
|
||||
(it: any) => it.role === 'heading'
|
||||
|
||||
@@ -21,4 +21,8 @@ beforeEach(async () => {
|
||||
await page.goto('http://localhost:3579');
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await context.close();
|
||||
});
|
||||
|
||||
export { browser, context, page };
|
||||
|
||||
@@ -136,7 +136,7 @@ export default function App() {
|
||||
const initialUrl = await Linking.getInitialURL();
|
||||
|
||||
if (Platform.OS !== 'web' || initialUrl === null) {
|
||||
const savedState = await AsyncStorage.getItem(
|
||||
const savedState = await AsyncStorage?.getItem(
|
||||
NAVIGATION_PERSISTENCE_KEY
|
||||
);
|
||||
|
||||
@@ -148,7 +148,7 @@ export default function App() {
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
const themeName = await AsyncStorage.getItem(THEME_PERSISTENCE_KEY);
|
||||
const themeName = await AsyncStorage?.getItem(THEME_PERSISTENCE_KEY);
|
||||
|
||||
setTheme(themeName === 'dark' ? DarkTheme : DefaultTheme);
|
||||
} catch (e) {
|
||||
@@ -207,7 +207,7 @@ export default function App() {
|
||||
ref={navigationRef}
|
||||
initialState={initialState}
|
||||
onStateChange={(state) =>
|
||||
AsyncStorage.setItem(
|
||||
AsyncStorage?.setItem(
|
||||
NAVIGATION_PERSISTENCE_KEY,
|
||||
JSON.stringify(state)
|
||||
)
|
||||
@@ -317,7 +317,7 @@ export default function App() {
|
||||
label="Dark theme"
|
||||
value={theme.dark}
|
||||
onValueChange={() => {
|
||||
AsyncStorage.setItem(
|
||||
AsyncStorage?.setItem(
|
||||
THEME_PERSISTENCE_KEY,
|
||||
theme.dark ? 'light' : 'dark'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user