Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ActivityIndicator][Android] Indicator stays hidden if initialized as animating={false} #9023

Closed
kulmajaba opened this issue Jul 26, 2016 · 33 comments
Labels
Bug Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@kulmajaba
Copy link

kulmajaba commented Jul 26, 2016

Originally discovered on http://stackoverflow.com/questions/38579665/reactnative-activityindicator-not-showing-when-animating-property-initiate-false

If ActivityIndicator is initialized with animating={false}, the Indicator will stay hidden even when changing animating to true. When initialized as animating the changes behave as expected.

Tested on Android emulator and Device, running Android 6.0 and 6.0.1. Also tested on iOS device which works as expected. Testing done with Windows 8.1.

'use strict'

import React, { Component } from 'react';
import {
    AppRegistry,
    Text,
    View,
    TouchableHighlight,
    ActivityIndicator
} from 'react-native';

class SampleApp extends Component {
    constructor() {
        super();

    this.state = {
            show: false
        };
    }

    render() {
        return (
            <View>
                <TouchableHighlight onPress={ () => this.setState({show: false}) } >
                    <Text>HIDE</Text>
                </TouchableHighlight>

                <TouchableHighlight onPress={ () => {this.setState({show: true}) } >
                    <Text>SHOW</Text>
                </TouchableHighlight>

                <ActivityIndicator animating={this.state.show} size="large"/>
            </View>
        );
    }
}

AppRegistry.registerComponent('SampleApp', () => SampleApp);
@alannesta
Copy link

alannesta commented Jul 31, 2016

@kulmajaba Which react-native version are you using ?
I got the same issue on Android with react-native 0.28. Seems to be a bug with the animating property. Currently using the walkaround of either rendering the ActivityIndicator or completely hide it based on the state

@kulmajaba
Copy link
Author

@alannesta Using React Native 0.30. I've used the same workaround, rendering a separate loading view when needed.

@antoinerousseau
Copy link
Contributor

I have the opposite bug: it sometimes freezes instead of hiding

@esutton
Copy link

esutton commented Aug 30, 2016

Same issue on React Native 0.32 on Android 6.0.1

ActivityIndicator did not work so I went back to AndroidProgressBar which had yellow box warning under 0.32 for manually calling a React.PropTypes validation function.

ActivityIndicator work-around was to use null when animating should be false

                  let spinner = (this.state.animate) ? (
                    <ActivityIndicator
                    animating={true}
                    size="small"
                    />
                  ) : (
                      null
                  );

@charpeni

This comment has been minimized.

@charpeni

This comment has been minimized.

@charpeni

This comment has been minimized.

@facebook-github-bot

This comment has been minimized.

@facebook-github-bot facebook-github-bot added Ran Commands One of our bots successfully processed a command. Icebox labels Nov 14, 2016
@prithsharma

This comment has been minimized.

@fcpauldiaz

This comment has been minimized.

@raphkr
Copy link

raphkr commented Feb 21, 2017

The simplest I did was

<ActivityIndicator
   animating={true}
   style = {{ opacity : this.state.animate ? 1 : 0 }}
/>

@Brian-Kaplan
Copy link

@raphkr i don't like that at all... Then it's always animating... not the best

@sryze
Copy link
Contributor

sryze commented Mar 3, 2017

I'm seeing this bug on Android too (Android 7.1 emulator). The opacity: 0 solution from this post worked for me:

http://stackoverflow.com/questions/38579665/reactnative-activityindicator-not-showing-when-animating-property-initiate-false

I think this issue needs to be reopened.

@mirzavu
Copy link

mirzavu commented Sep 15, 2017

This one is simple and background is not clickable when loading. Manage the loading icon using this.state.loading

{ this.state.loading &&
     <View style={styles.loading}>
          <ActivityIndicator
                 animating = {true}
                 color = '#bc2b78'
                 size = "large"/>
     </View>
}

and in styles

loading: {
    position: 'absolute',
    left: 0,
    right: 0,
    top: 0,
    bottom: 0,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#F5FCFF88'
  }

@Dror-Bar
Copy link

Dror-Bar commented Jan 10, 2018

Can confirm this is still happening in Android RN: 0.51.0.
I'm using a conditional JSX expression as a workaround but strange this hasn't been fixed yet.
Why was this closed at all if it's still an issue that needs to be addressed?

@alexsmartens

This comment has been minimized.

@charpeni charpeni reopened this Feb 19, 2018
@charpeni
Copy link
Contributor

Let's reopen it then.

@hramos hramos added Android and removed Icebox Ran Commands One of our bots successfully processed a command. labels Mar 5, 2018
@changulpaye

This comment has been minimized.

@fcpauldiaz
Copy link

@changulpaye

<ActivityIndicator
   animating={true}
   style = {{ opacity : this.state.animate ? 1 : 0 }}
/>

@react-native-bot react-native-bot added Android Ran Commands One of our bots successfully processed a command. labels Mar 18, 2018
@ocarreterom
Copy link

This is still happening in 0.54.4.

@djhr

This comment has been minimized.

@yagoazedias

This comment has been minimized.

@alexsmartens
Copy link

It's definitely a problem, however solution proposed by @esutton worked out for me

@MardariG

This comment has been minimized.

@hramos hramos added the Help Wanted :octocat: Issues ideal for external contributors. label Jun 12, 2018
@TingAli
Copy link

TingAli commented Dec 12, 2018

This is still an issue to this day :(

@Bradzer
Copy link

Bradzer commented Jan 31, 2019

Is there any way to work around that bug ?

@ocarreterom
Copy link

@Bradzer #9023 (comment)

@ernanirst
Copy link

Still running into this on react-native 0.58.3

@lucasmotta
Copy link

Just ran with this issue on react-native 0.59.0 too. My solution was to pass a key prop to the ActivityIndicator to trigger a re-render:

return <ActivityIndicator animating={loading} key={loading ? 'loading' : 'not-loading'} />

@nhunzaker
Copy link
Contributor

I took a layout snapshot of the example provided above, and it looks like the container for the progress indicator is displaying, but the actual indicator itself has width/height of 0:

image

For some reason the indicator's width/height isn't getting updated.

nhunzaker added a commit to nhunzaker/react-native that referenced this issue Jun 21, 2019
On Android, if the ActivityIndicator component is initially set to
animate={false}, it does not display if later set to true.

For some reason, the layout width/height of the associated ProgressBar
remains 0, despite the parent layout having the correct width/height.

I noticed that changing the visibility settings from View.GONE to
View.INVISIBLE didn't have an impact on the React Native layout, and
doing so appears to alleviate the issue.

Related to:
facebook#9023
@nhunzaker
Copy link
Contributor

I think I might have a fix for this here: #25354

Seems too trivial. Curious what others have to say.

@grantespo
Copy link

I have the latest version of RN, still getting this issue.

@borislemke
Copy link

Still getting this issue with RN 0.61.4

M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this issue Mar 10, 2020
…NE to hide ActivityIndicator (facebook#25354)

Summary:
On Android, if the ActivityIndicator component is initially set to `animate={false}`, it does not display if later set to `true` (facebook#9023)

For some reason, the layout width/height of the associated ProgressBar remains 0, despite the parent layout having the correct width/height:

![image](https://user-images.githubusercontent.com/590904/59955251-f8d2ef00-943d-11e9-8019-0977e19186b3.png)

I wasn't able to determine why this is the case, but I did notice that changing the visibility settings from `View.GONE` to `View.INVISIBLE` fixes the issue while not (as far as I can tell) having an impact on the React Native layout:

#### Before:

![before](https://user-images.githubusercontent.com/590904/59955177-a1cd1a00-943d-11e9-80da-876c99b7d5bf.gif)

#### After:

![after](https://user-images.githubusercontent.com/590904/59955183-a7c2fb00-943d-11e9-952b-892bdc23bd48.gif)

Using `View.INVISIBLE` appears to alleviate the issue.

This should fix facebook#9023

## Changelog

[Android][fixed] - ActivityIndicator appears as expected when `animated={false}` is later set to `true`.
Pull Request resolved: facebook#25354

Test Plan:
Link this branch to a new React native project with the following App.js class:

```javascript
import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  Button,
  View,
  ActivityIndicator,
  TouchableHighlight
} from "react-native";

export default class App extends Component {
  constructor() {
    super();

    this.state = {
      show: false
    };
  }

  hide = () => {
    this.setState({ show: false });
  };

  show = () => {
    this.setState({ show: true });
  };

  render() {
    return (
      <View>
        <ActivityIndicator
          animating={this.state.show}
          size="large"
          style={styles.indicator}
        />

        <ActivityIndicator
          animating={this.state.show}
          size="small"
          style={styles.indicator}
        />

        <View style={{ flexDirection: "row" }}>
          <Button title="Hide" style={styles.button} onPress={this.hide} />
          <Button title="Show" style={styles.button} onPress={this.show} />
        </View>

        <Text>Showing ? {this.state.show.toString()}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  indicator: {
    borderColor: "red",
    borderWidth: 1
  },
  button: {
    marginRight: 8
  }
});
```

Differential Revision: D15963366

Pulled By: cpojer

fbshipit-source-id: ee3df3fd84acbff342599dc6f4f4a391704876fa
@facebook facebook locked as resolved and limited conversation to collaborators Jun 24, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet