-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add option to use existing back button to navigate (#24)
* feat: Add option to use existing back button to navigate - Add an option that allows you to set your own back button, e.g. in the nav header and use that to navigate around the network logger - Handle hardware back press when on details page * Remove padding when close button is hidden
- Loading branch information
1 parent
7c21317
commit 054167f
Showing
7 changed files
with
143 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
let appBackHandler: (() => any) | undefined; | ||
let networkLoggerBackHandler: (() => void) | undefined; | ||
|
||
export const setBackHandler = (backHandler?: () => void) => { | ||
networkLoggerBackHandler = backHandler; | ||
}; | ||
|
||
const goBack = () => { | ||
if (networkLoggerBackHandler) { | ||
return networkLoggerBackHandler(); | ||
} | ||
appBackHandler?.(); | ||
}; | ||
|
||
export const backHandlerSet = () => { | ||
return !!appBackHandler; | ||
}; | ||
|
||
/** | ||
* Get a replacement back handler to use instead of your default navigation so you | ||
* can use your existing back button to navigate inside the network logger. | ||
* | ||
* If navigation has occurred in the logger app then pressing your back handler will | ||
* navigate internally. If it is already on the default page then it will call your | ||
* original back handler. | ||
* | ||
* e.g. | ||
* | ||
* const navigation = useNavigation() | ||
* | ||
* const onBack = getBackHandler(navigation.goBack) | ||
* | ||
* <Button onPress={onBack} title="Go back" /> | ||
* | ||
* @param backHandler App navigation default back handler | ||
*/ | ||
export const getBackHandler = (backHandler: () => any) => { | ||
appBackHandler = backHandler; | ||
|
||
return goBack; | ||
}; |
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
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