-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows us to always provide navigation actions, especially on Web.
- Loading branch information
Kévin Commaille
committed
Jan 23, 2021
1 parent
d6b2d09
commit 2e8bbbe
Showing
3 changed files
with
48 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from "react"; | ||
import { StackHeaderProps } from "@react-navigation/stack"; | ||
import { Appbar } from "react-native-paper"; | ||
|
||
import MenuButton from "./MenuButton"; | ||
|
||
export default function AppBar(props: StackHeaderProps & { menuFallback: boolean }) { | ||
const { insets, menuFallback, navigation, previous, scene } = props; | ||
const { options } = scene.descriptor; | ||
const title = (options.headerTitle) | ||
? options.headerTitle | ||
: (options.title) | ||
? options.title | ||
: scene.route.name; | ||
const left = (options.headerLeft) | ||
? options.headerLeft({}) | ||
: (previous) | ||
? <Appbar.BackAction onPress={navigation.goBack} /> | ||
: (menuFallback) | ||
? <MenuButton /> | ||
: null; | ||
const right = options.headerRight?.({}); | ||
|
||
return ( | ||
<Appbar.Header statusBarHeight={insets.top}> | ||
{left} | ||
<Appbar.Content title={title} /> | ||
{right} | ||
</Appbar.Header> | ||
); | ||
} |
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,13 @@ | ||
import * as React from "react"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
import { DrawerNavigationProp } from "@react-navigation/drawer"; | ||
import { Appbar } from "react-native-paper"; | ||
|
||
const MenuButton = React.memo(function MenuButton() { | ||
const navigation = useNavigation() as DrawerNavigationProp<any>; | ||
return ( | ||
<Appbar.Action icon="menu" accessibilityLabel="Main menu" onPress={() => navigation.openDrawer()} /> | ||
); | ||
}); | ||
|
||
export default MenuButton; |