【发布时间】:2016-11-29 11:58:19
【问题描述】:
我正在玩 react native 并且有一个奇怪的行为。
当我尝试为 Android 显示 ActivityIndicator 时,将其 animating 属性设置为 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});
}
}
但是如果我使用下面的代码,动画属性以 false 开头,那么使 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 的吗? facebook.github.io/react-native/docs/… 。默认情况下,当动画为假时它会隐藏
-
我遇到了同样的问题,无法正常工作。当状态为假时,我最终在视觉上隐藏了指示器 (
{height:0})。