custom header bar
continuous-integration/drone/push Build is failing Details

pull/20/head
Rémi REGNAULT 1 year ago
parent 983555ba20
commit 579db32a92

@ -11,6 +11,7 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import HomeStackScreen from './navigation/HomeStackScreen'; import HomeStackScreen from './navigation/HomeStackScreen';
import ProfilesStackScreen from './navigation/ProfileStackScreen'; import ProfilesStackScreen from './navigation/ProfileStackScreen';
import CookingStackScreen from './navigation/CookingStackScreen';
const Tab = createBottomTabNavigator(); const Tab = createBottomTabNavigator();
@ -45,9 +46,10 @@ export default function App() {
return ( return (
<NavigationContainer> <NavigationContainer>
<Tab.Navigator screenOptions={{ headerShown: false }}> <Tab.Navigator screenOptions={{ headerShown: false }} initialRouteName='Home'>
<Tab.Screen name="Home" component={HomeStackScreen} /> <Tab.Screen name='Profile' component={ProfilesStackScreen}/>
<Tab.Screen name="Profile" component={ProfilesStackScreen}/> <Tab.Screen name='Home' component={HomeStackScreen} />
<Tab.Screen name='Cooking' component={CookingStackScreen}/>
</Tab.Navigator> </Tab.Navigator>
</NavigationContainer> </NavigationContainer>
// <IngredientSelection listIngredient={ingredients}></IngredientSelection> // <IngredientSelection listIngredient={ingredients}></IngredientSelection>

@ -7,20 +7,19 @@ interface TopBarProps{
} }
export default function TopBar(props) { export default function TopBar(props) {
const _goBack = () => console.log('Went back');
const _handleSearch = () => console.log('Searching'); const _handleSearch = () => console.log('Searching');
const _handleMore = () => console.log('Shown more'); const _handleMore = () => console.log('Shown more');
return ( return (
<Appbar.Header style={{backgroundColor: '#F2F0E4'}} > <Appbar.Header style={{backgroundColor: '#F2F0E4'}} >
<Appbar.BackAction onPress={_goBack} />
<Appbar.Content title={props.title} /> <Appbar.Content title={props.title} />
{props.isVisible &&( {props.isVisible && (
<><Appbar.Action icon="magnify" onPress={_handleSearch} /> <>
<Appbar.Action icon="dots-vertical" onPress={_handleMore} /> <Appbar.Action icon="magnify" onPress={_handleSearch} />
</> <Appbar.Action icon="dots-vertical" onPress={_handleMore} />
</>
)} )}
</Appbar.Header> </Appbar.Header>
); );
} }

@ -0,0 +1,21 @@
import React from 'react'
import { StyleSheet } from 'react-native'
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import IngredientSelection from '../screens/IngredientSelection';
const CookingStack = createNativeStackNavigator()
export default function CookingStackScreen() {
return (
<CookingStack.Navigator>
<CookingStack.Screen
name='IngredientSelection'
component={IngredientSelection}
/>
</CookingStack.Navigator>
)
}
const styles = StyleSheet.create({
})

@ -8,64 +8,74 @@ import appLogo from '../assets/images/icon.png';
const HomeStack = createNativeStackNavigator() const HomeStack = createNativeStackNavigator()
function AppIcon() {
return (
<Image
source={appLogo}
style={styles.headerAppIcon}/>
)
}
function TextTitle(props) {
return (
<Text
style={styles.headerTitle}>
{props.title}
</Text>
)
}
export default function HomeStackScreen() { export default function HomeStackScreen() {
return ( return (
<HomeStack.Navigator> <HomeStack.Navigator>
<HomeStack.Screen <HomeStack.Screen
name="Home" name='Home'
component={HomePage} component={HomePage}
options={{ options={{
headerStyle: styles.headerBarContainer, headerStyle: styles.headerBarContainer,
headerLeft: () => (
<View style={styles.headerAppIconContainer}> headerLeft: () => (
<Image <AppIcon/>
source={appLogo} ),
style={styles.headerAppIcon}/>
</View> headerTitle: () => (
), <TextTitle title='LeftOvers'/>
headerTitle: () => ( ),
<Text style={styles.headerTitle}> headerTitleAlign: 'center',
LeftOvers
</Text> headerRight: () => (
), <AppIcon/>
headerRight: () => ( ),
<Image }}
source={appLogo} />
style={styles.headerAppIcon}/> <HomeStack.Screen
), name='Profiles'
headerTitleAlign: 'center' component={Profiles}
}} options={{
/> headerStyle: styles.headerBarContainer,
<HomeStack.Screen headerTitle: () => (
name='Profiles' <TextTitle title='Profiles'/>
component={Profiles} )
/> }}
</HomeStack.Navigator> />
) </HomeStack.Navigator>
)
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
headerBarContainer: { headerBarContainer: {
flexDirection: 'row',
width: "100%",
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#F2F0E4', backgroundColor: '#F2F0E4',
padding: 5,
}, },
headerTitle: { headerTitle: {
fontSize: 20, fontSize: 20,
fontWeight: "bold", fontWeight: "bold",
color: '#3F3C42', color: '#3F3C42',
textAlign: "center",
textAlignVertical: 'center',
flex: 0.8,
}, },
headerAppIcon: { headerAppIcon: {
width: 35, width: 35,
height: 35 height: 35,
}, borderRadius: 20,
headerAppIconContainer: { overflow:'hidden',
marginHorizontal: 10,
} }
}) })

@ -1,18 +1,24 @@
import React from 'react' import React from 'react'
import { View, Image, Text, StyleSheet } from 'react-native' import { View, StyleSheet } from 'react-native'
import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createNativeStackNavigator } from '@react-navigation/native-stack';
import Profiles from '../screens/Profiles'; import Profiles from '../screens/Profiles';
import TopBar from '../components/TopBar';
const ProfilesStack = createNativeStackNavigator() const ProfilesStack = createNativeStackNavigator()
export default function ProfilesStackScreen() { export default function ProfilesStackScreen() {
return ( return (
<ProfilesStack.Navigator> <ProfilesStack.Navigator>
<ProfilesStack.Screen <ProfilesStack.Screen
name='Profiles' name='Profiles'
component={Profiles} component={Profiles}
/> options={{
headerTitle: () => (
<TopBar title='Profiles' isVisible={true}/>
)
}}
/>
</ProfilesStack.Navigator> </ProfilesStack.Navigator>
) )
} }

@ -42,11 +42,6 @@ export default function HomePage({ navigation , props}) {
return ( return (
<SafeAreaProvider> <SafeAreaProvider>
<View style={styles.topBar}>
<Image source={require("../assets/images/logo.png")} style={{width: 40, height: 40, flex: 0.1, marginLeft: 10}}/>
<Text style={styles.appName}>LeftOvers</Text>
<Image source={require("../assets/images/logo.png")} style={{width: 40, height: 40, flex: 0.1, marginRight: 10}}/>
</View>
<View style={styles.container}> <View style={styles.container}>
<LinearGradient colors={['#2680AA', '#59BDCD']} style={styles.linearGradient}> <LinearGradient colors={['#2680AA', '#59BDCD']} style={styles.linearGradient}>
<View style={{marginTop: 20}}/> <View style={{marginTop: 20}}/>
@ -109,23 +104,22 @@ export default function HomePage({ navigation , props}) {
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
height: "100%", height: "100%",
width: "100%", width: "100%",
flex: 1, flex: 1,
backgroundColor: '#3F3C42', backgroundColor: '#3F3C42',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}, },
linearGradient: { linearGradient: {
height: "100%", height: "100%",
width: "100%", width: "100%",
flex: 1, flex: 1,
padding: 10, padding: 10,
paddingTop: 0, paddingTop: 0,
}, },
filterBar: {
filterBar: {
flexDirection: "row", flexDirection: "row",
width: 300, width: 300,
paddingTop: 10, paddingTop: 10,
@ -133,8 +127,8 @@ const styles = StyleSheet.create({
alignItems: "flex-end", alignItems: "flex-end",
justifyContent: "center", justifyContent: "center",
flex: 0.2, flex: 0.2,
}, },
filters: { filters: {
flex: 0.8, flex: 0.8,
fontSize: 20, fontSize: 20,
color: '#ACA279', color: '#ACA279',
@ -142,14 +136,13 @@ const styles = StyleSheet.create({
padding: 5, padding: 5,
paddingLeft: 0, paddingLeft: 0,
paddingBottom: 0, paddingBottom: 0,
}, },
nbSelected: { nbSelected: {
fontSize: 11, fontSize: 11,
color: "#3F3C42", color: "#3F3C42",
textAlign: "right", textAlign: "right",
}, },
profilesSelection: {
profilesSelection: {
flexDirection: 'column', flexDirection: 'column',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
@ -157,8 +150,8 @@ const styles = StyleSheet.create({
backgroundColor: '#F2F0E4', backgroundColor: '#F2F0E4',
paddingTop: 5, paddingTop: 5,
marginHorizontal: 10, marginHorizontal: 10,
}, },
welcome: { welcome: {
flexDirection: 'column', flexDirection: 'column',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
@ -167,18 +160,18 @@ const styles = StyleSheet.create({
paddingVertical: 10, paddingVertical: 10,
paddingHorizontal: 25, paddingHorizontal: 25,
marginHorizontal: 10, marginHorizontal: 10,
}, },
text: { text: {
fontSize: 20, fontSize: 20,
color: '#ACA279', color: '#ACA279',
}, },
name: { name: {
fontSize: 20, fontSize: 20,
fontWeight: "bold", fontWeight: "bold",
color: '#59BDCD', color: '#59BDCD',
textAlign: "left", textAlign: "left",
}, },
ingredientSelection: { ingredientSelection: {
flexDirection: 'column', flexDirection: 'column',
width: "90%", width: "90%",
alignItems: 'center', alignItems: 'center',
@ -189,20 +182,5 @@ const styles = StyleSheet.create({
borderColor: "#ACA279", borderColor: "#ACA279",
marginHorizontal: 10, marginHorizontal: 10,
padding: 5 padding: 5
}, },
appName: {
fontSize: 20,
fontWeight: "bold",
color: '#3F3C42',
textAlign: "center",
flex: 0.8,
},
topBar: {
flexDirection: 'row',
width: "100%",
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#F2F0E4',
padding: 5,
},
}); });
Loading…
Cancel
Save