2015-03-13 22:30:31 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-13 22:30:31 +00:00
|
|
|
*
|
2015-03-25 02:34:12 +00:00
|
|
|
* @flow
|
2017-12-14 00:16:34 +00:00
|
|
|
* @format
|
2015-03-13 22:30:31 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2017-12-14 00:16:34 +00:00
|
|
|
const RCTActionSheetManager = require('NativeModules').ActionSheetManager;
|
2015-03-17 20:42:44 +00:00
|
|
|
|
2017-12-14 00:16:34 +00:00
|
|
|
const invariant = require('fbjs/lib/invariant');
|
|
|
|
const processColor = require('processColor');
|
2015-03-13 22:30:31 +00:00
|
|
|
|
2017-11-20 21:07:10 +00:00
|
|
|
/**
|
|
|
|
* Display action sheets and share sheets on iOS.
|
2017-12-14 00:16:34 +00:00
|
|
|
*
|
2017-11-20 21:07:10 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/actionsheetios.html
|
|
|
|
*/
|
2017-12-14 00:16:34 +00:00
|
|
|
const ActionSheetIOS = {
|
2016-03-31 05:10:00 +00:00
|
|
|
/**
|
2017-11-20 21:07:10 +00:00
|
|
|
* Display an iOS action sheet.
|
2017-12-14 00:16:34 +00:00
|
|
|
*
|
2017-11-20 21:07:10 +00:00
|
|
|
* The `options` object must contain one or more of:
|
2017-12-14 00:16:34 +00:00
|
|
|
*
|
2016-03-31 05:10:00 +00:00
|
|
|
* - `options` (array of strings) - a list of button titles (required)
|
|
|
|
* - `cancelButtonIndex` (int) - index of cancel button in `options`
|
|
|
|
* - `destructiveButtonIndex` (int) - index of destructive button in `options`
|
|
|
|
* - `title` (string) - a title to show above the action sheet
|
|
|
|
* - `message` (string) - a message to show below the title
|
2017-12-14 00:16:34 +00:00
|
|
|
*
|
2017-09-21 18:41:12 +00:00
|
|
|
* The 'callback' function takes one parameter, the zero-based index
|
|
|
|
* of the selected item.
|
2017-12-14 00:16:34 +00:00
|
|
|
*
|
2017-11-20 21:07:10 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/actionsheetios.html#showactionsheetwithoptions
|
2016-03-31 05:10:00 +00:00
|
|
|
*/
|
2017-12-14 00:16:34 +00:00
|
|
|
showActionSheetWithOptions(
|
|
|
|
options: {|
|
|
|
|
+title?: ?string,
|
|
|
|
+message?: ?string,
|
|
|
|
+options: Array<string>,
|
|
|
|
+destructiveButtonIndex?: ?number,
|
|
|
|
+cancelButtonIndex?: ?number,
|
|
|
|
+anchor?: ?number,
|
|
|
|
+tintColor?: number | string,
|
|
|
|
|},
|
|
|
|
callback: (buttonIndex: number) => void,
|
|
|
|
) {
|
2015-03-13 22:30:31 +00:00
|
|
|
invariant(
|
|
|
|
typeof options === 'object' && options !== null,
|
2017-12-14 00:16:34 +00:00
|
|
|
'Options must be a valid object',
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
2017-12-14 00:16:34 +00:00
|
|
|
invariant(typeof callback === 'function', 'Must provide a valid callback');
|
|
|
|
|
2015-03-13 22:30:31 +00:00
|
|
|
RCTActionSheetManager.showActionSheetWithOptions(
|
2015-12-09 13:08:36 +00:00
|
|
|
{...options, tintColor: processColor(options.tintColor)},
|
2017-12-14 00:16:34 +00:00
|
|
|
callback,
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
|
|
|
},
|
2016-04-06 16:20:39 +00:00
|
|
|
|
2016-02-22 13:33:31 +00:00
|
|
|
/**
|
|
|
|
* Display the iOS share sheet. The `options` object should contain
|
2016-08-09 13:32:41 +00:00
|
|
|
* one or both of `message` and `url` and can additionally have
|
2016-06-03 09:49:21 +00:00
|
|
|
* a `subject` or `excludedActivityTypes`:
|
2016-04-06 16:20:39 +00:00
|
|
|
*
|
2016-02-22 13:33:31 +00:00
|
|
|
* - `url` (string) - a URL to share
|
2016-06-03 09:49:21 +00:00
|
|
|
* - `message` (string) - a message to share
|
|
|
|
* - `subject` (string) - a subject for the message
|
2017-12-14 00:16:34 +00:00
|
|
|
* - `excludedActivityTypes` (array) - the activities to exclude from
|
2017-11-20 21:07:10 +00:00
|
|
|
* the ActionSheet
|
2017-11-06 18:20:17 +00:00
|
|
|
* - `tintColor` (color) - tint color of the buttons
|
2016-02-22 13:33:31 +00:00
|
|
|
*
|
2017-09-21 18:41:12 +00:00
|
|
|
* The 'failureCallback' function takes one parameter, an error object.
|
|
|
|
* The only property defined on this object is an optional `stack` property
|
|
|
|
* of type `string`.
|
|
|
|
*
|
|
|
|
* The 'successCallback' function takes two parameters:
|
|
|
|
*
|
|
|
|
* - a boolean value signifying success or failure
|
|
|
|
* - a string that, in the case of success, indicates the method of sharing
|
2017-12-14 00:16:34 +00:00
|
|
|
*
|
2017-11-20 21:07:10 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/actionsheetios.html#showshareactionsheetwithoptions
|
2016-02-22 13:33:31 +00:00
|
|
|
*/
|
2015-03-25 02:34:12 +00:00
|
|
|
showShareActionSheetWithOptions(
|
|
|
|
options: Object,
|
|
|
|
failureCallback: Function,
|
2017-12-14 00:16:34 +00:00
|
|
|
successCallback: Function,
|
2015-03-25 02:34:12 +00:00
|
|
|
) {
|
2015-03-13 22:30:31 +00:00
|
|
|
invariant(
|
|
|
|
typeof options === 'object' && options !== null,
|
2017-12-14 00:16:34 +00:00
|
|
|
'Options must be a valid object',
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
typeof failureCallback === 'function',
|
2017-12-14 00:16:34 +00:00
|
|
|
'Must provide a valid failureCallback',
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
typeof successCallback === 'function',
|
2017-12-14 00:16:34 +00:00
|
|
|
'Must provide a valid successCallback',
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
|
|
|
RCTActionSheetManager.showShareActionSheetWithOptions(
|
2015-12-09 13:08:36 +00:00
|
|
|
{...options, tintColor: processColor(options.tintColor)},
|
2015-03-13 22:30:31 +00:00
|
|
|
failureCallback,
|
2017-12-14 00:16:34 +00:00
|
|
|
successCallback,
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
2017-12-14 00:16:34 +00:00
|
|
|
},
|
2015-03-13 22:30:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ActionSheetIOS;
|