ActivityIndicator remains on screen after being removed
See original GitHub issueI put an ActivityIndicator
on screen, which should be removed after some time (i.e. when the data arrives). But the problem is that it still remains on screen even after it is removed (or not outputted) in the render function. In addition, the backgroundColor
of the View
above disappears, too.
I also found out that doing one of the following things fixes the problem, but I don’t know why:
- Unset the
zIndex
for theView
above (havingzIndex
here has no reason what so ever, but I needed this in the project I was working on) - Set a
backgroundColor
for theView
element containing thisActivityIndicator
.
Public repository with runnable example Inline code:
export default class TestReport extends Component {
state = {
showIndicator: true,
};
componentDidMount() {
setTimeout(() => this.setState({showIndicator: false}), 3000);
}
render() {
return (
<View style={styles.container}>
<View style={styles.firstHalf}>
</View>
<View style={styles.secondHalf}>
{this.state.showIndicator
? (<ActivityIndicator size="large"/>)
: (<Text>hello</Text>)}
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
firstHalf: {
zIndex: 1,
flex: 1,
backgroundColor: "#2f2",
},
secondHalf: {
flex: 1,
},
});
Here’s a screen recording of what happens:
- What should happen: the indicator should be removed after 3 seconds and the message
hello
should appear. - What happens: the indicator remains after the 3 seconds, and the message
hello
appears. In addition, thebackgroundColor
of theView
above disappears.
Versions:
- react-native: 0.41.2
- react: 15.4.2
- react-native-cli: 2.0.1
- devices:
- Nexus 5 - Android version: 7.1
- LG G2 mini - Android version: 5.0.2
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Show Activity Indicator before Segue. - Apple Developer
When I tap the button for segue, the app gets into the inactive state for at least 5 seconds. I'm aiming to show...
Read more >Programmatically created activity indicator not removing
No need to remove activity indicator from the parent view. Just stop the activity indicator animating. -(void)DataReceived { dispatch_async( ...
Read more >How to build a customized React Native activity indicator
Learn how to customize cross-platform activity indicators in React Native from scratch, with third-party libraries, and inbuilt APIs!
Read more >Spinner and Progress Bar in Swift: Getting Started
As you did before, open Main.storyboard in a second editor and drag the IBOutlet connection to the newly created activity indicator view. Build ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like a bug with zIndex and view collapsing, the current implementation of zIndex is pretty buggy because it reorders views instead of just changing the drawing order.
As a workaround you could either
collapsable={false}
to your view that wraps the activity indicatorIf I do it this way, it works, but it still occupies space:
I can hide it like this, which is not pretty:
But if I do it this way, it doesn’t change anything:
I’m not particularly interested in getting this piece of code to work. I’m just asking, am I doing something wrong or is this not the expected behavior?