React Native 实战系列一

RN实战项目之--GoShopping

一.框架搭建

1.项目搭建 react-native init GoShopping

2.启动服务器:react-native start

3.编译客户端:react-native run-android

4.本项目仿照美团,分为首页,商家,我的,更多四个模块,所以分别新建

Home.js,Shop.js,Mine.js,More.js

使用 react-native-tab-navigator作为导航器,监听tab变化加载不同view,进而完成页面切换

1.资源文件报错:

“FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: Some file crunching failed, see logs for details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.381 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
这里报的问题可能是图片资源文件有问题需要排除

2.在使用react-native-tab-navigator时候

React.Children.only expected to receive a single React element child.
onlyChild
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:3952:93
render
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:55270:48
<unknown>
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20478:27
measureLifeCyclePerf
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19852:14
_renderValidatedComponentWithoutOwnerOrContext
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20477:45
_renderValidatedComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20498:78
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20066:55
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
mountChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19436:56
initializeChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18895:41
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18955:28
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
mountChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19436:56
initializeChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18895:41
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18955:28
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
mountChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19436:56
initializeChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18895:41
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18955:28
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
mountChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19436:56
initializeChildren
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18895:41
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:18955:28
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
performInitialMount
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:20079:48
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:19983:40
mountComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16251:49
mountComponentIntoNode
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:21222:46
perform
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16537:24
batchedMountComponentIntoNode
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:21229:22
perform
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16537:24
batchedUpdates
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16062:33
batchedUpdates
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:16131:41
renderComponent
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:21274:32
render
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:7102:42
renderApplication
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:46383:21
run
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:46171:33
runApplication
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:46211:26
__callFunction
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:4673:47
<unknown>
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:4544:29
guard
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:4508:7
callFunctionReturnFlushedQueue
    index.android.bundle?platform=android&dev=true&hot=false&minify=false:4543:12
这个问题是由于,react-native-tab-navigator在使用的时候TabNavigator.Item节点间需要有view填充,如下
<TabNavigator.Item
    selected={this.state.selectedTab === 'home'}
    title="Home"
    renderIcon={() => <Image source={...} />}
    renderSelectedIcon={() => <Image source={...} />}
    badgeText="1"
    onPress={() => this.setState({ selectedTab: 'home' })}>
    {homeView}
  </TabNavigator.Item>
3.效果图如下:


4.错误截图:






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值