ReactNative入坑 一些常用控件的使用(五)

441 阅读1分钟
button外面要包一个View,才能设置样式

这里是Button的源码, Button除了accessibilityLabel, color, onPress, title, disabled, testID, 这几个属性以外其他属性都不能生效, 需要外面套一个View 才能设置样式 再就是Button里面只有个自带的Text,自己往Button里塞的子控件不会显示的

TouchableHighlight

TouchableHighlight只能有一个子控件,如果既有文字又有图片等多个控件需要使用View包装一层

如何设置默认props

SectionList的用法


<SectionList
                ListHeaderComponent={<View style={{backgroundColor: "red", height: 40}} ></View>}
                ListFooterComponent={<View style={{backgroundColor: "green", height: 40}} ></View>}
                renderItem={({item, index, section}) => <Text style={{flex: 1, height: 50}}>section:{section.key}----{item.title}----{index}</Text>}
                renderSectionHeader={({section}) => <Text style={{backgroundColor: 'yellow'}}>Header:{section.key}</Text>}
                renderSectionFooter={({section}) => <Text style={{backgroundColor: 'purple'}}>Footer:{section.key}</Text>}
                stickySectionHeadersEnabled={false}
                sections={[
                    {
                        key: 's1',
                        data: [
                            {title: '0 item', key: '0'},
                            {title: '1 item', key: '1'},
                            {title: '2 item', key: '2'},
                    ]},
                    {
                        key: 's2',
                        data: [
                            {title: '0 item', key: '0'},
                            {title: '1 item', key: '1'},
                            {title: '2 item', key: '2'},
                            {title: '3 item', key: '3'},
                    ]},
                ]}
            />

其余的属性看官方SectionList文档