From 241b271898037607859dccae1514dc7140607b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 2 Dec 2020 21:08:23 +0100 Subject: [PATCH 1/2] Deprecate AlertMacOS in favor of Alert Deprecate AlertMacOS in favor of Alert move UIAlertController define to RCTAlertController.h define only on macos target revert podfile.lock --- Libraries/Alert/Alert.js | 66 +++++++++++++++++++++++++-- Libraries/Alert/AlertMacOS.js | 5 ++ Libraries/Alert/NativeAlertManager.js | 21 +-------- 3 files changed, 68 insertions(+), 24 deletions(-) diff --git a/Libraries/Alert/Alert.js b/Libraries/Alert/Alert.js index 1f2212179c1a51..82a872b5e3b882 100644 --- a/Libraries/Alert/Alert.js +++ b/Libraries/Alert/Alert.js @@ -29,6 +29,10 @@ export type Buttons = Array<{ type Options = { cancelable?: ?boolean, onDismiss?: ?() => void, + // [TODO(macOS ISS#2323203) + modal?: ?boolean, + critical?: ?boolean, + // ]TODO(macOS ISS#2323203) ... }; @@ -44,11 +48,20 @@ class Alert { buttons?: Buttons, options?: Options, ): void { - if ( - Platform.OS === 'ios' || - Platform.OS === 'macos' /* TODO(macOS GH#774) */ - ) { + if (Platform.OS === 'ios') { Alert.prompt(title, message, buttons, 'default'); + // [TODO(macOS ISS#2323203) + } else if (Platform.OS === 'macos') { + promptMacOS( + title, + message, + buttons, + 'default', + undefined, + options?.modal, + options?.critical, + ); + // ]TODO(macOS ISS#2323203) } else if (Platform.OS === 'android') { const NativeDialogManagerAndroid = require('../NativeModules/specs/NativeDialogManagerAndroid').default; @@ -154,10 +167,53 @@ class Alert { // [TODO(macOS GH#774) } else if (Platform.OS === 'macos') { const defaultInputs = [{default: defaultValue}]; - AlertMacOS.prompt(title, message, callbackOrButtons, type, defaultInputs); + promptMacOS(title, message, callbackOrButtons, type, defaultInputs); } // ]TODO(macOS GH#774) } } +// [TODO(macOS ISS#2323203) +function promptMacOS( + title: ?string, + message?: ?string, + callbackOrButtons?: ?((text: string) => void) | Buttons, + type?: ?AlertType = 'plain-text', + defaultInputs?: DefaultInputsArray, + modal?: ?boolean, + critical?: ?boolean, +): void { + let callbacks = []; + const buttons = []; + if (typeof callbackOrButtons === 'function') { + callbacks = [callbackOrButtons]; + } else if (callbackOrButtons instanceof Array) { + callbackOrButtons.forEach((btn, index) => { + callbacks[index] = btn.onPress; + if (btn.text || index < (callbackOrButtons || []).length - 1) { + const btnDef = {}; + btnDef[index] = btn.text || ''; + buttons.push(btnDef); + } + }); + } + + RCTAlertManager.alertWithArgs( + { + title: title || undefined, + message: message || undefined, + buttons, + type: type || undefined, + defaultInputs, + modal: modal || undefined, + critical: critical || undefined, + }, + (id, value) => { + const cb = callbacks[id]; + cb && cb(value); + }, + ); +} +// ]TODO(macOS ISS#2323203) + module.exports = Alert; diff --git a/Libraries/Alert/AlertMacOS.js b/Libraries/Alert/AlertMacOS.js index 9489a48e904682..69585a2b94d7f7 100644 --- a/Libraries/Alert/AlertMacOS.js +++ b/Libraries/Alert/AlertMacOS.js @@ -175,6 +175,11 @@ class AlertMacOS { modal?: ?boolean, critical?: ?boolean, ): void { + warnOnce( + 'deprecated-AlertMacOS', + '"AlertMacOS" module has been deprecated in favor of "Alert" and will be removed in a future version of react-native-macos', + ); + var callbacks = []; var buttons = []; if (typeof callbackOrButtons === 'function') { diff --git a/Libraries/Alert/NativeAlertManager.js b/Libraries/Alert/NativeAlertManager.js index 9a6bc3d6046363..d1fb7b2ba424fa 100644 --- a/Libraries/Alert/NativeAlertManager.js +++ b/Libraries/Alert/NativeAlertManager.js @@ -21,28 +21,11 @@ export type Args = {| cancelButtonKey?: string, destructiveButtonKey?: string, keyboardType?: string, - // [TODO(macOS GH#774) + // [TODO(macOS ISS#2323203) defaultInputs?: DefaultInputsArray, modal?: ?boolean, critical?: ?boolean, - // ]TODO(macOS GH#774) -|}; - -// TODO(macOS GH#774): stand-in for Args to make codegen happy -type NativeArgs = {| - title?: string, - message?: string, - buttons?: Array, // TODO(T67565166): have a better type - type?: string, - defaultValue?: string, - cancelButtonKey?: string, - destructiveButtonKey?: string, - keyboardType?: string, - // [TODO(macOS GH#774) - defaultInputs?: Array, - modal?: ?boolean, - critical?: ?boolean, - // ]TODO(macOS GH#774) + // ]TODO(macOS ISS#2323203) |}; export interface Spec extends TurboModule { From 04263ffbb59fb580133494ed988664d4a587aba1 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Tue, 6 Dec 2022 10:02:33 -0800 Subject: [PATCH 2/2] Remove AlertMacOS in favor of Alert Fix merge issue Get rid of workaround maybe? Better type? Fix codegen error Remove AlertMacOS altogether Space Refactor test page logic Delete AlertIOS Make promptMacOS work make example load Fix Alert.prompt() Move examples to AlertIOSExample Remove changes to AlertExample Remove more fix error More fixed --- Libraries/Alert/Alert.js | 145 +++++++--- Libraries/Alert/AlertMacOS.js | 216 -------------- Libraries/Alert/NativeAlertManager.js | 9 +- React/CoreModules/RCTAlertManager.mm | 2 +- index.js | 11 - .../js/examples/Alert/AlertIOSExample.js | 92 +++++- .../js/examples/Alert/AlertMacOSExample.js | 264 ------------------ .../rn-tester/js/utils/RNTesterList.ios.js | 5 - 8 files changed, 195 insertions(+), 549 deletions(-) delete mode 100644 Libraries/Alert/AlertMacOS.js delete mode 100644 packages/rn-tester/js/examples/Alert/AlertMacOSExample.js diff --git a/Libraries/Alert/Alert.js b/Libraries/Alert/Alert.js index 82a872b5e3b882..ab62486bc7666a 100644 --- a/Libraries/Alert/Alert.js +++ b/Libraries/Alert/Alert.js @@ -8,7 +8,6 @@ * @flow */ -import AlertMacOS from './AlertMacOS'; // TODO(macOS GH#774) import Platform from '../Utilities/Platform'; import type {DialogOptions} from '../NativeModules/specs/NativeDialogManagerAndroid'; import RCTAlertManager from './RCTAlertManager'; @@ -25,14 +24,21 @@ export type Buttons = Array<{ style?: AlertButtonStyle, ... }>; +// [TODO(macOS GH#774) +export type DefaultInputsArray = Array<{ + default?: string, + placeholder?: string, + style?: AlertButtonStyle, +}>; +// ]TODO(macOS GH#774) type Options = { cancelable?: ?boolean, onDismiss?: ?() => void, - // [TODO(macOS ISS#2323203) + // [TODO(macOS GH#774) modal?: ?boolean, critical?: ?boolean, - // ]TODO(macOS ISS#2323203) + // ]TODO(macOS GH#774) ... }; @@ -52,7 +58,7 @@ class Alert { Alert.prompt(title, message, buttons, 'default'); // [TODO(macOS ISS#2323203) } else if (Platform.OS === 'macos') { - promptMacOS( + Alert.promptMacOS( title, message, buttons, @@ -167,53 +173,100 @@ class Alert { // [TODO(macOS GH#774) } else if (Platform.OS === 'macos') { const defaultInputs = [{default: defaultValue}]; - promptMacOS(title, message, callbackOrButtons, type, defaultInputs); + Alert.promptMacOS(title, message, callbackOrButtons, type, defaultInputs); } // ]TODO(macOS GH#774) } -} -// [TODO(macOS ISS#2323203) -function promptMacOS( - title: ?string, - message?: ?string, - callbackOrButtons?: ?((text: string) => void) | Buttons, - type?: ?AlertType = 'plain-text', - defaultInputs?: DefaultInputsArray, - modal?: ?boolean, - critical?: ?boolean, -): void { - let callbacks = []; - const buttons = []; - if (typeof callbackOrButtons === 'function') { - callbacks = [callbackOrButtons]; - } else if (callbackOrButtons instanceof Array) { - callbackOrButtons.forEach((btn, index) => { - callbacks[index] = btn.onPress; - if (btn.text || index < (callbackOrButtons || []).length - 1) { - const btnDef = {}; - btnDef[index] = btn.text || ''; - buttons.push(btnDef); - } - }); - } + // [TODO(macOS GH#774) + /** + * Create and display a prompt to enter some text. + * @static + * @method promptMacOS + * @param title The dialog's title. + * @param message An optional message that appears above the text + * input. + * @param callbackOrButtons This optional argument should + * be either a single-argument function or an array of buttons. If passed + * a function, it will be called with the prompt's value when the user + * taps 'OK'. + * + * If passed an array of button configurations, each button should include + * a `text` key, as well as optional `onPress` key (see + * example). + * @param type This configures the text input. One of 'plain-text', + * 'secure-text' or 'login-password'. + * @param defaultInputs This optional argument should be an array of couple + * default value - placeholder for the input fields. + * @param modal The alert can be optionally run as an app-modal dialog, instead + * of the default presentation as a sheet. + * @param critical This optional argument should be used when it's needed to + * warn the user about severe consequences of an impending event + * (such as deleting a file). + * + * @example Example with custom buttons + * + * AlertMacOS.promptMacOS( + * 'Enter password', + * 'Enter your password to claim your $1.5B in lottery winnings', + * [ + * {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, + * {text: 'OK', onPress: password => console.log('OK Pressed, password: ' + password)}, + * ], + * 'secure-text' + * ); + * + * @example Example with the default button and a custom callback + * + * AlertMacOS.prompt( + * 'Update username', + * null, + * text => console.log("Your username is "+text), + * null, + * 'default' + * ); + */ + static promptMacOS( + title: ?string, + message?: ?string, + callbackOrButtons?: ?((text: string) => void) | Buttons, + type?: ?AlertType = 'plain-text', + defaultInputs?: DefaultInputsArray, + modal?: ?boolean, + critical?: ?boolean, + ): void { + let callbacks = []; + const buttons = []; + if (typeof callbackOrButtons === 'function') { + callbacks = [callbackOrButtons]; + } else if (callbackOrButtons instanceof Array) { + callbackOrButtons.forEach((btn, index) => { + callbacks[index] = btn.onPress; + if (btn.text || index < (callbackOrButtons || []).length - 1) { + const btnDef = {}; + btnDef[index] = btn.text || ''; + buttons.push(btnDef); + } + }); + } - RCTAlertManager.alertWithArgs( - { - title: title || undefined, - message: message || undefined, - buttons, - type: type || undefined, - defaultInputs, - modal: modal || undefined, - critical: critical || undefined, - }, - (id, value) => { - const cb = callbacks[id]; - cb && cb(value); - }, - ); + RCTAlertManager.alertWithArgs( + { + title: title || undefined, + message: message || undefined, + buttons, + type: type || undefined, + defaultInputs, + modal: modal || undefined, + critical: critical || undefined, + }, + (id, value) => { + const cb = callbacks[id]; + cb && cb(value); + }, + ); + } + // ]TODO(macOS GH#774) } -// ]TODO(macOS ISS#2323203) module.exports = Alert; diff --git a/Libraries/Alert/AlertMacOS.js b/Libraries/Alert/AlertMacOS.js deleted file mode 100644 index 69585a2b94d7f7..00000000000000 --- a/Libraries/Alert/AlertMacOS.js +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow - * @jsdoc - */ - -// TODO(macOS GH#774) - -'use strict'; - -import type {AlertType, AlertButtonStyle} from './Alert'; -import RCTAlertManager from './RCTAlertManager'; - -/** - * Array or buttons - * @typedef {Array} ButtonsArray - * @property {string=} text Button label - * @property {Function=} onPress Callback function when button pressed - */ -export type ButtonsArray = Array<{ - /** - * Button label - */ - text?: string, - /** - * Callback function when button pressed - */ - onPress?: ?Function, - /** - * An Alert button style - */ - style?: AlertButtonStyle, - ... -}>; - -/** - * Array of defaults input values - * @typedef {Array} DefaultsInputArray - * @property {string=} default input - * @property {string=} placeholder input - */ -export type DefaultInputsArray = Array<{ - /** - * Default input - */ - default?: string, - /** - * Placeholder input - */ - placeholder?: string, - - style?: AlertButtonStyle, -}>; - -/** - * @description - * `AlertMacOS` provides functionality to create a macOS alert dialog with a - * message or create a prompt for user input. - * - * Creating an macOS alert: - * - * ``` - * AlertMacOS.alert( - * 'Sync Complete', - * 'All your data are belong to us.' - * ); - * ``` - * - * Creating an macOS prompt: - * - * ``` - * AlertMacOS.prompt( - * 'Enter a value', - * null, - * text => console.log("You entered "+text) - * ); - * ``` - * - * We recommend using the [`Alert.alert`](docs/alert.html) method for - * cross-platform support if you don't need to create macOS-only prompts. - * - */ -class AlertMacOS { - /** - * Create and display a popup alert. - * @static - * @method alert - * @param title The dialog's title. - * @param message An optional message that appears below - * the dialog's title. - * @param callbackOrButtons This optional argument should - * be either a single-argument function or an array of buttons. If passed - * a function, it will be called when the user taps 'OK'. - * - * If passed an array of button configurations, each button should include - * a `text` key, as well as optional `onPress` key. - * - * @example Example with custom buttons - * - * AlertMacOS.alert( - * 'Update available', - * 'Keep your app up to date to enjoy the latest features', - * [ - * {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, - * {text: 'Install', onPress: () => console.log('Install Pressed')}, - * ], - * ); - */ - static alert( - title: ?string, - message?: ?string, - callbackOrButtons?: ?(() => void) | ButtonsArray, - ): void { - this.prompt(title, message, callbackOrButtons, 'default'); - } - - /** - * Create and display a prompt to enter some text. - * @static - * @method prompt - * @param title The dialog's title. - * @param message An optional message that appears above the text - * input. - * @param callbackOrButtons This optional argument should - * be either a single-argument function or an array of buttons. If passed - * a function, it will be called with the prompt's value when the user - * taps 'OK'. - * - * If passed an array of button configurations, each button should include - * a `text` key, as well as optional `onPress` key (see - * example). - * @param type This configures the text input. One of 'plain-text', - * 'secure-text' or 'login-password'. - * @param defaultInputs This optional argument should be an array of couple - * default value - placeholder for the input fields. - * @param modal The alert can be optionally run as an app-modal dialog, instead - * of the default presentation as a sheet. - * @param critical This optional argument should be used when it's needed to - * warn the user about severe consequences of an impending event - * (such as deleting a file). - * - * @example Example with custom buttons - * - * AlertMacOS.prompt( - * 'Enter password', - * 'Enter your password to claim your $1.5B in lottery winnings', - * [ - * {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, - * {text: 'OK', onPress: password => console.log('OK Pressed, password: ' + password)}, - * ], - * 'secure-text' - * ); - * - * @example Example with the default button and a custom callback - * - * AlertMacOS.prompt( - * 'Update username', - * null, - * text => console.log("Your username is "+text), - * null, - * 'default' - * ); - */ - static prompt( - title: ?string, - message?: ?string, - callbackOrButtons?: ?((text: string) => void) | ButtonsArray, - type?: ?AlertType = 'plain-text', - defaultInputs?: DefaultInputsArray, - modal?: ?boolean, - critical?: ?boolean, - ): void { - warnOnce( - 'deprecated-AlertMacOS', - '"AlertMacOS" module has been deprecated in favor of "Alert" and will be removed in a future version of react-native-macos', - ); - - var callbacks = []; - var buttons = []; - if (typeof callbackOrButtons === 'function') { - callbacks = [callbackOrButtons]; - } else if (callbackOrButtons instanceof Array) { - callbackOrButtons.forEach((btn, index) => { - callbacks[index] = btn.onPress; - if (btn.text || index < (callbackOrButtons || []).length - 1) { - var btnDef = {}; - btnDef[index] = btn.text || ''; - buttons.push(btnDef); - } - }); - } - - RCTAlertManager.alertWithArgs( - { - title: title || undefined, - message: message || undefined, - buttons, - type: type || undefined, - defaultInputs, - modal: modal || undefined, - critical: critical || undefined, - }, - (id, value) => { - var cb = callbacks[id]; - cb && cb(value); - }, - ); - } -} - -module.exports = AlertMacOS; diff --git a/Libraries/Alert/NativeAlertManager.js b/Libraries/Alert/NativeAlertManager.js index d1fb7b2ba424fa..943f95410405d0 100644 --- a/Libraries/Alert/NativeAlertManager.js +++ b/Libraries/Alert/NativeAlertManager.js @@ -10,7 +10,6 @@ import type {TurboModule} from '../TurboModule/RCTExport'; import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; -import type {DefaultInputsArray} from './AlertMacOS'; // TODO(macOS GH#774) export type Args = {| title?: string, @@ -21,16 +20,16 @@ export type Args = {| cancelButtonKey?: string, destructiveButtonKey?: string, keyboardType?: string, - // [TODO(macOS ISS#2323203) - defaultInputs?: DefaultInputsArray, + // [TODO(macOS GH#774) + defaultInputs?: Array, modal?: ?boolean, critical?: ?boolean, - // ]TODO(macOS ISS#2323203) + // ]TODO(macOS GH#774) |}; export interface Spec extends TurboModule { +alertWithArgs: ( - args: NativeArgs, // TODO(macOS GH#774): Args -> NativeArgs + args: Args, callback: (id: number, value: string) => void, ) => void; } diff --git a/React/CoreModules/RCTAlertManager.mm b/React/CoreModules/RCTAlertManager.mm index 530cd4a170cf77..336e05cece28ae 100644 --- a/React/CoreModules/RCTAlertManager.mm +++ b/React/CoreModules/RCTAlertManager.mm @@ -78,7 +78,7 @@ - (void)invalidate * The key from the `buttons` dictionary is passed back in the callback on click. * Buttons are displayed in the order they are specified. */ -RCT_EXPORT_METHOD(alertWithArgs : (JS::NativeAlertManager::NativeArgs &)args callback : (RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(alertWithArgs : (JS::NativeAlertManager::Args &)args callback : (RCTResponseSenderBlock)callback) { NSString *title = [RCTConvert NSString:args.title()]; NSString *message = [RCTConvert NSString:args.message()]; diff --git a/index.js b/index.js index e9c3e5745acf5a..ca224f802ee36e 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,6 @@ import typeof VirtualizedSectionList from './Libraries/Lists/VirtualizedSectionL // APIs import typeof ActionSheetIOS from './Libraries/ActionSheetIOS/ActionSheetIOS'; import typeof Alert from './Libraries/Alert/Alert'; -import typeof AlertMacOS from './Libraries/Alert/AlertMacOS'; // TODO(macOS GH#774) import typeof Animated from './Libraries/Animated/Animated'; import typeof Appearance from './Libraries/Utilities/Appearance'; import typeof AppRegistry from './Libraries/ReactNative/AppRegistry'; @@ -271,16 +270,6 @@ module.exports = { get Alert(): Alert { return require('./Libraries/Alert/Alert'); }, - // [TODO(macOS GH#774) - get AlertMacOS(): AlertMacOS { - warnOnce( - 'AlertMacOS-deprecated', - 'AlertMacOS has been deprecated and will be removed in a future release. ' + - 'Use Alert instead. ' + - 'See https://github.com/microsoft/react-native-macos/issues/354', - ); - return require('./Libraries/Alert/AlertMacOS'); - }, // ]TODO(macOS GH#774) get Animated(): Animated { return require('./Libraries/Animated/Animated'); }, diff --git a/packages/rn-tester/js/examples/Alert/AlertIOSExample.js b/packages/rn-tester/js/examples/Alert/AlertIOSExample.js index 984ff8b6324cc7..970800dbc47c5e 100644 --- a/packages/rn-tester/js/examples/Alert/AlertIOSExample.js +++ b/packages/rn-tester/js/examples/Alert/AlertIOSExample.js @@ -142,6 +142,80 @@ class PromptOptions extends React.Component { } } +// [TODO(macOS GH#774) +const PromptPresentation = () => { + return ( + + + Alert.promptMacOS( + 'Default sheet', + null, + null, + 'default', + [{default: '', placeholder: ''}], + false, + ) + }> + + Default sheet + + + + Alert.promptMacOS( + 'Modal', + null, + null, + 'default', + [{default: '', placeholder: ''}], + true, + ) + }> + + Modal + + + + ); +}; + +const PromptStyle = () => { + return ( + + + Alert.promptMacOS('Default warning style', null, null, 'default') + }> + + Default warning style + + + + Alert.promptMacOS( + 'Critical', + null, + null, + 'default', + [{default: '', placeholder: ''}], + false, + true, + ) + }> + + Critical + + + + ); +}; +// ]TODO(macOS GH#774) + const styles = StyleSheet.create({ wrapper: { borderRadius: 5, @@ -161,7 +235,7 @@ const styles = StyleSheet.create({ exports.framework = 'React'; exports.title = 'Alerts'; -exports.description = 'iOS alerts and action sheets'; +exports.description = 'iOS / macOS alerts and action sheets'; // TODO(macOS GH#774) exports.documentationURL = 'https://reactnative.dev/docs/alert'; exports.examples = ([ ...SharedAlertExamples, @@ -205,4 +279,20 @@ exports.examples = ([ ); }, }, + // [TODO(macOS GH#774) + { + title: 'Prompt Presentation', + platform: 'macos', + render(): React.Node { + return ; + }, + }, + { + title: 'Prompt Style', + platform: 'macos', + render(): React.Node { + return ; + }, + }, + // ]TODO(macOS GH#774) ]: Array); diff --git a/packages/rn-tester/js/examples/Alert/AlertMacOSExample.js b/packages/rn-tester/js/examples/Alert/AlertMacOSExample.js deleted file mode 100644 index da9c6a8d30febc..00000000000000 --- a/packages/rn-tester/js/examples/Alert/AlertMacOSExample.js +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow - */ - -'use strict'; - -const React = require('react'); -const ReactNative = require('react-native'); -const {StyleSheet, View, Text, TouchableHighlight, AlertMacOS} = ReactNative; - -const {examples: SharedAlertExamples} = require('./AlertExample'); - -import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; - -exports.framework = 'React'; -exports.title = 'AlertMacOS'; -exports.description = 'macOS alerts'; -exports.documentationURL = 'https://reactnative.dev/docs/alert'; -exports.examples = ([ - ...SharedAlertExamples, - { - title: 'Prompt Options', - render(): React.Element { - return ; - }, - }, - { - title: 'Prompt Types', - render(): React.Node { - return ( - - AlertMacOS.prompt('Plain Text Entry')}> - - plain-text - - - - AlertMacOS.prompt('Secure Text', null, null, 'secure-text') - }> - - secure-text - - - - AlertMacOS.prompt( - 'Login & Password', - null, - null, - 'login-password', - [ - {default: '', placeholder: 'login'}, - {default: '', placeholder: 'Password'}, - ], - ) - }> - - login-password - - - - ); - }, - }, - { - title: 'Prompt Presentation', - render(): React.Node { - return ( - - - AlertMacOS.prompt( - 'Default sheet', - null, - null, - 'default', - [{default: '', placeholder: ''}], - false, - ) - }> - - Default sheet - - - - AlertMacOS.prompt( - 'Modal', - null, - null, - 'default', - [{default: '', placeholder: ''}], - true, - ) - }> - - Modal - - - - ); - }, - }, - { - title: 'Prompt Style', - render(): React.Node { - return ( - - - AlertMacOS.prompt('Default warning style', null, null, 'default') - }> - - Default warning style - - - - AlertMacOS.prompt( - 'Critical', - null, - null, - 'default', - [{default: '', placeholder: ''}], - false, - true, - ) - }> - - Critical - - - - ); - }, - }, -]: RNTesterModuleExample[]); - -class PromptOptions extends React.Component<$FlowFixMeProps, any> { - state: any; - customButtons: Array; - - constructor(props) { - super(props); - - // $FlowFixMe this seems to be a Flow bug, `saveResponse` is defined below - this.saveResponse = this.saveResponse.bind(this); - - this.customButtons = [ - { - text: 'Custom OK', - onPress: this.saveResponse, - }, - { - text: 'Custom Cancel', - style: 'cancel', - }, - ]; - - this.state = { - promptValue: undefined, - }; - } - - render() { - return ( - - - Prompt value:{' '} - {this.state.promptValue} - - - - AlertMacOS.prompt('Type a value', null, value => - this.saveResponse(value), - ) - }> - - prompt with title & callback - - - - - AlertMacOS.prompt('Type a value', null, this.customButtons) - }> - - prompt with title & custom buttons - - - - - AlertMacOS.prompt( - 'Type a value', - null, - value => this.saveResponse(value), - undefined, - [{default: 'Default value', placeholder: ''}], - ) - }> - - prompt with title, callback & default inputs - - - - - AlertMacOS.prompt( - 'Type a value', - null, - this.customButtons, - 'login-password', - [ - {default: 'admin@site.com', placeholder: 'login'}, - {default: '', placeholder: 'password'}, - ], - ) - }> - - - prompt with title, custom buttons, login/password & default inputs - - - - - ); - } - - saveResponse(promptValue) { - this.setState({promptValue: JSON.stringify(promptValue)}); - } -} - -var styles = StyleSheet.create({ - wrapper: { - borderRadius: 5, - marginBottom: 5, - }, - button: { - backgroundColor: '#eeeeee', - padding: 10, - }, -}); diff --git a/packages/rn-tester/js/utils/RNTesterList.ios.js b/packages/rn-tester/js/utils/RNTesterList.ios.js index 6ca6190ffab730..7b862441843b8c 100644 --- a/packages/rn-tester/js/utils/RNTesterList.ios.js +++ b/packages/rn-tester/js/utils/RNTesterList.ios.js @@ -230,11 +230,6 @@ const APIs: Array = [ category: 'iOS', supportsTVOS: true, }, - // [TODO(macOS GH#774) - { - key: 'AlertMacOSExample', - module: require('../examples/Alert/AlertMacOSExample'), - }, // ]TODO(macOS GH#774) { key: 'AnimatedIndex', module: require('../examples/Animated/AnimatedIndex').default,