Skip to content

Commit

Permalink
feat: pass in component to back button
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Dec 28, 2020
1 parent 7e53b2a commit 158ae0d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type BackButtonProps = {
/**
* Value back button should display
*/
label?: string,
label?: string | JSX.Element,
} & Omit<TouchableOpacityProps, 'onPress' | 'children'>

const styles = StyleSheet.create( {
Expand All @@ -19,14 +19,15 @@ const styles = StyleSheet.create( {
},
} )

const BackButton = ( { label = 'Cancel', ...props }: BackButtonProps ) => {
const BackButton = ( { label: Label = 'Cancel', ...props }: BackButtonProps ) => {
const navigation = useNavigation()

const goBack = () => navigation.goBack()

return (
<TouchableOpacity onPress={goBack} {...props}>
<Text style={styles.label}>{label}</Text>
{Label && <Text style={styles.label}>{Label}</Text>}
{!Label && <Label />}
</TouchableOpacity>
)
}
Expand Down

0 comments on commit 158ae0d

Please sign in to comment.