-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly handle history if drawer is open by default
- Loading branch information
Showing
8 changed files
with
155 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type { DrawerStatus } from '@react-navigation/native'; | ||
import * as React from 'react'; | ||
|
||
const DrawerStatusContext = | ||
React.createContext<'open' | 'closed' | undefined>(undefined); | ||
React.createContext<DrawerStatus | undefined>(undefined); | ||
|
||
export default DrawerStatusContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import type { | ||
DrawerNavigationState, | ||
DrawerStatus, | ||
ParamListBase, | ||
} from '@react-navigation/native'; | ||
|
||
export default function getDrawerStatusFromState( | ||
state: DrawerNavigationState<ParamListBase> | ||
) { | ||
): DrawerStatus { | ||
if (state.history == null) { | ||
throw new Error( | ||
"Couldn't find the drawer status in the state object. Is it a valid state object of drawer navigator?" | ||
); | ||
} | ||
|
||
const entry = state.history.find((it) => it.type === 'drawer') as | ||
| { type: 'drawer'; status: 'open' } | ||
| { type: 'drawer'; status: DrawerStatus } | ||
| undefined; | ||
|
||
return entry?.status ?? 'closed'; | ||
return entry?.status ?? state.default ?? 'closed'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.