[mobile] hello world with navigation

This commit is contained in:
Halit Aksoy 2024-03-24 13:34:12 +03:00
parent e17f482f7c
commit 1d25e40bbe

View File

@ -1,118 +1,48 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react'; import * as React from 'react';
import type {PropsWithChildren} from 'react'; import { View, Text, Button } from 'react-native';
import { import { NavigationContainer } from '@react-navigation/native';
SafeAreaView, import { createNativeStackNavigator } from '@react-navigation/native-stack';
ScrollView, import type { NativeStackScreenProps } from '@react-navigation/native-stack';
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import { type RootStackParamList = {
Colors, Home: undefined,
DebugInstructions, Loby: undefined,
Header, Game: {gameId: string}
LearnMoreLinks, };
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
type SectionProps = PropsWithChildren<{ type HomeScreenProps = NativeStackScreenProps<RootStackParamList, 'Home'>;
title: string; type LobyScreenProps = NativeStackScreenProps<RootStackParamList, 'Loby'>;
}>;
function Section({children, title}: SectionProps): React.JSX.Element { function HomeScreen({ navigation, route }: HomeScreenProps) {
const isDarkMode = useColorScheme() === 'dark';
return ( return (
<View style={styles.sectionContainer}> <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text <Button
style={[ title='New Game'
styles.sectionTitle, onPress={() => navigation.navigate('Loby')}></Button>
{
color: isDarkMode ? Colors.white : Colors.black,
},
]}>
{title}
</Text>
<Text
style={[
styles.sectionDescription,
{
color: isDarkMode ? Colors.light : Colors.dark,
},
]}>
{children}
</Text>
</View> </View>
); );
} }
function App(): React.JSX.Element { function LobyScreen({ navigation, route }: LobyScreenProps) {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
return ( return (
<SafeAreaView style={backgroundStyle}> <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<StatusBar <Text>Loby Screen</Text>
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
backgroundColor={backgroundStyle.backgroundColor}
/>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<Section title="Step One">
Edit <Text style={styles.highlight}>App.tsx</Text> to change this
screen and then come back to see your edits.
</Section>
<Section title="See Your Changes">
<ReloadInstructions />
</Section>
<Section title="Debug">
<DebugInstructions />
</Section>
<Section title="Learn More">
Read the docs to discover what to do next:
</Section>
<LearnMoreLinks />
</View> </View>
</ScrollView>
</SafeAreaView>
); );
} }
const styles = StyleSheet.create({ const Stack = createNativeStackNavigator<RootStackParamList>();
sectionContainer: {
marginTop: 32, function App() {
paddingHorizontal: 24, return (
}, <NavigationContainer>
sectionTitle: { <Stack.Navigator>
fontSize: 24, <Stack.Screen name="Home" component={HomeScreen} />
fontWeight: '600', <Stack.Screen name="Loby" component={LobyScreen} />
}, </Stack.Navigator>
sectionDescription: { </NavigationContainer>
marginTop: 8, );
fontSize: 18, }
fontWeight: '400',
},
highlight: {
fontWeight: '700',
},
});
export default App; export default App;