Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native:Show spinner at the center of the screen

I want to show the spinner at the center of screen.I used alignItems, justifyContent and flex but there is no change in the position then i use margintop for correct positioning.why there is no change on the use of alignItems,justifyContent and flex?

here i m using spinner.

 return (
  <View style={style.spinnerStyle}>
  <Spinner size ="large" />
  </View>
 );
 const style = {
spinnerStyle: {
  flex: 1,
  marginTop:240
}
};

Spinner.js

  import React from 'react';
  import {View,ActivityIndicator} from 'react-native';

  const Spinner = ({size}) => {
  return (
  <View style = {styles.spinnerStyle}>
  <ActivityIndicator size={size || 'large'} />
  </View>
  );
 };

const styles = {
spinnerStyle: {
flex: 1,
justifyContent: 'center',
alignItems:'center'
 }
 };

export { Spinner };
like image 288
Chaitanya Parashar Avatar asked Jan 29 '23 22:01

Chaitanya Parashar


1 Answers

Can you please try with following:

where you are using Spinner

spinnerStyle: {
    flex: 1,
    marginTop:240,
    justifyContent: 'center',
    alignItems:'center'
}

In Spinner

spinnerStyle: {
    flex: 1
    alignSelf:'center'
}
like image 158
Jigar Shah Avatar answered Feb 01 '23 12:02

Jigar Shah