Reputation: 365
I have two views. ViewA is fixed size (60 * 60), and remaining space is for ViewB. How can I create these Views in React Native ? The image below is sample view that I want to create.
View code i'd tried:
<View style={{ width: '100%', height: 60, backgroundColor: 'green', flexDirection: 'row' }}>
<View style={{ backgroundColor: 'pink', flex: 2 }}/>
<View style={{ flex: 1, with: 60, height: 60, backgroundColor: 'purple', }}/>
</View>
Upvotes: 0
Views: 44
Reputation: 829
Try with this method
<View style={{flex:1}}>
<View style={{ width: '100%', flex:1, height: 60, backgroundColor: 'green', flexDirection: 'row-reverse', paddingTop: 20 }}>
<View style={{ height: 60,width:60, backgroundColor: 'purple', }}/>
<View style={{ height: 60,backgroundColor: 'pink', alignSelf:'stretch', flex:1 }}>
</View>
</View>
</View>
Check for this in https://snack.expo.io/@saravanansivalingam/top-padding
Upvotes: 0
Reputation: 262
Okay this should work. import Dimensions from react-native.
<View style={{ display: "flex", flexDirection: "row", flex: 1 }}>
<View style={{ width: Dimensions.get("window").width - 60, backgroundColor: "pink" }}></View>
<View style={{ width: 60, height: 60, backgroundColor: "purple" }}></View>
</View>
Upvotes: 1
Reputation: 829
You can use flex for this concept
<View style={{ flex:1, height: 60, backgroundColor: 'green', flexDirection: 'row' }}>
<View style={{ backgroundColor: 'pink', flex: 0.6 }}/>
<View style={{ flex: 0.4, backgroundColor: 'purple', }}/>
</View>
Upvotes: 0
Reputation: 624
Add some padding to the top.
working demo: https://snack.expo.io/Syp9bUrDm
<View style={{ width: '100%', height: 60, backgroundColor: 'green', flexDirection: 'row', paddingTop: 20 }}>
<View style={{ backgroundColor: 'pink', flex: 2 }}/>
<View style={{ flex: 1, width: 60, height: 60, backgroundColor: 'purple', }}/>
</View>
Upvotes: 0