@ant-design/react-native
Version:
基于蚂蚁金服移动设计规范的 React Native 组件库
61 lines • 2.34 kB
JavaScript
import React from 'react';
import { ActionSheetIOS, Platform, Share } from 'react-native';
import Portal from '../portal';
import ActionSheetAndroidContainer from './AndroidContainer';
var instance = void 0;
export default {
showActionSheetWithOptions: function showActionSheetWithOptions(config, callback) {
if (Platform.OS === 'ios') {
ActionSheetIOS.showActionSheetWithOptions(config, callback);
return;
}
var key = Portal.add(React.createElement(ActionSheetAndroidContainer, { visible: true, ref: function ref(_ref) {
return instance = _ref;
}, onAnimationEnd: function onAnimationEnd(visible) {
if (!visible) {
Portal.remove(key);
}
}, config: config, callback: callback }));
},
showShareActionSheetWithOptions: function showShareActionSheetWithOptions(config, failureCallback, successCallback) {
var content = {};
var options = {};
content.message = config.message;
if (config.title) {
content.title = config.title;
options.dialogTitle = config.title;
}
if (config.url) {
content.url = config.url;
}
if (config.excludedActivityTypes) {
options.excludedActivityTypes = config.excludedActivityTypes;
}
if (config.tintColor) {
options.tintColor = config.tintColor;
}
// promise is not called in Android
// https://github.com/facebook/react-native/blob/master/Libraries/Share/Share.js#L80
Share.share(content, options).then(function (result) {
if (result.action === Share.sharedAction) {
// completed successCallback(completed, method)
if (successCallback) {
successCallback(true, result.activityType);
}
} else if (result.action === Share.dismissedAction) {
if (successCallback) {
successCallback(false);
}
}
})['catch'](function (error) {
if (failureCallback) {
failureCallback(error);
}
});
},
close: function close() {
if (instance) {
instance.close();
}
}
};