单击按钮时显示加载程序

时间:2019-09-24 15:14:14

标签: javascript react-native

我试图在单击按钮(用于注册)时获得加载程序,而没有创建另一个页面(仅用于显示加载程序)。 我能怎么做??

这是我的代码,也是我尝试的(但没有出现)

row_number()

1 个答案:

答案 0 :(得分:1)

首先,您有一个不需要的关闭View标签。 假设这只是个问题,您可以使用JS三元运算符来实现。像这样:

<View style={style.container}>
        //code about signup
          <View style={style.footer}>
            {(!this.state.isLoading) ? <TouchableOpacity
              style={[style.button, style.buttonOK]}
              onPress={() => this.showLoader()}
            >
              <Text style={[style.buttonTesto]}>Signup</Text>
            </TouchableOpacity> : <ActivityIndicator animating={this.state.isLoading} size="large" color="#56cbbe" />}
          </View>
        </KeyboardAwareScrollView>
</View>

您可以了解有关三元运算符here

的更多信息

这应将按钮替换为加载动画。

如有任何疑问,请随时提出!我很乐意提供帮助!