question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ActivityIndicator remains on screen after being removed

See original GitHub issue

I 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 the View above (having zIndex here has no reason what so ever, but I needed this in the project I was working on)
  • Set a backgroundColor for the View element containing this ActivityIndicator.

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, the backgroundColor of the View above disappears. rn-activityindicator

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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
janicduplessiscommented, Feb 10, 2017

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

  • Remove the zIndex, if possible
  • Add collapsable={false} to your view that wraps the activity indicator
2reactions
farzadabcommented, Feb 8, 2017

If I do it this way, it works, but it still occupies space:

<ActivityIndicator size="large" animating={this.state.showIndicator}/>
{this.state.showIndicator ? null : (<Text>hello</Text>)}

I can hide it like this, which is not pretty:

<ActivityIndicator size="large" animating={this.state.showIndicator}
    style={this.state.showIndicator ? null : {height: 0}}/>
{this.state.showIndicator ? null : (<Text>hello</Text>)}

But if I do it this way, it doesn’t change anything:

{this.state.showIndicator
    ? (<ActivityIndicator size="large" animating={this.state.showIndicator}/>)
    : (<Text>hello</Text>)}

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?

Read more comments on GitHub >

github_iconTop 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 >
ActivityIndicator - React Native
Displays a circular loading indicator.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found