I've seen the same question many times, but none of the solutions I found worked for me.
return part
<View style={styles.root}>
<ScrollView contentContainerStyle={{ flexGrow: 1 }} scrollEnabled={true}>
<View style={styles.dpArea}>
<Image
source={{
uri: "URI GOES HERE",
}}
style={{ width: "100%", height: "100%" }}
resizeMode="contain"
/>
</View>
<View style={styles.nameArea}>
<View style={{ flex: 8, alignItems: "center" }}>
<Text style={styles.nameText}> {nameUpper}</Text>
</View>
<View style={{ flex: 2, paddingLeft: 10 }}>
<MaterialIcons name="edit" size={24} color="gray" />
</View>
</View>
<View style={styles.emailArea}>
<Text
style={{
fontFamily: "Reg",
fontSize: 12,
color: "gray",
marginRight: 4,
}}
>
Logged in using
</Text>
<Text style={{ fontFamily: "Reg", fontSize: 12 }}>{email}</Text>
</View>
<View style={styles.statsArea}>
<StatsContainer text="STAT 1" number="41" />
<StatsContainer text="STAT 2" number="93" />
</View>
<View style={styles.feedbackArea}>
<Text style={{ fontFamily: "Bold", fontSize: 12, color: "gray" }}>
Send feedbacks, feature requests or report bugs:
</Text>
<FeedbackArea content={feedback} />
</View>
<View style={styles.logoutArea}>
<GenButton content="LOGOUT" />
<DeleteAcButton content="DELETE ACCOUNT" />
</View>
<View style={styles.madeByArea}>
<Text style={styles.madebyText}>Developed by:</Text>
</View>
</ScrollView>
</View>
StyleSheet :
root: {
flex: 1,
},
dpArea: {
height: "30%",
marginTop: 20,
overflow: "hidden",
alignItems: "center",
justifyContent: "center",
},
nameArea: {
height: "10%",
flexDirection: "row",
justifyContent: "space-around",
alignItems: "center",
},
emailArea: { height: "10%", flexDirection: "row", justifyContent: "center" },
statsArea: { flexDirection: "row", height: "20%", marginBottom: "10%" },
feedbackArea: { height: "20%", marginHorizontal: "5%" },
logoutArea: {
width: "100%",
justifyContent: "space-around",
alignItems: "center",
height: "30%",
marginVertical: "5%",
},
madeByArea: {
height: "10%",
justifyContent: "flex-end",
alignItems: "center",
marginBottom: 3,
},
madebyText: {
fontFamily: "Reg",
fontSize: 12,
color: "gray",
},
nameText: {
fontFamily: "Bold",
fontSize: 30,
},
What I've tried: making scrollview the parent component, wrapping scrollview in a root view, flex & flexGrow=1 in contentContainerStyle, flex & flexGrow=1 in ScrollView style parameter.
What I've observed is, if I change any text's font size to say 300, then scroll works but not all components are rendered, however, with normal font size, there's no scroll even though the page exceeds the screen size.
I presume it's due to the way stylesheet is configured, but am unable to locate the error.
Related
I want to make feed screen and this is what i want to achieve for every post item.
This is what i have currently . I thought this will do the work. Am I making a mistake somewhere or I need to add someting else to the styles? I struggle with design and thought this will be enough to structure the components. For example, I expected the image to be the top element but somehow it is in the middle... Also, when I have such problems, how to cope with them, any tips?
<View style={styles.wrapper}>
<Opacity onPress={props.onPostSelect}>
<View style={{ ...styles.postContainer, ...props.style }}>
{/* thumbnail */}
<View style={styles.thumbnailContainer}>
<Image
resizeMode="contain"
source={{ uri: props.item.thumbnailURL }}
style={styles.thumbnail}
/>
</View>
{/* thumbnail end*/}
{/* info container */}
<View style={styles.infoContainer}>
<View style={styles.postDetailsContainer}>
{/* //TITLE */}
<View style={styles.title}>
<Text style={styles.text} numberOfLines={1}>
{props.item.title}
</Text>
</View>
{/* //TITLE end*/}
{/* LIKES/VIEWS */}
<View style={styles.likesAndViewsContainer}>
<Text style={styles.text}>{props.item.views} views | </Text>
{/* LIKES */}
<View style={styles.likesContainer}>
<MaterialIcons name="thumb-up" color="white" size={18} />
<Text style={styles.text}> {props.item.likes} </Text>
</View>
</View>
</View>
</View>
</View>
</Opacity>
</View>
the styles :
const styles = StyleSheet.create({
postContainer: {
justifyContent: "center",
borderWidth: 7,
borderColor: "brown",
borderRadius: 2,
backgroundColor: "pink",
marginHorizontal: 5,
height: "95%",
overflow: "hidden",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
},
wrapper: {
flex: 1,
flexGrow: 1,
height: 500,
width: "100%",
backgroundColor: Colors.secondaryColors.lightGray,
overflow: "hidden",
},
title: {
flexDirection: "column",
color: "white",
height: "80%",
},
likesAndViewsContainer: {
flexDirection: "row",
justifyContent: "flex-start",
overflow: "hidden",
},
text: {color:black},
likesContainer: {
flexDirection: "row",
},
thumbnail: {
flex: 1,
width: 100,
height: "100%",
position: "absolute",
},
thumbnailContainer: {
flex: 1,
height: "100%",
width: "100%",
marginVertical: 10,
position: "absolute",
right: 10,
left: 10,
},
infoContainer: {
flexDirection: "row",
},
postDetailsContainer: {
color: "white",
fontSize: 16,
flexDirection: "column",
},
});
i think there's something to do with your position:'absolute' and flex:1.
I've cleaned it up a bit, and do tell me, if this is what you're going for
<View style={styles.wrapper}>
<View style={styles.postContainer}>
<View style={styles.thumbnailContainer}>
<Image
resizeMode="contain"
source={{ uri: props.item.thumbnailURL }}
style={styles.thumbnail}
/>
</View>
<View style={styles.infoContainer}>
<Text style={styles.text} numberOfLines={1}>{props.item.title}</Text>
<View style={styles.likesAndViewsContainer}>
<Text style={styles.text}>{props.item.view} views | </Text>
<View style={styles.likesContainer}>
<MaterialIcons name="thumb-up" color="white" size={18} />
<Text style={styles.text}> {props.item.likes} </Text>
</View>
</View>
</View>
</View>
</View>
the styles:
const styles = StyleSheet.create({
postContainer: {
borderWidth: 1,
borderColor: "brown",
backgroundColor: "pink",
padding:15,
},
wrapper: {
flex:1,
backgroundColor: 'gray',
},
likesAndViewsContainer: {
flexDirection: "row",
justifyContent: "flex-start",
},
text: {
color:'black',
marginBottom:15,
fontWeight:'bold',
},
likesContainer: {
flexDirection: "row",
},
thumbnailContainer:{
height: 100,
width:100,
borderWidth:1,
alignSelf:'center',
},
thumbnail: {
height: 100,
width:100,
},
infoContainer: {
marginTop:15,
},
});
I am new in react native and I please need help. When the keyboard appears , the whole view is pushed upwards.I do not want that to happen.I saw other answers but none of them is working for me.I do not want the view to be pushed up when the keyboard appears and want to remain where they are.I am using expo and has given the code below with the images.
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { Image, StyleSheet, View, TextInput, Text, TouchableOpacity, ScrollView, KeyboardAvoidingView } from 'react-native';
export default function LoginScreen({ navigation }) {
return (
<View style={styles.container}>
<Image style={styles.logo} source={
{
uri: "https://i.ibb.co/4JK4T3P/deale-logo.jpg",
}} />
<StatusBar style="auto" />
<View style={styles.inputContainer} >
<TextInput
style={styles.loginInput}
placeholder='Phone Number or Email'
/>
<TextInput
style={styles.passwordInput}
placeholder='Password'
/>
<TouchableOpacity
style={{
width: 280,
height: 50,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgb(255, 77, 77)',
elevation: 5,
borderRadius: 10,
top: 35
}}
activeOpacity={0.8}>
<Text
style={{
color: 'white',
fontSize: 15,
fontWeight: 'bold',
}} >
LOG IN
</Text>
</TouchableOpacity>
<Text
onPress={() => console.log('g')}
style={{
position: 'relative',
top: '23%',
fontWeight: 'bold',
}} >
OR LOGIN WITH SOCIAL MEDIA ACCOUNT?
</Text>
<View style={{
flex: 1,
flexDirection: 'row',
bottom: 30,
justifyContent: 'space-evenly',
top: '22%',
width: 300
}} >
<TouchableOpacity activeOpacity={0.5} >
<Image source={
{ uri: 'https://cdn3.iconfinder.com/data/icons/popular-services-brands/512/facebook-512.png' }}
style={{
width: 60,
height: 60,
}} />
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.5} >
<Image source={
{ uri: 'https://lh3.googleusercontent.com/COxitqgJr1sJnIDe8-jiKhxDx1FrYbtRHKJ9z_hELisAlapwE9LUPh6fcXIfb5vwpbMl4xl9H9TRFPc5NOO8Sb3VSgIBrfRYvW6cUA' }}
style={{
width: 60,
height: 60,
}} />
</TouchableOpacity>
</View>
</View >
<View style={styles.loginButtonView} >
<TouchableOpacity
onPress={
() => navigation.navigate('Create')
}
style={{
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgb(145, 157, 230)',
top: 10,
elevation: 5,
borderRadius: 5
}}
activeOpacity={0.8}>
<Text
style={{ color: 'white', fontSize: 15, fontWeight: 'bold' }} >
CREATE ACCOUNT
</Text>
</TouchableOpacity>
<TouchableOpacity
style={{
justifyContent: 'center',
alignItems: 'center',
top: '40%'
}}
activeOpacity={0.1}>
<Text
style={{
color: 'black',
fontSize: 16,
top: 5
}} >
FORGOT PASSWORD
</Text>
</TouchableOpacity>
</View>
</View >
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
logo: {
position: 'absolute',
height: 100,
width: 150,
resizeMode: "contain",
top: '3 %'
},
loginInput: {
position: 'relative',
height: 50,
borderColor: 'black',
backgroundColor: 'rgb(240, 240, 242)',
borderRadius: 10,
width: 280,
color: 'black',
textAlign: 'center',
justifyContent: 'center',
alignItems: 'center',
borderColor: 'white',
},
inputContainer: {
position: 'absolute',
top: '18%',
alignItems: 'center',
},
passwordInput: {
position: 'relative',
height: 50,
borderColor: 'black',
backgroundColor: 'rgb(240, 240, 242)',
borderRadius: 10,
width: 280,
color: 'black',
textAlign: 'center',
justifyContent: 'center',
alignItems: 'center',
borderColor: 'white',
top: 10
},
loginButtonView: {
position: 'absolute',
height: 46,
width: '70%',
top: '80%'
}
});
I figured out the reason myself.It was happening because i had set my positions based on percentage and the popping of keyboard changed the dimensions resulting in the change of position.
Try to use the component KeyboardAvoidingView like this:
<KeyboardAvoidingView behavior={'height'} enabled style={styles.container}>
<Image style={styles.logo} source={
{
uri: "https://i.ibb.co/4JK4T3P/deale-logo.jpg",
}} />
<StatusBar style="auto" />
<View style={styles.inputContainer} >
<TextInput
style={styles.loginInput}
placeholder='Phone Number or Email'
/>
<TextInput
style={styles.passwordInput}
placeholder='Password'
/>
<TouchableOpacity
style={{
width: 280,
height: 50,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgb(255, 77, 77)',
elevation: 5,
borderRadius: 10,
top: 35
}}
activeOpacity={0.8}>
<Text
style={{
color: 'white',
fontSize: 15,
fontWeight: 'bold',
}} >
LOG IN
</Text>
</TouchableOpacity>
<Text
onPress={() => console.log('g')}
style={{
position: 'relative',
top: '23%',
fontWeight: 'bold',
}} >
OR LOGIN WITH SOCIAL MEDIA ACCOUNT?
</Text>
<View style={{
flex: 1,
flexDirection: 'row',
bottom: 30,
justifyContent: 'space-evenly',
top: '22%',
width: 300
}} >
<TouchableOpacity activeOpacity={0.5} >
<Image source={
{ uri: 'https://cdn3.iconfinder.com/data/icons/popular-services-brands/512/facebook-512.png' }}
style={{
width: 60,
height: 60,
}} />
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.5} >
<Image source={
{ uri: 'https://lh3.googleusercontent.com/COxitqgJr1sJnIDe8-jiKhxDx1FrYbtRHKJ9z_hELisAlapwE9LUPh6fcXIfb5vwpbMl4xl9H9TRFPc5NOO8Sb3VSgIBrfRYvW6cUA' }}
style={{
width: 60,
height: 60,
}} />
</TouchableOpacity>
</View>
</View >
<View style={styles.loginButtonView} >
<TouchableOpacity
onPress={
() => navigation.navigate('Create')
}
style={{
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgb(145, 157, 230)',
top: 10,
elevation: 5,
borderRadius: 5
}}
activeOpacity={0.8}>
<Text
style={{ color: 'white', fontSize: 15, fontWeight: 'bold' }} >
CREATE ACCOUNT
</Text>
</TouchableOpacity>
<TouchableOpacity
style={{
justifyContent: 'center',
alignItems: 'center',
top: '40%'
}}
activeOpacity={0.1}>
<Text
style={{
color: 'black',
fontSize: 16,
top: 5
}} >
FORGOT PASSWORD
</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView >
Try to use different values in the position prop.
If you want less job, you can use the react-native-keyboard-aware-scroll-view. It's a very good lib to work with Keyboard in different layouts.
Default
when open keyboard
function PINInsert({ navigation }){
clearText = () => {
_textInput.setNativeProps({text: ''});
}
var onoff = 0
hideText = () => {
if(onoff == 0){
_textInput.setNativeProps({secureTextEntry: false});
onoff = 1;
}else{
_textInput.setNativeProps({secureTextEntry: true})
onoff = 0;
}
}
return(
<KeyboardAvoidingView style={styles.container0}>
<View style={PINInsertstyles.div0}>
<View style={{
alignContent: "center",
justifyContent: "center"}}>
<Image style={PINInsertstyles.flag} source={require('./assets/en.png')} />
</View>
<View style={{
alignContent: "center",
justifyContent: "center"}}>
<Image style={PINInsertstyles.flag} source={require('./assets/br.png')} />
</View>
</View>
<View style={PINInsertstyles.div1}>
<View style={{
height: 100,
width: 100,
alignItems: "center",
justifyContent: "center"
}}>
<Image style={PINInsertstyles.logo} source={require('./assets/headphone.png')} />
</View>
<View>
<Text style={{fontSize: 40}}>SoundFly</Text>
</View>
</View>
<View style={PINInsertstyles.div2}>
<View style={{flexDirection: "row", justifyContent: "center", alignItems: 'center'}}>
<TextInput
ref={component => _textInput = component}
style={{
height: 40,
width: 200,
margin: 5,
marginTop: 20,
borderWidth: 1,
borderColor: '#ccc',
fontSize: 20,
backgroundColor: '#fff'
}}
maxLength={6}
secureTextEntry={true}
placeholder="PIN"
/>
<TouchableOpacity onPress={hideText} >
<Icon name="eye" size={20} />
</TouchableOpacity>
</View>
<View style={{flexDirection: 'row'}}>
<TouchableOpacity onPress={clearText}
style={{margin: 5, marginTop: 20, backgroundColor: 'red', padding: 5}}
>
<Text style={{justifyContent: 'center', alignItems: 'center', fontSize: 20}}>Clear text</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() =>
navigation.navigate('banner')}
style={{margin: 5, marginTop: 20, backgroundColor: 'purple', padding: 5}}
>
<Text style={{justifyContent: 'center', alignItems: 'center', fontSize: 20}}>Buscar</Text>
</TouchableOpacity>
</View>
<View style= {{height: 50}}></View>
</View>
</KeyboardAvoidingView>
);
};
const PINInsertstyles = StyleSheet.create({
div0: {
flex: 0.4,
backgroundColor: '#00FFEC',
flexDirection: "row-reverse",
alignItems: "flex-start",
},
div1: {
flex: 0.6,
backgroundColor: '#00DCCC',
alignItems: "center",
// justifyContent: "center"
},
div2: {
flex: 1,
backgroundColor: '#00BFBF',
alignItems: "center",
// justifyContent: "center"
},
flag: {
height: 50,
width: 80,
margin: 5
},
logo:{
height: 80,
width: 80,
margin: 10,
alignContent: "center",
justifyContent: "center",
alignItems: "center"
}
})
How I want is "When open keyboard, whole views go up without some view reducing size of itself."
I've tried a lot of example but my start is really different comparing with them cause most example starts complaining about keyboard covers contents but mine just send Views up but resizing them.
What am I doing wrong here?
You need to get dimension of window using
const windowHeight = Dimensions.get('window').height;
And then, insert justify-content: flex-end to container0.
Add a view right inside KeyboardAvoidingView and set minHeight to window height.
hi in my project I use nativeBase. I use <Button><Text>blablabla</Text></Button>
when running in android ok but when run-ios text not showing.
this is my component :
<View style={{ marginLeft: 7, flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
<View style={styles.btncontent}>
<Right style={{ flex: 0.2 }}>
<Image source={mapBtnLogo} style={styles.btnImage} />
</Right>
<Left style={{ flex: 0.8 }}>
<Button full transparent style={styles.btn} onPress={() => props.myProps.gotoMap([section.YPOINT, section.XPOINT])}>
<Text style={styles.btnText}>
نمایش روی نقشه
</Text>
</Button>
</Left>
</View>
</View>
and this is styles :
const styles = StyleSheet.create({
...Platform.select({
ios: {
btnImage: {
margin: 5,
marginRight: 20,
width: moderateScale(20),
height: moderateScale(20),
},
btn: {
//alignItems: 'flex-start',
width: '100%',
height: '10%',
},
btnText: {
fontFamily: 'IRANSansMobile',
fontSize: 15,
color: '#000',
},
}, android: {
btn: {
width: '100%',
height: '10%',
},
btnText: {
fontFamily: 'IRANSansMobile',
fontSize: 15,
color: '#000000'
},
btncontent: {
backgroundColor: '#59c5b8',
flexDirection: 'row-reverse',
alignItems: 'center',
borderWidth: 0.3,
borderRadius: 5,
marginLeft: 10,
width: '95%',
},
}
remove node module and install again not working.
and clear Xcode and run again but not working.
I read this post NativeBase Button doesn't show text but I don't use padding and still not showing text
You can try TouchableOpacity.
<Left style={{ flex: 0.8 }}>
<TouchableOpacity style={styles.btn} onPress={() => props.myProps.gotoMap([section.YPOINT, section.XPOINT])}>
<Text style={styles.btnText}>
نمایش روی نقشه
</Text>
</TouchableOpacity>
</Left>
I found my mistake in styling :
change height style btn in the stylesheet from 10% to 100% !!
thank
In my screen, I need to split the text into column view and need to align the right side text with the left side text. also, need to show the whole text line by line. Tested with giving some height, width, position: absolute but didn't work. Any idea how to solve this?
I'll post my current code and screenshot for your ref.
Many thanks for your help
<View style={styles.twoCol}>
<View style={styles.leftField}>
<Text style={styles.leftFieldTitle}>Location:</Text>
</View>
<View style={styles.locationRightSide}>
<Text style={styles.rightFieldTitle}>{location}</Text>
</View>
</View>
const styles = StyleSheet.create({
twoCol: {
alignItems: 'center',
flexDirection: 'row',
marginTop: 25,
},
leftField: {
alignItems: 'flex-end',
width: '25%',
},
leftFieldTitle: {
fontWeight: '700',
color: 'black'
},
},
locationRightSide: {
width: '70%',
alignItems: 'flex-start',
paddingLeft: 10
},
rightFieldTitle: {
fontSize: RF(2.8),
color: 'black'
},
)}
Problem solved!!! Thanks everyone!
<View style={{
padding: 10,
flexDirection: "row",
marginLeft: 10,
marginRight: 5,
marginTop: 5,
marginBottom: 3,
justifyContent: "flex-start",
width: '95%',
}} >
<View style={{
position: 'absolute',
marginTop: 10
}}>
<Text style={styles.leftFieldTitle}>Location:</Text>
</View>
<View style={{ marginLeft: '26%' }}>
<Text style={styles.rightFieldTitle}>{location}</Text>
</View>
</View>