项目地址为:https://github.com/StarkCoder/RNTest
首先我们来分析代码
跟平时不同的是,这个代码运行直接到的是HomePage页面

//index.js代码如下
/*** @format*/import {AppRegistry} from 'react-native';
import App from './App';
import HomePage from './app/views/home/HomePage'
import {name as appName} from './app.json';AppRegistry.registerComponent(appName, () => HomePage);
//app/views/home/HomePage.js
/*** HomePage页面*** */import React, {PureComponent} from 'react';
import {Platform,StyleSheet,Text,View,FlatList,TouchableOpacity,} from 'react-native';//多选框
import CheckBox from 'react-native-check-box';
import Toolbar from '../../component/header/Toolbar';
import SwipeableItem from '../../component/swipeable/SwipeableItem';const ListData = [{key: 'a'},{key: 'b'}
]export default class HomePage extends PureComponent {constructor(props) {super(props);this.state = {isEditMode: false,isChecked: false,}}componentDidMount(): void {}_keyExtractor = (item, index) => item.id;//渲染列表项_renderItem = (item, index) => {return (<SwipeableItemkey={index}title={'系统消息'}note={'2019.5.4'}content={'AAA'}isEditMode={this.state.isEditMode}/>);}render() {return (<View style={styles.container}><Toolbartitle='消息测试'hideLeftButtons={true}rightButtons={{text: '编辑',onPress: () => {const mode = this.state.isEditMode;this.setState({isEditMode: !mode})}}}/><View style={{paddingVertical: 10}}><CheckBoxstyle={{flex: 1, padding: 10}}onClick={() => {this.setState({isChecked: !this.state.isChecked})}}isChecked={this.state.isChecked}leftText={"CheckBox"}/><CheckBoxstyle={{flex: 1, padding: 10}}onClick={() => {this.setState({isChecked: !this.state.isChecked})}}isChecked={this.state.isChecked}leftText={"CheckBox"}/></View><FlatListdata={ListData}extraData={this.state.isEditMode}keyExtractor={this._keyExtractor}renderItem={this._renderItem}/></View>);}
}const styles = StyleSheet.create({container: {flex: 1,backgroundColor: '#e4e4e4',}
})
//app/component/header/Toolbar.js
import React, {PureComponent} from 'react';
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
// import {withNavigation} from 'react-navigation';
import PropTypes from 'prop-types';
import styles from './Toolbar.style';
import TextButton from '../button/TextButton';const ICON_BACK = require('../../constant/image/circle_drashed_32px.png');
const fallbackView = <View/>;class Toolbar extends PureComponent {static propTypes = {title: PropTypes.string.isRequired,hideLeftButtons: PropTypes.bool,leftButtons: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({text: PropTypes.string,onPress: PropTypes.func,})),PropTypes.shape({text: PropTypes.string,onPress: PropTypes.func,}),]),rightButtons: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({text: PropTypes.string,onPress: PropTypes.func,})),PropTypes.shape({text: PropTypes.string,onPress: PropTypes.func,}),]),onBackPress: PropTypes.func,};static defaultProps = {hideLeftButtons: false,};renderButton = (button, i) => {if (button.icon) {return (<TouchableOpacitykey={i}onPress={button.onPress}disabled={button.disabled}style={styles.iconButton}><Imagesource={button.icon}style={styles.buttonIcon}resizeMode="contain"/></TouchableOpacity>);} else {return (<TextButtonkey={i}text={button.text}disabled={button.disabled}onPress={button.onPress}/>)}};render() {const {title, hideLeftButtons, leftButtons, rightButtons, backgroundColor, style} = this.props;let leftButtonsView = fallbackView;if (leftButtons) {const finalLeftButtons = Array.isArray(leftButtons) ? leftButtons : [leftButtons];leftButtonsView = (<View style={styles.buttons}>{finalLeftButtons.map(this.renderButton)}</View>);} else if (!hideLeftButtons) {leftButtonsView = (<TouchableOpacityonPress={this.goBack}style={styles.backButton}><Imagesource={ICON_BACK}style={styles.backIcon}resizeMode="contain"/></TouchableOpacity>);}let rightButtonsView = fallbackView;if (rightButtons) {const finalRightButtons = Array.isArray(rightButtons) ? rightButtons : [rightButtons];rightButtonsView = (<View style={styles.buttons}>{finalRightButtons.map(this.renderButton)}</View>);}const containerStyle = StyleSheet.compose(styles.container, style);const finalContainerStyle = backgroundColor ? [containerStyle, {backgroundColor}] : containerStyle;return (<View style={finalContainerStyle}><View style={styles.titleContainer}><Text style={styles.title} numberOfLines={1}>{title}</Text></View><View style={styles.actionBar}>{leftButtonsView}{rightButtonsView}</View></View>);}goBack = () => {if (typeof this.props.onBackPress === 'function') {this.props.onBackPress();} else {this.props.navigation.goBack(null);}};
}// export default withNavigation(Toolbar);
export default Toolbar;
// app/component/swipeable/SwipeableItem.js
import React, {PureComponent} from 'react';
import {Platform,StyleSheet,Text,View,FlatList,TouchableOpacity,Image,} from 'react-native';
import PropTypes from 'prop-types';
import Swipeable from 'react-native-swipeable';const Dimensions  = require('Dimensions');
const screenWidth = Dimensions.get('window').width;const ICON_CIRCLE_CHECK = require('../../constant/image/circle_check_32px.png');
const ICON_CIRCLE_DASH = require('../../constant/image/circle_drashed_32px.png');const ITEM_HEIGHT = 60;const leftContent = <Text>Pull to activate</Text>;export default class SwipeableItem extends PureComponent {/*** isEditMode 是否是编辑模式** isChecked 是否被选中   内部状态* source  头部图片资源* title 左边文本* note 右边文本* content 下面文本*** */static propTypes = {// isChecked: PropTypes.bool.isRequired,isEditMode: PropTypes.bool.isRequired,}constructor(props) {super(props);this.state = {isChecked: false}}componentWillMount(): void {}//条目点击事件//在编辑模式下就是被选中,非编辑模式下就是跳转onItemPress = () => {if (this.props.isEditMode) {const isCheck = this.state.isChecked;this.setState({isChecked: !isCheck})} else {// this.navigation}}//渲染头部图片renderHeaderImage() {if (this.state.isChecked) {return (<Image source={ICON_CIRCLE_CHECK}/>);} else {return (<Image source={ICON_CIRCLE_DASH}/>);}}render() {const rightButtons = [<TouchableOpacitystyle={styles.buttonStyle1}><Text>{'已读'}</Text></TouchableOpacity>,<TouchableOpacitystyle={styles.buttonStyle2}><Text style={{color:'#FFF'}}>{'删除'}</Text></TouchableOpacity>];return (<SwipeableleftContent={leftContent}rightButtons={rightButtons}rightButtonWidth={75}rightActionActivationDistance={0}><TouchableOpacitystyle={styles.swipeContainer}onPress={this.onItemPress}>{this.props.isEditMode ? this.renderHeaderImage() : null}<Imagestyle={styles.headImage}source={this.props.source}/><View style={{flex: 1, paddingRight: 10}}><View style={styles.rightTexts}><Text>{this.props.title}</Text><Text>{this.props.note}</Text></View><Text>{this.props.content}</Text></View></TouchableOpacity></Swipeable>);}}const styles = StyleSheet.create({swipeContainer: {flex: 1,paddingLeft: 5,flexDirection: 'row',alignItems: 'center',marginBottom: 5,height: ITEM_HEIGHT,backgroundColor: '#FFF'},buttonStyle1: {// flex:1,width: 75,backgroundColor: '#ff7687',height: ITEM_HEIGHT,justifyContent: 'center',alignItems: 'center',},buttonStyle2: {// flex:1,width: 75,backgroundColor: '#b9ffb4',height: ITEM_HEIGHT,justifyContent: 'center',alignItems: 'center',},headImage: {marginRight: 5,},rightTexts: {flexDirection: 'row',justifyContent: 'space-between',alignItems: 'center'}}

后面这部分看不太懂

// app/navigation/index.js
import { createSwitchNavigator, createAppContainer } from 'react-navigation';
import AppStackNavigator from './AppStackNavigator';
import SplashScreen from '../views/SplashScreen';
import Login from '../views/login/Login';const routeConfigMap = {SplashScreen,App: AppStackNavigator,Login,
};const switchConfig = {headerMode: 'none',initialRouteName: 'SplashScreen',
};const AppNavigator = createSwitchNavigator(routeConfigMap, switchConfig);export default createAppContainer(AppNavigator);
//app/navigation/AppStackNavigator.js
import {createStackNavigator} from 'react-navigation';
// 首页
import HomePage from '../views/home/HomePage';const routeConfigMap = {HomePage: HomePage,
};const stackConfig = {headerMode: 'none',initialRouteName: 'HomePage',
};const AppStackNavigator = createStackNavigator(routeConfigMap, stackConfig);export default AppStackNavigator;
//app/navigation/NavigationService.js
import { NavigationActions } from 'react-navigation';let _navigator;function setNavigator(navigator) {_navigator = navigator;
}function navigate(routeName, params) {_navigator.dispatch(NavigationActions.navigate({routeName,params,}));
}export default {navigate,setNavigator,
};

未完,待续。。。我还差很远~

转载于:https://www.cnblogs.com/smart-girl/p/10880023.html

【水滴石穿】RNTest相关推荐

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

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

  2. 做人晶莹剔透,做事水滴石穿

    看了余世维的讲座,在最后的闭幕中,出现了这样的文字:做人晶莹剔透,做事水滴石穿.晶莹剔透意味着诚信光明,水滴石穿意味着用心坚持.让我心一惊,真是说得太对了.我要用他来鼓舞激励自己. 现在很多人都很虚伪 ...

  3. Redis 水滴石穿之(六)哨兵

    Redis-水滴石穿之(六)哨兵 目录 Redis-水滴石穿之(六)哨兵 一.概述 二.哨兵应用 2.1.主从及哨兵配置 2.2.依次启动主.从.哨兵 2.3.主从节点验证 2.4.故障迁移演示 2. ...

  4. 水滴石穿、坚持不懈,必能有所精进

    在跟随这门课程学习的过程中,我增长了很多大数据相关的知识,对于大数据技术和相关开源组件,也有了更深的了解.今天正好可以借着这个机会,来记录下自己的一点心得体会,也跟你分享一下我的学习思路,咱们一起聊一 ...

  5. 2.4 找准位置,水滴石穿

            考试时的方法多数不是"灵机一动"现场创造出来的,而是平时刻苦训练中积累出来的. 俗话说得好,"水滴石穿",但"水滴未必石穿" ...

  6. Redis 水滴石穿之(四)持久化

    Redis 水滴石穿之(四)持久化 目录 Redis 水滴石穿之(四)持久化 一.概述 二.RDB 1.RDB快照触发时机 1.1 手动触发 (save & bgsave) 1.2 自动触发 ...

  7. 不会-Redis 水滴石穿之(七)集群

    Redis 水滴石穿之(七)集群 目录 Redis 水滴石穿之(七)集群 一.概述 二.集群搭建 2.1.手动搭建集群 1.修改配置文件 2.启动节点 3.节点握手 4.分配槽 5.指定主从关系 2. ...

  8. 期货开户水滴石穿知行合一

    上千年来,人生价值一直都在改变,唯一没有改变的就是价值本身的规律.如果从另一个角度去观察,或许会有另外一番心境,有句老话叫做后生可畏,也许后生并不可畏,真正让人可畏可敬的或许是代表一个时代的思想和精神 ...

  9. 2022-1-14持之以恒,水滴石穿

    1.读到曾文正公修身之难皆因无恒,刚过30的我深有体会,回想往事从幼时读书学习开始总是3分钟热度,学习总浮于表面,老师布置的作业草草了事,出社会参加工作后书倒是买了一大堆,每本书总是翻完几页又想去读其 ...

最新文章

  1. 链表问题8——将单向链表按某值划分成左边小、中间相等、右边大的形式(初阶)
  2. Linux SSH远程文件/文件夹传输命令scp
  3. Visual Studio Code中文文档(一)-快速入门
  4. 阿里云高级技术专家空见: CDN的数据化之路
  5. mysql5.7 sqlmode_mysql 5.7 sql mode
  6. 多个vue项目合并成一个_集美们,快看如何一步将多个PDF合并成一个PDF
  7. Oracle_Rac_BackgroudProcess
  8. Nacos-快速入门
  9. 一些前端开发经典书籍推荐和下载链接分享
  10. 2021年度训练联盟热身训练赛第一场 E Early Orders 思维 + 栈
  11. JAVA入门级教学之(break跳出)
  12. Java 去除重复数据的五种方式
  13. Ubuntu12.04中安装ns-allinone-2.34
  14. Luogu3381【模板】最小费用最大流
  15. 内定抽奖小程序_excel怎么制作抽奖小程序?
  16. LinuxQt打包发布
  17. 计算机无法删除ie,ie删不掉的原因及解决方法【图解】
  18. HITB CTF 2018 gundam 做题笔记
  19. App Store榜单优化:App出海必须掌握的ASO技巧
  20. Krypital Group(金氪资本)宣布完成对Ambrus Studio的战略投资

热门文章

  1. C语言:一只公鸡值五钱,一只母鸡值三钱,三只小鸡值一钱,现在要用百钱买百鸡,请问公鸡、母鸡、小鸡各多少只?
  2. 高颜值第三方播放器:YesPlayMusic Mac
  3. 计算机桌面无法中英文切换,解决中文和英文无法正常切换问题
  4. php信息录入系统_YzmCMS PHP轻量级信息管理系统 v5.8
  5. 记一次Mysql数据恢复
  6. 消除数据信息碎片化 打通大数据应用“最后一公里”
  7. 华为Mate20 HL1HIMAM电路图
  8. 魔乐科技安卓开发教程----李兴华----11使用摄像头拍照
  9. 基于SSD的交通标志检测-介绍ssd算法
  10. 汽车诊断之UDS入门-0x2E(WriteDataByIdentifier)通过ID写数据