比较简单的项目

  1. //index.js
  2. /** @format */
  3. import {AppRegistry} from 'react-native';
  4. //默认创建的类
  5. import App from './App';
  6. //json
  7. import {name as appName} from './app.json';
  8. //FlatList类
  9. import DWBFlatList from './DWBHomeFlatList'
  10. import DWBTestVC from './DWBTestVC'
  11. import DWBTButton from './DWBTButton'
  12. // import DWBSwipeout from './DWBSwipeout'
  13. import DWBNavVC from './DWBNavVC'
  14. import DWBTouchableOpacity from './DWBTouchableOpacity'
  15. import DWBSectionList from './DWBSectionList'
  16. import DWBActionButton from './DWBActionButton'
  17. //修改这里可以切换不同的类显示: => App
  18. AppRegistry.registerComponent(appName, () => DWBFlatList);
  19. // react-native关闭所有黄色警告,将这两句话加在index.js文件中,放在AppRegistry.registerComponent('App', () => App)之前。
  20. console.ignoredYellowBox = ['Warning: BackAndroid is deprecated. Please use BackHandler instead.','source.uri should not be an empty string','Invalid props.style key'];
  21. console.disableYellowBox = true // 关闭全部黄色警告

  1. //DWBHomeFlatList.js
  2. import React, { Component } from 'react';
  3. import {
  4. AppRegistry,
  5. StyleSheet,
  6. Text,
  7. View,
  8. FlatList,
  9. TouchableOpacity, Button,
  10. } from 'react-native';
  11. // 初始化数据
  12. var Arr = [
  13. {name:'河北省',},
  14. {name:'山西省',},
  15. {name:'辽宁省',},
  16. {name:'吉林省',},
  17. {name:'黑龙江省',},
  18. {name:'江苏省',},
  19. {name:'浙江省',},
  20. {name:'福州省',}];
  21. export default class MyFlatList extends Component {
  22. render() {
  23. //给数据追加一个key的字段,不然会有警告的,参数数组中的每一项,需要包含 key 值作为唯一标示
  24. for (var i = 0; i < Arr.length; i++) {
  25. Arr[i]['key'] = i;
  26. }
  27. return (
  28. //初始化FlatList
  29. <View style={styles.container}>
  30. <FlatList style={styles.FlatListStyle}
  31. data = {Arr}
  32. ListHeaderComponent={this.ListHeaderComponent.bind(this)}
  33. ListFooterComponent={this.ListFooterComponent.bind(this)}
  34. renderItem={this.renderItemView.bind(this)}
  35. //分割线组件
  36. ItemSeparatorComponent={ItemDivideComponent}
  37. >
  38. </FlatList>
  39. </View>
  40. );
  41. }
  42. //列表的每一行
  43. renderItemView({item,index}){
  44. return(
  45. <TouchableOpacity onPress={()=>{
  46. this.Cellheader(item)}
  47. }
  48. >
  49. <View style={{
  50. backgroundColor:'#ffffff',//背景色
  51. height:59,//view高度
  52. justifyContent:'center',//内容上下居中
  53. alignItems: 'center'//内容左右居中
  54. }}>
  55. <Text>{item.name}</Text>
  56. </View>
  57. </TouchableOpacity>
  58. );
  59. }
  60. //点击每一行的对象
  61. Cellheader(data){
  62. alert(data.name);
  63. }
  64. //定义页头
  65. ListHeaderComponent(){
  66. return(
  67. <View style={{height:140,backgroundColor:'red',justifyContent: 'center',}}>
  68. <Text>我是页头</Text>
  69. </View>
  70. );
  71. }
  72. //定义页脚
  73. ListFooterComponent(){
  74. return(
  75. <View style={{height:140,backgroundColor:'yellow',justifyContent: 'center',}}>
  76. <Text>我是页脚</Text>
  77. </View>
  78. );
  79. }
  80. }
  81. // //设置分割线
  82. // renderSeparator(){
  83. // return (
  84. // <View style={{height: 1, backgroundColor: 'skyblue'}}></View>
  85. // );
  86. // };
  87. class ItemDivideComponent extends Component {
  88. render() {
  89. return (
  90. <View style={{height: 1, backgroundColor: 'skyblue'}}></View>
  91. );
  92. }
  93. };
  94. const styles = StyleSheet.create({
  95. //控制器属性
  96. container: {
  97. flex: 1,
  98. flexDirection: 'column',
  99. justifyContent: 'space-between',
  100. backgroundColor: '#F5FCFF',
  101. },
  102. //FlatList属性
  103. FlatListStyle:{
  104. backgroundColor:'#f6f6f6',
  105. flex:1,
  106. marginTop:64,
  107. marginBottom: 100,
  108. // width:300
  109. }
  110. });
  1. //DWBActionButton.js
  2. import React, { Component } from 'react';
  3. import { StyleSheet, View,Text,Alert } from 'react-native';
  4. import ButtonMy from 'apsl-react-native-button'
  5. export default class ActionButton extends Component {
  6. render() {
  7. return (
  8. <View style={styles.ViewSyt}>
  9. <ButtonMy style={{backgroundColor: '#c771ec'}} onPress={()=>{
  10. Alert.alert('我是一个button');
  11. }}>
  12. <View style={styles.actionButtonIcon}>
  13. <Text style={styles.actionButtonIcon}>我是一个button</Text>
  14. </View>
  15. </ButtonMy>
  16. </View>
  17. );
  18. }
  19. }
  20. const styles = StyleSheet.create({
  21. ViewSyt:{
  22. flex:1,
  23. marginTop:100,
  24. fontSize: 20,
  25. height: 40,
  26. color: 'white',
  27. },
  28. actionButtonIcon: {
  29. fontSize: 20,
  30. height: 22,
  31. color: 'white',
  32. },
  33. });

比较基础,=-=

【水滴石穿】MyFirstRNDemo的更多相关文章

  1. iOS 开发笔记 -- 各种细枝末节的知识(水滴石穿)

    在此总结整理,遇到的各种的小问题: 1.通过从字典(数组)中取出的NSString的length==0 作为if的判断条件导致的carsh: 由于在字典中通过Key取出值之后直接做了length相关操 ...

  2. 【水滴石穿】react-native-book

    先推荐一个学习的地址:https://ke.qq.com/webcourse/index.html#cid=203313&term_id=100240778&taid=12778558 ...

  3. 【水滴石穿】rnTest

    其实就是一个小的demo,不过代码分的挺精巧的 先放地址:https://github.com/linchengzzz/rnTest 来看看效果 确实没有什么可以说的,不过代码部分还行 先入口文件 / ...

  4. 【水滴石穿】rn_statusbar

    先放项目地址https://github.com/hezhii/rn_statusbar 来看一下效果 咩有感觉很怎么样,看代码 根入口文件 //index.js //看代码我们知道入口是app.js ...

  5. 【水滴石穿】react-native-ble-demo

    项目的话,是想打开蓝牙,然后连接设备 点击已经连接的设备,我们会看到一些设备 不过我这边在开启蓝牙的时候报错了 先放作者的项目地址: https://github.com/hezhii/react-n ...

  6. 【水滴石穿】ReactNative-Redux-Thunk

    老实说,运行出来的项目让人失望,毕竟我想看各种有趣的demo啊- 先放上源码地址:https://github.com/ludejun/ReactNative-Redux-Thunk 我们来一起看看代 ...

  7. 【水滴石穿】mobx-todos

    我觉得代码在有些程序员手里,就好像是画笔,可以创造很多东西 不要觉得创意少就叫没有创意,每天进步一点点,世界更美好 首先源码地址为:https://github.com/byk04712/mobx-t ...

  8. 【水滴石穿】ReactNativeMobxFrame

    项目地址如下:https://github.com/FTD-ZF/ReactNativeMobxFrame 应该可以说的是,项目也只是一个花架子,不过底部的tab稍微改变了 我们一起来看代码 //in ...

  9. 【水滴石穿】react-native-aze

    说个题外话,早上打开电脑的时候,电脑变成彩色的了,锅是我曾经安装的一个chrome扩展,没有经过我的同意开启了 (也许是昨天迷迷糊糊开启了) 上午运行项目都不成功,还以为被黑客攻击了---然后下午就排 ...

随机推荐

  1. hdu6277

    hdu6277结论题 #include<iostream> #include<cstdio> #include<queue> #include<algorit ...

  2. java虚拟机(十三)--GC调优思路

    GC调优对我们开发人员来说,如果你想要技术方面一直发展下去,这部分内容的了解是必不可少的,jvm对于工作.面试来说都很重要,GC调优的问题 更是重中之重,因为是对你jvm学习内容的实践,知识只有应用实 ...

  3. spring cloud深入学习(十)-----配置中心和消息总线(配置中心终结版)

    如果需要客户端获取到最新的配置信息需要执行refresh,我们可以利用webhook的机制每次提交代码发送请求来刷新客户端,当客户端越来越多的时候,需要每个客户端都执行一遍,这种方案就不太适合了.使用 ...

  4. Junit5的依赖添加及RunWith(SpringJUnit4ClassRunner.class)注解使用

    首先Junit5依赖应该配置为 <dependency> <groupId>org.junit.jupiter</groupId> <artifactId&g ...

  5. 简单linux查询

    1查看日志异常 tailf nohup.out|grep ERROR -A 3 --color   tailf nohup.out|grep ERROR|grep chunk -A 3 -B 3 -- ...

  6. Trees in a Wood UVA - 10214 欧拉函数模板

    太坑惹,,,没用longlong各种WA #include <iostream> #include <string.h> #include <cstdio> #in ...

  7. 用JetBrains PyCharm 2017.2创建运行Django程序

    在JetBrains PyCharm 2017.2里选择 文件(F) 新项目 点击  三角形  运行 修改Urls.py """S14Djngo URL Configur ...

  8. bzoj 3029 守卫者的挑战——概率期望dp+状态数思考

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3029 先随便写了个dfs,记录“前 i 次.成功 j 次.容量-残片=k”的概率.因为是否可 ...

  9. sublime中用less实现css预编译

    实现css预编译的方式有很多,听说glup很流行而且功能也很强大,但是就目前的工作而言,仅要css预编译和YUIcompress就够了,接下来切入正题 Less 是一门 CSS 预处理语言,它扩展了 ...

  10. [jnhs]netbeans使用debug模式频繁出现java.lang.OutOfMemoryError: PermGen space内存不足

    netbeans赠送的tomcat7 windows解决方法: 修改C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.27\b ...