[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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2014-08-05 [Javascript] Hositing