So I've been scratching my head on this for quite a while, and am not sure how to proceed. I'm fairly new to RN (2 Weeks). I'm building this list app. I am using AsyncStorage to set Two Items to True.
Then I check if they are true, and push an item to a list array if its true. If I change the AsyncStorage values, I want to refresh the screen, so I can clear the list and re-push the items that are true.
export default class CheckOut extends React.Component {
constructor() {
super()
this.state = {
refreshing: false,
checked: false,
one: false,
two: false,
list: []
}
}
static navigationOptions = {
header: null,
};
componentDidMount() {
this.setState({"refreshing" : "false"});
AsyncStorage.getItem("one").then((value) => {
this.setState({"one" : value});
if (this.state.one === "true"){
this.state.list.push({
name: 'Butter',
avatar_url: 'https://i.imgur.com/IueK52c.png',
checkbox: 1,
key: 1,
})
}
});
AsyncStorage.getItem("two").then((value) => {
this.setState({"two" : value});
if (this.state.two === "true"){
this.state.list.push({
name: 'Butter Milk',
avatar_url: 'https://i.imgur.com/9SENqe3.png',
checkbox: 2,
key: 2,
})
}
});
}
_onRefresh = () => {
this.setState({"refreshing" : "true"});
}
render() {
return(
<View containerStyle = {{backgroundColor: '#FFF'}}>
<ScrollView containerStyle = {{backgroundColor: '#FFF'}}>
<View>
<ScrollView>
<List containerStyle = {{
flex: 1,
marginTop: 0,
borderTopWidth: 0,
paddingBottom: 10
}}>
{this.state.list.map((l) => (
<ListItem containerStyle = {{ height: 80, paddingTop: 15, borderTopWidth:0, borderBottomWidth: 0.25}}
title={l.name}
/>
))
}
</List>
</ScrollView>
</View>
</ScrollView>
<TouchableOpacity
onPress={() => this._onRefresh}
>
<Icon
name={"refresh"}
size={30}
type='entypo'
color="#FFF"
/>
</TouchableOpacity>
</View>
)
}
}
Sorry for the crappy formatting. But yeah the refresh button is supposed to be inside the touchable opacity. I've tried changing state and forceupdate, but they haven't worked. I want to refresh the component and list, then push to the list again, when I press the refresh button.