React Native的学习之小练习-登录页

43 篇文章 0 订阅
16 篇文章 0 订阅

在项目中,有ios和Android的区别,不同的设备显示的内容也会有些差异,所以,布局时有时要改不同的样式才能显示一样的效果,所以可以把两个文件都映射到一个文件中只修改一个文件就可以达到这样的效果。先新建一个login.js.内容如下:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  TextInput
} from 'react-native';

class Login extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Image style={styles.Icon} source={require('./imgs/hb.jpg')}/>
        <TextInput 
        style={styles.userStyle}
        placeholder='请输入用户名'
        clearButtonMode='always' //never 永远不显示删除 always 一直显示  
        clearTextOnFocus={true}  //获取焦点时是否清空文字 、
        enablesReturnKeyAutomatically={false}  //是否自动启用回车键,有内容就显示,没有就不启用
        returnKeyType = 'go'  //回车键上的文字: go前往 join加入 next 下一项 route路线 send 发送 search 搜索 
        onChangeText={()=>{console.warn('用户名是...')}} //文字修改完重新给state的query赋值
        />
        <TextInput 
        style={styles.userStyle}
        placeholder='请输入密码'
        clearButtonMode='always' //never 永远不显示删除 always 一直显示  
        clearTextOnFocus={true}  //获取焦点时是否清空文字 
        password={true}
        enablesReturnKeyAutomatically={false}  //是否自动启用回车键,有内容就显示,没有就不启用
        returnKeyType = 'go'  //回车键上的文字: go前往 join加入 next 下一项 route路线 send 发送 search 搜索 
        onChangeText={()=>{console.warn('用户名是...')}} //文字修改完重新给state的query赋值
        />
        <View style={styles.loginStyle}>
          <Text style={styles.instructions}>
              登录
          </Text>
        </View>
        <View style={styles.more}>
           <Text style={styles.welcome}>
           忘记密码
          </Text>
          <Text style={styles.instructions}>
            注册
          </Text>
        </View>
        <View style={styles.otherLoginStyle}>
          <Text style={styles.instructions}>
            其他登录方式:
          </Text>
           <Image style={styles.icons} source={require('./imgs/hb.jpg')}/> 
           <Image style={styles.icons} source={require('./imgs/hb.jpg')}/> 
           <Image style={styles.icons} source={require('./imgs/hb.jpg')}/> 
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container:{
    flex: 1,
    alignItems:'center',
    backgroundColor:'#F5FCFF'
  },
  Icon:{
    width:200,
    height:200,
    borderRadius:100,
    marginTop:20,
    marginBottom:20,
  },
  userStyle:{
    width:300,
    height:50,
    textAlign:'center',
    // borderWidth:1,
    backgroundColor:'#ededed',
    marginBottom:10,

  },
  loginStyle:{
    width:200,
    marginBottom:10,
    alignItems:'center',
    backgroundColor:'pink',
  },
  more:{
    flexDirection:'row',
    width:200,
    justifyContent:'space-between',
  },
  otherLoginStyle:{
    flexDirection:'row',
    alignItems:'center',
    position:'absolute',
    left:10,
    bottom:20,
  },
  icons:{
    width:50,
    height:50,
    borderRadius:25,
    marginLeft:5,
  },
});

module.exports = Login

写完这个页面了,要在index.android.js和index.ios.js中引入这个组件,才能映射到这一个文件中,在这两个文件中可以直接这么写:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import Login from './login.js';
export default class Project extends Component {
  render() {
    return (
      <Login />
    );
  }
}

AppRegistry.registerComponent('Project', () => Project);

就可以一进来就到登录页了,贴张图:
login的页面

可能样式有些不太好看,就先这样看着吧,TextInput组件在Android上有个线,想去掉的话,加上那个属性就可以,我的博客里有一个写TextInput的,想了解的小伙伴可以戳TextInput
简单的登录页出来了。
有什么宝贵意见建议,可以在下方留言哦!十分感谢!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值