ReactNative ActivityIndicator not showing when animating property initiate false

后端 未结 10 1603

I\'m playing with react native and got a strange behaviour.

When I try to show a ActitvityIndicator for Android setting its animating property

10条回答
  •  囚心锁ツ
    2021-02-12 22:12

    This appears to be a bug in React Native. The code with initial state being showProgress: false works on iOS but not on Android.

    I've opened an issue on github if you want to follow the progression: https://github.com/facebook/react-native/issues/9023

    Option 1

    A workaround I've used is to use the showProgress variable to render a completely different view with the ActivityIndicator:

    render() {
        if (this.state.showProgress) {
            return this.renderLoadingView();
        } else {
            return this.renderMainView();
        }
    }
    

    Option 2

    You can also set the opacity of the ActivityIndicator according to the state:

    render() {
        return (
            
    
                
                    progressOff
                
    
                
                    progressOn
                
    
                
            
        );
    }
    

    However the spinner animation doesn't always start at the same position when using this method.

提交回复
热议问题