rapport-tp6-dev-mobile
rapport-tp6-dev-mobile
Affichage dynamique
Folder structure:
App.jsx file : in the app.jsx file we create our stack navigator and use it to
navigate between pages
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="PhotoScreen" component={PhotoScreen} />
<Stack.Screen name="PortfolioScreen"
component={PortfolioScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
HomeScreen.tsx :
<FlatList
data={DATA}
keyExtractor={(item, index) => index.toString()}
renderItem={({item}) => {
return (
<TouchableHighlight
onPress={() => {
navigation.navigate('PortfolioScreen', {profile:
item});
}}>
<View style={{marginVertical: 20, paddingHorizontal:
10}}>
<Text
style={{fontSize: 24, textAlign: 'center',
marginBottom: 10}}>
{item.name}
</Text>
<View
style={{
justifyContent: 'center',
alignItems: 'center',
padding: 10,
backgroundColor: '#f0f0f0',
borderRadius: 10,
}}>
<Image
source={{uri: item.img}}
style={{width: 300, height: 300, borderRadius: 10}}
/>
</View>
<Text
style={{fontSize: 20, textAlign: 'center', marginTop:
10}}>
{item.country}
</Text>
</View>
</TouchableHighlight>
);
}}
/>
</View>
);
};
Result:
PortfolioScreen.tsx file:
result:
Adding Drawer:
// Screens
import HomeScreen from "./screens/HomeScreen";
import PhotoScreen from "./screens/PhotoScreen";
import PortfolioScreen from "./screens/PortfolioScreen";
import FAQScreen from "./screens/FAQScreen";
<Drawer.Screen
name="FAQ"
component={FAQScreen}
options={{ title: "FAQ" }}
/>
</Drawer.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
}