推荐:跨平台React Native组件——@expo/react-native-action-sheet
warning:
这篇文章距离上次修改已过183天,其中的内容可能已经有所变动。
import React from 'react';
import { View, Button, StyleSheet } from 'react-native';
import * as ActionSheet from '@expo/react-native-action-sheet';
export default class App extends React.Component {
showActionSheet = () => {
ActionSheet.showActionSheetWithOptions({
options: ['选项一', '选项二', '取消'],
cancelButtonIndex: 2,
destructiveButtonIndex: 0,
}, buttonIndex => {
console.log('按下了按钮', buttonIndex);
});
}
render() {
return (
<View style={styles.container}>
<Button onPress={this.showActionSheet} title="显示动作表" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
这段代码演示了如何在React Native应用中使用@expo/react-native-action-sheet
模块来创建一个简单的动作表(ActionSheet)。当用户点击按钮时,会触发showActionSheet
函数,该函数调用ActionSheet.showActionSheetWithOptions
方法来显示动作表,并且定义了选项和按钮的行为。
评论已关闭