mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
feat(ios): Share with anchor (#35008)
Summary: [`Share`](https://reactnative.dev/docs/share) currently does not support the `anchor` option in iOS, so share sheets will always be displayed in the middle of the screen on iPads and on the top left corner of the window on Mac Catalyst. This PR utilizes the `anchor` functionality already implemented in [`ActionSheetIOS`](https://reactnative.dev/docs/actionsheetios) to bring this support to `Share` on iOS. ## Changelog [iOS] [Changed] - type definition for the `options` parameter of `Share.share` (added optional `anchor` property) [iOS] [Added] - `anchor` option support for `Share` Pull Request resolved: https://github.com/facebook/react-native/pull/35008 Test Plan: Tested with modified `rn-tester` that utilizes the `anchor` option on iPad simulator. Marked all 3 changes in code.  ```js const SharedAction = () => { const [shared, setShared] = React.useState(); const ref = React.useRef(); /* create ref (1/3) */ const sharedAction = async () => { try { const result = await Share.share( { title: 'Create native apps', message: ('React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces.': string), url: 'https://reactnative.dev/', }, { subject: 'MUST READ: Create native apps with React Native', dialogTitle: 'Share React Native Home Page', tintColor: 'blue', anchor: ref.current?._nativeTag, /* add anchor in options (2/3) */ }, ); if (result.action === Share.sharedAction) { setShared(result.action); } else if (result.action === Share.dismissedAction) { //iOS only, if dialog was dismissed setShared(null); } } catch (e) { console.error(e); } }; return ( <View style={styles.container}> <Text>action: {shared ? shared : 'null'}</Text> <Text style={styles.title}>Create native apps</Text> <Text> React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces. </Text> {/* supply ref to Node (3/3) */} <Text ref={ref} style={styles.button} onPress={sharedAction}> SHARE </Text> </View> ); }; ``` Reviewed By: cipolleschi Differential Revision: D40459336 Pulled By: skinsshark fbshipit-source-id: 72fbb3905ea0b982bb7f4b99967d121cd482181a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
42b3ab350f
commit
aeab38357f
@@ -30,6 +30,7 @@ export interface ShareActionSheetIOSOptions {
|
||||
message?: string | undefined;
|
||||
url?: string | undefined;
|
||||
subject?: string | undefined;
|
||||
anchor?: number | undefined;
|
||||
/** The activities to exclude from the ActionSheet.
|
||||
* For example: ['com.apple.UIKit.activity.PostToTwitter']
|
||||
*/
|
||||
|
||||
Vendored
+1
@@ -24,6 +24,7 @@ export type ShareOptions = {
|
||||
excludedActivityTypes?: Array<string> | undefined;
|
||||
tintColor?: ColorValue | undefined;
|
||||
subject?: string | undefined;
|
||||
anchor?: number | undefined;
|
||||
};
|
||||
|
||||
export type ShareSharedAction = {
|
||||
|
||||
@@ -31,6 +31,7 @@ type Options = {
|
||||
excludedActivityTypes?: Array<string>,
|
||||
tintColor?: string,
|
||||
subject?: string,
|
||||
anchor?: number,
|
||||
...
|
||||
};
|
||||
|
||||
@@ -131,6 +132,8 @@ class Share {
|
||||
url: typeof content.url === 'string' ? content.url : undefined,
|
||||
subject: options.subject,
|
||||
tintColor: typeof tintColor === 'number' ? tintColor : undefined,
|
||||
anchor:
|
||||
typeof options.anchor === 'number' ? options.anchor : undefined,
|
||||
excludedActivityTypes: options.excludedActivityTypes,
|
||||
},
|
||||
error => reject(error),
|
||||
|
||||
Reference in New Issue
Block a user