react-native 组件demo
2016-09-21 13:53
239 查看
所有代码下载:react-native 组件
1.ActivityIndicator
import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, ActivityIndicator, TouchableOpacity } from 'react-native'; export default class RNActivityIndicatorDemo extends Component { constructor(props) { super(props); this.state = {// 初始设为显示加载动画 animating: true, }; } // 按钮响应方法,切换显示与隐藏 showOrHide() { if (this.state.animating) { this.setState({ animating: false }); } else { this.setState({ animating: true }); } } render() { return ( <View style={styles.container}> <TouchableOpacity underlayColor="#fff" style={styles.btn} onPress={ this.showOrHide.bind(this)}> <Text style={{color:'#fff', fontSize: 20}}>显示/隐藏</Text> </TouchableOpacity> <ActivityIndicator animating={this.state.animating} style={[styles.centering, {height: 80}]} size="small" /> <ActivityIndicator animating={this.state.animating} style={[styles.centering, {height: 80}]} size="large" /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, centering: { alignItems: 'center', justifyContent: 'center', padding: 8, }, btn:{ marginTop:10, width:150, height:35, backgroundColor:'#3BC1FF', justifyContent:'center', alignItems:'center', borderRadius:4, }, });
2.DrawerLayoutAndroid
import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, DrawerLayoutAndroid, TouchableOpacity } from 'react-native'; export default class DrawerLayoutAndroidDemo extends Component { render() { var navigationView = ( <View style={{flex: 1, backgroundColor: '#fff'}}> <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>in the Drawer!</Text> </View> ); return ( <DrawerLayoutAndroid drawerWidth={300} drawerPosition={DrawerLayoutAndroid.positions.Left} renderNavigationView={() => navigationView}> <View style={{flex: 1, alignItems: 'center'}}> <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text> <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>World!</Text> </View> </DrawerLayoutAndroid> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, centering: { alignItems: 'center', justifyContent: 'center', padding: 8, }, btn:{ marginTop:10, width:150, height:35, backgroundColor:'#3BC1FF', justifyContent:'center', alignItems:'center', borderRadius:4, }, });
3.ToolBarAndroid
'use strict'; import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, DrawerLayoutAndroid, TouchableOpacity, ToastAndroid, } from 'react-native'; var ToolbarAndroid = require('ToolbarAndroid'); export default class ToolBarAndroidDemo extends Component { render() { return ( <ToolbarAndroid actions={toolbarActions} navIcon={require('../../app/image/weixin.png')} style={styles.toolbar} subtitle="副标题" title="主标题" onActionSelected={this.onActionSelected}></ToolbarAndroid> ); } // onActionSelected=function(position) { onActionSelected=(position)=>{ ToastAndroid.show('This is '+position, ToastAndroid.SHORT) } } var toolbarActions = [ {title: 'Create', icon: require('../../app/image/create.png'), show: 'always'}, {title: 'Filter'}, {title: 'Filter1'}, {title: 'Settings', icon: require('../../app/image/setting.png'), show: 'always'}, ]; const styles = StyleSheet.create({ toolbar: { backgroundColor: '#e9eaed', height: 56, }, });
相关文章推荐
- 开发一个基于React Native的简易demo--视频组件+布局
- 从零开始 React Native(6) 计时器案例(模块化_组件封装)有图有demo
- react-native制作新手引导组件
- React Native 组件样式测试
- React-Native 写的小项目Demo Gank.io
- ReactNative 如何获取组件的引用
- React-Native进阶_1.抽取样式和组件
- 在iOS6机子上运行 React-Native Demo, 自己编译 JavaScriptCore 源码,支持 iOS5.1 ,iOS 6
- react-native 与 native组件之间的通信
- react-native 侧滑组件 react-native-swipe-list-view
- react-native-swipe-list-view侧滑删除组件使用
- 【转】react-native-wechat组件使用介绍
- (四)React Native---Image组件
- 一起来点React Native——常用组件之Image
- React Native开源时间日期选择器组件
- 【React Native开发】React Native控件之Image组件讲解与美团首页顶部效果实例(10)
- React-Native-ListView、ListViewItem(子、父组件互相传值)
- React-native学习过程 八 组件综合应用
- React-Native(六):React Native完整的demo项目
- react native组件传递参数值给方法