samantha
samantha

Reputation: 11

Native Base spinner not working

I am trying to show a spinner on press of button in react-native, native-base after username is entered. It is not working. Here are my steps and code:

Steps:

  1. set loading true in constructor
  2. set loading false after fetching data
  3. if loading true render spinner else load other screen.

    constructor(props) {
            super(props);
            this.state = {
        loading: true,  
    }
    handleLoginPressed = async () => {
    
    //some code
    
         let resp = await tryAsk(this.state.sampleQuestion, this.state.username);
         this.setState({            
                  loading: false
              });
    
    }
    
    render() {
    if (this.state.fontsAreLoaded == true) {
      if (this.state.isLoggedIn === true) {
        if (this.state.loading === true){
          <View><Spinner /></View>
        }else{   
        return (
          <Somescreen/>
        );
      }    
    }
    

Upvotes: 1

Views: 4231

Answers (2)

Mahdi Pourrostam
Mahdi Pourrostam

Reputation: 29

you forget return

constructor(props) {
        super(props);
        this.state = {
    loading: true,  
}
handleLoginPressed = async () => {

//some code

     let resp = await tryAsk(this.state.sampleQuestion, this.state.username);
     this.setState({            
              loading: false
          });

}

render() {
if (this.state.fontsAreLoaded == true) {
  if (this.state.isLoggedIn === true) {
    if (this.state.loading === true){
      return <Spinner />
    }else{   
    return (
      <Somescreen/>
    );
  }    
}

Upvotes: 0

Supriya Kalghatgi
Supriya Kalghatgi

Reputation: 1155

Works fine for me This is with NativeBase 2.3.6

<Content>
  <Spinner />
  <Spinner color="red" />
  <Spinner color="green" />
  <Spinner color="blue" />
</Content>

Works with <View> as well

enter image description here

Upvotes: 2

Related Questions