收口移动导航响应边界
将 Expo 外链打开、WebView 刷新和受控导航成功响应包装收口到 navigation 模块 让移动 dispatch 只委托导航请求 同步移动壳配置门禁和共享记忆
This commit is contained in:
@@ -54,9 +54,9 @@ export async function dispatchMobileHostBridgeRequest(
|
||||
case 'appearance.getColorScheme':
|
||||
return getMobileHostBridgeAppearanceColorScheme(request);
|
||||
case 'app.openExternalUrl':
|
||||
return ok(request, await openMobileHostBridgeExternalUrl(request.payload));
|
||||
return openMobileHostBridgeExternalUrl(request);
|
||||
case 'app.reloadWebView':
|
||||
return ok(request, reloadMobileHostBridgeWebView(navigation));
|
||||
return reloadMobileHostBridgeWebView(request, navigation);
|
||||
case 'network.status':
|
||||
return getMobileHostBridgeNetworkStatus(request);
|
||||
case 'clipboard.writeText':
|
||||
@@ -92,10 +92,7 @@ export async function dispatchMobileHostBridgeRequest(
|
||||
case 'share.setTarget':
|
||||
return setMobileHostBridgeShareTarget(request);
|
||||
case 'navigation.openNativePage':
|
||||
return ok(
|
||||
request,
|
||||
openMobileHostBridgeNativePage(navigation, request.payload),
|
||||
);
|
||||
return openMobileHostBridgeNativePage(request, navigation);
|
||||
case 'auth.requestLogin':
|
||||
case 'payment.request':
|
||||
return failure(request, unsupported(request.method));
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as Linking from 'expo-linking';
|
||||
|
||||
import {
|
||||
type HostBridgeError,
|
||||
type HostBridgeRequest,
|
||||
type NavigateNativePagePayload,
|
||||
normalizeHostBridgeExternalUrlPayload,
|
||||
type OpenExternalUrlPayload,
|
||||
@@ -15,14 +16,15 @@ import { buildMobileShellUrl } from '../shell/url';
|
||||
import {
|
||||
type MobileHostBridgeNavigation,
|
||||
invalidRequest,
|
||||
ok,
|
||||
unsupported,
|
||||
} from './protocol';
|
||||
|
||||
export async function openMobileHostBridgeExternalUrl(
|
||||
payload: unknown,
|
||||
request: HostBridgeRequest,
|
||||
) {
|
||||
const externalUrlPayload = normalizeHostBridgeExternalUrlPayload(
|
||||
(payload as OpenExternalUrlPayload | undefined)?.url,
|
||||
(request.payload as OpenExternalUrlPayload | undefined)?.url,
|
||||
);
|
||||
if (!externalUrlPayload) {
|
||||
throw invalidRequest('url must use an allowed external protocol');
|
||||
@@ -37,18 +39,18 @@ export async function openMobileHostBridgeExternalUrl(
|
||||
} satisfies HostBridgeError;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ok(request, true);
|
||||
}
|
||||
|
||||
export function openMobileHostBridgeNativePage(
|
||||
request: HostBridgeRequest,
|
||||
navigation: MobileHostBridgeNavigation | null,
|
||||
payload: unknown,
|
||||
) {
|
||||
if (!navigation) {
|
||||
throw unsupported('navigation.openNativePage');
|
||||
}
|
||||
|
||||
const url = (payload as NavigateNativePagePayload | undefined)?.url;
|
||||
const url = (request.payload as NavigateNativePagePayload | undefined)?.url;
|
||||
if (typeof url !== 'string') {
|
||||
throw invalidRequest('url is required');
|
||||
}
|
||||
@@ -64,10 +66,11 @@ export function openMobileHostBridgeNativePage(
|
||||
navigation.openWebViewUrl(
|
||||
buildMobileShellUrl(webViewUrl, navigation.urlOptions),
|
||||
);
|
||||
return true;
|
||||
return ok(request, true);
|
||||
}
|
||||
|
||||
export function reloadMobileHostBridgeWebView(
|
||||
request: HostBridgeRequest,
|
||||
navigation: MobileHostBridgeNavigation | null,
|
||||
) {
|
||||
if (!navigation) {
|
||||
@@ -75,5 +78,5 @@ export function reloadMobileHostBridgeWebView(
|
||||
}
|
||||
|
||||
navigation.reloadWebView();
|
||||
return true;
|
||||
return ok(request, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user