TabNavigator covers content - reactjs

I have this component that contains a list that is covered on the bottom side by the TabNavigator. Any ideas how to fix it? Is there only a styling way?
render() {
return (
<Container style={{ paddingBottom: 5 }}>
<Header
backgroundColor={'#1E6EC7'}
placement="left"
leftComponent={{ icon: 'menu', color: '#fff' }}
centerComponent={{ text: 'Programul Zilei', style: { color: '#fff', fontWeight: 'bold', fontSize: 22 } }}
rightComponent={<Icon name="ios-add" style={{ color: 'white' }} onPress={() => {
const {students}=this.props;
this.props.navigation.navigate('AddClass', {students})}} />}
/>
<List>
<FlatList
data={this.props.classes}
keyExtractor={(item, index) => `${index}`}
extraData={this.state}
renderItem={({ item }) => {
<ListItem
leftIcon={<View style={{ flexDirection: 'row' }}><Icon1 name="times" size={24} style={{ paddingRight: 10, color: 'red' }} onPress={() => {
this.setState({ currentStudent: wantedEmployee })
this.setState({ currentClass: item })
this.props.classDeleteModalShowUp();
}} />
}
/>
</List>
</Container>

You can hide the tab navigator for that specific screen setting
tabBarVisible as false in navigationOptions.
But I think the issue is because of the header, you can try using the react navigation header bar.
Otherwise you could add to the container a paddingBottom of the same height as the header

Related

React Native: how can i press on flatlist item and open specific screen for that item?

I want to press on a flat item and then open a new screen which has details from the item but how is the best way to do that?
should I make a modal and give it the details?
or should I make a new screen for every item?
const renderRecipe = ({ item }) => {
return (
<View style={styles.item}>
<Image style={styles.image} source={{ uri: item.image }}>
</Image>
<Text style={{
color: '#00aecc', fontSize: 18,
marginTop: 15
}}>{item.label}</Text>
<View style={{ alignItems: "center" }}>
<Text style={{ color: '#fff', marginTop: 100, fontSize: 20 }}>Zutaten:</Text>
<Text style={{ color: '#00aecc', fontSize: 18, marginTop: 15 }}>{item.id}</Text>
</View>
</View >
)
}
return (
<View style={styles.container}>
{isLoading && <View style={{ height: "100%", width: "100%" }}><ActivityIndicator style={styles.loading} color='#00aecc' size="large" /></View>}
<FlatList
data={userRecipes}
renderItem={renderRecipe}
keyExtractor={(item) => item.id}>
</FlatList>
</View >
);
This is my item now how can I do what I want.
I will try to explain. You have two screens Home and Details.
Assume in your Home screen your Flatlist. So when you click to item on Flatlist you will navigate to Details screen with items details.That's it!
You can also do this with modal. But here it depends on requirement. There is not any perfect solution. Based on case scenario you do it.
In your case I will do followings.
First I will import TouchableOpactiy and useNavigation.
import {TouchableOpactiy} from 'react-native'
import { useNavigation } from '#react-navigation/native';
Then I will use it to my flatlist items.
Home Screen
const Home = () => {
const navigation = useNavigation();
const renderRecipe = ({ item }) => {
return (
<TouchableOpactiy onPress={()=> navigation.navigate('Details', {item} )}>
<View style={styles.item}>
<Image style={styles.image} source={{ uri: item.image }}>
</Image>
<Text style={{
color: '#00aecc', fontSize: 18,
marginTop: 15}}>{item.label}</Text>
<View style={{ alignItems: "center" }}>
<Text style={{ color: '#fff', marginTop: 100, fontSize: 20 }}>Zutaten:
</Text>
<Text style={{ color: '#00aecc', fontSize: 18, marginTop: 15 }}>{item.id}
</Text>
</View>
</View >
</TouchableOpactiy>
)
}
return (
/*your flalist*/
)
}
Details Screen
const Details = ({ route, navigation ) => {
const { item } = route.params;
return (
<Text>{item.label}</Text>
)
}

Unable to successfully resize icon in floating action button packages React Native

Will be providing images in the bottom to show what I mean
I was hoping to get some advice on what might be going wrong on my end. I keep trying to find different packages but am unable to get what I want. When I tried using react-native-floating-action it gave me the right size I was looking for except I can't control how the closing is done. Like I don't want it to close when an item gets pressed.
I also tried using react-native-paper but the icons are so tiny. If I try to resize it, they start to get cut off so was hoping some advice in regards to one of the two or something else if there is.
CODE
// react-native-paper
<Provider>
<Portal>
<FAB.Group
style={{
backgroundColor: 'transparent',
height: '100%',
width: '100%'
}}
open={isOpen}
fabStyle={{
marginBottom: 200,
backgroundColor: 'red'
}}
icon={(props) => (
<MaterialIcons
{...props}
name="add-circle-outline"
size={30}
color="white"
style={{
backgroundColor: 'blue',
position: 'absolute',
left: 0,
fontSize: 50,
width: 200
}}
/>
)}
actions={[
{
icon: (props) => {
console.log(props);
return (
<Avatar
containerStyle={{
backgroundColor: 'blue'
}}
size={30}
rounded
source={{
uri: 'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg'
}}
>
<AntDesign
style={{ position: 'absolute', left: 10, top: 15, color: 'red' }}
name="pluscircle"
size={15}
color="white"
/>
</Avatar>
);
},
onPress: () => console.log('Pressed star'),
style: {
backgroundColor: 'transparent',
size: 50,
backgroundColor: 'white'
}
},
{
icon: (props) => {
console.log(props);
return <AntDesign name="heart" size={props.size} color={props.color} />;
},
onPress: (e) => console.log(e)
},
{
icon: (props) => {
console.log(props);
return (
<AntDesign
{...props}
name="message1"
color={props.color}
style={{ width: props.size, height: props.size }}
/>
);
},
onPress: () => console.log('Pressed notifications')
}
]}
onStateChange={onStateChange}
onPress={() => {
setIsOpen((prev) => !prev);
if (isOpen) {
// do something if the speed dial is open
}
}}
/>
</Portal>
</Provider>
// react-native-floating-action
<FloatingAction
onPressMain={(e) => console.log(e)}
animated={false}
color={'transparent'}
showBackground={false}
distanceToEdge={{ vertical: 100, horizontal: 20 }}
floatingIcon={
<View
style={{
height: '100%',
width: '100%',
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}}
>
<MaterialIcons name="add-circle-outline" size={50} color="white" />
</View>
}
position={'right'}
actions={actions}
onPressBackdrop={(s) => console.log(s)}
onPressItem={(name) => {
console.log('PRESSING');
// console.log(floatB);
// floatB.animateButton();
if (name === 'bt_language') {
navigation.navigate('Language');
}
}}
/>
In the image below. It shows what happens when i try to increase the side of the icon while using react-native-paper.
The next image below is the react-native-floating-action. The icons are much better but the issue I'm having is mostly I'm unable to prevent the actions from collapsing after clicking on an item. I'm hoping to only open and close when the main button is pressed.
Thank you for all the help and advice about this one.

not able to logging out from the app in react native?

i am working on a react native project using redux. i have one stack navigator and one drawer navigator.
i am not able to logout from the app. i want to change store value while logging out. when i am dispatching the action from the logout onPress. it throws error: props.dispatch is not a function. how do i call. i tried many ways it always throwing an error. and how to set all reducers value to intial state while logout? Thank you in advance
App.js
<RootStack.Navigator screenOptions={{
headerShown: false
}}>
{/* <StatusBar backgroundColor={isLoading ? '#000000' : '#F3F3F3'} /> */}
{this.props.data.splashScreen.loading ?
(<RootStack.Screen name={'SplashScreen'} component={SplashScreen} />) :
this.props.data.login.isAuthorized ?
(<RootStack.Screen name="MainNavigator" component={MainNavigator} />)
:
(
<RootStack.Screen name="Login" component={MainStack} />)}
</RootStack.Navigator>
splashScreen and login are reducer store value
MainNavigator.js
const GradientHeader = (props) => (
<View style={{ backgroundColor: "transparent" }}>
<LinearGradient
colors={["#6CCFF6", "#596AB2"]}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 0 }}
style={
{
/* height: 128 */
/* height: Header.HEIGHT */
}
}
>
<Header {...props} />
</LinearGradient>
</View>
);
const DashboardStackScreen = ({ navigation }) => {
return (
<DashboardStack.Navigator
screenOptions={{
headerTitle: "Good Morning, John",
header: (props) => <GradientHeader {...props} />,
headerLeft: () => (
<TouchableOpacity onPress={navigation.openDrawer} style={{ padding: 20 }}>
<Image source={require("../assets/images/menu_bar.png")} style={{ width: 18, height: 12 }} />
</TouchableOpacity>
),
headerTransparent: true,
headerStyle: {
backgroundColor: "transparent",
},
headerTintColor: "#fff",
headerTitleStyle: { fontFamily: "OpenSans-SemiBold", fontSize: 20 },
}}
>
<DashboardStack.Screen name="Dashboard" component={Dashboard} />
</DashboardStack.Navigator>
);
};
export default ({ navigation }) => {
return (
<Drawer.Navigator
initialRouteName="Dashboard"
drawerContent={(props) => <DrawerContent {...props} />}
hideStatusBar={false}
focused={true}
labelStyle={{ fontSize: 14, fontFamily: "OpenSans-SemiBold" }}
drawerContentOptions={{ activeBackgroundColor: "#F1F1F1", activeTintColor: "#000000", inactiveTintColor: "#818181", itemStyle: { marginLeft: 0, paddingHorizontal: 10, width: "100%", borderRadius: 0 } }}
>
<Drawer.Screen
name="Dashboard"
component={DashboardStackScreen}
options={{
drawerIcon: ({ focused, size }) => <Image source={require("../assets/images/dashboard.png")} style={{ height: 17.78, width: 16 }} resizeMode="contain" />,
}}
/>
<Drawer.Screen
name="My Profile"
component={MyProfileStackScreen}
options={{
drawerIcon: ({ focused, size }) => <Image source={require("../assets/images/profile.png")} style={{ height: 16, width: 16 }} resizeMode="contain" />,
}}
/>
</Drawer.Navigator>
);
};
DrawerContent.js
import { resetData } from "../Storage/Storage";
export function DrawerContent(props) {
return (
<SafeAreaView style={styles.baseContainer}>
<KeyboardAvoidingView behaviour="padding" style={styles.baseContainer}>
<TouchableWithoutFeedback style={styles.baseContainer} onPress={Keyboard.dismiss}>
<View style={styles.baseContainer}>
<TouchableOpacity
style={{ flex: 2, alignItems: "center", justifyContent: "center" }}
onPress={() => {
props.navigation.navigate("Dashboard");
}}
>
<Image source={require("../assets/images/MJB_Logo.png")} style={{ width: 197, height: 59 }} />
</TouchableOpacity>
<View style={{ flex: 5 }}>
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<DrawerItem
labelStyle={{ fontSize: 14, fontFamily: "OpenSans-SemiBold" }}
activeBackgroundColor="#F1F1F1"
activeTintColor="#000000"
inactiveTintColor="#818181"
label="Logout"
icon={({ focused, color, size }) => {
return <Image source={require("../assets/images/logout.png")} style={{ height: 14.36, width: 14.36 }} resizeMode="contain" />;
}}
onPress={() => resetData()}
/>
</DrawerContentScrollView>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</SafeAreaView>
);
}
Storage.js
export const resetData = async () => {
try {
//await AsyncStorage.removeItem('isRemembered')
await AsyncStorage.removeItem("userDetails");
} catch (e) {
// saving error
}
};

How to make TabBar of react-native-tab-view smaller?

I am using react-native-tab-view, but the TabBar is big, I want to make it small. How to customize it ? Applying margin/padding 0 didn't work.
Applying small height worked but the text went missing.
How to make it small or more customizable ?
<TabView
...
renderTabBar={props =>
<TabBar
{...props}
indicatorStyle={{ backgroundColor: 'white' }}
style={{ backgroundColor: 'pink' }}
tabStyle={{ backgroundColor: 'teal' }}
renderLabel={({ route, focused, color }) => (
<Text style={{ color, margin: 8 }}>
{route.title}
</Text>
)}
}
Try to use tabStyle prop for TabBar. By default it has a style:
minHeight: 48,
So in your case:
<TabView
...
renderTabBar={props =>
<TabBar
{...props}
indicatorStyle={{ backgroundColor: 'white' }}
style={{ backgroundColor: 'pink' }}
tabStyle={{ backgroundColor: 'teal', minHeight: 30 }} // here
renderLabel={({ route, focused, color }) => (
<Text style={{ color, margin: 8 }}>
{route.title}
</Text>
)}
}

How to center the headerRight icon button

I use the react-navigation to set the header and headerRight.
but my headerRight icon button cannot be centered on the right.
following is my code
Activate_qrscan: {
screen: Activate_qrscan,
navigationOptions: ({navigation}) => ({
title: '123',
headerRight: (
<Button
transparent
onPress={ () => navigation.dispatch(navigateAction) }>
<Icon
name='close'
style={ { color: 'white' } } />
</Button>
),
headerStyle: {
backgroundColor: '#3b5998',
},
headerRightContainerStyle: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'normal',
},
}),
},
I have added the headerRightContainerStyle but it still not work!
Can anyone help me?
Don't use the button from react-native-elements, it adds bloat, and some stylish that you may not even need, remove your headerRightContainerStyle and switch button for this code, be aware that you need the Icon class from react-native-elements.
headerRight: (
<View style={{flexDirection: "row",justifyContent: "flex-end",paddingRight:10,width: 120}}>
<TouchableOpacity
onPress={() => console.log('Hey im centered')}
>
<Icon type="font-awesome" name="cog" color="white" />
</TouchableOpacity>
</View>
)

Resources