Created
August 14, 2022 08:23
-
-
Save josephajibodu/519a2ac54be0b601a63cb330ce0596a2 to your computer and use it in GitHub Desktop.
React Navigation with Typescript - Part 1
This file contains hidden or 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
declare global { | |
namespace ReactNavigation { | |
interface RootParamList extends RootStackParamList {} | |
} | |
} | |
export type RootStackParamList = { | |
Home: undefined; | |
Profile: undefined; | |
Settings: undefined; | |
}; |
This file contains hidden or 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
import { BottomTabScreenProps } from '@react-navigation/bottom-tabs'; | |
import { Button, StyleSheet } from 'react-native'; | |
import EditScreenInfo from '../components/EditScreenInfo'; | |
import { Text, View } from '../components/Themed'; | |
import { RootStackParamList } from '../types'; | |
export default function HomeScreen({ navigation }: BottomTabScreenProps<RootStackParamList, 'Home'>) { | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.title}>Home</Text> | |
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> | |
<EditScreenInfo path="/screens/HomeScreen.tsx" /> | |
<Button onPress={() => navigation.navigate('Settings')} title="Go to Settings" /> | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
title: { | |
fontSize: 20, | |
fontWeight: 'bold', | |
}, | |
separator: { | |
marginVertical: 30, | |
height: 1, | |
width: '80%', | |
}, | |
}); |
This file contains hidden or 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
import { StyleSheet } from 'react-native'; | |
import EditScreenInfo from '../components/EditScreenInfo'; | |
import { Text, View } from '../components/Themed'; | |
export default function ProfileScreen() { | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.title}>Profile</Text> | |
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> | |
<EditScreenInfo path="/screens/ProfileScreen.tsx" /> | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
title: { | |
fontSize: 20, | |
fontWeight: 'bold', | |
}, | |
separator: { | |
marginVertical: 30, | |
height: 1, | |
width: '80%', | |
}, | |
}); |
This file contains hidden or 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
import { StyleSheet } from 'react-native'; | |
import EditScreenInfo from '../components/EditScreenInfo'; | |
import { Text, View } from '../components/Themed'; | |
export default function SettingScreen() { | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.title}>Settings</Text> | |
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> | |
<EditScreenInfo path="/screens/SettingScreen.tsx" /> | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
title: { | |
fontSize: 20, | |
fontWeight: 'bold', | |
}, | |
separator: { | |
marginVertical: 30, | |
height: 1, | |
width: '80%', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment