跳到主要内容

Platform & ShareSheetHost

分享目标枚举与命令式面板的宿主组件。

引用

import {
Platform,
ShareSheetHost,
SUPPORTED_PLATFORMS,
PLATFORM_DISPLAY_NAMES,
PLATFORM_DEFAULT_SUBTITLES,
PLATFORM_BRAND_COLORS,
} from '@unif/react-native-umeng';

Platform 枚举

本桥首版支持的分享目标平台

enum Platform {
WECHAT_SESSION = 'wechat_session',
DINGTALK = 'dingtalk',
}
枚举值字符串值说明
Platform.WECHAT_SESSION'wechat_session'微信好友会话 / 群聊
Platform.DINGTALK'dingtalk'钉钉工作群 / 好友
不是 react-native 的 Platform

umeng 的 Platform分享目标枚举没有 .OS。判断操作系统请用 react-nativePlatform;同时用到两者时起别名:

import { Platform } from 'react-native'; // OS 判断
import { Platform as ShareTarget } from '@unif/react-native-umeng'; // 分享目标

相关常量

常量类型说明
SUPPORTED_PLATFORMSReadonlyArray<Platform>支持的平台列表(也是面板默认渲染顺序):[WECHAT_SESSION, DINGTALK]
PLATFORM_DISPLAY_NAMESRecord<Platform, string>显示名:微信 / 钉钉
PLATFORM_DEFAULT_SUBTITLESRecord<Platform, string>面板默认副标题:'发送给好友或群' / '发送至工作群'
PLATFORM_BRAND_COLORSRecord<Platform, string>品牌色:#07C160(微信)/ #2595E8(钉钉),用作面板平台前导小块实色

<ShareSheetHost />

分享面板的宿主组件,无任何 props。订阅模块级 shareSheetController,在 Share.openSheet() 触发时渲染 design 的 BottomSheet + Cell 面板。

const ShareSheetHost: React.FC; // 无 props

挂载

必须在 App 根挂载一次,且位于 GestureHandlerRootView 和 design 的 ThemeProvider 内部(面板用 useTheme / BottomSheet):

import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { ThemeProvider } from '@unif/react-native-design';
import { ShareSheetHost } from '@unif/react-native-umeng';

export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<ThemeProvider>
<YourNavigationStack />
<ShareSheetHost />
</ThemeProvider>
</GestureHandlerRootView>
);
}
openSheet 依赖此宿主

未挂载时 Share.openSheet() 立即 reject(E_UNKNOWN,message No <ShareSheetHost /> mounted);一次只能开一个面板,重入会 reject。挂载细节见快速上手

测试时官方 mock 的 ShareSheetHost 渲染 null(不引 design),见测试


平台支持

iOSAndroid
Platform 枚举 / 常量
<ShareSheetHost />