Browse Source

feat: show ActivityIndicator when pending login request

pull/1/head
kdxcxs 4 years ago
parent
commit
6713dc02ec
  1. 22
      src/ui/YooLoginUI.js

22
src/ui/YooLoginUI.js

@ -6,6 +6,7 @@ import {
TextInput, TextInput,
TouchableOpacity, TouchableOpacity,
Text, Text,
ActivityIndicator,
} from 'react-native'; } from 'react-native';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -57,14 +58,33 @@ function LoginInput(props) {
} }
export default class YooLoginUI extends Component { export default class YooLoginUI extends Component {
constructor(props) {
super(props);
this.state = {
loading: false,
};
this.onButtonPress = this.onButtonPress.bind(this);
}
onButtonPress() {
if (!this.state.loading) {
this.setState({loading: true});
this.props.loginCallback();
}
}
render() { render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Image source={require('../../assets/icon.png')} style={styles.logo} /> <Image source={require('../../assets/icon.png')} style={styles.logo} />
<LoginInput type={'username'} /> <LoginInput type={'username'} />
<LoginInput type={'password'} /> <LoginInput type={'password'} />
<TouchableOpacity style={styles.button}> <TouchableOpacity style={styles.button} onPress={this.onButtonPress}>
{this.state.loading ? (
<ActivityIndicator size="large" color="#00ff00" />
) : (
<Text style={styles.buttonText}>登录</Text> <Text style={styles.buttonText}>登录</Text>
)}
</TouchableOpacity> </TouchableOpacity>
</View> </View>
); );

Loading…
Cancel
Save