ReactNative ActivityIndicator not showing when animating property initiate false

后端 未结 10 1705
悲哀的现实
悲哀的现实 2021-02-12 21:31

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:18

    If in your project you can use third party components, I recommend the use of react-native-loading-spinner-overlay

    Solved easily our problems, beacause this component use a similar way to show or hide the Activity with the property visible.

    0 讨论(0)
  • 2021-02-12 22:18

    This is a bug of React-Native for component Activity Indicator. I am not sure that fb has already solved it but you can try this

     constructor(props) {
            super(props);
            this.state = {
                opacity: 0
            };
        }
    

    to show it use this.setState({opacity:1}) and to hide again this.setState({opacity:0}) in your called functions

    and in the render where you are using activity indicator

     <ActivityIndicator
        animating={true}
        color="#ffffff"
        style={{height: 80, marginTop: 10, opacity: this.state.opacity }}
        size="large"/>
    
    0 讨论(0)
  • 2021-02-12 22:26

    The transition of animating from false to true is too slow on Android. But you can force a re-render using the key prop:

    <ActivityIndicator
      key={`${props.animating}`}
      animating={props.animating}
    />
    

    When props.animating changes from false to true, they key also changes. This forces a re-render, meaning that a new component is rendered with animating = true, which will instantly start your spinner.

    0 讨论(0)
  • 2021-02-12 22:27

    The only problem I had with this, was that in Android it wasn't visible because of the background I had on my screen. I fixed by only changing the color prop to something I knew should stand out in the background:

    <ActivityIndicator color={theme.secondary.color} />

    0 讨论(0)
提交回复
热议问题