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

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文档

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容