My custom header component goes out of the screen in react native - react-native

Problem:
In my react native application I have set up a custom header component like this.
const ChatHeader = (props) => {
return (
<View style={styles.chatHederCiontainer}>
<View style={{flexDirection: 'row'}}>
<View>
<Image
source={require('_assets/img/doctor1.png')}
style={styles.chatImage}
resizeMode="contain"
/>
</View>
<View style={{justifyContent: 'center', marginLeft: 20}}>
{/* {props.name ? (
<View>
<Apptext styles={styles.ChatTextName}>{props.name}</Apptext>
<Apptext styles={styles.ChatTextStatus}>
{props.isActive ? strings('chat.active') : null}
</Apptext>
</View>
) : ( */}
<Apptext styles={styles.ChatText}>
Chat with Doctor and tell your problem
</Apptext>
{/* )} */}
</View>
</View>
</View>
);
};
const mapStateToProps = (state) => {
return {
name: state.feedbacks.chatperson,
isActive: state.feedbacks.active,
};
};
export default connect(mapStateToProps)(ChatHeader);
const styles = StyleSheet.create({
chatHederCiontainer: {
justifyContent: 'center',
alignItems: 'center',
},
chatImageConatiner: {
width: '20%',
},
ChatTextContainer: {
width: '50%',
justifyContent: 'center',
alignItems: 'center',
},
chatImage: {
height: 40,
width: 40,
},
ChatText: {
fontSize: normalize(15),
textAlign: 'center',
alignSelf: 'center',
},
ChatTextName: {
marginLeft: 10,
fontSize: normalize(12),
textAlign: 'center',
},
ChatTextStatus: {
marginLeft: 10,
fontSize: normalize(9),
textAlign: 'left',
},
});
This is how I have used that in my navigations.
<ChatStack.Screen
name="chat"
component={ChatScreen}
options={(props) => ({
headerShown: true,
headerLeft: () => (
<TouchableOpacity
accessibilityRole="tab"
hitSlop={{top: 15, bottom: 15, left: 50, right: 50}}
onPress={() => {
global.currentScreenIndex = 1;
props.navigation.goBack();
}}>
<Icon
name="chevron-left"
size={normalize(15)}
color="#aaaaaa"
style={{marginLeft: 20}}
/>
</TouchableOpacity>
),
headerTitle: () => <HeaderTitle />,
// headerTitleAlign: 'left',
headerStyle: {
backgroundColor: '#f2f2f2',
height: 90,
},
headerTransparent: false,
headerLeftContainerStyle: {},
headerStatusBarHeight: 0,
})}
/>
But when I run in the device it goes out of the device like this.
I tried a lot of things like changing styles but the issue is still the same can someone help me out with this. Thank you very much

Add props headerMode={'none'} to <ChatStack.Screen> tag. Hope help U

Related

How to show different tags, depending on the user logged. Expo react

I need to show different tags depending on which user is logged.
Franchisee will see: 'Central' 'Empleados' 'Clientes'.
Employee: 'Store' 'Clientes'
User: none. just the generic info.
Here is my code:
(this is the array that states the scrollview)
const Chats = (props) => {
const TAGS = [
"store",
"Clientes",
"Central",
"Empleados",
]
and this is the component:
import React, { useState } from "react";
import { StyleSheet, FlatList, TouchableOpacity, ScrollView, Image } from 'react-native';
import { SimpleHeader, View, Text } from '../../elements/index';
const Chatstores = ({ chatsstore, navigation }) => (
<View>
<TouchableOpacity onPress={() => navigation.navigate("ChatPersonal")}>
<View style={styles.list} >
<Image source={chatsstore.img} style={styles.iconimg} />
<View style={styles.dataText}>
<View style={styles.nametime}>
<Text style={styles.text}>{chatsstore.name} </Text>
<Text >{chatsstore.time}</Text>
</View>
<Text style={styles.msg}>{chatsstore.msg} </Text>
</View>
</View>
</TouchableOpacity>
</View>
);
const ChatClients = ({ chatsClients, navigation }) => (
<View>
<TouchableOpacity onPress={() => navigation.navigate("ChatPersonal")}>
<View style={styles.list}>
<Image source={chatsClients.img} style={styles.iconimg} />
<View style={styles.dataText}>
<View style={styles.nametime}>
<Text style={styles.text}>{chatsClients.name} </Text>
<Text >{chatsClients.time}</Text>
</View>
<Text style={styles.msg}>{chatsClients.msg} </Text>
</View>
</View>
</TouchableOpacity>
</View>
);
const Chats = (props) => {
const { TAGS, chatsstore, chatsClients, navigation } = props;
const [selectedTag, setSelectedTag] = useState(null)
const [routeDistance, setRouteDistance] = useState(0);
return (
<View style={styles.wrapper}>
<SimpleHeader
style={styles.head}
titleLeft="Chats"
onSearchPress
onAddPress
/>
{/**shows horizontal, scrollview of Tags. */}
<View style={styles.scrollview}>
<ScrollView horizontal showsHorizontalScrollIndicator={false} >
<View style={styles.viewcontainer}>
{TAGS.map((tag) => (
<TouchableOpacity
onPress={() =>
setSelectedTag(tag === selectedTag ? null : tag)
}>
<View
style={[
styles.tag,
selectedTag === tag ? styles.selectedTag : {}
]}>
<Text style={styles.textTag}>{tag}</Text>
</View>
</TouchableOpacity>
))}
</View>
</ScrollView>
</View>
{/**If tag is store, shows its data, otherwise the rest */}
{selectedTag === "store" ? (
<View style={styles.chat}>
<FlatList
data={chatsstore}
renderItem={({ item, index }) => (
<Chatstores
chatsstore={item}
index={index}
navigation={navigation}
/>
)}
keyExtractor={(chatsstore) => chatsstore.name}
ListEmptyComponent={() => (
<Text center bold>No hay ningĂșn mensaje de clientes</Text>
)}
/>
</View>
) :
<View style={styles.chat}>
<FlatList
data={chatsClients}
renderItem={({ item, index }) => (
<ChatClients
chatsClients={item}
index={index}
navigation={navigation}
/>
)}
keyExtractor={(chatsClients) => chatsClients.name}
ListEmptyComponent={() => (
<Text center bold>No hay ningĂșn mensaje de clientes</Text>
)}
/>
</View>
}
</View>
);
};
const styles = StyleSheet.create({
wrapper: {
backgroundColor: "#ffffff",
display: "flex",
flex: 1,
},
head: {
height: 80,
display: "flex",
alignItems: "center",
zIndex: 1,
top: 5,
},
scrollview: {
display: "flex",
alignItems: "center",
justifyContent: "space-evenly",
},
viewcontainer: {
display: "flex",
flexDirection: "row",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 1,
right: 10,
},
list: {
bottom: 15,
flexWrap: "wrap",
alignContent: "space-between",
position: "relative",
marginVertical: 2,
backgroundColor: "#fff",
shadowColor: "#000",
elevation: 2,
flexDirection: "row",
}, dataText: {
alignSelf: "center",
flexDirection: "column",
width: "80%",
},
nametime: {
display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
},
iconimg: {
display: "flex",
height: 43,
width: 43,
alignSelf: "center",
flexDirection: "column",
},
chat: {
margin: 10,
},
text: {
margin: 10,
fontFamily: "Montserrat_700Bold",
paddingHorizontal: 10,
},
msg: {
margin: 10,
fontFamily: "Montserrat_400Regular",
fontSize: 15,
paddingHorizontal: 10,
bottom: 10
},
map: {
display: "flex",
height: "100%",
},
tag: {
display: "flex",
alignSelf: "center",
marginBottom: 1,
width: 225,
padding: 10,
},
selectedTag: {
borderBottomColor: '#F5BF0D',
borderBottomWidth: 2,
},
textTag: {
fontFamily: "Montserrat_700Bold",
alignItems: "center",
textAlign: "center",
fontSize: 15,
},
buttonContainer: {
marginHorizontal: 20
},
button: {
backgroundColor: "#000000",
top: Platform.OS === 'ios' ? 12 : 20,
height: 60,
marginBottom: 40,
marginRight: 10,
},
});
export default Chats;
So I guess that in my "show horizontal tags" I should write some kind of if, that gets the role from the user token?
Or would it be better to write different routes into the navigation and handle it in 3 different components?

FlatList react native not scrolling

I have made sure that the parent Views contain flex:1, and I have wrapped the FlatList in a view with Flex 1 but nothing I seem to try enables my flat list to scroll.
I have gone through previous posts and none of the solutions have worked
Any help or suggestions would be greatly appreciated.
This is my code in order from parent to children
const App = () => {
return (
<View style={styles.container}>
<AuthProvider>
<Home />
</AuthProvider>
</View>
);
};
const styles = StyleSheet.create({
container: {flex: 1},
});
export default App;
const Home = () => {
const [userAuth] = useContext(AuthContext);
//{userAuth.auth && <Header title={'Stokebook'} />}
return (
<View style={styles.container}>
{userAuth.auth && <Profile />}
{!userAuth.auth && <LoginHome />}
</View>
);
};
const styles = StyleSheet.create({
container: {flex: 1},
});
const Profile = () => {
const [userAuth] = useContext(AuthContext);
const [Posts, setPosts] = useState();
const [isLoading, setisLoading] = useState(true);
//Loading screen will live here
useEffect(() => {
axios({
method: 'get',
url: 'http://192.168.1.112:3000/posts',
headers: {
Authorization: `${userAuth.token}`,
},
})
.then(response => {
setPosts(response.data.flat());
})
.then(setisLoading(false))
.catch(err => setPosts(err));
}, []);
return (
<View style={styles.PostContainer}>
<FlatList
contentContainerStyle={{height: '100%'}}
data={Posts}
renderItem={({item}) => <Post post={item} />}
/>
</View>
);
};
const styles = StyleSheet.create({
PostContainer: {
backgroundColor: 'grey',
flex: 1,
},
});
const Post = ({post}) => {
return (
<View style={styles.PostContainer}>
<View style={styles.PostHeader}>
<View style={styles.ProfileInfoView}>
<Text>Michael Wong</Text>
<Text>Yesterday at 6.30pm at point leo</Text>
</View>
</View>
<View style={styles.WaveInfo}>
<View>
<Text>Wave height </Text>
<Text> 6ft</Text>
</View>
<View>
<Text>tide </Text>
<Text>low</Text>
</View>
<View>
<Text>Break</Text>
<Text>crunchies</Text>
</View>
<View>
<Text>Wind </Text>
<Text>NE 10km/hr</Text>
</View>
</View>
<View style={styles.ImageView}>
<Image
source={require('../wave.webp')}
style={{flex: 1, width: undefined, height: undefined}}
/>
</View>
<View style={styles.FeedbackView}>
<Text>
<Icon name="thumbs-up" size={15} color="black" /> 13
</Text>
<Text>3 comments</Text>
</View>
<View style={styles.FooterView}>
<View style={styles.IconView}>
<Icon name="thumbs-up" size={30} color="white" />
<Icon name="envelope" size={30} color="white" />
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
PostContainer: {
backgroundColor: 'beige',
height: '80%',
},
PostHeader: {
height: '20%',
padding: '4%',
flexDirection: 'row',
},
Profileimg: {
height: 30,
width: 30,
borderRadius: 30,
},
ProfileInfoView: {
paddingLeft: '5%',
justifyContent: 'space-around',
},
WaveInfo: {
borderTopWidth: 1,
height: '12%',
flexDirection: 'row',
justifyContent: 'space-evenly',
alignItems: 'center',
},
ImageView: {
height: '60%',
width: '100%',
},
FeedbackView: {
height: '10%',
backgroundColor: 'beige',
flexDirection: 'row',
justifyContent: 'space-between',
padding: '3%',
alignItems: 'center',
},
FooterView: {
width: '100%',
height: '15%',
flexDirection: 'row',
justifyContent: 'center',
backgroundColor: 'black',
borderBottomColor: 'grey',
borderBottomWidth: 12,
},
IconView: {
height: '100%',
width: '70%',
justifyContent: 'space-around',
alignItems: 'center',
flexDirection: 'row',
},
});
export default Post;

ReactNative drawerNavigation custom footer

I have a drawer navigation where I am trying to put a footer on the bottom which would contain additional info (app version and logout link) ..
This is my navigation container:
<NavigationContainer style={styles.drawer}>
<Drawer.Navigator style={styles.drawer} drawerContent={props => <CustomDrawerContent {...props} />}>
<Drawer.Screen name="Home" component={Home}
options={{
drawerIcon: ({ focused, size }) => (
<Image source={require('./assets/icons/sidemenu-icon-account.png')} style={[{ height: 25, width: 25 }]} />
)
}} />
<Drawer.Screen name="LoginScreen" component={LoginScreen}
options={{
drawerIcon: ({ focused, size }) => (
<Image source={require('./assets/icons/sidemenu-icon-account.png')} style={[{ height: 25, width: 25 }]} />
)
}} />
</Drawer.Navigator>
</NavigationContainer>);
And this is the custom content:
function CustomDrawerContent(props) {
return (
<DrawerContentScrollView style={styles.drawer} {...props}>
<View style={styles.logoContainer}>
<Image source={require("./assets/logo.png")} style={{ height: "100%", width: "100%", resizeMode: "contain" }} />
</View>
<SafeAreaView style={styles.container}>
<View style={{flex: 1 }}>
<DrawerItemList {...props} />
</View>
<TouchableOpacity style={{backgroundColor: 'red', flexDirection: 'row', alignItems: 'center'}}>
<Text>Log Out</Text>
</TouchableOpacity>
</SafeAreaView>
</DrawerContentScrollView>
);
}
How can I push the log out link to be fixed at the bottom?
Styles:
const styles = StyleSheet.create({
img: {
height: 40,
width: 40,
marginTop: 6,
justifyContent: 'center',
textAlignVertical: 'center',
},
logout : {
backgroundColor: 'red' ,
bottom: 0,
position: 'absolute'
},
logoContainer: {
height: 140,
width: "80%",
marginTop: 20,
marginBottom: 20,
alignSelf: "center",
},
drawer: {
backgroundColor: 'yellow',
flex:1
},
labelBottom : {
position: 'relative',
bottom:0
},
redBottom: {
},
scrollView: {
backgroundColor: Colors.lighter,
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.red,
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
},
highlight: {
fontWeight: '700',
},
footer: {
color: Colors.dark,
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
Instead of style prop, you may use contentContainerStyle:
<DrawerContentScrollView
...
contentContainerStyle={styles.drawerContentContainer}
/>
while the style is something like:
drawerContentContainer: {justifyContent: 'space-between', flex: 1},
You can use a marginTop: 'auto' style for TouchableOpacity, also use the contentContainerStyle for scrollviews
function CustomDrawerContent(props) {
return (
<DrawerContentScrollView contentContainerStyle={styles.drawer} {...props}>
<View style={styles.logoContainer}>
<Image source={require("./assets/logo.png")} style={{ height: "100%", width: "100%", resizeMode: "contain" }} />
</View>
<SafeAreaView style={{flex:1}}>
<View>
<DrawerItemList {...props} />
</View>
<View style={{ marginTop: 'auto' }}>
<TouchableOpacity
style={{
backgroundColor: 'red',
flexDirection: 'row',
}}>
<Text>Log Out</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</DrawerContentScrollView>
);
}
I solved this by wrapping all the contents of my DrawerComponent inside a View element and then adding height: '100%' in the style prop of the root View element.
And finally adding marginTop: 'auto' will push the FooterComponent at the bottom (or you can use {position: 'absolute', bottom: 0} for style prop of FooterComponent).
<View style={{height: '100%'}}>
<HeaderComponent />
<DrawerItems {...props} />
<View style={{marginTop: 'auto'}}>
<FooterComponent />
</View>
</View>

How to create dynamic checkbox in react native

I am able to create the dynamic checkbox but i need to check and uncheck it separately, right now if i check one everything gets checked and if i uncheck everything gets unchecked.
How to change the value of checkbox separately for each checkbox from state?
import React from 'react';
import {View,Text,StyleSheet,TouchableOpacity,Image,Switch,Platform,Dimensions,PixelRatio,} from'react-native';
import ImagePicker from 'react-native-image-picker';
import { Input, Button } from 'react-native-elements';
import { moderateScale } from 'react-native-size-matters';
const deviceWidth = Dimensions.get('window').width;
const deviceHeight = Dimensions.get('window').height;
const calcHeight = x => PixelRatio.roundToNearestPixel((deviceHeight * x) / 100);
const calcWidth = x => PixelRatio.roundToNearestPixel((deviceWidth * x) / 100);
class ErrorScreen extends React.Component {
constructor() {
super();
this.state = {
arr: [],
parkPay: false,
itemChecked: false,
index: null,
};
}
functionTwo = () => {
alert('func 2');
this.setState(() => ({
parkPay: true,
}));
};
checkedItem = index => {
console.log('this is index', index);
// let itemChecked = this.state.itemChecked
if (this.state.index != index) {
this.setState(() => ({
index: index,
itemChecked: !this.state.itemChecked,
}));
}
};
addParkField = () => {
console.log('jjjjj');
console.log(' ^^ props in parking form ^^ ', this.props);
let x = 0;
this.setState(() => ({
arr: [...this.state.arr, ''],
}));
// this.addFieldSecond()
// this.props.addParkFieldSecond()
};
render() {
return (
<View>
<View
style={{flex: 1, paddingRight: calcWidth(4),paddingLeft: calcWidth(6), paddingTop: calcHeight(4),paddingBottom: calcHeight(4),
}}>
<Input
placeholder="Enter Amount"
label="Enter Amount"
labelStyle={{ fontWeight: '200', color: 'black' }}
inputContainerStyle={{
paddingRight: calcWidth(2),
paddingLeft: calcWidth(2),
paddingTop: calcHeight(1),
paddingBottom: calcHeight(1),
}}
// onChangeText={this.props.parkingAmount}
/>
<Text style={[styles.error]}>{this.state.errors.Amount}</Text>
<View
style={{ paddingLeft: calcWidth(2), paddingTop: calcHeight(4) }}>
<View style={{ paddingRight: calcWidth(70) }}>
<Switch
value={this.state.parkPay}
style={
Platform.OS === 'ios' ? styles.switchIOS : styles.switchAND
}
// onValueChange={(value) => {this.props.toggleCustomerParkingPay(value); this.functionTwo()}}
/>
</View>
<Text style={{ paddingTop: calcHeight(8) }}>Paid By Customer</Text>
</View>
</View>
<View style={{}}>
{this.state.arr.map((extra, index) => {
return (
<View
style={{
flex: 1,
paddingRight: calcWidth(4),
paddingLeft: calcWidth(20),
paddingTop: calcHeight(15),
paddingBottom: calcHeight(4),
}}
key={index}>
<Input
placeholder="Enter Amount"
label="Enter Amount"
labelStyle={{ fontWeight: '200', color: 'black' }}
inputContainerStyle={{
paddingRight: calcWidth(2),
paddingLeft: calcWidth(2),
paddingTop: calcHeight(1),
paddingBottom: calcHeight(1),
}}
// onChangeText={this.handleAmount}
// onChangeText={this.props.parkingAmount}
/>
<Text style={[styles.error]}>{this.state.errors.Amount}</Text>
<View style={{ paddingTop: calcHeight(4) }}>
<View style={{ paddingRight: calcWidth(70) }}>
<Switch
value={this.state.parkPay}
style={
Platform.OS === 'ios'
? styles.switchIOS
: styles.switchAND
}
// onValueChange={(value) => {this.props.toggleCustomerParkingPay(value);}}
/>
</View>
<Text style={{ paddingTop: calcHeight(8) }}>
Paid By Customer
</Text>
</View>
</View>
);
})}
<View>
<View
style={{ paddingLeft: calcWidth(60), paddingTop: calcHeight(2) }}>
<TouchableOpacity
style={[styles.cardCirclePassenger]}
onPress={this.addParkField}>
<View
style={{
justifyContent: 'center',
alignItems: 'center',
paddingTop: calcHeight(2.2),
}}>
{/* <Image
style={{width: 24, height: 24}}
source={require('../../images/Group424.png')}
/> */}
<Text>Add</Text>
</View>
</TouchableOpacity>
</View>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
cardCirclePassenger: {
backgroundColor: '#31588A',
marginBottom: 10,
marginLeft: '5%',
width: 60,
height: 60,
borderRadius: 60 / 2,
borderColor: 'white',
shadowOpacity: 0.2,
shadowRadius: 1,
shadowOffset: {
width: 3,
height: 3,
},
borderWidth: 1,
},
switchIOS: {
transform: [
{ scaleX: moderateScale(0.7, 0.2) },
{ scaleY: moderateScale(0.7, 0.2) },
],
},
switchAND: {
transform: [
{ scaleX: moderateScale(1, 0.2) },
{ scaleY: moderateScale(1, 0.2) },
],
},
});
export default ErrorScreen;
i worked around a little bit and found the below way to generate dynamic checboxes along with separate state values. hope this helps someone.
The below code creates dynamic key-value pairs in state. if you console.log the state in your render you'll see (check0:true check1:true check2: false ....) .
<Switch
value={this.state[`check${key}`]}
onValueChange={value => this.setState({ [`check${key}`]: value })}
/>

How to change backdrop color to transparent in react-navigation-drawer

Hi all, I am trying to add react-navigation-drawer in my app and I am facing this issue. whenever I open the drawer, backdrop or background got opaque black. I tried to add background colour but it didn't work for me.
Here my code for sidebar:-
import { Text, TouchableOpacity, View,StyleSheet, ScrollView, Dimensions,BackHandler} from "react-native";
import Icon from 'react-native-vector-icons/Entypo';
const { width, height } = Dimensions.get("window");
const window = Dimensions.get("window");
let h = window.height / 812;
let w = window.width / 375;
let p = (h + w) / 2;
export default class SideBar extends Component {
constructor(props) {
super(props)
this.state = {
refreshing: true,
index: '',
}
}
componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", () => this.hardwareBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener("hardwareBackPress", () => this.hardwareBackPress);
}
hardwareBackPress() {
this.props.navigation.closeDrawer();
}
navigate(location) {
this.props.navigation.closeDrawer();
this.props.navigation.navigate(location);
}
render() {
return (
<View style={styles.container}>
<View style={[styles.headerSection, { flexDirection: 'row', padding: 10, }]} >
<View style={{ alignItems: 'center', height: p * 90, width: p * 90, marginTop: p * 10, borderColor: '#fff', borderWidth: 4, borderRadius: p * 90, elevation: 2 }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ width: '70%', marginTop: p * 15, justifyContent: 'center' }}>
<Text style={{ width: '100%', textAlign: "center", fontSize: 16, marginTop: 10, fontWeight: 'bold' }}>{this.state.uname}</Text>
</View>
</View>
<View>
<ScrollView style={{ height: '100%', marginTop: 20 }}>
<TouchableOpacity
style={styles.container}>
<View style={styles.textView}>
<View style={{ padding: 8, justifyContent: 'center', alignItems: "center", width: '15%' }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ borderBottomColor: '#e6e6e6', borderBottomWidth: 1, width: "90%", padding: 8, flex: 1, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Lato-Light', color: '#000' }}>Edit Profile</Text>
</View>
</View>
</TouchableOpacity>
<TouchableOpacity
style={styles.container}>
<View style={styles.textView}>
<View style={{ padding: 8, justifyContent: 'center', alignItems: "center", width: '15%' }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ borderBottomColor: '#e6e6e6', borderBottomWidth: 1, width: "90%", padding: 8, flex: 1, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Lato-Light', color: '#000' }}>My Account</Text>
</View>
</View>
</TouchableOpacity>
<TouchableOpacity
style={styles.container}
onPress={() => this.navigate("HelpText")}>
<View style={styles.textView}>
<View style={{ padding: 8, justifyContent: 'center', alignItems: "center", width: '15%' }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ borderBottomColor: '#e6e6e6', borderBottomWidth: 1, width: "90%", padding: 8, flex: 1, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Lato-Light', color: '#000' }}> Help </Text>
</View>
</View>
</TouchableOpacity>
<TouchableOpacity
style={styles.container}
onPress={() => this.navigate("Notificationalert")}>
<View style={styles.textView}>
<View style={{ padding: 8, justifyContent: 'center', alignItems: "center", width: '15%' }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ borderBottomColor: '#e6e6e6', borderBottomWidth: 1, width: "90%", padding: 8, flex: 1, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Lato-Light', color: '#000' }}> Notification </Text>
</View>
</View>
</TouchableOpacity>
<TouchableOpacity
style={styles.container}
onPress={() => this.navigate("Support")}>
<View style={styles.textView}>
<View style={{ padding: 8, justifyContent: 'center', alignItems: "center", width: '15%' }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ borderBottomColor: '#e6e6e6', borderBottomWidth: 1, width: "90%", padding: 8, flex: 1, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Lato-Light', color: '#000' }}>Support</Text>
</View>
</View>
</TouchableOpacity>
<TouchableOpacity
style={styles.container}
onPress={() => this.navigate("AboutUs")}>
<View style={styles.textView}>
<View style={{ padding: 8, justifyContent: 'center', alignItems: "center", width: '15%' }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ borderBottomColor: '#e6e6e6', borderBottomWidth: 1, width: "90%", padding: 8, flex: 1, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Lato-Light', color: '#000' }}>About</Text>
</View>
</View>
</TouchableOpacity>
<TouchableOpacity
style={styles.container}>
<View style={styles.textView}>
<View style={{ padding: 8, justifyContent: 'center', alignItems: "center", width: '15%' }}>
<Icon name="home" size={20} color={tintColor} />
</View>
<View style={{ borderBottomColor: '#e6e6e6', borderBottomWidth: 1, width: "90%", padding: 8, flex: 1, justifyContent: 'center' }}>
<Text style={{ fontSize: 14, fontFamily: 'Lato-Light', color: '#000' }}>Sign_Out</Text>
</View>
</View>
</TouchableOpacity>
</ScrollView>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#ffffffff",
flex: 1,
},
textView: {
flex: 1,
flexDirection: 'row',
},
headerSection: {
backgroundColor: '#f5f5f5',
height: height / 6,
borderBottomColor: '#e6e6e6',
borderBottomWidth: 2,
},
textInput: {
marginTop: 10,
fontSize: p * 16,
height: p * 40,
paddingHorizontal: p * 10,
borderWidth: 2,
borderRadius: 3
},
scrollView: {
zIndex: 0,
width: width,
}
});
and here is my Navigator in which I added Drawernavigator.
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack'
import { createDrawerNavigator } from 'react-navigation-drawer';
import React from 'react';
import HomeScreen from './src/Dashboard'
import OtherScreen from './src/Screen2'
import AuthLoadingScreen from './src/LoadingScreen'
import SignInScreen from './src/Login'
import SignUpScreen from './src/Signup'
import ForgetPassword from './src/Forget'
import SideMenu from './utils/Sidebar'
const AppStack = createDrawerNavigator(
{
Home: { screen: HomeScreen },
Other: { screen: OtherScreen },
},
{
headerMode: 'screen',
navigationOptions: ({ navigation }) => ({
gesturesEnabled: false,
swipeEnabled: false,
drawerLockMode: 'locked-closed',
headerStyle: { backgroundColor: '#fff' }
}),
drawerPosition: 'right',
contentComponent: (props) => <SideMenu {...props} />
});
const AuthStack = createStackNavigator({ SignIn: SignInScreen, SignUp: SignUpScreen, Forget: ForgetPassword }, {
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
});
export default createAppContainer(
createSwitchNavigator(
{
AuthLoading: AuthLoadingScreen,
App: AppStack,
Auth: AuthStack,
},
{
initialRouteName: 'AuthLoading',
}
)
);
Please check this code and help me if anyone knows the solution.
I want to make the background transparent.
Thanks in advance.
Note: this only applies to react-navigation 3.*.*
createDrawerNavigator second argument (of type DrawerNavigatorConfig) has a property overlayColor. It can be set to any flat color using a string ("#FFF" or "rgba(0, 0, 0, 0.7)").
Was looking for this myself and dug it up in type definition file: https://github.com/react-navigation/react-navigation/blob/v3.13.0/typescript/react-navigation.d.ts#L1056
const MainStack = createDrawerNavigator(
{
Home: homeScreen,
AddCard: addCardScreen,
AddProduct: addProductScreen,
Detail: detailScreen,
Notification: notificationsScreen,
Products: productsScreen,
Profile: profileScreen,
Service: serviceScreen,
},
{
contentComponent: () => <SideBar />,
initialRouteName: "Home",
overlayColor: 'transparent'
}
);
If your React Navigation version is V4:
React Navigation 4.x
createDrawerNavigator(RouteConfigs, DrawerNavigatorConfig);
DrawerNavigatorConfig
drawerBackgroundColor - Use the Drawer background for some color. The
Default is white.
Usage
const AppStack = createDrawerNavigator(
{
Home: { screen: HomeScreen },
Other: { screen: OtherScreen },
},
{
headerMode: 'screen',
navigationOptions: ({ navigation }) => ({
gesturesEnabled: false,
swipeEnabled: false,
drawerLockMode: 'locked-closed'
}),
drawerBackgroundColor : 'transparent' // or 'rgba(0,0,0,0)'
drawerPosition: 'right',
contentComponent: (props) => <SideMenu {...props} />
});