In this final React Native lesson of the series we will finalize the Notes view component and squash a few bugs in the code.

  1. import firebase from 'firebase';
  2. import React from 'react';
  3. import {
  4. View,
  5. StyleSheet,
  6. Text,
  7. ListView,
  8. TextInput,
  9. TouchableHighlight
  10. } from 'react-native';
  11. import Badge from './Badge';
  12. import Divdir from './Helpers/divdir';
  13.  
  14. var styles = StyleSheet.create({
  15. container: {
  16. flex: ,
  17. flexDirection: 'column'
  18. },
  19. buttonText: {
  20. fontSize: ,
  21. color: 'white'
  22. },
  23. button: {
  24. height: ,
  25. backgroundColor: '#48BBEC',
  26. flex: ,
  27. alignItems: 'center',
  28. justifyContent: 'center'
  29. },
  30. searchInput: {
  31. height: ,
  32. padding: ,
  33. fontSize: ,
  34. color: '#111',
  35. flex:
  36. },
  37. rowContainer: {
  38. padding:
  39. },
  40. footerContainer: {
  41. backgroundColor: '#E3E3E3',
  42. alignItems: 'center',
  43. flexDirection: 'row'
  44. }
  45. });
  46.  
  47. // In the video there are a couple errors, fixed them so it would build.
  48. class Notes extends React.Component{
  49. constructor(props){
  50. super(props);
  51. this.ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
  52. this.notes = [];
  53. this.state = {
  54. note: '',
  55. dataSource: null,
  56. };
  57. // Initialize Firebase
  58. var config = {
  59. apiKey: "AIzaSyAs8HBqV2X6VIOE5MnDwENz1nRffNkUbiU",
  60. authDomain: "github-saver-9a338.firebaseapp.com",
  61. databaseURL: "https://github-saver-9a338.firebaseio.com",
  62. storageBucket: "github-saver-9a338.appspot.com",
  63. };
  64. firebase.initializeApp(config);
  65. }
  66. componentDidMount(){
  67. firebase.database().ref('notes/').on('child_added', (data)=>{
  68. this.notes.push(data.val());
  69. })
  70. }
  71. handleChange(e){
  72. this.setState({
  73. note: e.nativeEvent.text
  74. })
  75. }
  76. handleSubmit(){
  77. let note = this.state.note;
  78. firebase.database().ref('notes/').push({
  79. note,
  80. timestamp: +new Date()
  81. })
  82. this.setState({
  83. note: ''
  84. })
  85. }
  86. render(){
  87.  
  88. var notesHtml = this.notes && this.notes.map((note, index)=>{
  89. return (
  90. <View>
  91. <Text key={index}>{note.note}</Text>
  92. <Divdir />
  93. </View>
  94. );
  95. });
  96.  
  97. return (
  98. <View style={styles.container}>
  99. <Badge userInfo={this.props.userInfo}/>
  100. <View>
  101. {notesHtml}
  102. </View>
  103. <View style={styles.footerContainer}>
  104. <TextInput
  105. style={styles.searchInput}
  106. value={this.state.note}
  107. onChange={this.handleChange.bind(this)}
  108. placeholder="New Note" />
  109. <TouchableHighlight
  110. style={styles.button}
  111. onPress={this.handleSubmit.bind(this)}
  112. underlayColor="#88D4F5">
  113. <Text style={styles.buttonText}>Submit</Text>
  114. </TouchableHighlight>
  115. </View>
  116. </View>
  117. )
  118. }
  119. };
  120.  
  121. Notes.propTypes = {
  122. userInfo: React.PropTypes.object.isRequired
  123. };
  124.  
  125. module.exports = Notes;

[React Native] Complete the Notes view的更多相关文章

  1. React Native学习(二)之View

    React Native组件解析(二)之View 0.JSX React的核心机制之一就是虚拟DOM:可以在内存中创建的虚拟DOM元素.React利用虚拟DOM来减少对实际DOM的操作从而提升性能. ...

  2. React Native学习-measure测量view的宽高值

    measure()测量是根据view标签中的ref属性,使用方法如下: measureWatermarkerImage(){ this.refs.watermarkerImage.measure((a ...

  3. React Native实践之携程Moles框架

    编者:本文来自携程框架研发部高级经理魏晓军在第二期[携程技术微分享]上的分享,以下为整理后的文字实录.视频回放可点击这里.关注携程技术中心微信公号ctriptech,可获知更多微分享课程信息. 因为支 ...

  4. 【转】【React Native开发】

    [React Native开发]React Native控件之ListView组件讲解以及最齐全实例(19)  [React Native开发]React Native控件之Touchable*系列组 ...

  5. React Native专题

    转载注明出处:地址:http://www.lcode.org本文出自:[江清清的技术专栏]本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶 ...

  6. React Native之携程Moles框架

    因为支持用javascript开发原生应用,React Native一推出就受到不少公司热捧,各家都跃跃欲试.但有一个痛点是,在移动端,我们是否有必要开发多套程序:iOS.Android和H5?本次将 ...

  7. React Native专题-江清清

    本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 刚创建的React Native交流8群:533435865  欢迎各位大牛, ...

  8. React Native 常用插件案例

    (二).基础入门: 1.React Native For Android环境配置以及第一个实例 2.React Native开发IDE安装及配置 3.React Native应用设备运行(Runnin ...

  9. React Native简史

    诞生 React Native 诞生于 2013 年的 Facebook 内部黑客马拉松(hackathon): In the essence of Facebook’s hacker culture ...

随机推荐

  1. Notepad++加上xml格式化的功能

    工作中需要用代码创建一个XML文件,创建完发现XML内容都处在同一行,导致非常不容易查看清楚XML代码.于是习惯性地用 Notepad++查看,想用它来对XML代码格式化一下. 于是找到了TextFX ...

  2. Session简介

    摘要:虽然session机制在web应用程序中被采用已经很长时间了,但是仍然有很多人不清楚session机制的本质,以至不能正确的应用这一技术.本文将详细讨论session的工作机制并且对在Java ...

  3. Bsie(鄙视IE)

    http://www.bootcss.com/p/bsie/ 欢迎,这是bsie项目主页. 简介 bsie弥补了Bootstrap对IE6的不兼容.Bootstrap是 twitter.com 推出的 ...

  4. 使用BusyBox制作Linux根文件系统

    STEP 1:构建目录结构 创建根文件系统目录,主要包括以下目录/dev  /etc /lib  /usr  /var /proc /tmp /home /root /mnt /bin  /sbin  ...

  5. DataTable 分页

    #region DataTable 分页 /// <summary> /// Datatable 分页 /// </summary> /// <param name=&q ...

  6. Eclipse(非J2EE版本)配置Extjs环境以及安装部署Tomcat

    Eclipse(非J2EE版本)配置Extjs环境(Spket) 1. 安装spket插件,帮助->安装新软件->http://www.agpad.com/update. 2. 设置Spk ...

  7. CI支持各种文件上传-文件类型(Linux + window)

    $mimes = array( 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'c ...

  8. php支持rewrite 时创建.htaccess文件

    1.win+r 快捷键 运行中输入cmd 2.进入dos界面:输入copy con .htaccess   3.回车后可以输入内容,再次回车即可产生文件

  9. 你可能没听过的 Java 8 中的 10 个特性

    你以前听到的谈论关于Java8的所有都是围绕lambda表达式. 但它仅仅是Java8的一部分. Java 8 有许多新特性—一些强大的新类和语法, 还有其他的从一开始就应该具有的东西. 我将要介绍我 ...

  10. 说说单节点集群里安装hive、3\5节点集群里安装hive的诡异区别

    这几天,无意之间,被这件事情给迷惑,不解!先暂时贴于此,以后再解决! 详细问题如下: 在hive的安装目录下(我这里是 /home/hadoop/app/hive-1.2.1),hive的安装目录的l ...