React Native. Lagged scroll animation in ScrollView - reactjs

When I scroll vertically up and down, animation starts lagging in the first two components (CompetitionsList, CampList) after the slider (BannerSwiper). I couldn’t fix it. I tried using Animation.ScrollView with "UseNativeDriver: true", but it didn’t help. Something might be wrong with css.
Here is a gif of screen:
https://i.yapx.ru/DT9CR.gif
This is my code:
export default class HomeComponent extends React.Component {
render() {
return (
<View style={styles.container}>
<ScrollView >
<BannerSwiper/>
<CompetitionsList home={true} {...this.props}/>
<CustomDivider/>
<CampList home={true} {...this.props}/>
<CustomDivider/>
<NewsComponent home={true} {...this.props}/>
<CustomDivider/>
<AthletesBirthdayList {...this.props}/>
<CustomDivider/>
<RatingsBlock/>
<CustomDivider/>
<SocialBlock/>
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f2f2f2',
}
});
export default class CompetitionsList extends React.Component {
...
render() {
const {
compListForHome
} = this.props.competitions;
return (
<View style={styles.homeContainer}>
<View style={styles.headerContainer}>
<Text style={[styles.header, {marginRight: 'auto'}]}>СОРЕВНОВАНИЯ</Text>
<Text
style={[styles.header, {marginLeft: 'auto', color: '#2f95dc'}]}
onPress={() => this.props.routing('navigate', 'Competitions')}
>ВСЕ</Text>
</View>
<View style={{alignItems: 'center'}}>
<View style={styles.contentContainer}>
<ScrollView
style={{flex: 1}}
horizontal={true}
showsHorizontalScrollIndicator={false}>
<AnimatedComponent>
<View style={styles.cardContainer}>
<View style={styles.cardWrapper}>
{
compListForHome.map(event =>
<TouchableWithoutFeedback key={event.id} onPress={() => console.log(event.id)}>
<Card
containerStyle={styles.cardWidth}
title={
<View style={styles.cardTitleStyleContainer}>
<Text numberOfLines={1} style={styles.cardTitleStyleText}>{event.name}</Text>
</View>
}
imageStyle={styles.image}
image={event.URL_logo? {uri: event.URL_logo} : SP_IMAGE}>
<View style={styles.cardLabeledContainer}>
<Text style={styles.cardTextLabeled} numberOfLines={1}>{dateFormatter(event.start_date)}</Text>
<Text style={styles.cardTextLabeled} numberOfLines={1}>{dateFormatter(event.end_date)}</Text>
</View>
<Text style={styles.cardText} numberOfLines={1}>{getFullCourseNameByCode(event.course)}</Text>
<Text style={styles.cardText} numberOfLines={1}>{getFullCompetitionStatusByCode(event.status)}</Text>
{
event.reg_status
? <Text style={styles.cardText} numberOfLines={1}>Регистрация: {getFullRegistrationStatusByCode(event.reg_status)}</Text>
: null
}
</Card>
</TouchableWithoutFeedback>
)
}
</View>
</View>
</AnimatedComponent>
</ScrollView>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
spinContainer: {
height: 50
},
overlay: {
flex: 1,
position: 'absolute',
bottom: 10,
width: SCREEN_WIDTH,
justifyContent: 'center',
alignItems: 'center'
},
filterBtn: {
backgroundColor: '#2f95dc',
alignSelf: 'center'
},
homeContainer: {
flex: 1,
marginHorizontal: 50
},
fullListContainer: {
flex:1
},
headerContainer: {
flex: 1,
flexDirection: 'row',
width: SCREEN_WIDTH-80
},
header: {
fontSize: 17,
color: 'rgba(96,100,109, 1)',
lineHeight: 24,
marginTop: 15
},
contentContainer: {
flex: 1,
marginTop: 10,
width: SCREEN_WIDTH
},
cardContainer: {
flex: 1,
flexDirection: 'column',
marginRight: 10
},
cardWrapper: {
flex: 1,
flexDirection: 'row'
},
cardTitleStyleContainer: {
padding: 20,
marginBottom: 15,
borderTopStartRadius: 5,
borderTopEndRadius: 5,
backgroundColor: "#2f95dc",
alignItems: 'center'
},
cardTitleStyleText: {
fontSize: 16,
lineHeight: 24,
color: '#fff',
fontWeight: 'bold'
},
cardWidth: {
width: 250,
height: 360,
borderWidth: 1,
borderRadius: 6,
borderColor: '#ddd',
shadowColor: '#000',
shadowOffset: { width: 5, height: 5 },
shadowOpacity: 0.8,
shadowRadius: 5,
elevation: 4,
marginBottom: 7
},
image: {
width: 100,
height: 100,
borderRadius: 100,
overflow: 'hidden',
alignSelf: 'center'
},
cardText: {
color: 'rgba(96,100,109, 0.8)',
fontSize: 14,
lineHeight: 14,
alignSelf: 'center',
marginBottom: 10
},
cardLabeledContainer: {
backgroundColor: 'rgba(0,0,0,0.05)',
borderRadius: 3,
marginTop: 10,
marginBottom: 20,
marginHorizontal: 30,
padding: 5
},
cardTextLabeled: {
alignSelf: 'center',
fontSize: 15,
color: 'rgba(96,100,109, 0.8)'
}
});
Thank you for your help!

Related

Centering content in the middle of the screen in a react native application

i want to center my view at the center of the screen but its unable am using justifyContent: 'center',
alignItems: 'center', but its all unable to put the contents at the middle of the screen i want the content to go to middle of the screen
i want the buttons and the inputs all to be at the middle of the screen .
i have tried to align but its unable to
import React, {useState, useEffect, useContext} from 'react';
import UserContext from './useContextStore';
import {
Text,
View,
Button,
TextInput,
StyleSheet,
TouchableOpacity,
Platform,
} from 'react-native';
import AsyncStorage from '#react-native-async-storage/async-storage';
import auth from '#react-native-firebase/auth';
import DataViewDoc from './view';
const PhoneInput = ({navigation}) => {
const [number, setNumber] = useState({number: ''});
const [value, loadedVal] = useState({value: true});
const [screenDaetail, setScreenDaetail] = useState(true);
const [waiting, setwaiting] = useState(false);
const [code, setCode] = useState({code: '', number: ''});
const [confirm, setConfirm] = useState(null);
const [codee, setCodee] = useState('');
// let num;
const getNumber = (val) => {
setNumber({number: val});
};
const getCode = (val) => {
setCode({code: val, number: number.number});
};
//firebase**************************************************************************
async function signInWithPhoneNumber(phoneNumber) {
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
console.log('confirmation code is ', confirmation);
setConfirm(confirmation);
}
async function confirmCode() {
try {
await confirm.confirm(codee).then(() => {
console.log('logged in');
// setScreenDaetail(!screenDaetail);
navigation.navigate('codeForma');
});
} catch (error) {
console.log('Invalid code.');
}
}
return (
<View styles={style.container}>
{confirm ? (
<>
<View styles={style.content}>
<Text style={style.TextStyle1}>Enter Valid Code </Text>
</View>
<View style={style.viewForText}>
<TextInput
style={style.textinput}
onChangeText={(text) => setCodee(text)}
secureTextEntry={true}
maxLength={13}
value={codee}
/>
</View>
<View style={style.viewForSend}>
<TouchableOpacity
style={style.SubmitButtonStyle}
activeOpacity={0.1}
onPress={() => {
// sendPhoneCodeTwillio();
confirmCode();
}}>
<Text style={style.TextStyle}> SEND</Text>
</TouchableOpacity>
<TouchableOpacity
style={style.SubmitButtonStyle2}
activeOpacity={0.1}
onPress={() => {
// sendPhoneTwilio();
setConfirm(null);
}}>
<Text style={style.TextStyle}> Back </Text>
</TouchableOpacity>
</View>
</>
) : (
<>
<View styles={style.content}>
<Text style={style.TextStyle1}>Enter Phone number </Text>
</View>
<View style={style.viewForText}>
<TextInput
style={style.textinput}
onChangeText={(text) => {
getNumber(text);
}}
maxLength={13}
value={number.number}
/>
</View>
<View style={style.viewForSend}>
<TouchableOpacity
style={style.SubmitButtonStyle}
activeOpacity={0.1}
onPress={() => {
signInWithPhoneNumber(number.number);
}}>
<Text style={style.TextStyle}> SEND </Text>
</TouchableOpacity>
<TouchableOpacity
style={style.SubmitButtonStyle2}
activeOpacity={0.1}
onPress={() => {
signInWithPhoneNumber(number.number);
}}>
<Text style={style.TextStyle}> RESEND </Text>
</TouchableOpacity>
</View>
</>
)}
</View>
);
};
const style = StyleSheet.create({
container: {
flex: 1,
// paddingBottom: Platform.OS === 'android' ? 50 : 0,
justifyContent: 'center',
alignItems: 'center',
},
textinput: {
margin: 25,
borderColor: '#7a42f4',
borderWidth: 5,
borderRadius: 35,
color: 'black',
textAlign: 'center',
fontFamily: 'Cochin',
fontSize: 20,
fontWeight: 'bold',
},
viewForText: {width: 250, alignSelf: 'center'},
viewForSend: {
width: 400,
// alignSelf: 'baseline',
borderRadius: 20,
margin: 10,
flexDirection: 'row',
justifyContent: 'center',
alignSelf: 'center',
},
content: {
// justifyContent: 'center',
// // alignItems: 'flex-start',
flex: 2,
justifyContent: 'flex-end',
marginBottom: 36,
},
topTierblack: {
backgroundColor: 'black',
borderRadius: 100,
width: 300,
marginLeft: 40,
opacity: 0.5,
},
topTierRed: {
backgroundColor: 'red',
borderRadius: 100,
width: 300,
marginLeft: 40,
},
topTierGreen: {
backgroundColor: 'green',
borderRadius: 100,
width: 300,
marginLeft: 40,
opacity: 0.5,
},
viewForSend2: {
width: 200,
alignSelf: 'flex-end',
borderRadius: 20,
// margin: 10,
},
buttonContainer: {
width: '40%',
alignSelf: 'center',
marginVertical: 30,
color: 'red',
borderRadius: 10,
},
SubmitButtonStyle: {
marginTop: 10,
paddingTop: 15,
paddingBottom: 15,
marginLeft: 30,
marginRight: 30,
backgroundColor: '#00BCD4',
borderRadius: 10,
borderWidth: 1,
borderColor: '#fff',
shadowOpacity: 0.5,
shadowColor: 'blue',
height: 50,
width: 100,
},
SubmitButtonStyle2: {
marginTop: 10,
paddingTop: 15,
paddingBottom: 15,
marginLeft: 30,
marginRight: 30,
backgroundColor: 'black',
borderRadius: 10,
borderWidth: 1,
borderColor: '#fff',
shadowOpacity: 0.5,
shadowColor: 'blue',
height: 50,
width: 100,
},
TextStyle: {
color: '#fff',
textAlign: 'center',
},
TextStyle1: {
color: 'black',
textAlign: 'center',
fontFamily: 'Cochin',
fontSize: 20,
fontWeight: 'bold',
},
});
export default PhoneInput;
Remove the marginRight from SubmitButtonStyle and the marginLeft from SubmitButtonStyle2 and you should be fine.

Why my horizontal ScrollView is not working?

I´m trying without success to use the ScrollView component in React Native, below the code:
const width_proportion = '97%';
const height_proportion = '75%';
const styles = StyleSheet.create({
container: {
height: '100%'
},
image: {
flex: 1,
resizeMode: "cover",
justifyContent: "center"
},
text: {
color: "grey",
fontSize: 30,
fontWeight: "bold"
},
popup: {
color: '#CA0',
},
box: {
width: width_proportion,
height: height_proportion,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'steelblue',
// position: "absolute",
marginTop: '5%',
marginBottom: '3%',
marginLeft: '2%'
},
bottomBox: {
width: '97%',
height: 125,
backgroundColor: 'steelblue',
marginLeft: '2%',
marginBottom: 10,
marginTop: 5,
padding: 5
}
});
const MyTheme = {
colors: {
...DefaultTheme.colors,
background: '#EFA',
primary: '#000',
text: '#000',
},
};
function HomeScreen({ navigation }) {
return (
<View style={styles.container}>
<View style={{ width: '100%', height: 50, backgroundColor: 'steelblue' }}>
<TouchableOpacity onPress={() => navigation.toggleDrawer()}>
<Image source={hamburgerMenu} style={{ height: 45, width: 45, alignItems: 'center' }}>
</Image>
</TouchableOpacity>
</View>
<ImageBackground source={imgBackground} style={styles.image}>
<View style={styles.box}>
</View>
<ScrollView horizontal={true} >
<View style={styles.bottomBox}>
</View>
<View style={styles.bottomBox}>
</View>
<View style={styles.bottomBox}>
</View>
</ScrollView>
</ImageBackground>
</View >
);
}
When I set the horizontal property to "true" from ScrollView, the component disappears. Only I set horizontal to "false" and the ScrollView workks fine in Vertical.
wrap your scrollview like this
<ScrollView horizontal={true}>
<View style={styles.bottomBox} />
<View style={styles.bottomBox} />
<View style={styles.bottomBox} />
</ScrollView>
bottomBox : {
width: 40,
height: 125,
backgroundColor: 'steelblue',
padding: 5,
marginRight: 10,
}

react native video component is not showing?

Problem:
I have created a react component which is including a video that uses react native video library. But unfortunately, it is not showing a video component. This is how my code is.
import React, {createRef, useState} from 'react';
import {
View,
Image,
TouchableOpacity,
TouchableWithoutFeedback,
} from 'react-native';
import Icon from 'react-native-vector-icons/AntDesign';
import AppText from '_components/appText';
import Video, {
OnSeekData,
OnLoadData,
OnProgressData,
} from 'react-native-video';
import {strings} from '_translations/i18n';
import PlayerControls from '_components/playerControls';
const navigateToCameraView = (navigation) => {
navigation.navigate('videorecording');
};
const showControls = (state, setState) => {
state.showControls
? setState({...state, showControls: false})
: setState({...state, showControls: true});
};
const playVideo = (state, setState) => {
console.log('Hiii>>>>>>>>');
setState({...state, showControls: false, play: true});
};
const VideoPreview = (props) => {
const {styles, navigation, fileName} = props;
const [state, setState] = useState({
fullscreen: false,
play: false,
currentTime: 0,
duration: 0,
showControls: true,
});
const player = createRef();
return (
<View style={styles.previewInnerContainer}>
{fileName ? (
<>
<View style={styles.videoContainer}>
<View style={styles.videoInnerContainer}>
<TouchableWithoutFeedback
onPress={() => showControls(state, setState)}>
<View>
<Video
source={{uri: fileName}}
controls={false}
style={styles.backgroundVideo}
ref={player}
resizeMode={'contain'}
paused={!state.play}
/>
{state.showControls && (
<View style={styles.controlsOverlay}>
<View style={styles.wrapper}>
<TouchableOpacity
style={styles.touchable}
onPress={() => playVideo(state, setState)}>
<Image
source={require('_assets/img/play1.png')}
resizeMode="center"
style={styles.playIcon}
/>
</TouchableOpacity>
</View>
</View>
)}
</View>
</TouchableWithoutFeedback>
</View>
</View>
<View style={styles.videoBottomText}>
<TouchableOpacity onPress={() => navigateToCameraView(navigation)}>
<View style={styles.updateAgainContainer}>
<Icon name="reload1" style={styles.reloadIcon} />
<AppText styles={styles.reloadText}>
{strings('assetsment.reload')}
</AppText>
</View>
</TouchableOpacity>
</View>
</>
) : (
<>
<TouchableOpacity onPress={() => navigateToCameraView(navigation)}>
<Image
source={require('_assets/img/cmerap.png')}
resizeMode="center"
style={styles.camPImage}
/>
</TouchableOpacity>
<AppText styles={styles.camPText}>Tap to capture video</AppText>
</>
)}
</View>
);
};
export default VideoPreview;
I have embedded it in another component like this.
<View style={styles.questionsInnerContainer}>
<View style={styles.questionTitleView}>
<AppText styles={styles.questionTitle}>
{strings('assetsment.question', {id: question.questionId})}
</AppText>
</View>
<View style={styles.questionTextContainer}>
<AppText styles={styles.questionText}>{questionTitle}</AppText>
</View>
</View>
<View style={styles.previewContainer}>
<VideoPreview
styles={styles}
navigation={navigation}
fileName={fileName}
/>
</View>
This is my styling sheet.
patientView: {
flex: 1,
backgroundColor: '#ffffff',
flexDirection: 'column',
},
top: {
height: '10%',
},
updateAgainContainer: {
flexDirection: 'row',
// backgroundColor: 'red',
},
reloadIcon: {
fontSize: normalize(15),
color: '#417505',
fontWeight: '600',
textAlign: 'center',
},
questionsContainer: {
height: '78%',
// backgroundColor: '#f2f2f2',
// elevation: 5,
shadowColor: '#000',
shadowOffset: {width: 0, height: 4},
shadowOpacity: 0.8,
shadowRadius: 8,
flex: 1,
},
hr: {
marginTop: '5%',
borderBottomColor: '#c3c3c3',
borderBottomWidth: 2.0,
marginRight: 30,
marginLeft: 30,
justifyContent: 'center',
},
bottom: {
height: '7%',
justifyContent: 'center',
alignItems: 'center',
},
patientBottomView: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
patientBottomContainerText: {
fontSize: normalize(13),
color: '#444444',
fontWeight: '500',
},
bottomLinkText: {
fontSize: normalize(13),
color: '#484848',
borderBottomWidth: 2,
borderBottomColor: '#c3c3c3',
},
imageContainer: {
height: '30%',
justifyContent: 'center',
alignItems: 'center',
paddingTop: '25%',
},
questionsInnerContainer: {
height: '30%',
paddingRight: '5%',
paddingLeft: '3%',
paddingTop: '5%',
},
btnContainer: {
paddingLeft: '5%',
paddingRight: '5%',
marginBottom: '12%',
justifyContent: 'center',
},
emtyView: {
height: '5%',
},
img: {
width: '50%',
resizeMode: 'contain',
},
questionTitleView: {
paddingBottom: '2%',
position: 'relative',
},
questionTitle: {
color: '#444444',
fontSize: normalize(11),
fontWeight: '600',
},
questionTextContainer: {
backgroundColor: '#d1e5ff',
paddingTop: '6%',
paddingBottom: '6%',
paddingLeft: '4%',
borderRadius: 10,
},
questionText: {
fontSize: normalize(13),
color: '#444444',
fontWeight: '700',
},
questionsLodder: {
width: '20%',
height: '20%',
alignSelf: 'center',
justifyContent: 'center',
marginTop: '50%',
},
previewContainer: {
height: '50%',
marginLeft: '10%',
marginRight: '10%',
// alignItems: 'center',
marginBottom: '2%',
},
previewInnerContainer: {
flex: 1,
},
camPImage: {
alignSelf: 'center',
marginTop: '-15%',
},
camPText: {
color: '#444444',
fontSize: normalize(13),
fontWeight: '600',
marginTop: '-25%',
textAlign: 'center',
},
answersContainer: {
flex: 1,
paddingLeft: '8%',
paddingRight: '8%',
},
answerContentContainer: {
flexDirection: 'row',
paddingBottom: '5%',
paddingTop: '2%',
paddingLeft: '5%',
paddingRight: '5%',
},
answerTextContainer: {
flex: 1,
},
sendButton: {
flex: 1,
backgroundColor: '#3e92ff',
paddingTop: 10,
paddingBottom: 10,
alignItems: 'center',
borderRadius: 50,
marginTop: 25,
marginBottom: 20,
justifyContent: 'center',
},
sendButtonText: {
fontFamily: 'Montserrat-Medium',
color: '#ffffff',
fontWeight: '300',
fontSize: normalize(15),
textAlign: 'center',
letterSpacing: 2,
},
bimage: {
width: 25,
height: 25,
},
toggle: {
transform: [{scaleX: 1.6}, {scaleY: 1.6}],
elevation: 90,
shadowColor: '#000000',
shadowOffset: {width: 0, height: 3},
shadowOpacity: 0.9,
shadowRadius: 50,
},
answerText: {
color: '#444444',
fontWeight: '600',
fontSize: normalize(13),
},
backgroundVideo: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
videoContainer: {
height: '70%',
},
videoInnerContainer: {
flex: 1,
backgroundColor: '#b8b8b8',
},
videoBottomText: {
height: '20%',
alignItems: 'center',
justifyContent: 'center',
},
reloadText: {
textAlign: 'center',
marginLeft: '5%',
color: '#417505',
fontWeight: '600',
fontSize: normalize(14),
},
reloadTextContainer: {
flex: 1,
},
controlOverlay: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
justifyContent: 'space-between',
alignItems: 'center',
},
wrapper: {
paddingHorizontal: 5,
marginTop: '28%',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-evenly',
flex: 3,
},
touchable: {
padding: 5,
},
playIcon: {
// backgroundColor: '#b8b8b8',
},
I tried a lot to find out what is wrong with this. But i was unable to do so. Can someone help me to find out a solution to this problem ?. If someone can help me it is really really appreciated as I am completely help less with this.Thank you

ReactNative: View *behind* ScrollView

I have a View (containing an Icon and Text, to act as a big checkbox) which is placed above a ScrollView, however, the ScrollView is appearing in front of the View, and also the Text isn't displaying.
I've tried every combination of flex, sometimes ending up with both of them taking up half the screen.
The Icon/Text works fine on other screens.
this shows the view behind the scrollview, rather than neatly above it, with some margin.
this is what it looks like on another screen, fine with margins, etc.
export default StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
marginTop: 20,
marginBottom: 20,
backgroundColor: 'white',
},
scrollview: {
width: '100%',
paddingTop: 10,
paddingBottom: 10,
},
heading: {
fontSize: 36,
textAlign: 'center',
marginLeft: 20,
marginRight: 20,
},
subheading: {
fontSize: 20,
textAlign: 'center',
marginLeft: 20,
marginRight: 20,
},
});```
<View style={ style.container }>
<Text style={ style.heading }>{ this.state.list && this.state.list.name || 'My Gift List' }</Text>
{ this.state.list.date ? <Text style={ [ style.subheading, { marginTop: 5, marginBottom: 10 } ] }>{ formatDate( dateFromIso( this.state.list.date ), "%A %eth %B, %Y" ) }</Text> : null }
<View style={{ flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', marginTop: 10, marginBottom: 20 }}>
<Checkbox icon={ this.state.showTicked ? 'check' : null } onPress={ () => this.setState( { showTicked: ! this.state.showTicked } ) } />
<Text style={{ marginLeft: 10 }} onPress={ () => this.setState( { multiple: ! this.state.multiple } ) }>I would like more than one</Text>
</View>
{
this.state.list.items.length > 0 ?
<ScrollView style={ style.scrollview } >
<FlatList style={ { marginTop: 10, marginBottom: 50, width: "100%", borderTopColor: '#ddd', borderTopWidth: 1 } } data={ this.state.list.items } renderItem={ this.renderItem } />
</ScrollView>
: null
}
</View>```
const Checkbox = args => {
const props = Object.assign( {}, args );
props.containerStyle = Object.assign( { width: 40 }, props.containerStyle || {} );
props.buttonStyle = Object.assign( { backgroundColor: 'transparent', borderWidth: 1, borderColor: '#555', height: 40 }, props.buttonStyle || {} );
if ( props.icon )
{
let iconProps = Object.assign( { type: 'font-awesome', name: props.icon , color: "#555555", size: 20 }, props.iconStyle || {} );;
props.icon = <RNEIcon {...iconProps} />
}
return <RNEButton {...props} />
};
I think You just need to change the z index for the scroll view and the regular view in the style sheet
export default StyleSheet.create({
container: {
zIndex: 2,
flex: 1,
alignItems: 'center',
marginTop: 20,
marginBottom: 20,
backgroundColor: 'white',
},
scrollview: {
zIndex: 1,
width: '100%',
paddingTop: 10,
paddingBottom: 10,
},
heading: {
fontSize: 36,
textAlign: 'center',
marginLeft: 20,
marginRight: 20,
},
subheading: {
fontSize: 20,
textAlign: 'center',
marginLeft: 20,
marginRight: 20,
},
});```

React native app doesn`t fill the whole screen

I can't get my app to fill the whole screen. Whatever i do, there is always a white bar on the bottom of the page. It's so strange because it works on some devices but not others. i'm going crazy over this!
Ive tried const { height, width } = Dimensions.get('window'); and setting the app height with that, and it actually worked once, but now i can't get it to work again. ive tried rewrapping everything in different ways, with different views and scrollviews.
ps.: i removed all functions and useless code so it's not too much code, but
here is my code
import React, { Component } from 'react';
import {
View,
Switch,
Text,
TextInput,
TouchableOpacity,
ImageBackground,
Image,
Linking,
StatusBar,
Dimensions,
} from 'react-native';
import { ScaledSheet } from 'react-native-size-matters';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
export default class App extends Component {
constructor() {
super();
};
}
render() {
return (
<View style={styles.container}>
<KeyboardAwareScrollView
keyboardShouldPersistTaps={'always'}
style={styles.teste}
showsVerticalScrollIndicator={false}>
<StatusBar backgroundColor="#50a9f3" />
<ImageBackground source={require('./background.png')} style={styles.imagemBackground}>
<View style={styles.campos}>
<Image
style={{ width: 110, height: 110, alignSelf: 'center' }}
source={require('./logo.png')}
/>
<View style={styles.item}>
<Text style={styles.texto}>M²s do ambiente</Text>
<TextInput
style={styles.inputText}
keyboardType={'phone-pad'}
underlineColorAndroid={'white'}
onChangeText={mQuadrado => this.setState({ mQuadrado })}
/>
</View>
<View style={styles.item}>
<Text style={styles.texto}>Nº de pessoas</Text>
<TextInput
style={styles.inputText}
keyboardType={'phone-pad'}
underlineColorAndroid={'white'}
onChangeText={pessoas => this.setState({ pessoas })}
/>
</View>
<View style={styles.item}>
<Text style={styles.texto}>Nº de eletrodomésticos</Text>
<TextInput
style={styles.inputText}
keyboardType={'phone-pad'}
underlineColorAndroid={'white'}
onChangeText={eqps => this.setState({ eqps })}
/>
</View>
<View style={styles.item}>
<Text style={styles.texto}>Nº de janelas </Text>
<TextInput
style={styles.inputText}
keyboardType={'phone-pad'}
underlineColorAndroid={'white'}
onChangeText={jnls => this.setState({ jnls })}
/>
</View>
<View style={styles.switch}>
<Text style={styles.texto}>Recebe luz solar </Text>
<Switch
style={{ transform: [{ scaleX: 0.9 }, { scaleY: 0.9 }] }}
thumbColor="#ffffff"
trackColor={{ true: '#c0c0c0' }}
value={this.state.switch}
onValueChange={value => this.setState({ switch: value })}
/>
</View>
<View style={styles.input}>
<TouchableOpacity style={styles.opacity} onPress={this.calcular}>
<Text style={styles.textoCalcular}>CALCULAR</Text>
</TouchableOpacity>
</View>
<View style={styles.resultadoBox}>
<Text style={styles.textoResultado}>Você precisará de</Text>
<Text style={styles.resultado}>{btu == '0' ? null : btu + '.000 BTUS'}</Text>
</View>
</View>
<View style={styles.banner}>
<TouchableOpacity
style={styles.bannerContainer}
onPress={() => Linking.openURL('https://matum.com.br/produtos-sisum/')}>
<Text style={styles.bannerTexto}>Gerencie suas manutenções preventivas e corretivas</Text>
<Text style={styles.bannerTexto}>Relatório PMOC simples</Text>
<Text style={styles.bannerTextoX}>Saiba mais</Text>
</TouchableOpacity>
</View>
</ImageBackground>
</KeyboardAwareScrollView>
</View>
);
}
}
const { height, width } = Dimensions.get('window');
const heightCerto = height - StatusBar.currentHeight;
const styles = ScaledSheet.create({
container: {
flex: 1,
},
teste: {
flex: 1,
},
imagemBackground: {
flex: 1,
},
campos: {
flex: 95,
justifyContent: 'flex-start',
alignItems: 'stretch',
padding: '20#s',
paddingTop: '12#s',
},
item: {
flex: 1,
},
switch: {
paddingTop: '15#s',
flexDirection: 'row',
justifyContent: 'flex-start',
flex: 1,
},
textoCalcular: {
fontSize: '15#s',
color: '#ffffff',
textShadowColor: 'black',
textShadowRadius: 2,
},
input: {
padding: '20#s',
alignItems: 'center',
flex: 1,
},
opacity: {
backgroundColor: '#50a9f3',
borderWidth: '1.5#s',
borderRadius: '10#s',
borderColor: '#000000',
width: '190#s',
height: '39#s',
justifyContent: 'center',
alignItems: 'center',
},
resultadoBox: {
flex: 2,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(100,100,100,0.5)',
margin: 0,
borderColor: 'rgba(100,100,100,0.5)',
borderRadius: '10#s',
},
resultado: {
fontSize: '28#s',
color: 'white',
textShadowColor: 'black',
textShadowRadius: 5,
},
banner: {
flex: 10,
backgroundColor: 'rgba(140,140,140,0.5)',
margin: 0,
borderColor: '#50a9f3',
borderWidth: '1.5#s',
borderRadius: '10#s',
alignSelf: 'stretch',
},
bannerContainer: {
alignItems: 'center',
},
bannerTexto: {
color: '#ffffff',
fontSize: '12#s',
},
bannerTextoX: {
color: '#50a9f3',
fontSize: '10#s',
textShadowColor: 'black',
textShadowRadius: 4,
},
inputText: {
fontSize: '12#s',
color: 'white',
textShadowColor: 'black',
textShadowRadius: 5,
height: '38#s',
},
texto: {
fontSize: '13#s',
color: '#ffffff',
textShadowColor: 'black',
textShadowRadius: 5,
},
textoResultado: {
fontSize: '16#s',
color: 'white',
textShadowColor: 'black',
textShadowRadius: 5,
},
});
I think you're talking about the image background but not totally sure. I was able to get it to stretch to the full height by adding the following height declaration:
imagemBackground: {
flex: 1,
height: height,
},
link to example: https://snack.expo.io/r1Y-zpwMH
You are using flex:1 many times in style that is the problem.
please give flex:1 in container style and remove all flex:1 in other styles instead of flex:1 you can use width and height in percentage.
like style={{width:'100%',height:'40%'}}.
Thank you!

Resources