alignItems:决定其子元素沿着侧轴(次轴)的排列方式
justifyContent:决定其子元素沿着主轴的排列方式
width和height:react native指定宽高,其值不能带有单位,纯数字
实现效果如下——使元素相对屏幕水平居中,垂直居中:
代码:
import React from 'react'
import {ActivityIndicator, StyleSheet, Text, View} from 'react-native'
export default class LoadingIcon extends React.Component{
render(){
const {color} = this.props//通过父组件传递过来,控制loading icon和字体颜色
return (
<View style={style.loadWrap}>
<ActivityIndicator size={'large'} color={color}/>
<Text style={{color:color}}>数据获取中...</Text>
</View>
)
}
}
//react native中width和height是不能有单位的,但是可以通过引号来实现宽高100%占比
const style = StyleSheet.create({
loadWrap:{
alignItems: 'center',
justifyContent: 'center',
backgroundColor:'white',
height:'100%',
width: '100%'
}
})
拓展:
可以实现dialog对话框和自定义toast