1/** 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 * @format 8 */ 9 10/** 11 * @see https://reactnative.dev/docs/alert#content 12 */ 13export interface AlertButton { 14 text?: string | undefined; 15 onPress?: ((value?: string) => void) | undefined; 16 isPreferred?: boolean; 17 style?: 'default' | 'cancel' | 'destructive' | undefined; 18} 19 20interface AlertOptions { 21 /** @platform android */ 22 cancelable?: boolean | undefined; 23 userInterfaceStyle?: 'unspecified' | 'light' | 'dark'; 24 /** @platform android */ 25 onDismiss?: (() => void) | undefined; 26} 27 28/** 29 * Launches an alert dialog with the specified title and message. 30 * 31 * Optionally provide a list of buttons. Tapping any button will fire the 32 * respective onPress callback and dismiss the alert. By default, the only 33 * button will be an 'OK' button. 34 * 35 * This is an API that works both on iOS and Android and can show static 36 * alerts. To show an alert that prompts the user to enter some information, 37 * see `AlertIOS`; entering text in an alert is common on iOS only. 38 * 39 * ## iOS 40 * 41 * On iOS you can specify any number of buttons. Each button can optionally 42 * specify a style, which is one of 'default', 'cancel' or 'destructive'. 43 * 44 * ## Android 45 * 46 * On Android at most three buttons can be specified. Android has a concept 47 * of a neutral, negative and a positive button: 48 * 49 * - If you specify one button, it will be the 'positive' one (such as 'OK') 50 * - Two buttons mean 'negative', 'positive' (such as 'Cancel', 'OK') 51 * - Three buttons mean 'neutral', 'negative', 'positive' (such as 'Later', 'Cancel', 'OK') 52 * 53 * ``` 54 * // Works on both iOS and Android 55 * Alert.alert( 56 * 'Alert Title', 57 * 'My Alert Msg', 58 * [ 59 * {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')}, 60 * {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, 61 * {text: 'OK', onPress: () => console.log('OK Pressed')}, 62 * ] 63 * ) 64 * ``` 65 */ 66export interface AlertStatic { 67 alert: ( 68 title: string, 69 message?: string, 70 buttons?: AlertButton[], 71 options?: AlertOptions, 72 ) => void; 73 prompt: ( 74 title: string, 75 message?: string, 76 callbackOrButtons?: ((text: string) => void) | AlertButton[], 77 type?: AlertType, 78 defaultValue?: string, 79 keyboardType?: string, 80 options?: AlertOptions, 81 ) => void; 82} 83 84export type AlertType = 85 | 'default' 86 | 'plain-text' 87 | 'secure-text' 88 | 'login-password'; 89 90export const Alert: AlertStatic; 91export type Alert = AlertStatic; 92