Skip to content

Commit

Permalink
fix(boilerplate): fix deep link not working with navigation persist
Browse files Browse the repository at this point in the history
  • Loading branch information
vanenshi committed May 29, 2024
1 parent 7544fac commit fe53c17
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions boilerplate/app/navigators/navigationUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect, useRef } from "react"
import { BackHandler, Platform } from "react-native"
import { BackHandler, Linking, Platform } from "react-native"
import {
NavigationState,
PartialState,
Expand Down Expand Up @@ -147,8 +147,13 @@ export function useNavigationPersistence(storage: Storage, persistenceKey: strin

const restoreState = async () => {
try {
const state = (await storage.load(persistenceKey)) as NavigationProps["initialState"] | null
if (state) setInitialNavigationState(state)
const initialUrl = await Linking.getInitialURL()

// Only restore the state if app has not started from a deep link
if (!initialUrl) {
const state = (await storage.load(persistenceKey)) as NavigationProps["initialState"] | null
if (state) setInitialNavigationState(state)
}
} finally {
if (isMounted()) setIsRestored(true)
}
Expand Down

0 comments on commit fe53c17

Please sign in to comment.