Can't create rounded border with component "ImageBackground" - react-native

I need to create component like
Here is part of my code
<ImageBackground source={{uri}} style={{width: 234, height: 165, marginTop: 10, borderRadius: 10}}>
<Text style={{margin: 10, fontSize: 24, fontWeight: 'bold', color: 'white'}}>
Test
</Text>
<Text style={{marginLeft: 7, marginTop: 80, color: 'white'}}>
<Icons name="distance" size={25} style={{color: 'white'}}></Icons>
<Text style={{color: 'white'}}>
2 KM
</Text>
<Text> </Text>
<Icons name="star" size={25} style={{color: 'white'}}></Icons>
<Text style={{color: 'white'}}>
4.9
</Text>
</Text>
</ImageBackground>
Prop style borderRadius doesn't works with component ImageBackground.
I tried to use various wrappers, but didn't get any results, also I tried to use Image component, but this component cannot contain other components (Text for ex.)

Use this way
<ImageBackground
style={{height: 100, width: 100}}
imageStyle={{ borderRadius: 6}} < -- like this -->
source={{ uri: 'www.imageislocatedhere.com }}
>

Related

React Native Tab bar crashes the android app

This is the code for components and tab bar creation
const Tab = createMaterialTopTabNavigator<DownloadLedgerNavigatorParamList>()
function HomeScreen() {
return (
<View style={{ marginTop: 10, padding: 20 }}>
<Text style={{ fontSize: 18, fontWeight: 'bold' }}>
Material Goods
</Text>
<Text style={{ color: '#00B256', marginTop: 10 }}>
Note:
</Text>
<Text style={{ fontSize: 17, marginTop: 20 }}>
Select Date Range
</Text>
<View style={{ borderWidth: 1, borderColor: '#A0AEC0', height: 40, marginTop: '10' }}>
<Text>Select Date</Text>
</View>
</View>
)
}
function SettingsScreen() {
return (
<View>
<Text>Settings Screen</Text>
</View>
)
}
Now when Home Screen is called, then the app crashes
export function DownloadNavigator() {
return (
<>
<AppGradient style={GRADIENT} />
<Tab.Navigator>
<Tab.Screen name="Aaa" component={HomeScreen} />
<Tab.Screen name="Bbb" component={SettingsScreen} />
</Tab.Navigator>
</>
)
}
But if I call the settings screen in both components then it is working fine. The problem is with HomeScreen only. Is it a bug?
Try this for the HomeScreen. I don't think you can add the styling you are trying to add to Text components. So I would suggest layering them in a View Component. Also in the last View Component, you wrote marginTop: '10' as a string, not a number.
<View style={{ marginTop: 10, padding: 20 }}>
<Text>
Material Goods
</Text>
<View style = {{marginTop: 10}}>
<Text style={{ color: '#00B256'}}>
Note:
</Text>
</View>
<View style = {{marginTop: 20}}>
<Text style={{ fontSize: 17}}>
Select Date Range
</Text>
<View style={{ borderWidth: 1, borderColor: '#A0AEC0', height: 40, marginTop: 10 }}>
<Text>Select Date</Text>
</View>
</View>

ScrollView don't scroll all the way down - React Native

I've had a problem with my ScrollView for a few days, it doesn't want to scroll all the way down. However when I remove the View above the ScrollView, there is no more problem, but that is not what I am trying to do. Using a paddingBottom in the contentContainerStyle doesn't seem like the best solution in my opinion. Do you know how to fix this? And also, the flex: 1 bottom everything disappears.
This is a base on my component
Demo: https://gyazo.com/9e1425b3ebf582112813b02b02750192
<View style={{}}>
<View style={{
paddingBottom: 23,
backgroundColor: '#b61414',
}}>
<SafeAreaView>
<View style={{ justifyContent: 'space-between', flexDirection: 'row', alignItems: 'center', marginLeft: 20, marginRight: 20 }}>
<View>
<View style={{ marginRight: 15 }}></View>
</View>
<View>
<Text maxFontSizeMultiplier={1} style={{ color: '#fff', fontWeight: '500', fontSize: 18 }}>{this.props.loggedIn.pseudonyme}</Text>
</View>
<View>
<TouchableOpacity style={{ paddingBottom: 10, marginTop: 12 }} onPress={() => this._actionProfile()}>
<Icon maxFontSizeMultiplier={1} color="#fff" type="ionicon" name="ios-more" />
</TouchableOpacity>
</View>
</View>
</SafeAreaView>
</View>
<ScrollView>
</ScrollView>
</View>
Thank !

Adapt Webview height depending on the content inside

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.

React native minheight justify content

I try to set a minHeight for a View (half height of a screen) and in this View the items need to be space-between.
Example without space between :
<ScrollView>
<View style={{minHeight:height}>
<View>
<Text style={{textAlign: 'center',fontFamily: 'Roboto',fontStyle: 'normal',fontWeight: 'normal',fontSize: 18,marginTop: 20}}>{contact.name}
</Text>
</View>
<View style={{backgroundColor:'grey', height: 20}}/>
</View>
</ScrollView>
When I try without the space-between , the height of the view is half screen but if i add space-between :
<ScrollView>
<View style={{minHeight:height,justifyContent:'space-between'}}>
<View>
<Text style={{textAlign: 'center',fontFamily: 'Roboto',fontStyle: 'normal',fontWeight: 'normal',fontSize: 18,marginTop: 20}}>{contact.name}
</Text>
</View>
<View style={{backgroundColor:'grey', height: 20}}/>
</View>
</ScrollView>
The height of the view is increase and I don't know why. I want the height is equals to half height if the view can contains the items. And if the items in the view are too big , the height of the view will increase.
How can I solve this ?
I have made an example with expo :
Example
Try to remove justify content. Y ou will understand what I mean.
EDIT
this is my code with the bug :
<View style={{flex:1}}>
<View style={{minHeight:'50%', backgroundColor:'blank',justifyContent: 'space-between'}}>
<Text style={{textAlign: 'center',fontFamily: 'Roboto',fontStyle: 'normal',fontWeight: 'normal',fontSize: 18,marginTop: 20}}>hello </Text>
<View style={{backgroundColor:'grey', height: 20}}/>
</View>
<Text>test</Text>
</View>
The result :
The grey bar should be at the middle on the screen
<ScrollView>
<View style={{minHeight:'50%', backgroundColor:'green'}}>
<Text style={{textAlign: 'center',fontFamily: 'Roboto',fontStyle: 'normal',fontWeight: 'normal',fontSize: 18,marginTop: 20}}>hello
</Text>
</View>
<View style={{minHeight:'50%', backgroundColor:'red'}}>
<Text style={{textAlign: 'center',fontFamily: 'Roboto',fontStyle: 'normal',fontWeight: 'normal',fontSize: 18,marginTop: 20}}>hello1
</Text>
</View>
</ScrollView>
You can set minHeight:'50%' and it will help to divide your component in half screen.
Your Solution:
<View style={{ flex: 1 }}>
<View style={{ minHeight: '50%', backgroundColor: 'green', justifyContent: 'space-between' }}>
<Text style={{ height: 130, textAlign: 'center', fontStyle: 'normal', fontWeight: 'normal', fontSize: 18, marginTop: 0, backgroundColor: 'red' }}>hello </Text>
<Text style={{ height: 130, textAlign: 'center', fontStyle: 'normal', fontWeight: 'normal', fontSize: 18, marginTop: 0, backgroundColor: 'blue' }}>hello </Text>
<Text style={{ height: 130, textAlign: 'center', fontStyle: 'normal', fontWeight: 'normal', fontSize: 18, marginTop: 0, backgroundColor: 'yellow' }}>hello </Text>
<Text style={{ height: 130, textAlign: 'center', fontStyle: 'normal', fontWeight: 'normal', fontSize: 18, marginTop: 0, backgroundColor: 'blue' }}>hello </Text>
<View style={{ justifyContent: 'flex-end', backgroundColor: 'grey', height: 20 }} />
</View>
<Text>test</Text>
</View>

Scrollview not working in right way in react native

render() {
return (
<View style={{ flex: 1}}>
{/*for header*/}
<View style = {{flexDirection:'row',justifyContent:'space-between',alignItems: 'center',width:'100%',height:'10%',backgroundColor: '#BE6507',padding:10}}>
<TouchableWithoutFeedback onPress={() =>this.props.navigation.goBack()}>
<Image style={{width: 25, height: 25}} source={require('../assets/back.png')} />
</TouchableWithoutFeedback>
<View/>
<View/>
{/*main content*/}
<ScrollView style={{padding:20,paddingTop:25 }}>
<View style={{alignItems:'center',marginBottom:20, width:Dimensions.get('window').width * 90 / 100}}>
<Image style={{height:"30%",width:"90%",marginBottom:10}} source={require("../assets/logo.png")}/>
<Text style={{fontSize: 21, color: "black",margin:6,marginBottom:25}}>ADD CARD DETAILS</Text>
<TextInput
value={this.state.nameoncard}
onChangeText={(nameoncard) => this.setState({ nameoncard:nameoncard })}
placeholder={'Name On Card'}
placeholderTextColor={'black'}
style={styles.input}
/>
<TextInput
value={this.state.card_num}
onChangeText={(card_num) => this.setState({ card_num:card_num})}
placeholder={'Card Number'}
placeholderTextColor={'black'}
style={styles.input}
/>
<TouchableOpacity style={{width:'90%',margin:10,backgroundColor:'black',padding:10,borderRadius:5,borderWidth:1,marginTop:20,marginBottom:20,height:45}}>
<Text style={{fontSize: 19,fontWeight: 'bold', color: "white", textAlign:'center'}}>Proceed to Pay</Text>
</TouchableOpacity>
</View>
</ScrollView>
);
In above code firstly i made a header for navigation.I want content below header to be scrollview.But above code does not seems to work and after half side of screen in vertical direction i does not see any views? What i am doing wrong here? How can i make scrollview to work correctly in above code?
You can try scrollEnabled with this.
First of all in your return of render() method you can have just one child. So, wrap the View and the ScrollView in a single View. You've also typos in the first section, look at how you're closing those Views: <View/> instead of </View>.
The correct code should be:
return (
<View style={{ flex: 1 }}>
{/*for header*/}
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
height: '10%',
backgroundColor: '#BE6507',
padding: 10,
}}>
<TouchableWithoutFeedback
onPress={() => this.props.navigation.goBack()}>
<Image
style={{ width: 25, height: 25 }}
source={require('../assets/back.png')}
/>
</TouchableWithoutFeedback>
</View>
{/*main content*/}
<ScrollView style={{ padding: 20, paddingTop: 25 }}>
<View
style={{
alignItems: 'center',
marginBottom: 20,
width: (Dimensions.get('window').width * 90) / 100,
}}>
<Image
style={{ height: '30%', width: '90%', marginBottom: 10 }}
source={require('../assets/logo.png')}
/>
<Text
style={{
fontSize: 21,
color: 'black',
margin: 6,
marginBottom: 25,
}}>
ADD CARD DETAILS
</Text>
<TextInput
value={this.state.nameoncard}
onChangeText={nameoncard =>
this.setState({ nameoncard: nameoncard })
}
placeholder={'Name On Card'}
placeholderTextColor={'black'}
style={styles.input}
/>
<TextInput
value={this.state.card_num}
onChangeText={card_num => this.setState({ card_num: card_num })}
placeholder={'Card Number'}
placeholderTextColor={'black'}
style={styles.input}
/>
<TouchableOpacity
style={{
width: '90%',
margin: 10,
backgroundColor: 'black',
padding: 10,
borderRadius: 5,
borderWidth: 1,
marginTop: 20,
marginBottom: 20,
height: 45,
}}>
<Text
style={{
fontSize: 19,
fontWeight: 'bold',
color: 'white',
textAlign: 'center',
}}>
Proceed to Pay
</Text>
</TouchableOpacity>
</View>
</ScrollView>
</View>
);