8

I am creating an androidTV application and trying to get the current FlatList focused item using TouchableNativeFeedback.

I have tried using "onFocus" to change a state when the FlatList item has focus but when the application rendered it seemed to focus on every item as it was loaded into the FlatList resulting in an error for to many SetState updates. I tried using "()=>" in the onfocus to stop it running at render but this seemed to stop it working completly

<View style={styles.containerItemNow}>
    <TouchableNativeFeedback background={TouchableNativeFeedback.Ripple('#f14621', true)} onFocus={this.UpdateStatus(item.status)} onPress={() => this.downloadfile(item.url)}>
        <View style={styles.containerItemNowSelected}>
            <Text style={{color: 'white'}}>{item.title}</Text>
        </View>
    </TouchableNativeFeedback>
</View>

I was hoping when the users move using there d-pad the item highlights with the ripple effect and runs the onfocus and updates the needed state but this does not happen even when the items ripple effect shows the onfocus does not run

Dude2019
  • 95
  • 9
  • hey why don't you try react native :'react-native-focus-scroll'. i think its better solution for get focus of element. – Mahesh Keshvala Feb 19 '19 at 10:48
  • @MaheshKeshvala this would be a bad idea as it uses a scrollview and not FlatList the scroll view has some performance limitations as my list data is dynamic and comes from an api it could be considerably long depending on where the data is coming from a scrollview would load everything at once taking up more memory where as a flatlist only renders what is needed at a given time it also gives me access to use a custom seporator component witch i need as i have my own function to place an add into the seporator component after x amount of items and allows for a pull to refresh the list of data – Dude2019 Feb 19 '19 at 18:16

0 Answers0