2020-10-28

Get Key of nested Array from Flatlist

I have a flatlist that is receiving a friendsArray with the following data structure...

enter image description here

I have a modal that has an onPress function, with that onPress i'd like to get the value of this key. I have the following Code, but usually this code provides me with the key of whatever i just selected in the flatlist... i'd like to get the key of the item selected one level deeper, how do i do this?

Here is App.js

onFriendChatPress = key => {
   let friend = this.state.friendsArray.find(game => { return game.key === key })
}


render(){
return{
    <View>
        <FriendsModal
            onChatPress={() => this.onChatPress()}
            onClosePress={() => this.closeModal()}
            onFriendPress={() => this.onFriendPress()}
            onFriendChatPress={() => this.onFriendChatPress()}
            selGame={this.state.selGame}
            visible={this.state.modalVisible}
            selGame={this.state.selGame}
        />
    </View>
}

Here is FlatList in the FriendsModal

      <FlatList
           style={styles.flatList}
           data={this.props.selGame.friends}
           horizontal={true}
           renderItem={(info) => (
                       <ModalProfileCard
                               displayName={info.item.displayName}
                               image={info.item.image}
                               onFriendPress={() => this.props.onFriendPress(info.item.key)}
                               onFriendChatPress={() => this.props.onFriendChatPress(info.item.key)}
                        />
                       )
                      }
              />

Here is the Card in the modal


function modalProfileCard(props) {
    return (
        <View style={styles.container}>
            <TouchableOpacity onPress={props.onFriendsPress} style={styles.friendInfo}>
                <Image style={styles.profImage} source= />
                <View style={styles.nameContainer}>
                    <Text style={styles.name}>{props.displayName}</Text>
                </View>
            </TouchableOpacity>
            <TouchableOpacity style={styles.button} onPress={props.onFriendChatPress}>
                {buttonText}
            </TouchableOpacity>
        </View >
    )
}


from Recent Questions - Stack Overflow https://ift.tt/34zrG7y
https://ift.tt/35JoyFz

No comments:

Post a Comment