use*_*ser 6 facebook react-native
我想知道如何在ReactNative RC中导入/使用/测试新组件?具体来说,我想导入并使用0.27.0-rc1中的SwipeableRow 组件.有一次,我可以将其导入,我可以在代码库,了解PARAMS和选项挖过来,但我甚至无法让过去的一步......import
我通过安装了正确的标记版本npm,但是当我尝试导入组件时,它们显示为undefined:
import {
ListView,
ScrollView,
StyleSheet,
SwipeableListView,
Text,
TouchableHighlight,
View
} from 'react-native';
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
渲染代码(触发上述代码):
render() {
var ds = new SwipeableListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
blah blah blah
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将SwipeableRow文件夹移动为子文件Libraries(而不是Libraries- > Experimental- > SwipeableRow,现在它是Libraries- > SwipeableRow).同样的错误.
我已尝试导入Experimental然后使用<Experimental.SwipeableRow.SwipeableListView>,但这也会抛出"未定义不是对象"异常.
正如所建议的那样,我也尝试使用直接路径到节点模块进行导入:
import {
SwipeableListView
} from '../../../node_modules/react-native/Libraries/Experimental/SwipeableRow';
Run Code Online (Sandbox Code Playgroud)
结果导致:
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
Run Code Online (Sandbox Code Playgroud)
然后我尝试了:
import {
SwipeableListView
} from '../../../node_modules/react-native/Libraries/Experimental/SwipeableRow/SwipeableListView';
Run Code Online (Sandbox Code Playgroud)
结果导致:
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).
Run Code Online (Sandbox Code Playgroud)
有没有办法使用和测试这些实验组件?或者我只是要等待官方发布?
由于模块有@providesModule注释,因此可以直接使用.这是反应原生使用的包装商特有的东西!
你可以这样做
const SwipeableRow = require('SwipeableRow');
// or
import SwipeableRow from 'SwipeableRow';
Run Code Online (Sandbox Code Playgroud)
要修复空函数问题,只需将require更改为以下内容:
const emptyFunction = require('fbjs/lib/emptyFunction');
Run Code Online (Sandbox Code Playgroud)
在等待下一个版本出来的时候.
| 归档时间: |
|
| 查看次数: |
1328 次 |
| 最近记录: |