javascript 重新编写RN登录表单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 重新编写RN登录表单相关的知识,希望对你有一定的参考价值。

import React from 'react';
import PropTypes from 'prop-types';
import { 
	compose,
	withHandlers, 
	withState,
	setStatic,
	setPropTypes
} from 'recompose';
import { View } from 'react-native';
import { Button, FormInput, FormLabel } from 'react-native-elements';
import styles  from './Styles/LoginStyle';
import color from '../Themes/Colors';

const enhance = compose(
	setStatic('navigationOptions', { header: null }),
	setPropTypes({ onPress: PropTypes.func }),
	withState('username', 'userValue', ''),
	withState('password', 'passValue', ''),
	withHandlers({
		onUserChange: props => user => props.userValue(user),
		onPwdChange: props => pwd => props.passValue(pwd),
		onLogin: props => () => {
			props.navigation.navigate('main')
		}
	})
);

const Login = enhance(({
	username,
	password,
	onLogin, 
	onUserChange,
	onPwdChange,
}) => (
	<View style={styles.container}>
		<FormLabel>Username</FormLabel>
		<FormInput
			style={styles.textInput}
			placeholder="Username"
			value={username}
			onChangeText={onUserChange}
		/>
		<FormLabel>Password</FormLabel>
		<FormInput
			style={styles.textInput}
			placeholder="Password"
			secureTextEntry
			value={password}
			autoCapitalize={'none'}
			onChangeText={onPwdChange}
		/>
		<Button
			raised
			buttonStyle={styles.signBtn}
			title="SIGN IN"
			color={color.white}
			onPress={onLogin}
		/>
	</View>
))

export default Login;

以上是关于javascript 重新编写RN登录表单的主要内容,如果未能解决你的问题,请参考以下文章

React Native深入理解Native与RN通信原理

React Native深入理解Native与RN通信原理

React Native深入理解Native与RN通信原理

React Native深入理解Native与RN通信原理

RN与系统底层交互

RN与系统底层交互