React-Native学习笔记之:实现简单地登录页面
来源:互联网 发布:yy挂机喊话软件 编辑:程序博客网 时间:2024/06/09 01:34
学习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 },})
丑陋的效果图:
2 0
- React-Native学习笔记之:实现简单地登录页面
- React-Native学习笔记之:导航器Navigator实现页面间跳转
- React-Native学习笔记之React-Native升级
- React Native 仿登录页面
- React-native学习笔记之<BackAndroid>
- react-native学习笔记之<TextInput>
- react native 学习笔记之hello world
- react native 学习笔记之Props
- react native 学习笔记之state
- React-Native学习笔记之生命周期
- React Native 学习笔记之--布局
- React-Native 学习笔记
- react native学习笔记
- react-native 学习笔记
- 学习笔记 - React Native
- React Native 学习笔记
- React Native 学习笔记
- react-native 学习笔记
- 视频的输出模式以及音视频不同步问题
- 模拟实现定制删除器的SharedPtr
- 完美世界2017实习生面试
- 不得不看!国内深度摄像头方案大起底
- jquery 实现 点击按钮后倒计时效果,多用于实现发送手机验证码、邮箱验证码
- React-Native学习笔记之:实现简单地登录页面
- 在服务器上部署项目时Tomcat内存溢出
- JAVA程序员必看的15本书-JAVA自学书籍推荐
- 在Ubuntu16.10上开启docker17.03.0-ce的https认证
- dropload.js+anjular实现的无线下拉。。。。
- tpf 团队开发vs 多人签入后出现资源冲突
- 对象的作用域,对象方法扩展
- Android WebView的使用集锦(支持Html5)
- Linux下安装mysql