1. 程式人生 > >react-native 實現微信頭部編寫

react-native 實現微信頭部編寫

react-native 編寫微信頭部要點:

   1、圖示佈局(左右居右、上下居中)

   2、可以點選事件,點選時有個背景色

佈局實現

    1、在react-native中無法使用float、display:inline-block

    2、使用Flexbox(彈性盒子): flex, alignItems,justifyContent

本例通過Flexbox實現圖示佈局

header:{ height: height(150), backgroundColor: '#373a3f', paddingRight: width(70) }, headerTools: { flex:
1, alignItems: 'center', justifyContent: 'flex-end', flexDirection: 'row' },headerIcon:{ alignItems: 'center', justifyContent: 'center', width: height(150), height: height(150) }

點選事件

點選事件實現需要使用TouchableHighlight控制元件

<View style={style.header}> <View style={style.headerTools
}> <TouchableHighlight onPress={this.search} > <View style={style.headerIcon}> <Search color={'#fff'}></Search> </View> </TouchableHighlight> <TouchableHighlight onPress={this.create} > <
View style={style.headerIcon}> <Add color={'#fff'}></Add> </View> </TouchableHighlight> </View></View>

最終實現效果