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

Non-stop spinner. #30

Closed
Arkanine opened this issue Oct 6, 2016 · 45 comments
Closed

Non-stop spinner. #30

Arkanine opened this issue Oct 6, 2016 · 45 comments

Comments

@Arkanine
Copy link

Arkanine commented Oct 6, 2016

Sometimes spinner not stops even when visible param receive "true".

@comountainclimber
Copy link

Im experiencing the exact same issue after upgrading to react-native 34.1... The spinner works as expected most of the time but then fails to turn off under certain circumstances forcing me to exit the app - this appears to only occur on iOS

@comountainclimber
Copy link

UPDATE: downgrading from react-native 34.1 => .33 solved the issue... it doesnt seem to have anything to do with the react-native-loading-spinner-overlaypackage but rather an update to the ActivityIndicator API which I dont currently have time to track down at the moment

@sergiocloud
Copy link

same issue here

@comountainclimber isn't good idea downgrading react-native to fix a component bug

@comountainclimber
Copy link

@sergiocloud I think you would agree its better than having the entire application non functional

@norikt
Copy link

norikt commented Oct 25, 2016

I suspect that the cause is setting Modal visible to false not working...

@b8ne
Copy link
Contributor

b8ne commented Nov 15, 2016

Hey guys can you post your implementation or steps to reproduce?

@damir-sirola
Copy link

Might be related to facebook/react-native#10471 ?

@gsavvid
Copy link
Contributor

gsavvid commented Nov 24, 2016

I have the same issue. In random cases but quite often the spinner won't disappear even though I set visible to false. I'm using RN 0.33.0. It happens only in iOS whereas it works perfectly fine in Android.

@b8ne Sample code:

 render() {
    if (this.state.isFetching) {
      return (
        <Spinner visible={this.state.isFetching} />
      )

    } else {
      return (
        <VerticalList data={this.state.data.components}/>
      )
    }
  }

Initially, this.state.isFetching is set to true and the Spinner is shown. Later it's set to false, the VerticalList is rendered but the Spinner keeps spinning on top of it. I've tried several different variations of the above code but without any luck. For example, I've also tried the following but the result remained the same (the VerticalList is rendered and the Spinner keeps spinning on top of it):

  render() {
      return (
        <View style={{flex:1}} >
          <Spinner visible={this.state.isFetching} />
          <VerticalList data={this.state.data.components}/>
        <View />
      )
  }

@b8ne
Copy link
Contributor

b8ne commented Nov 29, 2016

Hey @gsavvid sorry ive been working on my apps backend lately so havent looked at much RN stuff. Just spent a bit of time looking into it and im tending to agree with @damir-sirola that its related to the iOS issue of not updating UI correctly after state change. Ill have a play around tomorrow :)

@gsavvid
Copy link
Contributor

gsavvid commented Nov 29, 2016

I also think it's related to Modal. I've implemented a workaround using ActivityIndicator in a View and the problem seems to have been resolved but I don't think it's such a nice solution.

@mattotodd
Copy link

+1

1 similar comment
@gillesBzk
Copy link

+1

@prithsharma
Copy link

Any update on this?

@comountainclimber
Copy link

Any updates on this?? Has anyone found any work arounds currently running rn 39.0 with "react-native-loading-spinner-overlay": "0.4.1" and this issue seemingly occurs completely randomly

@comountainclimber
Copy link

I can confirm it is definitely related to facebook/react-native#10471

You will only ever see this issue when attempting to combine Alert component with the busy spinner...

@niftylettuce
Copy link
Collaborator

Same issue here, with Alert in combination on later versions of RN, still an issue.

@niftylettuce
Copy link
Collaborator

Here's a temporary fix everyone (just wrap it with a setTimeout of like 100 ms, seems to work for me hahaha)....

this.setState({ spinner: false });
setTimeout(() => {
  Alert.alert('Oops!', err.message);
}, 100);

cc @comountainclimber @prithsharma @gillesBzk @mattotodd @gsavvid @b8ne @damir-sirola @norikt @sergiocloud @Arkanine

@drinkingcode
Copy link

drinkingcode commented Feb 20, 2017

finally, I solve this problem as following:

`export default class Loading extends Component{

constructor(props){
    super(props);
    this.state={
        visible:this.props.visible
    };
    this._show=this._show.bind(this);
    this._hide=this._hide.bind(this);
}

render(){
    return(
        <Modal
            animationType={'none'}
            transparent={true}
            visible={this.state.visible}
            onRequestClose={this.props.onDismissLoadingCallback}>
            <View style={{flex:1}}/>
            <View style={{
                height:80,
                width:80,
                alignItems:'center',
                justifyContent:'center',
                backgroundColor:'#3434347f',
                borderRadius:10,alignSelf:'center'}}>
                <ActivityIndicator
                    animating={true}
                    size={"large"}
                    color={'white'}
                />
            </View>
            <View style={{flex:1}}/>
        </Modal>
    );
}

_show() {
this.setState({visible:true});
}

_hide(){
this.setState({visible:false});
}

`

it works well !

@ithieund
Copy link

Same for me,
Upgrading to 0.4.1 does not help.

@deepaksisodiya
Copy link

@niftylettuce thanks :)

@pwoltman
Copy link

pwoltman commented Mar 7, 2017

Another workaround, assuming you are having the issue of the spinner not dismissing as desired when an Alert has been used on iOS, is to update the visible property when dismissing the Alert itself.

For example:

Alert.alert(
  'Alert Title Goes Here',
  'Alert Message Goes Here,
  [
    {text: 'OK', onPress: () => this.setState({spinnerVisible: false})}
  ],
  { cancelable: false }
)

<Spinner visible={this.state.spinnerVisible} textContent={"Processing..."} textStyle={{color: '#FFF'}} />

I add the cancelable: false so that Android users can't dismiss without clicking the OK, though this issue doesn't seem to exist on Android so its likely unnecessary.

@saeropark
Copy link

saeropark commented May 25, 2017

mine works. if anyone needs.

basically mine will spin until data is fully loaded.
important to note is the visible state

RN 0.43

class MyList extends React.Component {
  static navigationOptions = {
    header: null,
  }
  constructor(props) {
        super(props);
        
        this.state = {
            visible: true,
            dataSource: new ListView.DataSource({
            rowHasChanged: (row1, row2)=> row1 !== row2
            })
        };
    }

    componentDidMount() {
            this.fetchData();
    }

 
    // --- calls Google API ---
    fetchData() {
        fetch(REQUEST_URL)
        .then((response) => response.json())
        .then((responseData) => {
            responseData = this.removeDuplicates(responseData);
            this.setState({
                dataSource: this.state.dataSource.cloneWithRows(responseData),
                visible: false,
            });
        })
        .done();
    }
    render() {
        return (
          <View style={styles.mainContainer}>
          
                  <Spinner visible={this.state.visible} textContent={"Loading..."} textStyle={{color: '#FFF'}} />
           
            <ListView
                dataSource = {this.state.dataSource}
                renderRow = {this.renderBus.bind(this)}
                style = {styles.listView}
            />
            </View>
            
        );

Dynamic JSON url finish loading, the spinner will stop. hope it helps.

@tatva-nisarg
Copy link

Any updated on this?

@niftylettuce
Copy link
Collaborator

niftylettuce commented Jun 2, 2017 via email

@tatva-nisarg
Copy link

tatva-nisarg commented Jun 2, 2017

I am using
React native : 0.39.2
React native Cli : 1.3.0

I am trying to debug your file and I found that model was not close while visibility is false any idea about it?

@mealbarracin10
Copy link

i am using
react-native-cli: 2.0.1
react-native: 0.46.1

and don't stop spinner, Any updated on this ?

@DoubleOTheven
Copy link

DoubleOTheven commented Nov 14, 2017

This issue still exists. note: I am not using an alert, and the Activity Indicator spins forever after the component that rendered it has unmounted. The RN ActivityIndicator does not produce this error, so I think there is a bug in this library. Maybe a race condition?

I'm using react-native: 0.48.4

@DoubleOTheven
Copy link

DoubleOTheven commented Nov 14, 2017

I built my own modal spinner, and have the same issue. The problem is that the RN Modal component is never dismissed. This happens one out of five times. Any ideas for how to fix this?

@niftylettuce
Copy link
Collaborator

This solution does not work? @Sonblind @mealbarracin10 @tatva-nisarg

#30 (comment)

@DoubleOTheven
Copy link

@niftylettuce I am not using an Alert. I am changing the navigator.

@DoubleOTheven
Copy link

DoubleOTheven commented Nov 18, 2017

@niftylettuce The issue is that the react component will sometimes unmount before unmounting the modal component inside of this library.

Solution:

When implementing, add the loading screen at the root level and control it by a global store vs having multiple loading spinner components inside the children. This ensures that the parent component is always in memory and can unmount the modal component inside the library.

I'm using mobX, so I achieve this by calling LoadingScreenStore.setIsVisible(true) from any component that would need it. I have not see the bug anymore after doing it this way. 👍

@mealbarracin10 @tatva-nisarg

@derakhshanfar
Copy link

same issue for me

@mrgcohen
Copy link

mrgcohen commented Jan 25, 2018

@derakhshanfar Does { loading && <Spinner /> } rather than <Spinner visible={loading} /> work?

@aouaki
Copy link

aouaki commented Feb 5, 2018

It does not change anything on my and @mrgcohen

@izikandrw
Copy link

izikandrw commented Apr 5, 2018

still a problem with Alerts RN 0.54.4

@MedinaGitHub
Copy link

a solution that worked for me, when I make it visible true and then visible false very quickly it falls, so with a setTimeout in the false it is fixed.

WORK
this.setState({ visible:true })

setTimeout(() => {

              this.setState({ visible:false })  

            }, 3000);

NOT WORK
this.setState({ visible:true })
this.setState({ visible:false })

@yingdongzhang
Copy link

yingdongzhang commented Jun 1, 2018

@MedinaGitHub

Just FYI

this.setState({ visible:true })
this.setState({ visible:false })

won't work because setState is async, there's a callback function you can pass into setState:

this.setState({ visible: true }, () => { this.setState({ visible: false }) })

@mrjackyliang
Copy link

Just re-confirming here: Putting a delay on the Alert solves the issue. In addition, not sure if it's also related to my problem, hiding the Modal causes a setState on unmounted component error.

@mbret
Copy link

mbret commented Aug 7, 2018

Using a delay on the alert does not always solves this issue. Most of the time it will but sometimes it will not and you would use another delay value... You can still use a rather long delay to cover most of the case if not every cases. ex: 300ms

@Darking360
Copy link

Darking360 commented Aug 31, 2018

I've tried using delays or hiding the component if not loading but spinner mantains on in iOs always, using this code:
{ loading && ( <Spinner visible={loading} textContent={''} textStyle={styles.colorWhite} /> ) }

@hungdev
Copy link

hungdev commented Oct 10, 2018

i resolved by using set timeout for alert.

      setTimeout(() => {
        alert('Invalid username or password!')
      }, 500);

@niftylettuce
Copy link
Collaborator

I'm going to document this solution along with using it in the root in the README of this project shortly.

@yeomann
Copy link

yeomann commented Oct 28, 2018

while this might be a solution but i'm using redux also since states are being managed by redux, it will be a long wrong around to call alert and sometimes or i think most of the time. i don't need to show alert as well. i don't know how this is a fix.

maybe, its modal fault. should you try react-native-modal instead, i don't know

@cristianoccazinsp
Copy link

Do we really need to wrap all our alerts in a timeout in order for this to work properly? Seems like a bad solution.

@ladjs ladjs deleted a comment from aprilmintacpineda May 11, 2019
@ladjs ladjs locked as resolved and limited conversation to collaborators May 11, 2019
@niftylettuce
Copy link
Collaborator

Pull requests to fix bugs are accepted.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests