我正在玩反应本机,并得到了一个奇怪的行为。ReactNative ActivityIndicator不显示动画属性启动虚假时
当我试图表明一个ActitvityIndicator为Android其动画属性设置为true,在状态的showProgress
变量如果变量开始为假这是行不通的。
在下面的示例中,如果ActivityIndicator动画属性的起始值为true,那么按钮会使ActivityIndicator隐藏或正确显示。
import React, { Component } from 'react';
import {
Text,
View,
StyleSheet,
TextInput,
TouchableHighlight,
ActivityIndicator
} from 'react-native';
export class Login extends Component {
constructor(props) {
super(props);
this.state = {
showProgress: true
};
}
render() {
return (
<View>
<TouchableHighlight onPress={this.progressOff.bind(this)}>
<Text>progressOff</Text>
</TouchableHighlight>
<TouchableHighlight onPress={this.progressOn.bind(this)}>
<Text>progressOn</Text>
</TouchableHighlight>
<ActivityIndicator animating={this.state.showProgress} size="large"/>
</View>
);
}
progressOff() {
this.setState({showProgress: false});
}
progressOn() {
this.setState({showProgress: true});
}
}
但是,如果使用下面的代码,用动画属性起假,那么按钮使ActivityIndicator出现不工作:
import React, { Component } from 'react';
import {
Text,
View,
StyleSheet,
TextInput,
TouchableHighlight,
ActivityIndicator
} from 'react-native';
export class Login extends Component {
constructor(props) {
super(props);
this.state = {
showProgress: false
};
}
render() {
return (
<View>
<TouchableHighlight onPress={this.progressOff.bind(this)}>
<Text>progressOff</Text>
</TouchableHighlight>
<TouchableHighlight onPress={this.progressOn.bind(this)}>
<Text>progressOn</Text>
</TouchableHighlight>
<ActivityIndicator animating={this.state.showProgress} size="large"/>
</View>
);
}
progressOff() {
this.setState({showProgress: false});
}
progressOn() {
this.setState({showProgress: true});
}
}
缺少什么我在这里?
是,对于IOS? https://facebook.github.io/react-native/docs/activityindicator.html#hideswhenstopped。默认情况下,它在动画设置为假时隐藏 –
我有同样的问题,无法正常工作。当状态为假时,我最终在视觉上隐藏了指示符('{height:0}')。 – zvona