我想要做width: 100% - 50
,所以我可以在右邊添加一個寬度爲50的圖標。反應原生樣式。 width:percent - number
我有width: 100% - 20%
使用react-native-extended-styles工作,但我不明白爲什麼這是有用的,因爲你可以做width: '80%'
。我無法獲得width: 100% - 50
的工作。有沒有辦法?
試圖使用onLayout
事件獲取容器寬度,然後將<autocomplete>
設置爲容器寬度的100% - 50
,但它不起作用。
let Location = (props) => {
let locationInputElement
const blur =() => {
locationInputElement.blur()
}
let inputContainerWidth
return (
<View style={styles.formItem}>
<View
onLayout={(event) => {
inputContainerWidth = event.nativeEvent.layout.width
console.log(inputContainerWidth)
}}
<Autocomplete
data={props.autocompleteResults.predictions}...
style={{
borderRadius: 8,
backgroundColor: 'red',
alignSelf: 'stretch',
paddingLeft: 10,
position: 'relative',
...styles.label,
...styles.labelHeight,
width: inputContainerWidth - 50
}}
/>
</View>
</View>
)
}
它CONSOLE.LOG 335
當它console.logs inputContainerWidth
但<autocomplete>
的寬度是100%還是。
爲什麼不使用flexbox? –
@ViktorSeč就我所知,Flexbox沒有辦法從全寬拿走50個像素。 – BeniaminoBaggins