gpt4 book ai didi

facebook - React-Native:如何导入/使用 RC 实验组件,即 SwipeableRow (0.27 rc)?

转载 作者:行者123 更新时间:2023-11-30 05:21:39 27 4
gpt4 key购买 nike

我想知道如何在 ReactNative RC 中导入/使用/测试新组件?具体来说,我想导入并使用 SwipeableRow components0.27.0-rc1 .一旦我可以导入它,我就可以在代码库中挖掘以了解参数和选项,但我什至无法通过 import步骤...

我通过 npm 安装了正确标记的版本,但是当我尝试导入组件时,它们显示为 undefined :

import {
ListView,
ScrollView,
StyleSheet,
SwipeableListView,
Text,
TouchableHighlight,
View
} from 'react-native';

我收到如下错误:

screenshot

呈现代码(触发上述代码):

render() {
var ds = new SwipeableListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
blah blah blah
}

我也试过移动 SwipeableRow文件夹是 Libraries 的子文件夹(而不是 Libraries -> Experimental -> SwipeableRow ,现在是 Libraries -> SwipeableRow )。同样的错误。

我试过导入 Experimental然后使用 <Experimental.SwipeableRow.SwipeableListView> ,但这也会引发“Undefined is not an object”异常。

按照建议,我还尝试使用指向节点模块的直接路径进行导入:

import {
SwipeableListView
} from '../../../node_modules/react-native/Libraries/Experimental/SwipeableRow';

结果是:

Unable to resolve module ../../../node_modules/react-native/Libraries/Experimental/SwipeableRow from <source component path>: File <path>/node_modules/react-native/Libraries/Experimental/SwipeableRow/index doesnt exist

然后我尝试了:

import {
SwipeableListView
} from '../../../node_modules/react-native/Libraries/Experimental/SwipeableRow/SwipeableListView';

结果是:

Unable to resolve module emptyFunction from <path>/Libraries/Experimental/SwipeableRow/SwipeableRow.js: Unable to find this module in its module map or any of the node_modules directories under /Users/node_modules/emptyFunction and its parent directories. This might be related to github issue 4968 (paraphrasing).

有没有办法使用和测试这些实验组件?还是只能等官方发布?

最佳答案

由于模块有一个@providesModule注解,所以可以直接请求它。这是 react-native 中使用的包装器特有的东西!

你可以这样做

const SwipeableRow = require('SwipeableRow');
// or
import SwipeableRow from 'SwipeableRow';

要解决空函数问题,只需将要求更改为以下内容:

const emptyFunction = require('fbjs/lib/emptyFunction'); 

在等待 next version 时出来。

关于facebook - React-Native:如何导入/使用 RC 实验组件,即 SwipeableRow (0.27 rc)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37489145/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com