简体   繁体   English

本机基础微调器不起作用

[英]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. 输入用户名后,我试图显示在react-native,native-base中按下按钮时的微调器。 It is not working. 它不起作用。 Here are my steps and code: 这是我的步骤和代码:

Steps: 脚步:

  1. set loading true in constructor 在构造函数中设置加载为true
  2. set loading false after fetching data 将获取数据后设置为false
  3. if loading true render spinner else load other screen. 如果加载true渲染微调器,则加载其他屏幕。

     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/> ); } } 

Works fine for me This is with NativeBase 2.3.6 对我来说很好,这是与NativeBase 2.3.6一起使用

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

Works with <View> as well 也可以与<View>一起使用

在此处输入图片说明

you forget return 你忘记了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/>
    );
  }    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM