我刚开始使用本机反应,我想知道如何建立登录和登录表单共享同一个屏幕。登录和登录选项卡都显示在一个屏幕上。只需点击任何选项卡,就会打开相同的表格来填写。请查看下面视频的 url 以参考我尝试使用 React native https://drive.google.com/file/d/1HH2PmZUAhsgBa6iqyt4-uHVvZXIp30H3/view?usp=drivesdk实现的目标
2 回答
1
您可以在状态中使用某些东西作为标志,例如,如果您触摸登录,则标志变为真,如果您触摸唱歌,则标志变为假,通过这种方式,您可以显示 2 个屏幕
于 2018-08-20T05:24:54.123 回答
1
我已经在设计这种类型的屏幕,我管理状态以改变这样的形式
import React from 'react';
import { View, Text, StatusBar, TouchableOpacity, ImageBackground, Image, ScrollView, UIManager, LayoutAnimation, BackHandler } from 'react-native'
import styles from '../stylesheet/LoginSignup';
import SignupForm from '../components/SignupForm';
import SigninForm from '../components/SigninForm';
export default class Auth extends React.Component {
static navigationOptions = {
header: null
};
constructor(props)
{
super(props);
this.state = {
IsOpenTab : 'SignIn', // 'SignIn', 'SignUp' OR 'ResetPassword'
};
UIManager.setLayoutAnimationEnabledExperimental &&
UIManager.setLayoutAnimationEnabledExperimental(true);
// LayoutAnimation.spring();
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}
handleBackPress = () => {
return false;
};
render() {
return (
<ScrollView style={styles.container} keyboardShouldPersistTaps='always'>
<StatusBar backgroundColor='#2c8ba6' barStyle='light-content' />
<View style={styles.TopLogoArea}>
<ImageBackground source={require('../assets/bg_top.png')} style={styles.TopLogoAreaBackground}>
<View style={{paddingTop: 20}}>
<Image source={require('../assets/logo.png')} resizeMode='contain' style={{width: 150, height: 150,}}/>
</View>
<View style={{flexDirection:'row'}}>
{
this.state.IsOpenTab === 'SignIn' ? <View style={styles.TabArea}><View style={styles.TabActiveArea}><Text style={styles.TabActiveLable}>SIGN IN</Text><View style={styles.TabActiveLine}/></View></View> : <TouchableOpacity onPress={()=>this.NavigateForm('SignIn')} activeOpacity={0.8} style={styles.TabArea}><Text style={styles.TabDeactiveLable}>SIGN IN</Text></TouchableOpacity>
}
<View style={styles.TabArea}>
<Text style={{color:'#2dc7b0', fontWeight:'bold', fontSize: 12}}>OR</Text>
</View>
{
this.state.IsOpenTab === 'SignUp' ? <View style={styles.TabArea}><View style={styles.TabActiveArea}><Text style={styles.TabActiveLable}>SIGN UP</Text><View style={styles.TabActiveLine}/></View></View> : <TouchableOpacity onPress={()=>this.NavigateForm('SignUp')} activeOpacity={0.8} style={styles.TabArea}><Text style={styles.TabDeactiveLable}>SIGN UP</Text></TouchableOpacity>
}
</View>
</ImageBackground>
</View>
<View style={{paddingVertical:40,}}>
{
this.state.IsOpenTab === 'SignIn' ? <SigninForm navigation={this.props.navigation} /> : <SignupForm navigation={this.props.navigation} />
}
</View>
</ScrollView>
);
}
NavigateForm = (method) => {
const CustomLayoutLinear = {
duration: 300,
create: {
type: LayoutAnimation.Types.linear,
property: LayoutAnimation.Properties.opacity,
},
update: {
type: LayoutAnimation.Types.linear,
property: LayoutAnimation.Properties.opacity,
},
};
LayoutAnimation.configureNext(CustomLayoutLinear );
if(method === 'SignUp'){
this.setState({
IsOpenTab : 'SignUp',
});
}else{
this.setState({
IsOpenTab : 'SignIn',
});
}
}
}
于 2018-08-20T05:34:23.550 回答