2017-09-16 5 views
0

RNのShare API機能を利用したExpoでアプリを構築しています。私はイメージを共有するために次のものをうまく実装しました:ユーザーがReact Nativeで共有オプションを閉じるタイミングを知る方法

Share.share(
{ 
    message: 'This is a message', 
    url: FileSystem.documentDirectory + imageUrlDate 
}, 
{ 
    dialogTitle: 'Share Today', 
    excludedActivityTypes: [ 
    'com.apple.mobilenotes.SharingExtension', 
    'com.apple.reminders.RemindersEditorExtension' 
    ] 
} 

);

私が知りたいのは、sharedAction()dismissedAction()のオプションの使い方です。

基本的には、ユーザーが共有をキャンセルするかどうかを知りたいと思っています。

ありがとうございます!

答えて

1

docsから読み取ることができるように、Share.share()Promiseを返し、ユーザーがダイアログを共有または却下した場合に戻るアクションが表示されます。解任された行為はiOSのためのものなので、実装が必要な場合はplatform specific codeと書く必要があります。

は、iOSでは、 アクション、ActivityTypeをを含むオブジェクトを呼び出すことになる約束を返します。ユーザーがダイアログを閉じると、Promise は解決されますが、アクションはShare.dismissedActionで、 のすべてのキーは未定義です。

では、アクション がShare.sharedActionで常に解決されるプロミスを返します。

ですから、このような何かを行うことができ、

Share.share({ message: 'This is a message', url: FileSystem.documentDirectory + imageUrlDate }, 
{ 
    dialogTitle: 'Share Today', 
    excludedActivityTypes: [ 
    'com.apple.mobilenotes.SharingExtension', 
    'com.apple.reminders.RemindersEditorExtension' 
    ] 
}).then(({action, activityType}) => { 
    if(action === Share.dismissedAction) console.log('Share dismissed'); 
    else console.log('Share successful'); 
}); 
0

bennygenels答えは(ほとんどは正しいが共有である)、それは実際に動作させるために} resolves as an object約束を返しますので、我々はいくつかの余分な中括弧{必要:

Share.share({ message: 'This is a message', url: FileSystem.documentDirectory + imageUrlDate }, 
{ 
    dialogTitle: 'Share Today', 
    excludedActivityTypes: [ 
    'com.apple.mobilenotes.SharingExtension', 
    'com.apple.reminders.RemindersEditorExtension' 
    ] 
}).then(({action, activityType}) => { 
    if(action === Share.dismissedAction) console.log('Share dismissed'); 
    else console.log('Share successful'); 
}); 
+1

答えにいくつかの詳細を追加します。 – Billa

関連する問題