How do I overlay ActivityIndicator in react-native?

前端 未结 8 2308
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 05:55

I have a View with few form elements and a button (TouchableHighlight). On clicking the button, an Activity Indicator should be shown as an overlay to the existing view. The

8条回答
  •  一生所求
    2020-12-13 06:29

    You can use StyleSheet.absoluteFill to shorten code. Add this to your render:

    
      //... other code here
      {this.state.loading && 
          
      }
    

    Improvement:

    You can also create a Loading component:

    Loading.js

    import React from 'react';
    import {View, ActivityIndicator, StyleSheet} from 'react-native';
    
    export const Loading = ({theme = 'white', size = 'large'}) => {
      const color = theme === 'white' ? '#00bdcd' : '#fff';
      return (
        
          
        
      );
    };

    Then use it anywhere you want

    
       //... other code here
       // remember to import Loading component
       {this.state.loading && }
    

提交回复
热议问题