mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Update RN Share.share()'s argument types to be more explicit (#44887)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44887 The previous inexact object types and documentation for Share.share()'s arguments have led to confusion in how this library should be used. This diff updates the argument types to be more explicit, and rewrites some of the documentation for clarity. Changelog: [General][Breaking] Update `Share.share()`'s argument types to be more explicit. Reviewed By: NickGerleman Differential Revision: D58224906 fbshipit-source-id: 5ac8efe7caa0ecdd430fa7a1951c73c4acd8c6a1
This commit is contained in:
1 parent
261f7b9f11
commit
8b53d41a88
3 files changed
+43
-39
No files matched your search
+17
-11
@@ -12,11 +12,13 @@ import {ColorValue} from '../StyleSheet/StyleSheet';
|
||||
export type ShareContent =
|
||||
| {
|
||||
title?: string | undefined;
|
||||
message: string;
|
||||
url: string;
|
||||
message?: string | undefined;
|
||||
}
|
||||
| {
|
||||
title?: string | undefined;
|
||||
url: string;
|
||||
url?: string | undefined;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type ShareOptions = {
|
||||
@@ -40,29 +42,33 @@ export interface ShareStatic {
|
||||
* If the user dismissed the dialog, the Promise will still be resolved with action being `Share.dismissedAction`
|
||||
* and all the other keys being undefined.
|
||||
*
|
||||
* In Android, Returns a Promise which always be resolved with action being `Share.sharedAction`.
|
||||
* In Android, Returns a Promise which always resolves with action being `Share.sharedAction`.
|
||||
*
|
||||
* ### Content
|
||||
*
|
||||
* - `message` - a message to share
|
||||
* - `title` - title of the message
|
||||
*
|
||||
* #### iOS
|
||||
*
|
||||
* - `url` - an URL to share
|
||||
* - `url` - a URL to share
|
||||
* - `message` - a message to share
|
||||
*
|
||||
* At least one of URL and message is required.
|
||||
* At least one of `URL` or `message` is required.
|
||||
*
|
||||
* #### Android
|
||||
*
|
||||
* - `title` - title of the message (optional)
|
||||
* - `message` - a message to share (often will include a URL).
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* #### iOS
|
||||
*
|
||||
* - `excludedActivityTypes`
|
||||
* - `tintColor`
|
||||
* - `subject` - a subject to share via email
|
||||
* - `excludedActivityTypes`
|
||||
* - `tintColor`
|
||||
*
|
||||
* #### Android
|
||||
*
|
||||
* - `dialogTitle`
|
||||
* - `dialogTitle`
|
||||
*
|
||||
*/
|
||||
share(content: ShareContent, options?: ShareOptions): Promise<ShareAction>;
|
||||
|
||||
+16
-17
@@ -15,24 +15,23 @@ const processColor = require('../StyleSheet/processColor').default;
|
||||
const Platform = require('../Utilities/Platform');
|
||||
const invariant = require('invariant');
|
||||
|
||||
type Content =
|
||||
| {
|
||||
title?: string,
|
||||
message: string,
|
||||
...
|
||||
}
|
||||
export type ShareContent =
|
||||
| {
|
||||
title?: string,
|
||||
url: string,
|
||||
...
|
||||
message?: string,
|
||||
}
|
||||
| {
|
||||
title?: string,
|
||||
url?: string,
|
||||
message: string,
|
||||
};
|
||||
type Options = {
|
||||
export type ShareOptions = {
|
||||
dialogTitle?: string,
|
||||
excludedActivityTypes?: Array<string>,
|
||||
tintColor?: string,
|
||||
subject?: string,
|
||||
anchor?: number,
|
||||
...
|
||||
};
|
||||
|
||||
class Share {
|
||||
@@ -43,21 +42,21 @@ class Share {
|
||||
* If the user dismissed the dialog, the Promise will still be resolved with action being `Share.dismissedAction`
|
||||
* and all the other keys being undefined.
|
||||
*
|
||||
* In Android, Returns a Promise which always be resolved with action being `Share.sharedAction`.
|
||||
* In Android, Returns a Promise which always resolves with action being `Share.sharedAction`.
|
||||
*
|
||||
* ### Content
|
||||
*
|
||||
* - `message` - a message to share
|
||||
*
|
||||
* #### iOS
|
||||
*
|
||||
* - `url` - a URL to share
|
||||
* - `message` - a message to share
|
||||
*
|
||||
* At least one of URL and message is required.
|
||||
* At least one of `URL` or `message` is required.
|
||||
*
|
||||
* #### Android
|
||||
*
|
||||
* - `title` - title of the message
|
||||
* - `title` - title of the message (optional)
|
||||
* - `message` - a message to share (often will include a URL).
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
@@ -73,8 +72,8 @@ class Share {
|
||||
*
|
||||
*/
|
||||
static share(
|
||||
content: Content,
|
||||
options: Options = {},
|
||||
content: ShareContent,
|
||||
options: ShareOptions = {},
|
||||
): Promise<{action: string, activityType: ?string}> {
|
||||
invariant(
|
||||
typeof content === 'object' && content !== null,
|
||||
@@ -82,7 +81,7 @@ class Share {
|
||||
);
|
||||
invariant(
|
||||
typeof content.url === 'string' || typeof content.message === 'string',
|
||||
'At least one of URL and message is required',
|
||||
'At least one of URL or message is required',
|
||||
);
|
||||
invariant(
|
||||
typeof options === 'object' && options !== null,
|
||||
|
||||
@@ -7340,29 +7340,28 @@ declare export default typeof NativeShareModule;
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Share/Share.js 1`] = `
|
||||
"type Content =
|
||||
| {
|
||||
title?: string,
|
||||
message: string,
|
||||
...
|
||||
}
|
||||
"export type ShareContent =
|
||||
| {
|
||||
title?: string,
|
||||
url: string,
|
||||
...
|
||||
message?: string,
|
||||
}
|
||||
| {
|
||||
title?: string,
|
||||
url?: string,
|
||||
message: string,
|
||||
};
|
||||
type Options = {
|
||||
export type ShareOptions = {
|
||||
dialogTitle?: string,
|
||||
excludedActivityTypes?: Array<string>,
|
||||
tintColor?: string,
|
||||
subject?: string,
|
||||
anchor?: number,
|
||||
...
|
||||
};
|
||||
declare class Share {
|
||||
static share(
|
||||
content: Content,
|
||||
options: Options
|
||||
content: ShareContent,
|
||||
options: ShareOptions
|
||||
): Promise<{ action: string, activityType: ?string }>;
|
||||
static sharedAction: \\"sharedAction\\";
|
||||
static dismissedAction: \\"dismissedAction\\";
|
||||
|
||||
Reference in new issue
Block a user