[React Native] Complete the Notes view

來源:互聯網
上載者:User

標籤:

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;

 

[React Native] Complete the Notes view

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.