From 3e59bd70e54ab8c8ce0651f99a447cd62d2b5e68 Mon Sep 17 00:00:00 2001 From: Kshitij Kotasthane Date: Sat, 7 Nov 2020 22:32:17 +0530 Subject: [PATCH 1/3] Added sharedAction example for Share API --- .../js/examples/Share/ShareExample.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/rn-tester/js/examples/Share/ShareExample.js b/packages/rn-tester/js/examples/Share/ShareExample.js index 3ec9a7d6f5c89f..1bcd7cfd174da7 100644 --- a/packages/rn-tester/js/examples/Share/ShareExample.js +++ b/packages/rn-tester/js/examples/Share/ShareExample.js @@ -76,6 +76,46 @@ const ShareMessageWithTitle = () => { ); }; +const SharedAction = () => { + const [shared, setShared] = React.useState(); + + 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', + }, + ); + 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 ( + + action: {shared ? shared : 'null'} + Create native apps + + React Native combines the best parts of native development with React, a + best-in-class JavaScript library for building user interfaces. + +