[React Native] Complete the Notes view

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: 1,
        flexDirection: ‘column‘
    },
    buttonText: {
        fontSize: 18,
        color: ‘white‘
    },
    button: {
        height: 60,
        backgroundColor: ‘#48BBEC‘,
        flex: 3,
        alignItems: ‘center‘,
        justifyContent: ‘center‘
    },
    searchInput: {
        height: 60,
        padding: 10,
        fontSize: 18,
        color: ‘#111‘,
        flex: 10
    },
    rowContainer: {
        padding: 10
    },
    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;
时间: 2024-08-06 11:54:53

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

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

measure()测量是根据view标签中的ref属性,使用方法如下: measureWatermarkerImage(){ this.refs.watermarkerImage.measure((a, b, width, height, px, py) => this.setState({watermarkerImageWidth: width}) );} with:宽:height:高:px:x轴方向距离左边多少像素:py:y轴方向距离上边多少像素: 根据项目需要,如果需要在页面加载完成后进

React Native专题-江清清

本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 刚创建的React Native交流8群:533435865  欢迎各位大牛,React Native技术爱好者加入交流!同时博客右侧欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! 关于React Native各种疑难杂症,问题深坑总结方案请点击查看: Mac和Windows安装搭建React Native环境教程如下: Mac OS X版本:Mac OS X安装R

React Native 从零到高级- 0基础学习路线

React Native QQ交流群(美团,饿了么,阿里的大神都在里面):576089067 React Native  从0 基础到高级 视频教程正在重录中,要了解最新进度可以关注菜鸟窝微信公众号(下图),旧版视频教程可以点击这里在线学习 学习路线(文章版),江清清老师出品,点击这里关注江清清 ,同时可以关注一下他的课程 基础入门:1.React Native For Android环境配置以及第一个实例2.React Native开发IDE安装及配置3.React Native应用设备运行(

【REACT NATIVE 系列教程之十三】利用LISTVIEW与TEXTINPUT制作聊天/对话框&&获取组件实例常用的两种方式

本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/react-native/2346.html 本篇Himi来利用ListView和TextInput这两种组件实现对话.聊天框. 首先需要准备的有几点:(组件的学习就不赘述了,简单且官方有文档) 1. 学习下 ListView: 官方示例:http://reactnative.cn/docs/0.27/tutorial.html#content

React Native专题文章讲解,不断更新中.....

转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50633488 本文出自:[江清清的博客] 本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 关于React Native各种疑难杂症,问题深坑总结方案请点击查看: Mac和Windows安装搭建React Native环境教程如下: Mac OS X版本:Mac OS X安装React Nati

React Native专题

刚创建的React Native技术交流1群(282693535),React Native技术交流2群(496601483),React Native技术交流3群(496508742).欢迎各位大牛,React Native技术爱好者加入交流!同时博客右侧欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! 关于React Native各种疑难杂症,问题深坑总结方案请点击查看: Mac和Windows安装搭建React Native环境教程如下: Mac OS X版本:Mac OS X安装

React Native实践之携程Moles框架

编者:本文来自携程框架研发部高级经理魏晓军在第二期[携程技术微分享]上的分享,以下为整理后的文字实录.视频回放可点击这里.关注携程技术中心微信公号ctriptech,可获知更多微分享课程信息. 因为支持用javascript开发原生应用,React Native一推出就受到不少公司热捧,各家都跃跃欲试.但有一个痛点是,在移动端,我们是否有必要开发多套程序:iOS.Android和H5?本次将通过对Moles框架的分享,介绍携程在React Native方面的实战干货,希望给大家一些灵感和启发.

【转】【React Native开发】

[React Native开发]React Native控件之ListView组件讲解以及最齐全实例(19) [React Native开发]React Native控件之Touchable*系列组件详解(18) [React Native开发]React Native控件之ViewPagerAndroid讲解以及美团首页顶部效果实例(17) [React Native开发]React Native控件之Switch开关与Picker选择器组件讲解以及使用(16) [React Native开发

[React Native] Animate Styles of a React Native View with Animated.timing

In this lesson we will use Animated.timing to animate the opacity and height of a View in our React Native application. This function has attributes that you can set such as easing and duration. import React, {Component} from 'react'; import {Text, V