2015-03-13 15:30:31 -07:00
|
|
|
/**
|
2015-03-23 15:07:33 -07:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-16 18:24:55 -08: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 15:30:31 -07:00
|
|
|
*
|
2015-03-24 19:34:12 -07:00
|
|
|
* @flow
|
2017-12-13 16:16:34 -08:00
|
|
|
* @format
|
2015-03-13 15:30:31 -07:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2017-12-13 16:16:34 -08:00
|
|
|
const RCTActionSheetManager = require('NativeModules').ActionSheetManager;
|
2015-03-17 13:42:44 -07:00
|
|
|
|
2017-12-13 16:16:34 -08:00
|
|
|
const invariant = require('fbjs/lib/invariant');
|
|
|
|
const processColor = require('processColor');
|
2015-03-13 15:30:31 -07:00
|
|
|
|
2017-11-20 13:07:10 -08:00
|
|
|
/**
|
|
|
|
* Display action sheets and share sheets on iOS.
|
2017-12-13 16:16:34 -08:00
|
|
|
*
|
2017-11-20 13:07:10 -08:00
|
|
|
* See http://facebook.github.io/react-native/docs/actionsheetios.html
|
|
|
|
*/
|
2017-12-13 16:16:34 -08:00
|
|
|
const ActionSheetIOS = {
|
2016-03-30 22:10:00 -07:00
|
|
|
/**
|
2017-11-20 13:07:10 -08:00
|
|
|
* Display an iOS action sheet.
|
2017-12-13 16:16:34 -08:00
|
|
|
*
|
2017-11-20 13:07:10 -08:00
|
|
|
* The `options` object must contain one or more of:
|
2017-12-13 16:16:34 -08:00
|
|
|
*
|
2016-03-30 22:10:00 -07: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-13 16:16:34 -08:00
|
|
|
*
|
2017-09-21 11:41:12 -07:00
|
|
|
* The 'callback' function takes one parameter, the zero-based index
|
|
|
|
* of the selected item.
|
2017-12-13 16:16:34 -08:00
|
|
|
*
|
2017-11-20 13:07:10 -08:00
|
|
|
* See http://facebook.github.io/react-native/docs/actionsheetios.html#showactionsheetwithoptions
|
2016-03-30 22:10:00 -07:00
|
|
|
*/
|
2017-12-13 16:16:34 -08: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 15:30:31 -07:00
|
|
|
invariant(
|
|
|
|
typeof options === 'object' && options !== null,
|
2017-12-13 16:16:34 -08:00
|
|
|
'Options must be a valid object',
|
2015-03-13 15:30:31 -07:00
|
|
|
);
|
2017-12-13 16:16:34 -08:00
|
|
|
invariant(typeof callback === 'function', 'Must provide a valid callback');
|
|
|
|
|
2015-03-13 15:30:31 -07:00
|
|
|
RCTActionSheetManager.showActionSheetWithOptions(
|
2015-12-09 05:08:36 -08:00
|
|
|
{...options, tintColor: processColor(options.tintColor)},
|
2017-12-13 16:16:34 -08:00
|
|
|
callback,
|
2015-03-13 15:30:31 -07:00
|
|
|
);
|
|
|
|
},
|
2016-04-06 09:20:39 -07:00
|
|
|
|
2016-02-22 05:33:31 -08:00
|
|
|
/**
|
|
|
|
* Display the iOS share sheet. The `options` object should contain
|
2016-08-09 06:32:41 -07:00
|
|
|
* one or both of `message` and `url` and can additionally have
|
2016-06-03 02:49:21 -07:00
|
|
|
* a `subject` or `excludedActivityTypes`:
|
2016-04-06 09:20:39 -07:00
|
|
|
*
|
2016-02-22 05:33:31 -08:00
|
|
|
* - `url` (string) - a URL to share
|
2016-06-03 02:49:21 -07:00
|
|
|
* - `message` (string) - a message to share
|
|
|
|
* - `subject` (string) - a subject for the message
|
2017-12-13 16:16:34 -08:00
|
|
|
* - `excludedActivityTypes` (array) - the activities to exclude from
|
2017-11-20 13:07:10 -08:00
|
|
|
* the ActionSheet
|
2017-11-06 10:20:17 -08:00
|
|
|
* - `tintColor` (color) - tint color of the buttons
|
2016-02-22 05:33:31 -08:00
|
|
|
*
|
2017-09-21 11:41:12 -07: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-13 16:16:34 -08:00
|
|
|
*
|
2017-11-20 13:07:10 -08:00
|
|
|
* See http://facebook.github.io/react-native/docs/actionsheetios.html#showshareactionsheetwithoptions
|
2016-02-22 05:33:31 -08:00
|
|
|
*/
|
2015-03-24 19:34:12 -07:00
|
|
|
showShareActionSheetWithOptions(
|
|
|
|
options: Object,
|
|
|
|
failureCallback: Function,
|
2017-12-13 16:16:34 -08:00
|
|
|
successCallback: Function,
|
2015-03-24 19:34:12 -07:00
|
|
|
) {
|
2015-03-13 15:30:31 -07:00
|
|
|
invariant(
|
|
|
|
typeof options === 'object' && options !== null,
|
2017-12-13 16:16:34 -08:00
|
|
|
'Options must be a valid object',
|
2015-03-13 15:30:31 -07:00
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
typeof failureCallback === 'function',
|
2017-12-13 16:16:34 -08:00
|
|
|
'Must provide a valid failureCallback',
|
2015-03-13 15:30:31 -07:00
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
typeof successCallback === 'function',
|
2017-12-13 16:16:34 -08:00
|
|
|
'Must provide a valid successCallback',
|
2015-03-13 15:30:31 -07:00
|
|
|
);
|
|
|
|
RCTActionSheetManager.showShareActionSheetWithOptions(
|
2015-12-09 05:08:36 -08:00
|
|
|
{...options, tintColor: processColor(options.tintColor)},
|
2015-03-13 15:30:31 -07:00
|
|
|
failureCallback,
|
2017-12-13 16:16:34 -08:00
|
|
|
successCallback,
|
2015-03-13 15:30:31 -07:00
|
|
|
);
|
2017-12-13 16:16:34 -08:00
|
|
|
},
|
2015-03-13 15:30:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ActionSheetIOS;
|