From a2c977c265a996ee9f157cc3c702cbd3be9e96be Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 29 Jul 2021 05:20:58 -1000 Subject: [PATCH] Fix broken list components --- src/components/OptionsList.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/OptionsList.js b/src/components/OptionsList.js index cfb25b7e5e19..715edea1c35c 100644 --- a/src/components/OptionsList.js +++ b/src/components/OptionsList.js @@ -113,6 +113,7 @@ class OptionsList extends Component { this.renderSectionHeader = this.renderSectionHeader.bind(this); this.extractKey = this.extractKey.bind(this); this.onScrollToIndexFailed = this.onScrollToIndexFailed.bind(this); + this.onViewableItemsChanged = this.onViewableItemsChanged.bind(this); this.viewabilityConfig = {viewAreaCoveragePercentThreshold: 95}; this.didLayout = false; } @@ -137,6 +138,15 @@ class OptionsList extends Component { return false; } + onViewableItemsChanged() { + if (this.didLayout || !this.props.onLayout) { + return; + } + + this.didLayout = true; + this.props.onLayout(); + } + /** * We must implement this method in order to use the ref.scrollToLocation() method. * See: https://reactnative.dev/docs/sectionlist#scrolltolocation @@ -238,14 +248,7 @@ class OptionsList extends Component { maxToRenderPerBatch={5} windowSize={5} viewabilityConfig={this.viewabilityConfig} - onViewableItemsChanged={() => { - if (this.didLayout) { - return; - } - - this.didLayout = true; - this.props.onLayout(); - }} + onViewableItemsChanged={this.onViewableItemsChanged} /> );