【发布时间】:2017-06-10 03:22:17
【问题描述】:
我有一个 ActivityIndicator,它在 fetch 加载时显示,当 componentDidMount 被触发时,滚轮消失,但在布局中保留并留空块空间。我在猜测如何卸载这个组件,但一切都对我有用。
我目前正在使用这些版本:
react-native-cli: 2.0.1
react-native: 0.40.0
这是我正在使用的代码的一部分:
import React, { Component } from 'react';
import {
StyleSheet,
View,
... // Couple more components here
ActivityIndicator,
} from 'react-native';
import NewsList from './NewsList';
export default class HomeView extends Component {
constructor(props) {
super(props);
this.state = {
noticias: [],
animating: true,
};
}
componentDidMount(){
fetchFunction() // My fetch function here
.then(data => this.setState({ data:data }))
this.state.animating = false
}
render() {
return (
<View>
<NewsList data={data} /> // My custom component
<ActivityIndicator
animating={this.state.animating}
style={[{height: 80}]}
color="#C00"
size="large"
hidesWhenStopped={true}
/>
</View>
);
}
}
PS:我没有使用 Redux。
ActivityIndicator with animation working fine The empty space when animating is set to false
【问题讨论】:
-
this.state.animating = false为什么不像上一行那样使用 setState? -
我改成:
.then(data => this.setState({ data:data, animating: false }))得到了同样的结果
标签: javascript react-native jsx uiactivityindicatorview activity-indicator