React-Native学习笔记之:实现简单地登录页面
2017-04-19 15:10
696 查看
学习React Native一些时间了,想自己根据学习的知识开发个简单地独立地APP,今天开始第一步,实现登录界面功能:
index.ios.js或者index.android.js
import React, {Component} from 'react'; import { AppRegistry, } from 'react-native'; import Welcome from './pages/Welcome' AppRegistry.registerComponent('DeviceRnApp', () => Welcome);
Login.js:
import React, {Component} from 'react'; import { AppRegistry, StyleSheet, Text, View, Navigator, TextInput, TouchableHighlight } from 'react-native'; import MainPage from './MainPage' export default class Login extends Component { constructor(props) { super(props); } render() { return (<View style={styles.container}> <View style={styles.item}><Text style={styles.textStyle}>用户帐号:</Text> <TextInput ref="inputLoginName" autoFocus={true} underlineColorAndroid="gray" placeholder="请输入用户名" clearTextOnFocus={true} clearButtonMode="while-editing" style={{flex: 1}} onChangeText={(input) => this.setState({username: input})} ></TextInput> </View> <View style={styles.item}><Text style={styles.textStyle}>用户密码:</Text> <TextInput ref="inputLoginPwd" underlineColorAndroid="gray" placeholder="请输入密码" clearTextOnFocus={true} clearButtonMode="while-editing" style={{flex: 1}} onChangeText={(input) => this.setState({userpwd: input})}></TextInput> </View> <TouchableHighlight style={styles.login} underlayColor='transparent' onPress={()=>this.loginInMainpage()}><Text style={styles.loginText}>登录</Text></TouchableHighlight> </View>) } /** * 登录进入主页面 */ loginInMainpage() { this.refs.inputLoginName.blur(); this.refs.inputLoginPwd.blur(); this.props.navigator.resetTo({ component: MainPage, params: { logNmae: this.state.username, logPwd: this.state.userpwd, parentComponent: this, ...this.props }, }); } setLoginName(input) { this.setState = {inputName: input} } setLoginPwd(input) { this.setState = {inputPwd: input} } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center' }, item: { flexDirection: 'row', alignItems: 'center', margin: 10 }, textStyle: { fontSize: 18, color: 'black', marginRight: 10 }, login: { height: 40, backgroundColor: 'green', margin: 20, justifyContent: 'center', }, loginText: { fontSize: 20, alignSelf: 'center', color: '#FFF' } })
点击登录跳转到MainPage.js:
import React, {Component} from 'react'; import { AppRegistry, StyleSheet, Text, View, Navigator, } from 'react-native'; export default class MainPage extends Component { constructor(props) { super(props); } render() { return (<View style={styles.container}> <Text style={styles.textStyle}>欢迎来到主界面</Text> <Text style={styles.textStyle}>您当前的用户名是:{this.props.logNmae}</Text> <Text style={styles.textStyle}>您当前的密码是:{this.props.logPwd}</Text> </View>) } } const styles = StyleSheet.create({ container: { flex: 1, }, textStyle: { fontSize: 18, color: 'black', marginRight: 10 }, })
丑陋的效果图:
相关文章推荐
- React-Native学习笔记之:导航器Navigator实现页面间跳转
- Struts 1 学习笔记-1(简单登录模块的实现,Struts初步了解)
- React-Native学习笔记之:Modal实现覆盖效果(类似安卓中PopuWindow)
- 使用if-else实现简单的登录注销(学习笔记)
- Django框架学习笔记(10.基于ORM实现简单的用户登录)
- React Native学习笔记之--向原生应用中集成RN页面
- Spring MVC 学习笔记9 —— 实现简单的用户管理(4)用户登录显示局部异常信息
- React-Native实现登录页面,并显示和清除用户的输入
- Spring MVC 学习笔记8 —— 实现简单的用户管理(4)用户登录
- struts2第十二讲学习笔记,综合使用实现登录,页面中使用ognl表达式请求值
- React-Native学习笔记之:弹框框架Popover简单使用
- Silverlight学习笔记一(理解一下机制,使用一下布局,实现一个简单的用户登录)
- JAVA 用于练手的超简单登录注册,jdbc实现【学习笔记】
- JFinal学习笔记(二) 实现简单的用户登录
- React-Native傻瓜式学习笔记(一):ListView的简单使用
- ReactNative学习笔记--下拉选择菜单的简单封装
- Spring MVC 学习笔记10 —— 实现简单的用户管理(4.3)用户登录显示全局异常信息
- 【学习笔记⑦】登录页面怎样实现验证码登录功能
- react-native学习笔记——简单尝试
- ASP.NET jQuery 食谱11 (通过使用jQuery validation插件简单实现用户登录页面验证功能)