Reputation: 318
I want to put two view with 4:6 width in my app, and put text inside them.
import React, { Component } from 'react';
import { AppRegistry, View , Text} from 'react-native';
class FixedDimensionsBasics extends Component {
render() {
return (
<View style={{flex:1, flexDirection: "row"}}>
<View style={{flex:0.4, backgroundColor: 'powderblue'}}>
<Text>sfasdfadsfdasfas</Text>
</View>
<View style={{flex:0.6, backgroundColor: 'skyblue'}}>
<Text>sfasdfadsfdasfas</Text>
</View>
</View>
);
}
}
AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
but when I add text in side, it becomes like this
Question: Is there a way to keep the view with fixed width and make text adjust with the width?
Thanks!
p.s. I use the React Native Doc for code example & debug.
Upvotes: 1
Views: 1030
Reputation: 318
So I found an answer. Using flexBasis:0.4
.
import React, { Component } from 'react';
import { AppRegistry, View , Text} from 'react-native';
class FixedDimensionsBasics extends Component {
render() {
return (
<View style={{flex:1, flexDirection: "row"}}>
<View style={{flex:0.4, flexBasis:0.4, backgroundColor: 'powderblue'}}>
<Text>sadfsfsdfasdfdsfasdsadfasdf</Text>
</View>
<View style={{flex:0.6, flexBasis:0.6, backgroundColor: 'skyblue'}}>
<Text>fasddfsadfsaf</Text>
</View>
</View>
);
}
}
AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
Then the view fixed with 0.4 width.
Here is the description for flex-base in CSS CSS trick flex-base
Upvotes: 3