首页 > 解决方案 > 在 ScrollView 和 FlatList 中引用子视图(div)

问题描述

长话短说,我正在努力将电视支持添加到 react-native-web。这允许 Touchable 具有焦点的想法,AndroidTV 和 AppleTV 会根据具有焦点的项目自动滚动 ScrollViews 和 FlatLists。

我使用 scrollToIndex 等可以正常工作,但在某些情况下,我需要访问 Scroll 或 FlatList 的子滚动 div 以供参考 FlastList 创建一个包装 div,它代表带有内部 div 的 scrollView 的“窗口”包装视图中的所有项目。

请先原谅我,因为我的大多数用例都是水平滚动的,所以我经常混淆宽度/高度,那么“标准”是什么

基本上,我试图找到“惯用的”反应原生方式来获得对该内部 div 的引用。这仅适用于网络,因为我正在复制本机功能。

<div> <-- Container div, width/height is width/height of Scroll View, the "ref" I can get a node from -->
     <div> <--  I Want this "ref" - Inner div, width/height is width/height of all its children, overflows parent with enough items -->
           <div> <-- All the children -->
           <div>
            ....
           <div>
</div>

我可以使用scrollview ref的firstChild访问节点并使其工作。这很好,但依赖于 HTML 的一些一致性,所以它看起来“脆弱”。有一些方法,如 'getScrollableNode' 和 'getNativeScrollRef' ,它们看起来可能有效,但它们要么不存在,要么引用父节点。

标签: react-nativereact-native-web

解决方案


推荐阅读