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

import firebase from 'firebase';
import React from 'react';
import {
View,
StyleSheet,
Text,
ListView,
TextInput,
TouchableHighlight
} from 'react-native';
import Badge from './Badge';
import Divdir from './Helpers/divdir'; var styles = StyleSheet.create({
container: {
flex: ,
flexDirection: 'column'
},
buttonText: {
fontSize: ,
color: 'white'
},
button: {
height: ,
backgroundColor: '#48BBEC',
flex: ,
alignItems: 'center',
justifyContent: 'center'
},
searchInput: {
height: ,
padding: ,
fontSize: ,
color: '#111',
flex:
},
rowContainer: {
padding:
},
footerContainer: {
backgroundColor: '#E3E3E3',
alignItems: 'center',
flexDirection: 'row'
}
}); // In the video there are a couple errors, fixed them so it would build.
class Notes extends React.Component{
constructor(props){
super(props);
this.ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
this.notes = [];
this.state = {
note: '',
dataSource: null,
};
// Initialize Firebase
var config = {
apiKey: "AIzaSyAs8HBqV2X6VIOE5MnDwENz1nRffNkUbiU",
authDomain: "github-saver-9a338.firebaseapp.com",
databaseURL: "https://github-saver-9a338.firebaseio.com",
storageBucket: "github-saver-9a338.appspot.com",
};
firebase.initializeApp(config);
}
componentDidMount(){
firebase.database().ref('notes/').on('child_added', (data)=>{
this.notes.push(data.val());
})
}
handleChange(e){
this.setState({
note: e.nativeEvent.text
})
}
handleSubmit(){
let note = this.state.note;
firebase.database().ref('notes/').push({
note,
timestamp: +new Date()
})
this.setState({
note: ''
})
}
render(){ var notesHtml = this.notes && this.notes.map((note, index)=>{
return (
<View>
<Text key={index}>{note.note}</Text>
<Divdir />
</View>
);
}); return (
<View style={styles.container}>
<Badge userInfo={this.props.userInfo}/>
<View>
{notesHtml}
</View>
<View style={styles.footerContainer}>
<TextInput
style={styles.searchInput}
value={this.state.note}
onChange={this.handleChange.bind(this)}
placeholder="New Note" />
<TouchableHighlight
style={styles.button}
onPress={this.handleSubmit.bind(this)}
underlayColor="#88D4F5">
<Text style={styles.buttonText}>Submit</Text>
</TouchableHighlight>
</View>
</View>
)
}
}; Notes.propTypes = {
userInfo: React.PropTypes.object.isRequired
}; 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. ORACLE【1】:触发器详解

    转自:http://blog.csdn.net/indexman/article/details/8023740 ORACLE PL/SQL编程之八: 把触发器说透 本篇主要内容如下: 8.1 触发器 ...

  2. UVa 442 (栈) Matrix Chain Multiplication

    题意: 给出一个矩阵表达式,计算总的乘法次数. 分析: 基本的数学知识:一个m×n的矩阵A和n×s的矩阵B,计算AB的乘法次数为m×n×s.只有A的列数和B的行数相等时,两个矩阵才能进行乘法运算. 表 ...

  3. I.MX6 Android i2c-tools porting

    /************************************************************************** * I.MX6 Android i2c-tool ...

  4. Java String 的equals, == , hascode的区别

    1.equals 和 == ==在java中是比较引用的,即在内存中的地址.而String的equals()是比较字符串的内容 http://blog.csdn.net/barryhappy/arti ...

  5. Entity Framework 增删改查和事务操作

    1.增加对象 DbEntity db = new DbEntity(); //创建对象实体,注意,这里需要对所有属性进行赋值(除了自动增长主键外),如果不赋值,则会数据库中会被设置为NULL(注意是否 ...

  6. Sql2005 全文索引详解

    1.前言 14.1  全文索引的介绍 14.2  全文索引中常用的术语 14.3  全文索引的体系结构 14.4  全文目录管理 14.4.1  创建全文目录 14.4.2  查看与修改全文目录 14 ...

  7. Loader for loading embedded assemblies z

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Ref ...

  8. Webdriver API (一)

    (转载) 1.1  下载selenium2.0的包 官方download包地址:http://code.google.com/p/selenium/downloads/list 官方User Guid ...

  9. delphi获取mdb密码

    function GetPasswordFromAccess(AFileName: string): string;var  myms: TMemoryStream;  b: array of Byt ...

  10. Code First 更新数据库结构(简单实现方法:会删除原来的数据)

    之前在 http://www.cnblogs.com/mmcmmc/p/3833265.html 写到关于“Code First 更新数据库结构”的东西. 可是由于某种原因,新手们会出现各种问题,好了 ...