-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! ✨ TopAppBarMenu - add custom menu
- Loading branch information
1 parent
7d65e40
commit 6b9d2c7
Showing
9 changed files
with
133 additions
and
246 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 was deleted.
Oops, something went wrong.
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,75 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { Modal, Portal } from 'react-native-paper'; | ||
import { useTheme } from '../../../styles/themes'; | ||
import TopAppBarAction from '../TopAppBarAction'; | ||
|
||
type TopAppBarMenuContextValue = | ||
| { isOpen: boolean; setIsOpen: (isOpen: boolean) => void } | ||
| undefined; | ||
|
||
const TopAppBarMenuContext = | ||
React.createContext<TopAppBarMenuContextValue>(undefined); | ||
|
||
type TopAppBarMenuProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
const TopAppBarMenu = ({ children }: TopAppBarMenuProps) => { | ||
const styles = useStyles(); | ||
|
||
const [isOpen, setIsOpen] = React.useState(false); | ||
|
||
const value = { isOpen, setIsOpen }; | ||
|
||
return ( | ||
<> | ||
<Portal> | ||
<Modal | ||
visible={isOpen} | ||
onDismiss={() => setIsOpen(false)} | ||
style={styles.modal} | ||
contentContainerStyle={styles.modalContent} | ||
> | ||
<TopAppBarMenuContext.Provider value={value}> | ||
<View style={styles.menu}>{children}</View> | ||
</TopAppBarMenuContext.Provider> | ||
</Modal> | ||
</Portal> | ||
<TopAppBarAction | ||
accessibilityLabel='Menu' | ||
icon='dots-vertical' | ||
onPress={() => setIsOpen(true)} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
function useTopAppBarMenu() { | ||
const context = React.useContext(TopAppBarMenuContext); | ||
if (context === undefined) { | ||
throw new Error('useTopAppBarMenu must be used within a TopAppBarMenu'); | ||
} | ||
return context; | ||
} | ||
|
||
function useStyles() { | ||
const theme = useTheme(); | ||
return StyleSheet.create({ | ||
modal: { | ||
alignItems: 'flex-end', | ||
justifyContent: 'flex-start', | ||
}, | ||
modalContent: { | ||
marginTop: 84, | ||
marginRight: theme.sw.spacing.xs, | ||
}, | ||
menu: { | ||
backgroundColor: theme.sw.colors.neutral['50'], | ||
borderRadius: 18, | ||
width: 248, | ||
}, | ||
}); | ||
} | ||
|
||
export { TopAppBarMenu, useTopAppBarMenu }; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.