React-Native Flatlist getItemLayout with dynamic item height : <p>I am trying to implement a scrollToIndex function on a flatlist so that it scrolls to a specific item when it renders. The issue I am running into is that the items the flatlist renders have a <code>minHeight</code>. The issue with that is, the flatlist needs to implement a function to calculate the offset for every element. I cant think of a way to <code>pre-render</code> the flatlist and get the height of every item in it. As you can see I am simply adding a static number for the offset and that is not what I need. </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;FlatList
  data={data}
  renderItem={this.renderItem}
  getItemLayout={(dat, index) =&gt; {
    let offset = 0;
    for (let i = 0; i &lt; index; i++) {
      if (data[i].headerText) {
        offset += 33;
      } else {
        offset += 80;
      }
    }
    return { length: 0, offset, index }
  }
  }
  ref={(ref) =&gt; { this.flatListRef = ref; }}
/&gt;</code></pre>
</div>
</div>
</p>
