提交 229c6907 编写于 作者: fxy060608's avatar fxy060608

feat(v3): add navigator api(view)

上级 784d0e2b
......@@ -3,6 +3,8 @@ export {
}
from 'uni-core/service/api/base/upx2px'
export * from 'uni-platform/view/api'
export {
getSystemInfoSync
}
......
......@@ -8819,6 +8819,7 @@ var serviceContext = (function () {
const WEBVIEW_READY = 'webviewReady';
const VD_SYNC_CALLBACK = 'vdSyncCallback';
const INVOKE_API = 'invokeApi';
function perf (type, startTime) {
/* eslint-disable no-undef */
......@@ -8897,6 +8898,15 @@ var serviceContext = (function () {
}
}
function onInvokeApi ({
data: {
method,
args
}
}) {
uni[method] && uni[method](args);
}
function initSubscribeHandlers () {
const {
subscribe,
......@@ -8924,6 +8934,8 @@ var serviceContext = (function () {
subscribe(VD_SYNC, onVdSync);
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback);
subscribe(INVOKE_API, onInvokeApi);
}
let appCtx;
......
......@@ -14,3 +14,4 @@ export const APP_SERVICE_ID = '__uniapp__service'
export const WEBVIEW_READY = 'webviewReady'
export const WEBVIEW_UI_EVENT = 'webviewUIEvent'
export const VD_SYNC_CALLBACK = 'vdSyncCallback'
export const INVOKE_API = 'invokeApi'
......@@ -3,6 +3,7 @@ import initSubscribe from 'uni-core/service/bridge/subscribe'
import {
VD_SYNC,
VD_SYNC_CALLBACK,
INVOKE_API,
WEBVIEW_READY
} from '../../../constants'
......@@ -15,6 +16,8 @@ import onWebviewReady from './on-webview-ready'
import onVdSync from './on-vd-sync'
import onVdSyncCallback from './on-vd-sync-callback'
import onInvokeApi from './on-invoke-api'
export function initSubscribeHandlers () {
const {
subscribe,
......@@ -42,4 +45,6 @@ export function initSubscribeHandlers () {
subscribe(VD_SYNC, onVdSync)
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback)
subscribe(INVOKE_API, onInvokeApi)
}
export default function onInvokeApi ({
data: {
method,
args
}
}) {
uni[method] && uni[method](args)
}
import {
INVOKE_API
} from '../../constants'
function invokeApi (method, args = {}) {
UniViewJSBridge.publishHandler(INVOKE_API, {
data: {
method,
args
},
options: {
timestamp: Date.now()
}
})
}
export function navigateTo (args) {
invokeApi('navigateTo', args)
}
export function navigateBack (args) {
invokeApi('navigateBack', args)
}
export function reLaunch (args) {
invokeApi('reLaunch', args)
}
export function redirectTo (args) {
invokeApi('redirectTo', args)
}
export function switchTab (args) {
invokeApi('switchTab', args)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册