Last active
July 24, 2016 03:23
-
-
Save tonysherbondy/4d4b41d73a3622f93d3b57835b44a32d to your computer and use it in GitHub Desktop.
Start of implementing Search Bar in React Native Guide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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