如何获取具有动态项目高度的 getItemLayout - Flatlist React Native Hooks

Bru*_*uiz 5 react-native expo flatlist

我正在尝试使用 onLayout 获取高度,但 getItemLayout 首先运行 onLoad 并写入此错误 [Unhandled Promise Rejection: Invariant Violation: [5063,"RCTView",911,{"height":"<>"}] 是不能用作本机方法参数]

如何在 getItemLayout 运行之前获取高度?

const [size, setSize] = useState([]);

 const renderItemFinal = useCallback(({ item, index }) => {
    return (
      <View
        style={{ flex: 1 }}>
        <Post
          postAtivo={false}
          onViewRef={itemState?.item?.post_id == item?.post_id && itemState?.isViewable && ready ? true : false}
          user={item.user}
          page={item.page}
          item={item}
        />
      </View>
    )
  }, [itemState])
    
    
    
    const getItemLayout = (data, index) => {
        const length = size[index];
        const offset = size.slice(0, index).reduce((a, c) => a + c, 0)
        return { length, offset, index }
      }
        
    <FlatList
            getItemLayout={getItemLayout}
            ref={flatlistRed}
            showsVerticalScrollIndicator={false}
            onViewableItemsChanged={onViewRef.current}
            viewabilityConfig={viewConfigRef.current}
            data={posts}
            windowSize={5}
            initialNumToRender={5}
            refreshControl={refreshControlJsx}
            onEndReachedThreshold={0.2}
            onEndReached={endReached}
            ListEmptyComponent={empty}
            renderItem={renderItemFinals}
            keyExtractor={keyExtractor}
            decelerationRate={'normal'}
            ListFooterComponent={footerJsx}
            removeClippedSubviews={Platform.OS === 'ios' ? false : true}
          />
Run Code Online (Sandbox Code Playgroud)