How to align text with line? - react-native

I want to achieve this below thing. Putting text between two lines. But I am failing to do so far.
.
So far what I achieved is look like this
My code is
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<View
style={{
width: Dimensions.get('screen').width / 2 - 20,
height: 3,
borderStyle: 'solid',
backgroundColor: 'black',
marginBottom: 15,
marginTop: 8,
left: 0,
}}
/>
<Text
style={[
{
fontSize: 18,
padding: 5,
marginBottom: 10,
color: 'black',
},
global.fontNormal,
]}>
{'or'}
</Text>
<View
style={{
width: Dimensions.get('screen').width / 2 - 20,
height: 3,
borderStyle: 'solid',
backgroundColor: 'black',
marginBottom: 15,
marginTop: 8,
right: 0,
}}
/>
</View>
Is there a better way to achieve that?
Suggest me how to achieve that?
Thanks,

Need to add alignItems:'center'
As when you make the flex direction row then the alignitems property aline the content vertically and justifycontents aline items horizontally
<View style={{ flexDirection: 'row', justifyContent: 'space-between', flex:1 , alignItems:'center'}}>
Sample code: https://snack.expo.io/#msbot01/center-line

Related

Touchable Opacity is half way through

My code is the following
My touchable opacity that does the d.onSelect is not being responsive, it only responds to the upper top half around the border, but nothing happens when I press on a players component from the bottom half. can any one explain or help
<>
<TouchableOpacity
onPress={
props.disabled === true
? () => null
: d.onSelect
}
style={{
backgroundColor: 'red'
}}
>
<LinearGradient
colors={[Colors.Player1, Colors.Player2]}
style={{
borderRadius: 10,
margin: 10,
paddingHorizontal: 3,
paddingVertical: 10,
justifyContent: 'center',
alignItems: 'center',
borderColor: Colors.Player1,
borderWidth: 3,
backgroundColor: Colors.NewBlue
}}
>
<ImageBackground
source={require('../assets/frame2.png')}
style={{
height: 40,
width: 40,
justifyContent: 'center',
alignItems: 'center',
overflow: 'hidden'
}}
>
<Image
source={{ uri: d.image }}
style={{
height: '75%',
width: '75%'
}}
resizeMode='contain'
/>
</ImageBackground>
<Text
style={{
textAlign: 'center',
color: '#fff',
textShadowColor:
'rgba(0, 0, 0, 0.75)',
textShadowOffset: {
width: 1,
height: 1
},
textShadowRadius: 1,
fontSize: 9,
fontFamily: 'Montserrat_semi_bold'
}}
>
{d.name && d.name.split(' ', 1)}
</Text>
</LinearGradient>
</TouchableOpacity>
</>
which results in the image
Without knowing all the context or having an expo snack, I'd say you need to ensure you have flex:1 set on the TouchableOpacity component. In addition, assure that the rest of your images fit within that flex:1

Expo crash once put <Text> inside <View> without error

This is the most weird thing in Expo i never face before. I try to design new UI. but this is the first time i face this kind of issue. If i put any hi at the position i mark "HERE", once i open that screen the app will crash without error. then i remove the hi, open back Expo, its ok
Feel free to test my code. I wonder why is this happen. If i put other than such as it works.
Ive tried few times, it is confirm the error cause by only.
Ive tested on several IOS simulator, already restart the simulator even on my iphone SE 2020, it will result the same. Crashed without error
Please help me
<View
style={{
flex: 1,
}}
>
<View
style={{
flexDirection: "row",
backgroundColor: "#3341B0",
height: screenHeight / 7,
justifyContent: "space-evenly",
}}
>
<View
style={{
flexDirection: "row",
backgroundColor: "transparent",
alignItems: "flex-end",
marginBottom: 20,
width: screenWidth / 2,
}}
>
<View
style={{
width: 20,
alignItems: "flex-start",
justifyContent: "flex-start",
}}
></View>
<View
style={{
width: screenWidth,
alignItems: "stretch",
flexDirection: "column",
}}
>
<Text
style={{
fontSize: 20,
fontWeight: "700",
fontStyle: "normal",
color: "white",
}}
>
{username !== "" && <Text>{`Hello ${username}`}</Text>}
</Text>
<Text
style={{
fontSize: 10,
fontWeight: "700",
fontStyle: "normal",
color: "white",
}}
>
Company : Testing
</Text>
</View>
</View>
<View
style={{
flexDirection: "row",
backgroundColor: "transparent",
alignItems: "flex-end",
marginBottom: 20,
width: screenWidth / 2,
}}
>
<Text
style={{
fontSize: 10,
fontWeight: "700",
fontStyle: "normal",
color: "white",
}}
>
Department : Sales and Marketing
</Text>
</View>
</View>
<View
style={{
flexDirection: "row",
backgroundColor: "#3341B0",
alignItems: "flex-start",
width: screenWidth,
height: 250,
}}
>
<View
style={{
flexDirection: "column",
backgroundColor: "white",
alignItems: "flex-start",
width: screenWidth,
height: 250,
borderTopLeftRadius: 20,
borderTopRightRadius: 20,
}}
>
<View
style={{
flexDirection: "row",
backgroundColor: "transparent",
alignItems: "baseline",
marginBottom: 10,
marginTop: 10,
marginLeft: 20,
}}
>
<Text
style={{
fontSize: 15,
fontWeight: "700",
fontStyle: "normal",
color: "black",
}}
>
Work Orders
</Text>
</View>
<View
style={{
flexDirection: "row",
backgroundColor: "transparent",
alignItems: "baseline",
marginBottom: 10,
marginLeft: 10,
marginRight: 10,
marginTop: 10,
}}
>
<View
style={{
width: screenWidth / 3 - 20,
height: 80,
backgroundColor: "#041FFB",
marginLeft: 10,
borderRadius: 5,
alignItems: "center",
justifyContent: "center",
}}
>HERE</View>
<View
style={{
width: screenWidth / 3 - 20,
height: 80,
backgroundColor: "#FBD15F",
marginLeft: 10,
borderRadius: 5,
}}
>HERE</View>
<View
style={{
width: screenWidth / 3 - 20,
height: 80,
backgroundColor: "pink",
marginLeft: 10,
borderRadius: 5,
}}
>
HERE
</View>
</View>
</View>
</View>
</View>

how to add a reset state when user deletes text from otp text inputs using React native otp input?

I have created an OTP screen using react-native-otp-input as follows:
when I enter the code the continue button turns pink as code state is set to the value like follows
but when I try emptying the code inputs the continue button is still pink as the code state is not refreshed
My code for the otp input view and continue button is as follows:
<View style={{alignItems: 'center'}}>
<OTPInputView
style={{width: '90%', height: 40}}
pinCount={5}
codeInputFieldStyle={{
width: 30,
height: 45,
borderWidth: 0,
borderBottomWidth: 1,
borderBottomColor: '#808080',
}}
codeInputHighlightStyle={{
borderBottomColor: '#000',
color: '#000',
borderBottomWidth: 1,
borderWidth: 0,
}}
codeInputFieldStyle={{
color: '#000',
borderBottomColor: '#000',
borderBottomWidth: 1,
borderWidth: 0,
}}
onCodeFilled={(code) => {
setCode(code);
}}
/>
</View>
</KeyboardAvoidingView>
<View style={{alignItems: 'center', justifyContent: 'center'}}>
{code == '' ? (
<TouchableOpacity
style={{
backgroundColor: '#C0C0C0',
width: 250,
height: 50,
alignItems: 'center',
justifyContent: 'center',
borderRadius: 20,
marginTop: '10%',
}}
disabled={true}>
<Text style={{color: 'white', fontSize: 18}}>Continue</Text>
</TouchableOpacity>
) : otpresponseLoading == true ? (
<ActivityIndicator
size="large"
color="#FE017E"
style={{marginTop: '10%'}}
/>
) : (
<TouchableOpacity
style={{
backgroundColor: '#FF1493',
width: 250,
height: 50,
alignItems: 'center',
justifyContent: 'center',
borderRadius: 20,
marginTop: '10%',
}}
onPress={() => onContinueHandlePress()}>
<Text style={{color: 'white', fontSize: 18}}>Continue</Text>
</TouchableOpacity>
)}
</View>
Could anyone please let me know how do I handle the backpress in this dependency? and refresh the state of code when user deletes code?
Any lead would be great, do let me know if anything else is required for better understanding
thank you in advance.
let's try :
<KeyboardAvoidingView>
<View style={{ alignItems: 'center' }}>
<OTPInputView
style={{ width: '90%', height: 40 }}
pinCount={5}
codeInputFieldStyle={{
width: 30,
height: 45,
borderWidth: 0,
borderBottomWidth: 1,
borderBottomColor: '#808080',
}}
codeInputHighlightStyle={{
borderBottomColor: '#000',
color: '#000',
borderBottomWidth: 1,
borderWidth: 0,
}}
codeInputFieldStyle={{
color: '#000',
borderBottomColor: '#000',
borderBottomWidth: 1,
borderWidth: 0,
}}
onCodeChanged={(code) => {
setCode(code);
}}
/>
</View>
</KeyboardAvoidingView>
<View style={{ alignItems: 'center', justifyContent: 'center' }}>
{code.length !== 5 ? (
<TouchableOpacity
style={{
backgroundColor: '#C0C0C0',
width: 250,
height: 50,
alignItems: 'center',
justifyContent: 'center',
borderRadius: 20,
marginTop: '10%',
}}
disabled={true}>
<Text style={{ color: 'white', fontSize: 18 }}>Continue</Text>
</TouchableOpacity>
) : otpresponseLoading == true ? (
<ActivityIndicator
size="large"
color="#FE017E"
style={{ marginTop: '10%' }}
/>
) : (
<TouchableOpacity
style={{
backgroundColor: '#FF1493',
width: 250,
height: 50,
alignItems: 'center',
justifyContent: 'center',
borderRadius: 20,
marginTop: '10%',
}}
onPress={() => onContinueHandlePress()}>
<Text style={{ color: 'white', fontSize: 18 }}>Continue</Text>
</TouchableOpacity>
)}
</View>

design functionality React native

I want user profile pic in half on modal and half on outside of modal
i have tried this
height: PROFILE_DIAMETER,
width: PROFILE_DIAMETER,
borderRadius: PROFILE_DIAMETER / 2,
marginLeft: 20,
top: -20,
flex: 0,
resizeMode: 'cover',
overflow: 'hidden',
transform: [{translateY: translateImageY()}, {scale: imgScale()}, {translateX: translateImageX()}]
}}
want to achieve this design functionality to react-native
<Image style={{width: '100%', zIndex: -1}} source={require('../assets/capa.png')} />
<View style={{
width: '90%',
backgroundColor: 'white',
alignSelf: 'center',
borderRadius: 10,
paddingBottom: 20
}}>
<View style={{
marginTop: -100
}}>
<Avatar
rounded
size='xlarge'
containerStyle={{ alignSelf: "center", marginTop: 20 }}
overlayContainerStyle={{
borderWidth: 1,
borderColor: '#00a9cf',
backgroundColor: 'white'
}}
source={{
uri:
'https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg',
}}
/>
<Text style={{ color: '#383941', fontSize: 22, alignSelf: "center", fontFamily: 'PTSans-Bold' }}>{this.state.name}</Text>
<Text style={{ color: '#79787b', fontSize: 15, alignSelf: "center", fontFamily: 'PTSans-Italic' }}>{this.state.profession}</Text>
</View>
</View>
Observe the image with zindex -1 and the view containing the avatar with the negative marginTop

Vertical centering in React Native doesn't work

I use a ScrollView and I am not able to center an icon in one of inner Views.
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
<ScrollView>
...
<View style={styles.detailRowContainer}>
<View style={{flex: 1}}>
<Text style={styles.label} numberOfLines={1}>
{'Phone Number'}
</Text>
<Text style={styles.value} numberOfLines={1}>
{phone}
</Text>
</View>
<View style={styles.round}>
<TouchableWithoutFeedback onPress={this._onPressPhone}>
<Icon size={22} name="phone" />
</TouchableWithoutFeedback>
</View>
</View>;
...
</ScrollView>
detailRowContainer: {
flexDirection: 'row',
justifyContent: 'center',
flex: 1,
marginTop: 10,
paddingBottom: 10,
borderBottomWidth: 1,
borderBottomColor: Colors.lightGray,
},
label: {
color: Colors.glofoxDark,
marginBottom: 3,
},
value: {
color: Colors.glofoxDark,
fontWeight: '800',
borderBottomWidth: 1,
borderBottomColor: Colors.lightGray,
},
round: {
backgroundColor: Colors.lightBlue,
width: 30,
height: 30,
borderRadius: 30,
overflow: 'hidden',
justifyContent: 'center',
alignItems: 'flex-end',
flexDirection: 'row',
padding: 4,
},
The styles need to be modified in this way.
Right now you're doing
flexDirection: row along justifyContent: center. Since your first child element is taking complete parent flex, therefore it does not show its effect
paddingBottom is given but , for centering an equivalent paddingTop must be given
padding for the round style should be replaced with margin, otherwise it affects the position of the inner elements
alignItems in round , must not be flex-end, it should be replaced with center
Here are the styles that will fix the vertical centering
detailRowContainer: {
flexDirection: 'row',
alignItems: 'center',
flex: 1,
marginTop: 10,
paddingTop: 10,
paddingBottom: 10,
borderBottomWidth: 1,
borderBottomColor: Colors.lightGray,
},
round: {
backgroundColor: Colors.lightBlue,
width: 30,
height: 30,
borderRadius: 30,
overflow: 'hidden',
justifyContent: 'center',
alignItems: 'center',
margin: 4
},