As given in the image, the text 10 shares is on the top left corner. I want to center 10 shares vertically. I have tried some methods to make it come to the center of the yellow view.
JavaScript
x
141
141
1
render() {
2
return (
3
<View
4
style={styles.grandParentView}>
5
<View
6
style={styles.parentView}>
7
<View
8
style={styles.childView}>
9
<Text
10
style={styles.topLeftView}
11
key={'cardTitle'}>
12
{`APPL`}
13
</Text>
14
<Text
15
style={styles.topRightView}
16
key={'cardTitle2'}>
17
{`$1000.00`}
18
</Text>
19
</View>
20
<View
21
style={styles.childView}>
22
<Text
23
style={styles.bottomLeftView}
24
key={'cardTitle3'}>
25
{`10 shares`}
26
</Text>
27
<View
28
style={styles.redView}
29
key={'cardTitle4'}>
30
<Text
31
style={styles.buttonLeftView}
32
key={'cardTitle4'}>
33
{`+$200.00`}
34
</Text>
35
<Text
36
style={styles.buttonRightView}
37
key={'cardTitle4'}>
38
{`+0.02%`}
39
</Text>
40
</View>
41
</View>
42
</View>
43
</View>
44
)
45
}
46
47
48
const styles = StyleSheet.create({
49
grandParentView: {
50
flex: 1,
51
marginTop: 60,
52
alignSelf: 'baseline',
53
flexDirection: 'row'
54
},
55
newView:{
56
flex:1,
57
alignContent: 'center'
58
},
59
parentView: {
60
flex: 1,
61
marginVertical: 5,
62
marginHorizontal: 5,
63
alignSelf: 'baseline',
64
backgroundColor: 'blue',
65
flexDirection: 'column',
66
},
67
childView: {
68
marginVertical: 5,
69
marginHorizontal: 5,
70
paddingHorizontal: 5,
71
backgroundColor: 'green',
72
flexDirection: 'row',
73
alignContent: 'center',
74
justifyContent: 'center'
75
},
76
topLeftView: {
77
flex: 1,
78
color: 'black',
79
marginVertical: 5,
80
marginHorizontal: 5,
81
backgroundColor: 'yellow',
82
alignSelf: 'stretch',
83
textAlign: 'left',
84
paddingLeft: 5
85
},
86
bottomLeftView: {
87
flex: 1,
88
color: 'black',
89
marginVertical: 5,
90
marginHorizontal: 5,
91
backgroundColor: 'yellow',
92
height: 50,
93
alignSelf: 'stretch',
94
textAlign: 'left',
95
paddingLeft: 5
96
},
97
topRightView: {
98
flex: 1,
99
color: 'black',
100
marginVertical: 5,
101
marginHorizontal: 5,
102
backgroundColor: 'red',
103
alignSelf: 'stretch',
104
textAlign: 'right',
105
paddingRight: 5
106
},
107
redView: {
108
flex: 1,
109
flexDirection: 'row',
110
color: 'black',
111
marginVertical: 5,
112
marginHorizontal: 5,
113
backgroundColor: 'red',
114
alignSelf: 'stretch',
115
textAlign: 'right',
116
paddingRight: 5
117
},
118
buttonLeftView:{
119
flex: 6,
120
color: 'black',
121
marginVertical: 5,
122
height: 50,
123
marginHorizontal: 5,
124
backgroundColor: 'cyan',
125
alignSelf: 'stretch',
126
textAlign: 'right',
127
paddingRight: 5
128
},
129
buttonRightView:{
130
flex: 4,
131
color: 'black',
132
height: 50,
133
marginVertical: 5,
134
marginHorizontal: 5,
135
backgroundColor: 'cyan',
136
alignSelf: 'stretch',
137
textAlign: 'right',
138
paddingRight: 5
139
}
140
});
141
I want to center the bottomLeft item (10 shares) vertically. Now it is showing top left in the view. I am new to react-native so I don’t have much experience using flex and alignment. Thanks for the help in advance.
Advertisement
Answer
add textAlignVertical property and set it to center and change textAlign to center in your bottomLeftView
style.
JavaScript
1
13
13
1
bottomLeftView: {
2
flex: 1,
3
color: "black",
4
marginVertical: 5,
5
marginHorizontal: 5,
6
backgroundColor: "yellow",
7
height: 50,
8
alignSelf: "stretch",
9
textAlign: "center",
10
paddingLeft: 5,
11
textAlignVertical: "center"
12
}
13