Flow Type ActionSheetIOS

Reviewed By: sahrens

Differential Revision: D6548474

fbshipit-source-id: dac0cb2cdd85bc49d4302b4382142fd70ab4ecc4
This commit is contained in:
Eli White 2017-12-13 16:16:34 -08:00 committed by Facebook Github Bot
parent 85503a0612
commit 61d046be3c
1 changed files with 34 additions and 24 deletions

View File

@ -8,48 +8,58 @@
* *
* @providesModule ActionSheetIOS * @providesModule ActionSheetIOS
* @flow * @flow
* @format
*/ */
'use strict'; 'use strict';
var RCTActionSheetManager = require('NativeModules').ActionSheetManager; const RCTActionSheetManager = require('NativeModules').ActionSheetManager;
var invariant = require('fbjs/lib/invariant'); const invariant = require('fbjs/lib/invariant');
var processColor = require('processColor'); const processColor = require('processColor');
/** /**
* Display action sheets and share sheets on iOS. * Display action sheets and share sheets on iOS.
* *
* See http://facebook.github.io/react-native/docs/actionsheetios.html * See http://facebook.github.io/react-native/docs/actionsheetios.html
*/ */
var ActionSheetIOS = { const ActionSheetIOS = {
/** /**
* Display an iOS action sheet. * Display an iOS action sheet.
* *
* The `options` object must contain one or more of: * The `options` object must contain one or more of:
* *
* - `options` (array of strings) - a list of button titles (required) * - `options` (array of strings) - a list of button titles (required)
* - `cancelButtonIndex` (int) - index of cancel button in `options` * - `cancelButtonIndex` (int) - index of cancel button in `options`
* - `destructiveButtonIndex` (int) - index of destructive button in `options` * - `destructiveButtonIndex` (int) - index of destructive button in `options`
* - `title` (string) - a title to show above the action sheet * - `title` (string) - a title to show above the action sheet
* - `message` (string) - a message to show below the title * - `message` (string) - a message to show below the title
* *
* The 'callback' function takes one parameter, the zero-based index * The 'callback' function takes one parameter, the zero-based index
* of the selected item. * of the selected item.
* *
* See http://facebook.github.io/react-native/docs/actionsheetios.html#showactionsheetwithoptions * See http://facebook.github.io/react-native/docs/actionsheetios.html#showactionsheetwithoptions
*/ */
showActionSheetWithOptions(options: Object, callback: Function) { showActionSheetWithOptions(
options: {|
+title?: ?string,
+message?: ?string,
+options: Array<string>,
+destructiveButtonIndex?: ?number,
+cancelButtonIndex?: ?number,
+anchor?: ?number,
+tintColor?: number | string,
|},
callback: (buttonIndex: number) => void,
) {
invariant( invariant(
typeof options === 'object' && options !== null, typeof options === 'object' && options !== null,
'Options must be a valid object' 'Options must be a valid object',
);
invariant(
typeof callback === 'function',
'Must provide a valid callback'
); );
invariant(typeof callback === 'function', 'Must provide a valid callback');
RCTActionSheetManager.showActionSheetWithOptions( RCTActionSheetManager.showActionSheetWithOptions(
{...options, tintColor: processColor(options.tintColor)}, {...options, tintColor: processColor(options.tintColor)},
callback callback,
); );
}, },
@ -61,7 +71,7 @@ var ActionSheetIOS = {
* - `url` (string) - a URL to share * - `url` (string) - a URL to share
* - `message` (string) - a message to share * - `message` (string) - a message to share
* - `subject` (string) - a subject for the message * - `subject` (string) - a subject for the message
* - `excludedActivityTypes` (array) - the activities to exclude from * - `excludedActivityTypes` (array) - the activities to exclude from
* the ActionSheet * the ActionSheet
* - `tintColor` (color) - tint color of the buttons * - `tintColor` (color) - tint color of the buttons
* *
@ -73,32 +83,32 @@ var ActionSheetIOS = {
* *
* - a boolean value signifying success or failure * - a boolean value signifying success or failure
* - a string that, in the case of success, indicates the method of sharing * - a string that, in the case of success, indicates the method of sharing
* *
* See http://facebook.github.io/react-native/docs/actionsheetios.html#showshareactionsheetwithoptions * See http://facebook.github.io/react-native/docs/actionsheetios.html#showshareactionsheetwithoptions
*/ */
showShareActionSheetWithOptions( showShareActionSheetWithOptions(
options: Object, options: Object,
failureCallback: Function, failureCallback: Function,
successCallback: Function successCallback: Function,
) { ) {
invariant( invariant(
typeof options === 'object' && options !== null, typeof options === 'object' && options !== null,
'Options must be a valid object' 'Options must be a valid object',
); );
invariant( invariant(
typeof failureCallback === 'function', typeof failureCallback === 'function',
'Must provide a valid failureCallback' 'Must provide a valid failureCallback',
); );
invariant( invariant(
typeof successCallback === 'function', typeof successCallback === 'function',
'Must provide a valid successCallback' 'Must provide a valid successCallback',
); );
RCTActionSheetManager.showShareActionSheetWithOptions( RCTActionSheetManager.showShareActionSheetWithOptions(
{...options, tintColor: processColor(options.tintColor)}, {...options, tintColor: processColor(options.tintColor)},
failureCallback, failureCallback,
successCallback successCallback,
); );
} },
}; };
module.exports = ActionSheetIOS; module.exports = ActionSheetIOS;