mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 18:15:13 +00:00
@@ -41,6 +41,7 @@ module.exports = {
|
|||||||
SafeAreaView: true,
|
SafeAreaView: true,
|
||||||
ScrollView: true,
|
ScrollView: true,
|
||||||
SectionList: true,
|
SectionList: true,
|
||||||
|
Share: true,
|
||||||
Slider: true,
|
Slider: true,
|
||||||
StatusBar: true,
|
StatusBar: true,
|
||||||
StyleSheet: true,
|
StyleSheet: true,
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-present, Nicolas Gallagher.
|
||||||
|
* Copyright (c) 2016-present, Facebook, Inc.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
|
*/
|
||||||
|
|
||||||
|
import invariant from 'fbjs/lib/invariant';
|
||||||
|
|
||||||
|
type Content =
|
||||||
|
| { title?: string, message?: string, url: string }
|
||||||
|
| { title?: string, message: string, url?: string };
|
||||||
|
|
||||||
|
class Share {
|
||||||
|
static share(content: Content, options: Object = {}): Promise<Object> {
|
||||||
|
invariant(
|
||||||
|
typeof content === 'object' && content !== null,
|
||||||
|
'Content to share must be a valid object'
|
||||||
|
);
|
||||||
|
invariant(
|
||||||
|
typeof content.url === 'string' || typeof content.message === 'string',
|
||||||
|
'At least one of URL and message is required'
|
||||||
|
);
|
||||||
|
invariant(typeof options === 'object' && options !== null, 'Options must be a valid object');
|
||||||
|
invariant(
|
||||||
|
!content.title || typeof content.title === 'string',
|
||||||
|
'Invalid title: title should be a string.'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (window.navigator.share !== undefined) {
|
||||||
|
return window.navigator.share({
|
||||||
|
title: content.title,
|
||||||
|
text: content.message,
|
||||||
|
url: content.url
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Promise.reject(new Error('Share is not supported in this browser'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The content was successfully shared.
|
||||||
|
*/
|
||||||
|
static get sharedAction(): string {
|
||||||
|
return 'sharedAction';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The dialog has been dismissed.
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
static get dismissedAction(): string {
|
||||||
|
return 'dismissedAction';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Share;
|
||||||
+3
@@ -29,6 +29,7 @@ import NetInfo from './exports/NetInfo';
|
|||||||
import PanResponder from './exports/PanResponder';
|
import PanResponder from './exports/PanResponder';
|
||||||
import PixelRatio from './exports/PixelRatio';
|
import PixelRatio from './exports/PixelRatio';
|
||||||
import Platform from './exports/Platform';
|
import Platform from './exports/Platform';
|
||||||
|
import Share from './exports/Share';
|
||||||
import StyleSheet from './exports/StyleSheet';
|
import StyleSheet from './exports/StyleSheet';
|
||||||
import UIManager from './exports/UIManager';
|
import UIManager from './exports/UIManager';
|
||||||
import Vibration from './exports/Vibration';
|
import Vibration from './exports/Vibration';
|
||||||
@@ -101,6 +102,7 @@ export {
|
|||||||
PanResponder,
|
PanResponder,
|
||||||
PixelRatio,
|
PixelRatio,
|
||||||
Platform,
|
Platform,
|
||||||
|
Share,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
UIManager,
|
UIManager,
|
||||||
Vibration,
|
Vibration,
|
||||||
@@ -172,6 +174,7 @@ const ReactNative = {
|
|||||||
PanResponder,
|
PanResponder,
|
||||||
PixelRatio,
|
PixelRatio,
|
||||||
Platform,
|
Platform,
|
||||||
|
Share,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
UIManager,
|
UIManager,
|
||||||
Vibration,
|
Vibration,
|
||||||
|
|||||||
Reference in New Issue
Block a user