I want to position 2 components underneath each other. My component looks like this :
import React from 'react';
import {connect} from 'react-redux';
import {Text, StyleSheet, View, ListView, Switch, TextInput} from 'react-native';
import {List, ListItem} from 'native-base';
import SearchBar from '../shared/search-bar';
const mapStateToProps = (state) => {
return {
movies: state.movies.movies
};
};
const mapDispatchToProps = (dispatch) => {
return {};
};
const Component = ({movies}) => {
return (
<View style={styles.container}>
<SearchBar style={styles.searchBarContainer}/>
<List
style={styles.list}
dataArray={movies}
renderRow={movie => <ListItem><Text>{movie.title}</Text></ListItem>}
/>
</View>
);
};
let styles = StyleSheet.create({
container: {
flexDirection: 'column',
flex: 1,
},
searchBarContainer: {
flex: 0
},
list: {
flex: 1
}
});
export default connect(mapStateToProps, mapDispatchToProps)(Component);
For some reason, when they are rendered, the list is just rendered over the searchbar. Why does the flexDirection:'column' not position them underneath each other?
I feel like I'm missing something about the flexbox layout.
The overlapping CSS property in react js allows you to tell the browser that a line of text inside the targeted element can be broken into numerous lines at an ordinarily unbreakable location. This prevents a particularly long string of text from producing layout issues due to overflow.
Wrap both of your components inside the <SafeAreaView/> component which React Native provides. The BottomContainer wraps the content of the scroll view. I have assigned the Image Height to 450px. This can vary depending upon the design and screen dimensions.
zIndex is the Expo and React Native analog of CSS's z-index property which lets the developer control the order in which components are displayed over one another.
position in React Native is similar to regular CSS, but everything is set to relative by default, so absolute positioning is always relative to the parent. If you want to position a child using specific numbers of logical pixels relative to its parent, set the child to have absolute position.
in your style.container, remove the flex entry but keep the flexDirection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With