开发一个基于React Native的简易demo--导航栏+轮播图
2017-12-07 10:19
253 查看
文件位置:App.js
一、导航栏
引进react-navigation组件,详细用法见官网:https://reactnavigation.org
编码
1.在文件开头引进react-navigation
2.页面有4个tab,分别是:精选: JingxuanScreen、最新: ShipinScreen 、关注: RecentChatsScreen 、排行榜: AllContactsScreen 。而react-navigation的使用根简单,只需要把各个界面包含进来即可:
就是这么简单!!!
二、轮播图,这里使用react-native-swiper
,详见官网:https://github.com/leecade/react-native-swiper
引进react-native-swiper
编码
1.引进react-native-swiper
2.代码,Swiper中的horizontal为true表示滚动视图的子节点是水平排列,false表示竖直排列,autoplay是自动播放的意思
注意事项
如果出现了轮播图出不来的情况,看看代码里面是不是有标签,两者一起用有问题,解决方法在下一篇的布局当中讲解。
如果一切顺利,那么导航栏和轮播图就出来了:
一、导航栏
引进react-navigation组件,详细用法见官网:https://reactnavigation.org
yarn add --save react-navigation react-native run-android
编码
1.在文件开头引进react-navigation
import { TabNavigator } from "react-navigation";
2.页面有4个tab,分别是:精选: JingxuanScreen、最新: ShipinScreen 、关注: RecentChatsScreen 、排行榜: AllContactsScreen 。而react-navigation的使用根简单,只需要把各个界面包含进来即可:
export const MainScreenNavigator = TabNavigator({ 精选: { screen: JingxuanScreen }, 最新: { screen: ShipinScreen }, 关注: { screen: RecentChatsScreen }, 排行榜: { screen: AllContactsScreen }, });
就是这么简单!!!
二、轮播图,这里使用react-native-swiper
,详见官网:https://github.com/leecade/react-native-swiper
引进react-native-swiper
yarn add --save react-native-swiper react-native run-android
编码
1.引进react-native-swiper
import Swiper from 'react-native-swiper';
2.代码,Swiper中的horizontal为true表示滚动视图的子节点是水平排列,false表示竖直排列,autoplay是自动播放的意思
... const { width } = Dimensions.get('window') ... <Swiper style={styles.wrapper} horizontal={true} autoplay={true}> <View style={styles.slide1} title={<Text numberOfLines={1}>Aussie tourist dies at Bali hotel</Text>}> <Image resizeMode='cover' style={styles.imageSwiper} source={require('./img/1.jpg')} /> </View> <View style={styles.slide1} title={<Text numberOfLines={1}>Big lie behind Nine’s new show</Text>}> <Image resizeMode='cover' style={styles.imageSwiper} source={require('./img/2.jpg')} /> </View> <View style={styles.slide1} title={<Text numberOfLines={1}>Why Stone split from Garfield</Text>}> <Image resizeMode='cover' style={styles.imageSwiper} source={require('./img/3.jpg')} /> </View> <View style={styles.slide1} title={<Text numberOfLines={1}>Learn from Kim K to land that job</Text>}> <Image resizeMode='cover' style={styles.imageSwiper} source={require('./img/4.jpg')} /> </View> </Swiper> ... const styles = StyleSheet.create({ ... wrapper: { }, slide: { flex: 1, justifyContent: 'center', backgroundColor: 'transparent' }, imageSwiper: { width:width, height:150 }, ...
注意事项
如果出现了轮播图出不来的情况,看看代码里面是不是有标签,两者一起用有问题,解决方法在下一篇的布局当中讲解。
如果一切顺利,那么导航栏和轮播图就出来了:
下一篇:开发一个基于React Native的简易demo–视频组件+布局
相关文章推荐
- 开发一个基于React Native的简易demo--源码
- 开发一个基于React Native的简易demo--视频组件+布局
- 开发一个基于React Native的简易demo--前记
- 开发一个基于React Native的简易demo--读取网络数据并展示
- 基于react-redux开发一个待办事项的demo–todoList的笔记
- 安装React Native开发环境 (基于mac)
- 基于React-Native的高仿「ONE·一个」
- 【React Native开发】 - ViewParger轮播组件
- 基于react+react-router+redux+socket.io+koa开发一个聊天室
- 基于 react-native+redux 开发的高仿 V2EX 客户端
- React Native之无fixed属性,如何开发一个悬浮按钮
- .net和C#基于nethereum开发以太坊的一个demo
- 一个简单的demo说明集成reactnative到android项目
- 基于React Native + redux 开发的客户端(适配IOS和Android),可查看保存妹纸,收藏分享文章等
- 基于Redux的ReactNative项目开发总结(一)
- 基于WebStorm, React和Ant.Design开发WebAppDemo
- 基于Redux的ReactNative项目开发总结(二)
- 使用angular.js开发的一个简易todo demo
- 基于WebStorm, React和Ant.Design开发WebAppDemo
- 基于 React + NodeJS + Express + MongoDB 开发的一个社区系统