Skip to content

Instantly share code, notes, and snippets.

@VictorKoenders
Created July 10, 2015 07:18
Show Gist options
  • Save VictorKoenders/8e030bda22729c27bc91 to your computer and use it in GitHub Desktop.
Save VictorKoenders/8e030bda22729c27bc91 to your computer and use it in GitHub Desktop.
Memory leak in React-native
/**
* Created by hmxdeveloper on 02/07/15.
*/
var React = require('react-native'),
icons = require('../../utils/icons'),
database = require('../../data/database'),
DatabaseUpdateMixin = require('../../mixins/DatabaseUpdateMixin'),
_ = require('../../translations');
var {
ScrollView,
Text,
View,
TextInput,
ActivityIndicatorIOS,
TouchableHighlight
} = React;
var EmployeeSearchList = React.createClass({
mixins: [DatabaseUpdateMixin],
getInitialState: function () {
return {
search: '',
data: [],
loading: true
};
},
setSearchText: function (text) {
this.setState({
search: text
});
},
loadData: function () {
this.setState({loading: true});
database.employee.search(this.state.search)
.then(data => this.setState({
data: data,
loading: false
}));
},
render: function () {
var list = [];
if (this.state.loading)
{
list.push(<ActivityIndicatorIOS size="large" style={styles.center} key={-1}/>);
}
else if (!this.state.data.length)
{
list.push(<Text style={styles.center} key={-2}>{_('noResults')}</Text>);
}
else
{
this.state.data.forEach(row => {
console.log(row);
list.push(<TouchableHighlight key={row.Oid}>
<Text>
{row.Fullname}
</Text>
</TouchableHighlight>)
});
}
return <View>
<View style={styles.inputContainer}>
<TextInput style={styles.input} onChangetext={this.setSearchText}
onSubmitEnding={this.loadData} returnKeyType="search"
placeholder={icons.search + " Search"} autoCorrect={false}
textAlign="center" autoCapitalize="none" clearButtonMode="always"/>
</View>
<ScrollView key={list.length}>
{list}
</ScrollView>
</View>;
}
});
var styles = React.StyleSheet.create({
inputContainer: {
backgroundColor: 'gray',
padding: 5
},
input: {
height: 30,
width: 230,
backgroundColor: 'white',
borderRadius: 5,
paddingLeft: 10,
paddingRight: 10
},
row: {
width: 240,
borderWidth: 1,
borderColor: 'lightgray',
paddingLeft: 15,
paddingTop: 9,
paddingBottom: 9
},
active: {
backgroundColor: '#4F1B59',
color: 'white'
},
rowText: {
fontSize: 18,
fontWeight: '400',
color: '#6F3B79'
},
center: {
width: 220,
alignSelf: 'center',
//textAlign: 'center'
}
});
module.exports = EmployeeSearchList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment