I want to make hide and show each view which have {param.body} in the list when I onPress the each TouchableOpacity. But all of my list view is hiding and showing when I onPress only one. How can I make only one view hide and show?
I've got the key value in each View.
this is my code
const DOWN_ARROW = require('../assets/images/ic_arr_down.png');
const UP_ARROW = require('../assets/images/ic_arr_up.png');
export default class Schedule extends Component{
constructor(props){
super(props);
this.state = {showbody : true, activeImage : true}
}
toggleBody = () =>{
this.setState({showbody : !this.state.showbody, activeImage : !this.state.activeImage,})
}
data = {
contents: [
{
date: '4/3',
money: '$15000',
body: 'this is component 1',
},
{
date: '4/4',
money: '$200000',
body: 'this is component 2',
},
]
}
render() {
let arrowImage = this.state.activeImage ? DOWN_ARROW : UP_ARROW;
return(
<View style = {styles.container}>
<ScrollView style={{alignSelf: 'stretch'}}>
{
this.data.contents ? this.data.contents.map((param, i) => {
return(
<View>
<View style={styles.dropdown} key={i}>
<Text style={{fontSize: 16}}>{param.date}</Text>
<TouchableOpacity style={{backgroundColor: 'blue'}} onPress={this.toggleBody}>
<Image source={arrowImage}/>
</TouchableOpacity>
</View>
{this.state.showbody ? (<View><Text>{param.body}</Text></View>) : null}
</View>
);
})
: null
}
</ScrollView>
</View>
)
}
}
I expect when I press image on view which key is 1, the view right below that contains {param.body} do hide and show. but all of the view is hide and showing. :(