2015-03-13 22:30:31 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-03-13 22:30:31 +00:00
|
|
|
*
|
|
|
|
* @providesModule ActionSheetIOS
|
2015-03-25 02:34:12 +00:00
|
|
|
* @flow
|
2015-03-13 22:30:31 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-03-18 22:57:49 +00:00
|
|
|
var RCTActionSheetManager = require('NativeModules').ActionSheetManager;
|
2015-03-17 20:42:44 +00:00
|
|
|
|
2016-03-02 12:27:13 +00:00
|
|
|
var invariant = require('fbjs/lib/invariant');
|
2015-12-09 13:08:36 +00:00
|
|
|
var processColor = require('processColor');
|
2015-03-13 22:30:31 +00:00
|
|
|
|
|
|
|
var ActionSheetIOS = {
|
2016-03-31 05:10:00 +00:00
|
|
|
/**
|
|
|
|
* Display an iOS action sheet. The `options` object must contain one or more
|
|
|
|
* of:
|
|
|
|
*
|
|
|
|
* - `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
|
|
|
|
*/
|
2015-03-25 02:34:12 +00:00
|
|
|
showActionSheetWithOptions(options: Object, callback: Function) {
|
2015-03-13 22:30:31 +00:00
|
|
|
invariant(
|
|
|
|
typeof options === 'object' && options !== null,
|
2016-03-31 05:10:00 +00:00
|
|
|
'Options must be a valid object'
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
typeof callback === 'function',
|
|
|
|
'Must provide a valid callback'
|
|
|
|
);
|
|
|
|
RCTActionSheetManager.showActionSheetWithOptions(
|
2015-12-09 13:08:36 +00:00
|
|
|
{...options, tintColor: processColor(options.tintColor)},
|
2015-03-13 22:30:31 +00:00
|
|
|
callback
|
|
|
|
);
|
|
|
|
},
|
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
|
|
|
|
* - `excludedActivityTypes` (array) - the activites to exclude from the ActionSheet
|
2016-02-22 13:33:31 +00:00
|
|
|
*
|
|
|
|
* NOTE: if `url` points to a local file, or is a base64-encoded
|
|
|
|
* uri, the file it points to will be loaded and shared directly.
|
|
|
|
* In this way, you can share images, videos, PDF files, etc.
|
|
|
|
*/
|
2015-03-25 02:34:12 +00:00
|
|
|
showShareActionSheetWithOptions(
|
|
|
|
options: Object,
|
|
|
|
failureCallback: Function,
|
|
|
|
successCallback: Function
|
|
|
|
) {
|
2015-03-13 22:30:31 +00:00
|
|
|
invariant(
|
|
|
|
typeof options === 'object' && options !== null,
|
2016-03-31 05:10:00 +00:00
|
|
|
'Options must be a valid object'
|
2015-03-13 22:30:31 +00:00
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
typeof failureCallback === 'function',
|
|
|
|
'Must provide a valid failureCallback'
|
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
typeof successCallback === 'function',
|
|
|
|
'Must provide a valid successCallback'
|
|
|
|
);
|
|
|
|
RCTActionSheetManager.showShareActionSheetWithOptions(
|
2015-12-09 13:08:36 +00:00
|
|
|
{...options, tintColor: processColor(options.tintColor)},
|
2015-03-13 22:30:31 +00:00
|
|
|
failureCallback,
|
|
|
|
successCallback
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ActionSheetIOS;
|