Skip to content

Instantly share code, notes, and snippets.

@tonysherbondy
Last active July 24, 2016 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonysherbondy/4d4b41d73a3622f93d3b57835b44a32d to your computer and use it in GitHub Desktop.
Save tonysherbondy/4d4b41d73a3622f93d3b57835b44a32d to your computer and use it in GitHub Desktop.
Start of implementing Search Bar in React Native Guide
import React from 'react'
import {
View,
ListView,
Text,
StyleSheet,
} from 'react-native'
import names from './names'
const styles = StyleSheet.create({
container: {
flex: 1,
},
navbar: {
padding: 5,
height: 50,
justifyContent: 'flex-end',
alignItems: 'center',
backgroundColor: 'rgb(222, 222, 222)',
},
navbarText: {
fontWeight: 'bold',
fontSize: 20,
},
list: {
},
row: {
padding: 10,
height: 50,
borderBottomColor: 'gray',
borderBottomWidth: StyleSheet.hairlineWidth,
},
})
class SearchBar extends React.Component {
state = {
dataSource: new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
}),
}
getFilteredData() {
const { dataSource } = this.state
return dataSource.cloneWithRows(names)
}
render() {
const renderRow = row => (
<View style={styles.row}>
<Text>{row}</Text>
</View>
)
return (
<View style={styles.container}>
<View style={styles.navbar}>
<Text style={styles.navbarText}>Top Passwords</Text>
</View>
<ListView
style={styles.list}
dataSource={this.getFilteredData()}
renderRow={renderRow}
/>
</View>
)
}
}
export default SearchBar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment