如何制作一个自定义的警报对话框,当被驳回时自我销毁,并使用静态方法从应用程序中的任何地方调用。与反应-本机方法相同
警戒()
我现在的代码是:
import { View } from 'react-native';
import { Portal, Dialog } from 'react-native-paper';
static function showDialog(title, paragraph, buttonLabelText, onDismissHandler, canDismiss) {
return (
<View style={{ flex: 1 }}>
<Portal>
<Dialog dismissable={canDismiss} visible={need a value here} onDismiss={() => {this.onDismissHandler()}}>
<Dialog.Title>{title}</Dialog.Title>
<Dialog.Content>
<Paragraph>{paragraph}</Paragraph>
</Dialog.Content>
<Dialog.Actions>
<Button onPress={() => {this.onDismissHandler()}}>{buttonLabelText}}</Button>
</Dialog.Actions>
</Dialog>
</Portal>
</View>
)
}
export default { showDialog };
发布于 2019-02-12 06:04:35
React本机有它在Alert
上,您可以使用如下所示。
import { Alert } from 'react-native';
import _ from 'lodash';
export const showPopupAlert = (message, onOKPressed: _.noop) => {
Alert.alert(
'',
message,
[
{ text: 'OK', onPress: onOKPressed },
],
);
};
export const showOptionAlert = (message, buttonOk, buttonCancel, action, title) => {
Alert.alert(
title,
message,
[
{ text: buttonOk, onPress: action },
{ text: buttonCancel },
],
{ cancelable: false },
);
};
将其保存为ShowAlert.js
作为根laval组件,并调用如下所示。
import { showPopupAlert } from 'yourpath/ShowAlert';
showPopupAlert('Your message');
//这样的呼叫
https://stackoverflow.com/questions/54651656
复制相似问题