ReactNative drawerNavigation custom footer - react-native

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>

Related

Touchable Opacity not working when nested inside View component but works if Touchable opacity is made the parent component to wrap other components

I have the following component created for showing an image card on screen. Inside this card there is an image that I am trying to make touchable, however, its does seem to work and when I try clicking on it, nothing happens.
But if I make the Touchable opacity as a parent component below, then the complete image card component becomes touchable and it works on screen. However, I do not want that and only want to target sub elements in this below card component. Not sure how to fix this!
import React, { useState } from "react";
import {
View,
Image,
Text,
StyleSheet,
TouchableOpacity,
} from "react-native";
const ImageCardView = ({
title,
category,
Price,
description,
imageUrl,
rating,
}) => {
return (
<View style={{ backgroundColor: "#d3c4de" }}>
<View style={styles.cardContainer}>
<RedCircle />
<TouchableOpacity onPress={() => navigation.navigate("showCase")}>
<Image
source={{
uri: imageUrl,
}}
style={styles.image}
/>
</TouchableOpacity>
<SeparatorVertical />
<View style={styles.textContainer}>
<Text style={styles.title}>{title}</Text>
<Text style={styles.category}>{category}</Text>
<Text style={styles.price}>${Price}</Text>
<SeparatorHorizontal />
<Text numberOfLines={2} style={styles.description}>
{description}
</Text>
<View style={styles.rightBottom}>
<TouchableOpacity
style={styles.button}
onPress={() => setIsPressed(!isPressed)}
>
<Text>Add To Cart</Text>
</TouchableOpacity>
{/* {isPressed && (
<View
style={{
backgroundColor: "white",
paddingLeft: 16,
paddingRight: 16,
}}
>
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingBottom: 12,
}}
>
<TouchableOpacity
disabled={!items.length}
onPress={removeItemFromBasket}
>
<Icon
name="minus-circle"
size={40}
color={items.length > 0 ? "#00CCBB" : "gray"}
/>
</TouchableOpacity>
<Text>{items.length}</Text>
<TouchableOpacity onPress={addItemToBasket}>
<Icon name="plus-circle" size={40} color="#00CCBB" />
</TouchableOpacity>
</View>
</View>
)} */}
<View style={styles.ratingContainer}>
{[...Array(5)].map((star, i) => {
const ratingValue = i + 1;
return (
<Text
key={i}
style={[
styles.star,
ratingValue <= rating && styles.filledStar,
]}
>
★
</Text>
);
})}
</View>
</View>
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
cardContainer: {
flexDirection: "row",
alignItems: "center",
backgroundColor: "white",
borderRadius: 5,
overflow: "hidden",
marginVertical: 10,
marginLeft: 3,
width: "98%",
height: 300,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
image: {
width: 150,
height: 228,
resizeMode: "cover",
},
textContainer: {
paddingLeft: 10,
},
title: {
fontWeight: "bold",
fontSize: 20,
marginBottom: 10,
},
category: {
color: "#d6c3b9",
},
price: {
fontSize: 20,
fontWeight: "bold",
color: "#05c3fa",
},
description: {
flexDirection: "row",
flexWrap: "wrap",
fontSize: 15,
color: "#666",
marginBottom: 20,
},
ratingContainer: {
flexDirection: "row",
alignItems: "center",
},
button: {
alignItems: "center",
backgroundColor: "#5cb85c",
borderRadius: 5,
padding: 10,
},
rightBottom: {
flexDirection: "row",
},
star: {
fontSize: 18,
color: "#888",
},
filledStar: {
color: "#ffd700",
},
});
export default ImageCardView;
Without seeing the all the code, my suggestion is to make sure your TouchableOpacity is being imported from "react-native" and not from "react-native-gesture-handler" or some other npm package like "react-native-web".
Check the below code and logs, it's working fine:
import React, { useState } from "react";
import {
View,
Image,
Text,
StyleSheet,
TouchableOpacity,
} from "react-native";
const App = ({
title,
category,
Price,
description,
imageUrl,
rating,
}) => {
const [isPressed, setIsPressed] = useState(false)
return (
<View style={{ backgroundColor: "#d3c4de" }}>
<View style={styles.cardContainer}>
<TouchableOpacity onPress={() => {
console.log("on pressed!!!!")
navigation.navigate("showCase")
}
}>
<Image
source={{
uri: imageUrl,
}}
style={styles.image}
/>
</TouchableOpacity>
<View style={styles.textContainer}>
<Text style={styles.title}>{title}</Text>
<Text style={styles.category}>{category}</Text>
<Text style={styles.price}>${Price}</Text>
<Text numberOfLines={2} style={styles.description}>
{description}
</Text>
<View style={styles.rightBottom}>
<TouchableOpacity
style={styles.button}
onPress={() => {
console.log("Add to card pressed!!!!")
setIsPressed(!isPressed)
}}>
<Text>Add To Cart</Text>
</TouchableOpacity>
{isPressed && (
<View
style={{
backgroundColor: "white",
paddingLeft: 16,
paddingRight: 16,
}}
>
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingBottom: 12,
}}
>
<TouchableOpacity
disabled={!items.length}
onPress={removeItemFromBasket}
>
<Icon
name="minus-circle"
size={40}
color={items.length > 0 ? "#00CCBB" : "gray"}
/>
</TouchableOpacity>
<Text>{items.length}</Text>
<TouchableOpacity onPress={addItemToBasket}>
<Icon name="plus-circle" size={40} color="#00CCBB" />
</TouchableOpacity>
</View>
</View>
)}
<View style={styles.ratingContainer}>
{[...Array(5)].map((star, i) => {
const ratingValue = i + 1;
return (
<Text
key={i}
style={[
styles.star,
ratingValue <= rating && styles.filledStar,
]}
>
★
</Text>
);
})}
</View>
</View>
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
cardContainer: {
flexDirection: "row",
alignItems: "center",
backgroundColor: "white",
borderRadius: 5,
overflow: "hidden",
marginVertical: 10,
marginLeft: 3,
width: "98%",
height: 300,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
image: {
width: 150,
height: 228,
resizeMode: "cover",
},
textContainer: {
paddingLeft: 10,
},
title: {
fontWeight: "bold",
fontSize: 20,
marginBottom: 10,
},
category: {
color: "#d6c3b9",
},
price: {
fontSize: 20,
fontWeight: "bold",
color: "#05c3fa",
},
description: {
flexDirection: "row",
flexWrap: "wrap",
fontSize: 15,
color: "#666",
marginBottom: 20,
},
ratingContainer: {
flexDirection: "row",
alignItems: "center",
},
button: {
alignItems: "center",
backgroundColor: "#5cb85c",
borderRadius: 5,
padding: 10,
},
rightBottom: {
flexDirection: "row",
},
star: {
fontSize: 18,
color: "#888",
},
filledStar: {
color: "#ffd700",
},
});
export default App;
For navigation, you need to get it referenced from parent props.
Thanks everyone. I got it fixed, in my case somehow the component was blocking the Touchable opacity, so included that inside my Touchable capacity to include the with the image and it started working

REACT NATIVE QUESTION TypeError: undefined is not an object (evaluating 'navigation.navigate') ...,

App.js (Login)
import * as React from 'react';
import {useState} from 'react';
import { Text, StyleSheet,
KeyboardAvoidingView, ScrollView, Image,
TextInput, TouchableOpacity, View } from 'react-native';
import { CheckBox } from 'react-native-elements';
import {Ionicons} from '#expo/vector-icons'
import {statusBar01} from './src/statusBar';
const Login = ({navigation}) => {
const [input, setInput] = useState('');
const [hidePass, setHidePass] = useState(true);
const [ischecked1, setIschecked1] = useState(true)
//const navigation = useNavigation();
return (
<KeyboardAvoidingView
style={styles.container}
>
<ScrollView>
<Image
source={require('./assets/logo.png')}
style={styles.logo}
/>
<Text style={styles.helloText}>
Olá de novo !
</Text>
<Text style={styles.welcomeText}>
Bem-vindo(a) de volta,
sentimos sua falta!
</Text>
<TextInput
style={styles.inputArea}
placeholder="Digite o e-mail"
/>
<TextInput
style={styles.inputArea}
placeholder="Senha"
value={input}
onChangeText={ (texto) => setInput(texto)}
secureTextEntry={hidePass}
/>
<TouchableOpacity style={styles.eye} onPress={ () => setHidePass(!hidePass) }>
<Ionicons name={hidePass ? 'eye' : 'eye-off'}
color="#A0D800" size={25}
/>
</TouchableOpacity>
<View style={styles.checkBoxStyle}>
<CheckBox
left
size={18}
checkedColor='#A0D800'
value={ischecked1}
checked={ischecked1}
onPress={() => setIschecked1(!ischecked1)}
containerStyle={{ backgroundColor: "transparent",
borderColor: "transparent", marginRight: 0}}
/>
<TouchableOpacity>
<Text style={styles.Connected}>
Manter-se conectado
</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.forgotPassword}>
Esqueci minha senha
</Text>
</TouchableOpacity>
</View>
<TouchableOpacity
style={styles.botao}
onPress={() => navigation.navigate('HomeScreen')}
>
<Text style={styles.botaoText}>Entrar</Text>
</TouchableOpacity>
</ScrollView>
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
container: {
flex: 2,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff'
},
logo: {
marginTop:50,
marginBottom: 80,
width: 150,
height: 40,
},
inputArea:{
marginTop: 30,
padding: 15,
height: 60,
width: 370,
borderColor: '#808080',
borderWidth: 1,
backgroundColor: '#fff',
fontSize: 16,
fontWeight: 'bold',
borderRadius: 15
},
botao: {
width: 350,
height: 60,
backgroundColor: '#000000',
marginTop: 35,
marginLeft: 8,
borderRadius: 15,
alignItems: 'center',
justifyContent: 'center',
},
botaoText: {
fontSize: 15,
fontWeight: 'bold',
color: '#fff'
},
helloText: {
fontSize: 40,
fontWeight: 'bold',
marginTop: 15,
color: '#000000',
marginEnd: 120,
marginTop: 8
},
welcomeText: {
fontSize: 16,
marginTop: 10,
marginEnd: 35,
marginVertical: 10,
color: '#808080',
},
forgotPassword: {
textDecorationLine: 'underline',
fontWeight: 'bold',
marginTop: 15,
marginBottom: 15,
marginLeft: 30,
fontSize: 12
},
Connected:{
textDecorationLine: 'underline',
fontWeight: 'bold',
marginTop: 15,
fontSize: 12,
marginRight: 55,
marginLeft: -5
},
checkBoxStyle:{
marginTop: 15,
flexDirection: 'row',
marginStart: -10
},
eye:{
alignSelf: 'flex-end',
bottom: 42,
right: 40
}
})
export default Login;
HomeScreen.js
import * as React from 'react';
import { useState } from 'react';
import { Text, View, ScrollView, KeyboardAvoidingView, Image, TouchableOpacity} from 'react-native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import { Entypo, Feather } from 'react-native-vector-icons';
import SwitchSelector from "react-native-switch-selector";
import {Card} from 'react-native-shadow-cards';
import * as Progress from 'react-native-progress';
import { NavigationContainer } from '#react-navigation/native';
import statusBar01 from './src/statusBar';
import 'react-native-gesture-handler';
import {createStackNavigator} from 'react-navigation/stack'
import Login from '../../App';
//import { HomeScreen } from './src/screens/HomeScreen';
//import { TasksScreen } from './src/screens/TasksScreen';
//import { SettingsScreen } from './src/screens/SettingsScreen';
function TasksScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Tasks!</Text>
</View>
);
}
function HomeScreen() {
const options = [
{ label: "Active", value: "a" },
{ label: "New", value: "n" },
];
const [showHide, setShowHide] = useState(false);
return (
<KeyboardAvoidingView style={{
flex: 2,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff'
}}>
<ScrollView >
<Text style={{textAlign:'left', fontSize: 33,
fontWeight:'bold', paddingTop: 100,
paddingLeft: 20, bottom: 55}}>
{'Olá, \nUsuário!'}
</Text>
<Text style={{paddingLeft: 20,
color: '#808080', bottom: 80,
fontSize: 20 , paddingTop: 50}}>
Minhas tasks</Text>
<Image
source={require('./assets/images/user.jpeg')}
style={{marginTop:50,
width: 55,
height: 55,
borderRadius: 10,
top: -250,
left: 300,
borderColor: '#ECECEC',
borderWidth: 1
}
}
/>
<SwitchSelector
style={{width:390,paddingLeft: 15, bottom: 160}}
textColor={'#FFFFFF'}
selectedColor={'#000000'}
fontSize={15}
height={60}
bold
backgroundColor={'#000000'}
valuePadding={-1}
hasPadding
borderRadius={15}
options={options}
initial={0}
//onPress={value => console.log(`Call onPress with value: ${value}`)}
/>
<Card style={{ margin: 19, height: 170,
marginTop: -125}}>
<Feather name={'file-text'}
color={'#F2CB1D'}
size={20}
style={{paddingLeft: 20,
top: 20,}}/>
<Text
style={{paddingLeft: 50}}>Task 59788</Text>
<Entypo name={'controller-record'}
style={{paddingLeft: 270, bottom: 14
}}
color={'#007ACC'}
size={10}
/>
<Text
style={{paddingLeft: 290, bottom: 30}}
>Active</Text>
<Text style={{fontSize: 12,
paddingLeft: 20, bottom: 15
}}>App corporativo OnlineTeam</Text>
<Text style={{paddingLeft: 20,
fontSize: 20, bottom: 10}}>Criar telas no Figma</Text>
<Text style={{paddingLeft: 20,
fontSize: 12}}>Original Estimate: 4h</Text>
<Text style={{paddingLeft: 250,
bottom: 17, fontSize: 12}}>Completed: 2h</Text>
<Text style={{textAlign: 'left',
bottom: 10, fontSize: 10,
paddingLeft: 55}}>
0%</Text>
<Progress.Bar progress={0.1}
width={200}
color={'#A0D800'}
backgroundColor={'#ECECEC'}
borderColor={'transparent'}
height={10}
borderRadius={10}
style={{alignSelf: 'center'}}
bottom={20}
/>
<Text style={{textAlign: 'right',
fontSize: 10,bottom: 35,
paddingRight: 40}}>
100%</Text>
</Card>
<Card style={{ margin: 19, height: 170,
marginTop: -125, marginTop: 5}}>
<Entypo name={'bug'}
color={'#FF0000'}
size={20}
style={{paddingLeft: 20,
top: 20,}}/>
<Text
style={{paddingLeft: 50}}>Bug 59352</Text>
<Entypo name={'controller-record'}
style={{paddingLeft: 270, bottom: 14
}}
color={'#FF0000'}
size={10}
/>
<Text
style={{paddingLeft: 290, bottom: 30}}
>Issue</Text>
<Text style={{fontSize: 12,
paddingLeft: 20, bottom: 15
}}>Cargo Online Team</Text>
<Text style={{paddingLeft: 20,
fontSize: 20, bottom: 10}}>
Acusando duplicidade de contrato...</Text>
<Text style={{paddingLeft: 20,
fontSize: 12}}>Original Estimate: 4h</Text>
<Text style={{paddingLeft: 250,
bottom: 17, fontSize: 12}}>Completed: 2h</Text>
<Text style={{textAlign: 'left',
bottom: 10, fontSize: 10,
paddingLeft: 55}}>
0%</Text>
<Progress.Bar progress={0.1}
width={200}
color={'#A0D800'}
backgroundColor={'#ECECEC'}
borderColor={'transparent'}
height={10}
borderRadius={10}
style={{alignSelf: 'center'}}
bottom={20}
/>
<Text style={{textAlign: 'right',
fontSize: 10,bottom: 35,
paddingRight: 40}}>
100%</Text>
</Card>
</ScrollView>
</KeyboardAvoidingView>
);
}
function SettingsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
export default function App() {
const Tab = createBottomTabNavigator();
return (
<NavigationContainer>
<Tab.Navigator
screenOptions={{
tabBarActiveTintColor: "#A0D800",
tabBarInactiveTintColor: "#FFFFFF",
//tabBarActiveBackgroundColor: "#FFFFFF",
//tabBarInactiveBackgroundColor: "#000000",
backgroundColor: "#FFFFFF",
headerShown: false,
tabBarSelectedItemStyle: {
borderBottomWidth: 2,
borderBottomColor: 'red',
},
tabBarStyle: [
{
display: "flex",
backgroundColor: "#000000",
borderTopLeftRadius: 20,
borderTopRightRadius: 20,
height: 70,
overflow: 'hidden',
alignItems: 'center',
justifyContent: 'center',
},
null,
],
tabBarHideOnKeyboard: true,
tabBarLabelStyle:{
//fontSize: 20,
//fontWeight: 'bold',
backgroundColor: "#000000",
width: 60,
flex: 0.000004,
},
}}
>
<Tab.Screen name=" "
component={TasksScreen}
options={{
tabBarIcon: ({ color}) => (
<Entypo name="add-to-list"
size={30}
color={color}
/>
)
}}
/>
<Tab.Screen name=" "
component={HomeScreen}
options={{
tabBarIcon: ({ color}) => (
<Feather name="home"
size={30}
color={color}
/>
)
}} />
<Tab.Screen name=" "
component={SettingsScreen}
options={{
tabBarIcon: ({ color}) => (
<Feather name="settings"
size={30}
color={color}
/>
)
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
I'm not managing to organize the code or implement a navigation on the login button for the home screen, someone helps me please???
I tried to create a Login.js and export it and the HomeScreen to the App.js but it also failed.
Could someone help me with the resolution so I can proceed with my code?
I need help whit this
I am a begginer dev
Please :( :( :(
Instead of relying on getting the navigation object as a prop, import useNavigation from react-navigation/core
import { useNavigation } from '#react-navigation/core';
export default function App(){
const navigation = useNavigation()
return(
<View>
<Button onPress={()=> navigation.navigate("homescreen")}/>
</View>
)
}
It seems that you did not import useNavigation. Add this to your code:
import { useNavigation } from '#react-navigation/native';
then declare a const within your login function:
const navigation = useNavigation();
then try it again. Also ensure you are calling the correct component name within the navigation.navigate('')
You should define names to your screens.
For example:
<Tab.Screen name="TasksScreen"
component={TasksScreen}
options={{
tabBarIcon: ({ color}) => (
<Entypo name="add-to-list"
size={30}
color={color}
/>
)
}}
/>
<Tab.Screen name="HomeScreen"
component={HomeScreen}
options={{
tabBarIcon: ({ color}) => (
<Feather name="home"
size={30}
color={color}
/>
)
}} />
<Tab.Screen name="SettingsScreen"
component={SettingsScreen}
options={{
tabBarIcon: ({ color}) => (
<Feather name="settings"
size={30}
color={color}
/>
Then you can navigate them with their names like navigation.navigate("HomeScreen")
You should name them carefully.
For detailed information and examples you can check:
https://reactnative.dev/docs/navigation
Have a good day!

I want to change the width of the KeyboardAvoidingView movement with custom TextInput

I am developing iOS apps in React Native Expo.
To display the image icon and placeholder in the Input column, I set it to Image icon and TextInput in the View.
When using KeyboardAvoidingView, the keyboard scrolls to the bottom of TextInput as shown in the attached image (1), but does anyone know if it is possible to scroll to the bottom of the description of the input field as shown in image (2)?
Image(1)
Image(2)
The article is based on the following.
https://reactnative.dev/docs/keyboardavoidingview
Parent function code.
<KeyboardAvoidingView behavior="padding" style={styles.containerStyle}>
<SafeAreaView style={styles.containerStyle}>
<ScrollView style={styles.containerStyle}>
<View style={styles.headContainerStyle}></View>
<View style={styles.mainContainerStyle}></View>
<View style={styles.headMessageContainerStyle}>
<Text style={styles.headMessageTextStyle}>Sign Up</Text>
</View>
{/* Email */}
<MailForm
inputAccessoryViewID={inputAccessoryViewID}
isCorrectMail={isCorrectMail}
setIsCorrectMail={setIsCorrectMail}
/>
{/* Password */}
<PasswordForm
inputAccessoryViewID={inputAccessoryViewID}
isCorrectPassewordSymbol={isCorrectPassewordSymbol}
setIsCorrectPassewordSymbol={setIsCorrectPassewordSymbol}
isCorrectPassewordStringCount={isCorrectPassewordStringCount}
setIsCorrectPassewordStringCount={setIsCorrectPassewordStringCount}
/>
{/* UserId */}
<UserIdForm
inputAccessoryViewID={inputAccessoryViewID}
isCorrectUserIdSymbol={isCorrectUserIdSymbol}
setIsCorrectUserIdSymbol={setIsCorrectUserIdSymbol}
isCorrectUserIdStringCount={isCorrectUserIdStringCount}
setIsCorrectUserIdStringCount={setIsCorrectUserIdStringCount}
isAvailableUserId={isAvailableUserId}
setIsAvailableUserId={setIsAvailableUserId}
/>
{/* Screen Bottom */}
<View style={styles.bottomStyle}>
{isCorrectMail && isCorrectPassewordSymbol && isCorrectPassewordStringCount && isCorrectUserIdSymbol && isCorrectUserIdStringCount && isAvailableUserId ?
(
<TouchableOpacity
style={styles.buttonContainerStyle}>
<Text style={styles.buttonTextStyle}>Sign Up</Text>
</TouchableOpacity>
) : (
<TouchableOpacity
style={[styles.buttonContainerStyle, styles.buttonContainerInvalidStyle]}
onPress={() => navigation.navigate('SignUp')}>
<Text style={styles.buttonTextStyle}>Sign Up</Text>
</TouchableOpacity>
)}
<View style={styles.toLoginStyle}>
<Text style={styles.toLoginTextStyle}>Do you have an account?</Text>
<Text style={[styles.toLoginTextStyle, styles.toLoginTextLinkStyle]}>Login here</Text>
</View>
</View>
</ScrollView>
</SafeAreaView>
</KeyboardAvoidingView>
The code for the <UserId/> component, which we want to support scrolling for this time.
<View>
<View style={styles.searchBoxStyle}>
<View style={styles.searchWrapperStyle}>
<Pressable style={styles.searchContainerStyle} onPress={() => textInputUserId.focus()}>
<Text style={styles.searchTitleStyle}>UserId</Text>
{/* <KeyboardAvoidingView behavior="padding"> */}
<View style={defaultUserIdBorderColor ? isCorrectUserIdSymbol && isCorrectUserIdStringCount ? styles.searchViewStyle : [styles.searchViewStyle, styles.inputIncorrectBorderColorStyle]: styles.searchViewStyle}>
<Image source={require("../../../assets/profile.png")} style={styles.searchIconStyle}/>
{/* <KeyboardAvoidingView behavior="padding"> */}
<TextInput
onChangeText={onChangeUserIdText}
style={styles.searchContentStyle}
value={userIdText}
placeholder="test1234"
inputAccessoryViewID={inputAccessoryViewID}
ref={(input) => textInputUserId = input}
autoCapitalize="none"
maxLength={100}
textContentType="username"
onFocus={() => {
…
}}
onEndEditing={() => {
…
}}
/>
</View>
</Pressable>
</View>
</View>
{/* UserId Description */}
{displayUserIdDescription ? !isCorrectUserIdSymbol || !isCorrectUserIdStringCount || !isAvailableUserId ? (
<View style={styles.descriptionBoxStyle}>
<View style={styles.descriptionWrapperStyle}>
<View style={styles.descriptionContainerStyle}>
{!defaultDisplayUserIcons ? isCorrectUserIdSymbol ? <Image source={require("../../../assets/correct.png")} style={styles.descriptionIconStyle}/>: <Image source={require("../../../assets/incorrect.png")} style={styles.descriptionIconStyle}/>: null}
<Text style={styles.descriptionTextStyle}>Half-width alphanumeric characters only.</Text>
</View>
<View style={styles.descriptionContainerStyle}>
{!defaultDisplayUserIcons ? isCorrectUserIdStringCount ? <Image source={require("../../../assets/correct.png")} style={styles.descriptionIconStyle}/>: <Image source={require("../../../assets/incorrect.png")} style={styles.descriptionIconStyle}/>: null}
<Text style={styles.descriptionTextStyle} >More than 4 words and less than 100 words.</Text>
</View>
<View style={styles.descriptionContainerStyle}>
{!defaultDisplayUserIcons ? isAvailableUserId ? <Image source={require("../../../assets/correct.png")} style={styles.descriptionIconStyle}/>: <Image source={require("../../../assets/incorrect.png")} style={styles.descriptionIconStyle}/>: null}
<Text style={styles.descriptionTextStyle} >Available.</Text>
</View>
</View>
</View>
) : null: null}
</View>
Style sheet code.
import { StyleSheet } from 'react-native';
export const styles = StyleSheet.create({
containerStyle: {
flex: 1,
backgroundColor: "#1B1C56",
},
headContainerStyle: {
width: "100%",
height: "10%",
height: 40,
backgroundColor: "#1B1C56",
},
headMessageContainerStyle: {
backgroundColor: "#feffff",
alignItems: 'center',
},
headMessageTextStyle: {
fontSize: 50,
fontFamily: "AlfaSlabOne_400Regular",
color: "#1B1C56",
marginBottom: 32,
},
mainContainerStyle: {
width: "100%",
height: "15%",
backgroundColor: "#feffff",
borderTopLeftRadius: 50,
alignItems: 'center',
},
searchBoxStyle: {
flex: 1,
backgroundColor: "#feffff",
},
searchWrapperStyle: {
flex: 1,
alignItems: "center",
paddingBottom: 10,
},
searchContainerStyle: {
},
searchTitleStyle: {
fontFamily: "ABeeZee_400Regular_Italic",
color: "#262626",
marginBottom: 5,
},
searchIconStyle: {
width: 24,
height: 24,
marginRight: 10,
marginLeft: 10,
},
searchViewStyle: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#F6F7FB',
borderWidth: 0.5,
height: 60,
borderRadius: 5,
width: 300,
borderColor: "#F6F7FB",
},
searchContentStyle: {
flex: 1
},
inputIncorrectBorderColorStyle:{
borderWidth: 2,
borderColor: "#ED195E",
},
completeBoxStyle: {
width: 60,
alignItems: "center",
padding: 10,
},
completeTextStyle: {
fontSize: 18,
fontWeight: "bold",
color: "hsl(210, 100%, 60%)"
},
passwordIconStyle: {
marginRight: 10
},
descriptionBoxStyle:{
display: "flex",
alignItems: "center",
backgroundColor: "#feffff",
paddingBottom: 10,
},
descriptionWrapperStyle: {
},
descriptionContainerStyle: {
flexDirection: "row",
width: 300,
},
descriptionTextStyle: {
color: "#262626",
fontSize: 12,
overflow: "visible"
},
descriptionIconStyle:{
marginRight: 10,
width: 12,
height: 12,
},
bottomStyle: {
display: "flex",
alignItems: "center",
height: "100%",
backgroundColor: "#feffff",
},
buttonContainerStyle: {
alignItems: "center",
justifyContent: "center",
backgroundColor: "#1B1C56",
width: 300,
height: 60,
borderRadius: 10,
fontSize: 18,
},
buttonContainerInvalidStyle:{
backgroundColor: "#C5C5C7",
},
buttonTextStyle: {
color: "#feffff",
fontFamily: "ABeeZee_400Regular_Italic",
},
toLoginStyle: {
marginTop: 10,
height: "5%",
flexDirection: "row"
},
toLoginTextStyle: {
fontFamily: "ABeeZee_400Regular_Italic",
},
toLoginTextLinkStyle: {
color: "#ED195E",
marginLeft: 10,
},
});
Swapped the positions of KeyboardAvoidingView, SafeAreaView and ScrollView. I have tried to set the keyboardVerticalOffset and the keyboardVerticalOffset, but each had its own problems, and the current code was the closest to the ideal.

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} />
});

How to put text on the ParallaxImage

I am using react-native-snap-carousel.
How can I have the text on the image?
<View style={styles.item}>
<ParallaxImage
source={{ uri: item.illustration }}
containerStyle={styles.imageContainer}
style={styles.image}
parallaxFactor={0.35}
{...parallaxProps}
/>
</View>
<View style={styles.textContainer}>
<Text styke={styles.title}>{item.title}</Text>
<Text style={styles.subtitle}>{item.subtitle}</Text>
</View>
Styles:
const styles = StyleSheet.create({
item: {
width: screenWidth - 60,
height: screenWidth - 250
},
imageContainer: {
flex: 1,
marginBottom: Platform.select({ ios: 0, android: 1 }), // Prevent a random Android rendering issue
backgroundColor: 'white',
borderTopLeftRadius: 5,
borderTopRightRadius: 5
},
image: {
...StyleSheet.absoluteFillObject,
resizeMode: 'cover'
},
textContainer: {
justifyContent: 'center',
paddingTop: 20 - 8,
paddingBottom: 20,
paddingHorizontal: 16,
borderBottomLeftRadius: 5,
borderBottomRightRadius: 5,
backgroundColor: colors.gray3
},
title: {
color: colors.black,
fontSize: 13,
fontWeight: 'bold',
letterSpacing: 0.5
},
subtitle: {
marginTop: 6,
color: colors.gray,
fontSize: 12,
fontStyle: 'italic'
}
});
Add a bottom of a value such as
return (
<View style={styles.item}>
<ParallaxImage
source={item.thumbnail}
containerStyle={styles.imageContainer}
style={styles.image}
parallaxFactor={0.4}
{...parallaxProps}
/>
<View style={{bottom: 40}}>
<Text style={{color:'white', fontSize: scale(20), }}>
{item.title}
</Text>
</View>
</View>
Could you try this?
<View style={styles.item}>
<ParallaxImage
source={{ uri: item.illustration }}
containerStyle={styles.imageContainer}
style={styles.image}
parallaxFactor={0.35}
{...parallaxProps}
/>
<Text styke={styles.title}>{item.title}</Text>
<Text style={styles.subtitle}>{item.subtitle}</Text>
</View>
....
<Carousel
...
itemWidth={screenWidth - 60}
/>
...
item: {
width: screenWidth - 60,
height: screenWidth - 60
}