-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ios): Share
with anchor
#35008
feat(ios): Share
with anchor
#35008
Conversation
Base commit: a0ee6fa |
Base commit: 0481948 |
hey @zhumingcheng697 thank you for your PR! there are a couple CI tests failing, could you please take a look? |
Hi @skinsshark, the analyze_code test seems to be a dependency issue where TypeScript complains that some internal modules and/or type declarations cannot be found. The other test_windows one failed rather curiously in a test case for I can’t figure out how my changes could have led to the failing tests. Besides, these two tests also seem to be affecting other PRs like #35000 or even latest pushes on the main branch like 0481948. |
@skinsshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
i fixed the errors called out from the analyze_code test and will rebase your PR on top and land both- thanks! |
This pull request was successfully merged by @zhumingcheng697 in aeab383. When will my fix make it into a release? | Upcoming Releases |
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: facebook#35008 Test Plan: Tested with modified `rn-tester` that utilizes the `anchor` option on iPad simulator. Marked all 3 changes in code. ![Simulator Screen Shot - iPad Pro (11-inch) (3rd generation) - 2022-10-17 at 15 44 23](https://user-images.githubusercontent.com/31050761/196271991-469cac23-ef2b-4be5-aee2-b4197936007e.png) ```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
Summary
Share
currently does not support theanchor
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 inActionSheetIOS
to bring this support toShare
on iOS.Changelog
[iOS] [Changed] - type definition for the
options
parameter ofShare.share
(added optionalanchor
property)[iOS] [Added] -
anchor
option support forShare
Test Plan
Tested with modified
rn-tester
that utilizes theanchor
option on iPad simulator. Marked all 3 changes in code.