I want to add multiple images behind header with a swiper. I tried implementing this using Native-base and react-native-swiper. However, what was resulted is, as following.
Following is my code
<View style={{flex:1, elevation:2}}>
<Swiper style={StyleSheet.flatten( {backgroundColor: '#fff'})}>
<ImageBackground
source={require('../../img/auth_background.png')}
style={this.styles.backgroundStyle}
imageStyle={this.styles.backgroundImage}
>
<Header style={{
marginTop: StatusBar.currentHeight,
backgroundColor: 'transparent',
justifyContent: 'center',
alignItems: 'center',
}}>
<StatusBar
backgroundColor={Colors.statusBar}
barStyle="light-content"
/>
<Left>
<Button transparent onPress={this.handleBackButtonClick} small={true}>
<Icon name='ios-arrow-back' size={30} color={Colors.textWhite}/>
</Button>
</Left>
<Body/>
<Right/>
</Header>
</ImageBackground>
<ImageBackground
source={require('../../img/auth_background.png')}
style={this.styles.backgroundStyle}
imageStyle={this.styles.backgroundImage}
>
<Header style={{
marginTop: StatusBar.currentHeight,
backgroundColor: 'transparent',
justifyContent: 'center',
alignItems: 'center',
borderBottomWidth: 0, shadowOffset: {height: 0, width: 0},
shadowOpacity: 0, elevation: 0
}}>
<StatusBar
backgroundColor={Colors.statusBar}
barStyle="light-content"
/>
<Left>
<Button transparent onPress={this.handleBackButtonClick} small={true}>
<Icon name='ios-arrow-back' size={30} color={Colors.textWhite}/>
</Button>
</Left>
<Body/>
<Right/>
</Header>
</ImageBackground>
</Swiper>
</View>
I want to fix the header so that it won't also swipe with the images. Can anyone help me with this? Thanks in-advance.
React-Native-Swiper in android will display blank content when swiper height and width aren't shown.
please add fixed height and width to view or to the swiper
Keep your Header outside Swiper and make its position absolute
<Header style={{
marginTop: StatusBar.currentHeight,
backgroundColor: 'transparent',
justifyContent: 'center',
alignItems: 'center',
position:'absolute',
top:0,
left:0
}}>
I found the solution using zIndex and position. I guess there is some issue when using native-base header and container with zIndex.
<View style={{flex: 1}}>
<View style={{flex:1, zIndex: 2, position: 'absolute', marginTop: StatusBar.currentHeight, marginLeft:'2%'}}>
<Button iconLeft transparent>
<Icon name='ios-arrow-back' size={30} color={Colors.textWhite}/>
</Button>
</View>
<View style={{width: '100%', height: '50%', zIndex: 1, position: 'absolute'}}>
<Swiper style={StyleSheet.flatten( {backgroundColor: '#fff',zIndex:1, flex:1})}>
<ImageBackground
source={require('../../img/auth_background.png')}
style={this.styles.backgroundStyle}
imageStyle={this.styles.backgroundImage}
>
</ImageBackground>
<ImageBackground
source={require('../../img/auth_background.png')}
style={this.styles.backgroundStyle}
imageStyle={this.styles.backgroundImage}
>
</ImageBackground>
</Swiper>
</View>
Related
I have a problem where the two materialicons / touchables in the view can't be clicked. (refer to the code section with the View and zIndex.
I may just be nesting the views wrongly.
When i add a zIndex, it fixes for IOS, but dosen't work for Android.
When i remove the ZIndex, it fixes for Android but dosen't work for IOS.
When i remove the whole it works on both, but i lose the
ability to do the space-between as i want to put the icons on the
opposite end of the row.
Would love some advice on why this is the case. Thank you.
<Modal
visible={props.showFilter}
backdropOpacity={0.3}
transparent={true}
animationType={'slide'}
>
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-end',
alignItems: 'center'}}>
<View style={{
backgroundColor:'white',
width: wp('100%'),
height: hp('80%')}}>
>>> <View style={{zIndex:10, flexDirection: 'row', justifyContent: 'space-between'}}>
<TouchableOpacity
onPress={()=> props.close()}
style={{ zIndex:10, paddingHorizontal: 10,top: hp('5%') }} >
<MaterialIcon
name="close"
size={30}
color="#828282"
/>
</TouchableOpacity>
<TouchableOpacity
onPress={()=> props.showHelp(true)}
style={{ zIndex:10, paddingHorizontal: 10,top: hp('5%') }} >
<MaterialIcon
name="help"
size={30}
color="#828282"
/>
</TouchableOpacity>
</View>
<View style={{flex:1, alignItems: 'center', paddingTop: 40,}}>
<Text style ={{ fontSize:wp('3.5%'),
fontFamily: 'Gilroy-Bold',
color: '#4F4F4F',
marginBottom: hp("2%"),}}>Filter</Text>
</View>
</View>
</View>
</Modal>
I took a crash course on flex and solved it using good flex skills then relying on Z-Index
https://medium.com/#ManningBooks/in-depth-styling-with-react-native-and-flexbox-ee1bda2c5b24
<View style={{flex:1}}>
<View style ={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between'}}>
<TouchableOpacity
onPress={()=> props.show(false)}
style={{ flex:1, paddingHorizontal: 10,top: hp('5%') }} >
<MaterialIcon
name="close"
size={30}
color="#828282"
/>
</TouchableOpacity>
<TouchableOpacity
onPress={()=> console.log("onpress")}
style={{ flex:0, paddingHorizontal: 10,top: hp('5%') }} >
<Text
style ={{
color: "#828282",
fontFamily: 'Gilroy-Regular',
textDecorationLine: 'underline',
fontSize:wp('3.5%')}}> Refresh </Text>
</TouchableOpacity>
</View>
<View style ={{flex:8, alignItems: 'center'}}>
<Text style ={{ fontSize:wp('3.5%'),
fontFamily: 'Gilroy-Bold',
color: '#4F4F4F',
marginBottom: hp("2%"),}}>Filter Tags</Text>
<Text style={{
marginBottom: hp("2%"),
color: "#828282",
fontFamily: 'Gilroy-Regular',
fontSize:wp('3.5%'),
width: '80%'
}}>
text
</Text>
</View>
</View>
I'm using native base as my app template and I've been trying to position two button elements above the footer using only flex. Here is how the buttons are positioned currently.
I tried doing justifyContent: flex-end / space-between but the buttons remains far away from the footer.
<Container>
<Header>
<MainHeader />
</Header>
<Content>
<View style={{flex: 1, justifyContent: 'center'}} >
<View style={{ borderBottomColor: 'black', borderBottomWidth: 1, height: 50 }}>
<View style={{ flexDirection: 'row' }}>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Name</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Sales</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Commission</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Payout</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Profit</Text>
</View>
</View>
</View>
{this.renderRow()}
<View style={{ flexDirection: 'column', justifyContent: 'space-between' }} >
<View style={{ flexDirection: 'row', alignSelf: 'stretch', height: 50, justifyContent: 'space-between' }} >
<View style={{flex:1, alignSelf: 'center'}}>
<Button onPress={() => this.share(this.state.response)} title="Share"></Button>
</View>
<View style={{flex:1, alignSelf: 'center'}}>
<Button onPress={() => this.share(this.state.response)} title="Share"></Button>
</View>
</View>
</View>
</View>
</Content>
<Footer>
<MainFooter />
</Footer>
</Container>
I want the share buttons to be at the bottom of the page above the footer.
The reason is basically because everything is inside content which is basically a scrollview. You can't send something to the end of scrollview as it is parent.
You can access the prop of contentContainerStyle of content from native base and then give it style of justifyConent & alignItens -> flex-end.
I hope it'll work.
This will help you.
I am using Webview component in React Native to render HTML content. The problem I am facing is that I cannot make the height variable so it can adapt to any content it has.
return (
<View style={{flex: 1}}>
<Header
containerStyle={{
backgroundColor: 'white',
borderBottomColor: '#dee0e2',
borderBottomWidth: 1
}}
centerComponent={{ text: 'Noticia', style: { color: 'black' } }}
leftComponent={
<TouchableHighlight onPress={() => navigate('homeScreen')}>
<Text style={{color: '#4289f4'}}>AtrĂ¡s</Text>
</TouchableHighlight>
}
/>
<ScrollView style={{padding: 5}}>
<View style={{flexDirection: 'column'}}>
<Text style={{textAlign: 'center', fontSize: 17, fontWeight: 'bold'}}>{noticia[0].titulo}</Text>
<Image style={{width: '100%', height: 200, alignSelf: 'stretch', marginTop: 10}} source={{uri: noticia[0].imagen}} />
<View style={{height: 200, backgroundColor: 'red'}}>
<WebView
source={{html: noticia[0].articulo}}
scalesPageToFit={(Platform.OS === 'ios') ? false : true}
/>
</View>
</View>
</ScrollView>
</View>
);
If I don't give the <View>' that contents ' <Webview>' a height it does show me nothing. Tried already withflex: 1` but nothing changes.
In your parent view (root view directly under return()) style it as
height: '100%',
width: '100%'
It will adopt to any size screen.
I am trying to build a Search component with Textfield with both right view and left view(Images at both end). Text Input wraps itself to the length of the content, so component no covering entire parent width. How to stretch the component so that entire component occupies the full width of parent.
<View
style={{
flexDirection: "row",
height: 40,
alignSelf: "stretch",
backgroundColor: "red"
}}
>
<Image
source={require("./image_assets_rn/search_rn.png")}
style={{ alignSelf: "center" }}
/>
<TextInput
placeholder="Search Jet"
style={{ backgroundColor: "white", alignSelf: "stretch" }}
/>
<Image
source={require("./image_assets_rn/search_rn.png")}
style={{ alignSelf: "center" }}
/>
</View>;
Below is the output. I want to stretch the textfield along the main axis(width)
It can be achieved giving the TextInput flex:1, there is no need to use stretch.
<View style={styles.container}>
<View style={{flexDirection:'row', width: 300, height:40,backgroundColor:'lightgray'}}>
<Image
source={require('./image_assets_rn/search_rn.png')}
style={{ height: 30, width: 20,margin: 5}}
/>
<TextInput
placeholder="Search Jet"
style={{backgroundColor:'white', flex:1}}
/>
<Image
source={require('./image_assets_rn/search_rn.png')}
style={{ height: 30, width: 20, margin:5}}
/>
</View>
</View>
Check it on snack
I recommend you this tutorial to have a grasp on how flexbox works.
Hope it helps!
I just add component flexbox in each component that wrapped in component View. I think it will make every component follow the parent width.
<View style={{ flexDirection:'row',
height:40,
alignSelf:'stretch',
backgroundColor:'red' }}>
<Image source={ require('./image_assets_rn/search_rn.png')}
style={{ flex:1, alignSelf:'center' }}/>
<TextInput placeholder="Search Jet"
style={{ flex:1, backgroundColor:'white',
alignSelf:'stretch' }}/>
<Image source={ require('./image_assets_rn/search_rn.png')}
style={{ flex:1, alignSelf:'center' }}/>
</View>
If you want to learn more about Flexbox maybe you can read on the Official Web ReactNative.
I hope this can help you :))
I can't configure modal height and width using style property. Is there any other way to set modal height and width?
<Modal style={{height: 300, width: 300}}
visible={this.state.isVisible}
onRequestClose={this.closeModal}>
</Modal>
The code above doesn't work.
According to the Modal documentation, there is no style prop to be set.
You can try setting the <View> dimensions inside the <Modal> instead:
<Modal transparent={true}
visible={this.state.isVisible}
onRequestClose={this.closeModal}>
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'}}>
<View style={{
width: 300,
height: 300}}>
...
</View>
</View>
</Modal>
Try adding margin:0 in the style of the <Modal> Component
In the Modal documentation it is not mentioned it but it has a style property.
The following works for me.
<Modal
style={styles.modalContent}
isVisible={this.state.isVisible}
onBackdropPress={this.closeModal}
>
<Component {...componentProps} />
</Modal>
const styles = StyleSheet.create({
modalContent: {
justifyContent: 'center',
alignItems: 'center',
margin: 0
},
});
Only thing that solved it was passing transparent={true} in the Modal props
The following worked for me after i have tried other methods, I had to give the modal some style.
<Modal isVisible={this.state.isModalAddCompanionVisible} >
<Button
block
style={{ marginTop: 20}}>
<Text style={{ color: "white" }} >Add Another Companion</Text>
</Button>
<View style={{backgroundColor: "white", height: 120}}>
</View>
<View style={{flexDirection: 'row'}}>
<Button
block
style={{ marginTop: 0,width: '40%'}} onPress={this._toggleModalAddCompanion.bind(this)} >
<Text style={{ color: "white" }} >Cancel</Text>
</Button>
<Button
block
style={{ marginTop: 0,width: '60%',}} >
<Text style={{ color: "white" }} >Add</Text>
</Button>
</View>
</Modal>