接入发布分享原生系统分享路径
发布分享弹窗在 native_app 中调用 share.open 保留复制链接与下载卡片回退路径 补充 HostBridge 分享测试和宿主壳能力文档
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
getNativeAppHostRuntime,
|
||||
isWechatMiniProgramWebViewRuntime,
|
||||
navigateHostNativePage,
|
||||
openHostShare,
|
||||
openHostShareGrid,
|
||||
openWechatMiniProgramShareGridPage,
|
||||
postWechatMiniProgramMessage,
|
||||
@@ -319,6 +320,13 @@ describe('hostBridge', () => {
|
||||
await expect(setHostAppTitle({ title: ' 拼图 - 陶泥儿 ' })).resolves.toBe(
|
||||
true,
|
||||
);
|
||||
await expect(
|
||||
openHostShare({
|
||||
title: '暖灯猫街',
|
||||
message: '邀请你来玩',
|
||||
url: 'https://app.genarrative.world/works/detail?work=PZ-1',
|
||||
}),
|
||||
).resolves.toBe(true);
|
||||
|
||||
expect(invoke).toHaveBeenCalledWith('host_bridge_request', {
|
||||
request: expect.objectContaining({
|
||||
@@ -364,6 +372,16 @@ describe('hostBridge', () => {
|
||||
},
|
||||
}),
|
||||
});
|
||||
expect(invoke).toHaveBeenCalledWith('host_bridge_request', {
|
||||
request: expect.objectContaining({
|
||||
method: 'share.open',
|
||||
payload: {
|
||||
title: '暖灯猫街',
|
||||
message: '邀请你来玩',
|
||||
url: 'https://app.genarrative.world/works/detail?work=PZ-1',
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
test('原生 App 宿主不支持能力时回退到 H5 路径', async () => {
|
||||
@@ -404,6 +422,13 @@ describe('hostBridge', () => {
|
||||
false,
|
||||
);
|
||||
await expect(setHostAppTitle({ title: ' ' })).resolves.toBe(false);
|
||||
await expect(
|
||||
openHostShare({
|
||||
title: '暖灯猫街',
|
||||
message: '邀请你来玩',
|
||||
url: 'https://app.genarrative.world/works/detail?work=PZ-1',
|
||||
}),
|
||||
).resolves.toBe(false);
|
||||
});
|
||||
|
||||
test('普通浏览器不处理宿主文本导出', async () => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
HapticsImpactPayload,
|
||||
HostBridgeMethod,
|
||||
HostBridgeRuntimeResult,
|
||||
ShareOpenPayload,
|
||||
} from '../../../packages/shared/src/contracts/hostBridge';
|
||||
import type {
|
||||
WechatMiniProgramPayParams,
|
||||
@@ -72,6 +73,8 @@ export type HostAppTitleRequest = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
export type HostShareOpenRequest = ShareOpenPayload;
|
||||
|
||||
function isUnsupportedHostBridgeError(error: unknown) {
|
||||
return (
|
||||
error instanceof Error &&
|
||||
@@ -446,6 +449,18 @@ export function setHostShareTarget(message: unknown) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function openHostShare(params: HostShareOpenRequest) {
|
||||
if (getHostRuntime().kind !== 'native_app') {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return await requestNativeHostBoolean('share.open', params);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function postWechatMiniProgramMessage(message: unknown) {
|
||||
return setHostShareTarget(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user