代码拉取完成,页面将自动刷新
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
import React, { Component } from 'react'
import {
AppRegistry,
StatusBar,
StyleSheet,
Text,
View,
Alert
} from 'react-native'
import demoList from './data'
import SearchList, { HighlightableText } from './library'
import Touchable from './library/utils/Touchable'
const rowHeight = 40
export default class example extends Component {
constructor (props) {
super(props)
this.state = {
dataSource: demoList
}
}
// custom render row
renderRow (item, sectionID, rowID, highlightRowFunc, isSearching) {
return (
<Touchable onPress={() => {
Alert.alert('Clicked!', `sectionID: ${sectionID}; item: ${item.searchStr}`,
[
{text: 'OK', onPress: () => console.log('OK Pressed')}
],
{cancelable: true})
}}>
<View key={rowID} style={{flex: 1, marginLeft: 20, height: rowHeight, justifyContent: 'center'}}>
{/* use `HighlightableText` to highlight the search result */}
<HighlightableText
matcher={item.matcher}
text={item.searchStr}
textColor={'#000'}
hightlightTextColor={'#0069c0'}
/>
</View>
</Touchable>
)
}
// render empty view when datasource is empty
renderEmpty () {
return (
<View style={styles.emptyDataSource}>
<Text style={{color: '#979797', fontSize: 18, paddingTop: 20}}> No Content </Text>
</View>
)
}
// render empty result view when search result is empty
renderEmptyResult (searchStr) {
return (
<View style={styles.emptySearchResult}>
<Text style={{color: '#979797', fontSize: 18, paddingTop: 20}}> No Result For <Text
style={{color: '#171a23', fontSize: 18}}>{searchStr}</Text></Text>
<Text style={{color: '#979797', fontSize: 18, alignItems: 'center', paddingTop: 10}}>Please search again</Text>
</View>
)
}
render () {
return (
<View style={styles.container}>
<StatusBar backgroundColor='#F00' barStyle='light-content' />
<SearchList
data={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
renderEmptyResult={this.renderEmptyResult.bind(this)}
renderBackButton={() => null}
renderEmpty={this.renderEmpty.bind(this)}
rowHeight={rowHeight}
toolbarBackgroundColor={'#2196f3'}
title='Search List Demo'
cancelTitle='取消'
onClickBack={() => {}}
searchListBackgroundColor={'#2196f3'}
searchBarToggleDuration={300}
searchInputBackgroundColor={'#0069c0'}
searchInputBackgroundColorActive={'#6ec6ff'}
searchInputPlaceholderColor={'#FFF'}
searchInputTextColor={'#FFF'}
searchInputTextColorActive={'#000'}
searchInputPlaceholder='Search'
sectionIndexTextColor={'#6ec6ff'}
searchBarBackgroundColor={'#2196f3'}
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#efefef',
flexDirection: 'column',
justifyContent: 'flex-start'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5
},
emptyDataSource: {
flex: 1,
alignItems: 'center',
flexDirection: 'column',
justifyContent: 'flex-start',
marginTop: 50
},
emptySearchResult: {
flex: 1,
alignItems: 'center',
flexDirection: 'column',
justifyContent: 'flex-start',
marginTop: 50
}
})
AppRegistry.registerComponent('example', () => example)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。