How can I disable double border on every TouchableOpacity? - css

I'm making an React Native App in which i have 2 buttons/ TouchableOpacity's. When styling these buttons, they both get double border even when explicitly stating 'solid' borderstyle in the respective stylesheets. ( On the attached screenshot the middle button is all white, but when I make the border a different color it is a double one as well ). No where in the whole file have I defined a double borderstyle.
bottom left button stylesheet:
roomsbutton: {
alignItems: 'center',
backgroundColor: '#009DDC',
padding: 5,
borderRadius: 2,
borderWidth: 1,
borderStyle: "solid",
borderColor: 'white',
color: 'white',
}
and its parent view:
<View style={styles.bottom}>
<TouchableOpacity
style={styles.roomsbutton}
onPress={() => Alert.alert('more rooms')}
>
<Text style={styles.roomsbutton} >FIND MORE FREE ROOMS</Text>
</TouchableOpacity>
</View>

You are passing the styles to the <TouchableOpacity> and the <Text> components. So they are both surrounded by the border

You pass style={styles.roomsbutton} to both the TouchableOpacity and the Text components. Each have a solid white border

this is happining because you apply className .roomsbutton two times in a button. once in TouchableOpacity and once in Text.
just remove style={styles.roomsbutton} form Text like below..
<Text>FIND MORE FREE ROOMS</Text>

Related

How can I insert an image into a <Text> React Native component?

<View style={{flexDirection: 'row', flexWrap: 'wrap'}}>
<Text>{'hello1234567890texthello1234567890texthello1234567890texthello1234567890texthello1234567890text'}</Text>
<Icon iconStyle={{ width: 15, height: 15 }} type={Icon.Type.copy} />
</View>
I have a multiline textbox, and I would like to display an image at the end of the textbox prompt, so when the user starts typing it stays on the end of the textbox value.
Text is multi-line.
I want make the icon follow text, as last word of text.

zIndex issue in android for react-native-autocomplete-input

I am running into an issue in my react native app that uses react-native-autocomplete-input. The issue only occurs in android, which, according to the react-native-autocomplete-input has known issues:
Android does not support overflows (#20), for that reason it is
necessary to wrap the autocomplete into a absolute positioned view on
Android. This will allow the suggestion list to overlap other views
inside your component.
I am wrapping the autocomplete in an absolute positioned view, as suggested. And this solves some issues.
However, what's still happening is, if I have two autocomplete fields - one appearing higher on the screen than another, when the first field has the suggestion box open up, overlaying on the screen, if a user clicks on a suggestion that happens to line up with the input field immediately "under" that suggestion, the cursor suddenly jumps to that input field. So this is obviously some kind of zIndex issue.
The thing is, I have tried setting various zIndex values, so that the text field and its container has a lower value than the autocomplete suggestion box, but this is not preventing the behavior I described above from happening.
I have read about elevation in android. Is this something I can use, and if so, how? Any suggestions would be appreciated. Here is the relevant android styling for react-native-autcomplete-input. And list refers to the autocomplete suggestions box that overlays on the screen:
const androidStyles = {
container: {
flex: 1,
position: 'relative',
},
inputContainer: {
marginBottom: 0,
zIndex: -1,
left: 40,
},
input: {
zIndex: -1,
flex: 1,
flexDirection: 'row',
alignSelf: 'flex-start',
justifyContent: 'flex-end',
maxHeight: 200,
fontSize: 15,
borderWidth: 0,
textAlign: 'right',
},
list: {
...border,
backgroundColor: 'white',
borderTopWidth: 1,
margin: 10,
marginTop: 1,
zIndex: 99999,
borderRadius: 15,
width: '65%',
zIndex: 99999,
},
listContainer: {
zIndex: 99999,
}
};

ReactNative Layout Process & how flex impacts it?

I am trying to understand why the below layouts work differently.
Can someone explain how the internal layout process happen, in terms of rules? And why below examples behave differently. Except just saying that this is how it is.
Example1:
return (
<View style = {{borderWidth : 1, borderColor : 'red'}}>
<View style = {{borderWidth : 1, borderColor : 'black'}}>
<Text>TestText</Text>
</View>
</View>
)
This renders the red box around the black box around the Text. Which means that View resizes based on its content. inner view resizes to consider the text, outer view considers inner view(which already has considered inner text to determine its dimensions), hence everything is as expected.
Example2:
return (
<View style = {{borderWidth : 1, borderColor : 'red'}}>
<View style = {{flex:1,borderWidth : 1, borderColor : 'black'}}>
<Text>TestText</Text>
</View>
</View>
)
The text now comes outside both the Views. The inner view still rests inside the outer view though.
Now i tried a little different variation:
Example3:
return <View style = {{borderWidth:1, borderColor:'red', height:10}}>
<View style = {{flex:1, borderWidth:1, borderColor:'black'}}>
<Text>HelloWorld</Text>
</View>
</View>
This one renders a little better, i.e the text atleast seems to start inside both the views. But still not as expected.
Questions i have:
1) in case #2 above, Why does the text flow outside both the views? Whereas inner View still stays inside outer?
Can some content ever go beyond the bounds of its parent View? Shouldn't the parent View expand to contain it, as long as we haven't provided specific dimensions to it?
2)In case #3, things behave a little bit as expected..Text is inside the views somewhat, but still overflows..
3)How does this rendering happen in ReactNative internally & how does it determine the effective heights of these views above?
Example with flex
flex: 1, obligates child to follow parent's height, "Black view" will fill all the space available of the "Red view", which is height:60.
<View style={{ borderColor: "red", height: 60 }}>
<View style={{ borderColor: "black", flex: 1 }}>
<Text>HelloWorld</Text>
...
</View>
</View>
Example without flex:1
Here without flex, "Black view" will occupy all space of its children, it won't matter height of the parent ("Red view").
<View style={{ borderColor: "red", height: 60 }}>
<View style={{ borderColor: "black" }}>
<Text>HelloWorld</Text>
...
</View>
</View>
The thing is in simple terms the outline misbehaves in case of 2nd one , i.e :
<View style = {{borderWidth : 1, borderColor : 'red'}}>
<View style = {{flex:1,borderWidth : 1, borderColor : 'black'}}>
<Text>TestText</Text>
</View>
</View>
Is because the parent View component doesnt have a flex property so it doesnt take up whole the space and since you have added flex:1 in the child View it tries to take up as whole space as its alloted , hence black border Dominates and TestText is below it.
But if you provide flex:1 , to parent View you will see the same structure as it was with no flex given at all. Try :
<View style = {{flex:1,borderWidth : 1, borderColor : 'red'}}>
<View style = {{flex:1,borderWidth : 1, borderColor : 'black'}}>
<Text>TestText</Text>
</View>
</View>
Hope it helps . feel free for doubts

React Native - Responsive image widths (percentages?)

I have a responsive photo grid built within a RN app -
I'd like 3 images to fit across the screen with the respective margin guttering. All images are squares.
I'm after some tips on the best way to achieve this - i'd use percentages in a web build for each image square but understand this isnt a possibility in RN..
This is what I have so Far:
The code basically pulls images out of an array via a map function and adds the grey image upload button at the same size after them as below:
<View style={PhotoStyles.imgThumbnailWrap}>
{this.state.ADImageArray.map((prop, key) => {
return (
<Image
source={{uri: prop, isStatic: true}}
style={PhotoStyles.imgThumbnail}
/>
);
})}
<TouchableOpacity onPress={this.photoAdditional} >
<View style={PhotoStyles.imgThumbAddMore}>
<Image source={require('../images/icons/ico-upload-
photo.png')} style={PhotoStyles.imgThumbnailBtn} />
</View>
</View>
Heres the Styles:
imgThumbnailWrap: {
flex:1,
flexDirection: 'row',
justifyContent: 'flex-start',
flexWrap:'wrap',
},
imgThumbnail: {
backgroundColor:'#f79431',
width:100,
height:100,
margin:8,
},
imgThumbAddMore: {
width:100,
height:100,
margin:8,
backgroundColor: '#e9e9e9',
alignItems:'center',
justifyContent: 'center',
},
As you can see the two image classes (imgThumbnail and imgThumbAddMore) have fixed widths in the above example - i'd like to make them fit in a row of 3 width percentage widths and height based on the width of the parent container (imgThumbnailWrap). Any advice?
You can divide the width of the device and subtract the margin on the outside
import { Dimensions } from "react-native";
const padding = 10
const itemWidth = (Dimensions.get('window').width / 3) - (padding * 4)
Use the itemWidth with both the width and height so you get perfect squares.
This problem can easily solve by using paddingTop, width, and position. Just try the below code.
<View style={{width:'100%',paddingTop:'100%'}}>
<Image source={{uri:url}} style={{position:'absolute',left:0,bottom:0,right:0,top:0,resizeMode:'contain'}} />
</View>

How to put button over row In react-native?

I have text and image in one row. and now I want to put button over the row with exact size of row.
used flexDirection: 'row'
Any help?
You can wrap your text and image inside the TouchableOpacity component
<TouchableOpacity onPress={() => doYourThing()}>
<Text>{yourText}</Text>
<Image source={{}} />
</TouchableOpacity>
If the text and image are already wrapped in a View, you can just replace the View component with the TouchableOpacity component. It takes all the props which View takes.

Resources