gpt4 book ai didi

javascript - 如何在react-native中覆盖ActivityIndi​​cator?

转载 作者:行者123 更新时间:2023-12-03 06:01:27 25 4
gpt4 key购买 nike

我有一个带有几个表单元素和一个按钮(TouchableHighlight)的 View 。单击该按钮后,事件指示器应显示为现有 View 的覆盖层。事件指示器应位于页面中心,现有 View 应稍微模糊以指示重叠。我尝试了不同的选项,但无法使其正常工作。

render() {
const { username, password } = this.state;

return (
<View style={styles.container}>
<View style={styles.group}>
<Text style={styles.text}>Username:</Text>
<TextInput
style={styles.input}
onChangeText={this.handleUserNameChange.bind(this)}
value={username}
underlineColorAndroid="transparent"
/>
</View>
<View style={styles.group}>
<Text style={styles.text}>Password:</Text>
<TextInput
style={styles.input}
secureTextEntry={true}
onChangeText={this.handlePasswordChange.bind(this)}
value={password}
underlineColorAndroid="transparent"
/>
</View>
<TouchableHighlight
style={styles.button}
onPress={this.handleLogin.bind(this)}>
<Text style={styles.buttonText}>Logon</Text>
</TouchableHighlight>
</View>
);
}

现有样式:

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
backgroundColor: '#F5FCFF',
marginTop: 60
},
group: {
alignItems: 'flex-start',
padding: 10
},
input: {
width: 150,
padding: 2,
paddingLeft: 5,
borderColor: 'gray',
borderWidth: 1
},
text: {
padding: 0
},
button: {
width: 150,
backgroundColor: '#2299F2',
padding: 15,
marginTop: 20,
borderRadius: 5
},
buttonText: {
textAlign: 'center',
color: '#fff',
fontSize: 24
},
});

我需要一个 ActivityIndi​​cator 到上面的 View ,覆盖 View ,并将 ActivityIndi​​cator 居中。

最佳答案

要实现此功能,您需要绝对定位它,并在应该位于叠加层下方的元素之后渲染它:

  loading: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
alignItems: 'center',
justifyContent: 'center'
}

然后只需根据加载状态有条件地将其组合到 render 方法中即可。我假设 this.handleLogin 已经设置了某种加载状态。

确保它最后渲染,以便它优先。

...
{this.state.loading &&
<View style={styles.loading}>
<ActivityIndicator size='large' />
</View>
}

关于javascript - 如何在react-native中覆盖ActivityIndi​​cator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44046500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com