提交 1087dbb5 编写于 作者: Q qiang

wip: uni-app x iOS

上级 26dda7d4
......@@ -3,9 +3,7 @@
"input": {
"src/service/api/plugin/uts.ts": "src/service/api/plugin/uts.js"
},
"external": [
"@vue/shared"
],
"external": ["@vue/shared"],
"replaceAfterBundled": {
"@vue/shared": "uni-shared"
}
......@@ -17,10 +15,7 @@
"output": {
"format": "cjs"
},
"external": [
"@dcloudio/uni-app-uts",
"@dcloudio/uni-app-vite"
]
"external": ["@dcloudio/uni-app-uts", "@dcloudio/uni-app-vite"]
},
{
"input": {
......@@ -42,11 +37,7 @@
"__UNI_FEATURE_I18N_ZH_HANS__": "true",
"__UNI_FEATURE_I18N_ZH_HANT__": "true"
},
"external": [
"vue",
"@vue/shared",
"@dcloudio/uni-shared"
]
"external": ["vue", "@vue/shared", "@dcloudio/uni-shared"]
},
{
"input": {
......@@ -76,10 +67,29 @@
"__UNI_FEATURE_I18N_ZH_HANS__": "true",
"__UNI_FEATURE_I18N_ZH_HANT__": "true"
},
"external": [
"@dcloudio/uni-shared",
"@vue/shared",
"vue"
]
"external": ["@dcloudio/uni-shared", "@vue/shared", "vue"]
},
{
"input": {
"src/x/index.ts": "dist/uni.x.runtime.esm.js"
},
"output": {
"freeze": false
},
"replacements": {
"__PLATFORM__": "'app'",
"__APP_VIEW__": "false",
"__X__": "true",
"__VUE_OPTIONS_API__": "true",
"__VUE_PROD_DEVTOOLS__": "false",
"__UNI_FEATURE_WX__": "true",
"__UNI_FEATURE_PROMISE__": "false",
"__UNI_FEATURE_I18N_EN__": "true",
"__UNI_FEATURE_I18N_ES__": "true",
"__UNI_FEATURE_I18N_FR__": "true",
"__UNI_FEATURE_I18N_ZH_HANS__": "true",
"__UNI_FEATURE_I18N_ZH_HANT__": "true"
},
"external": ["vue", "@vue/shared", "@dcloudio/uni-shared"]
}
]
\ No newline at end of file
]
const downgrade = plus.os.name === 'Android' && parseInt(plus.os.version!) < 6
const downgrade =
!__X__ && plus.os.name === 'Android' && parseInt(plus.os.version!) < 6
export const ANI_SHOW = downgrade ? 'slide-in-right' : 'pop-in'
export const ANI_DURATION = 300
......
......@@ -43,8 +43,9 @@ export function initLaunchOptions({
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {},
channel: plus.runtime.channel,
launcher: plus.runtime.launcher,
// TODO uni-app x
channel: __X__ ? undefined : plus.runtime.channel,
launcher: __X__ ? undefined : plus.runtime.launcher,
})
extend(enterOptions, launchOptions)
return extend({}, launchOptions)
......
......@@ -15,7 +15,7 @@ function isVuePageAsyncComponent(
return isFunction(component)
}
const pagesMap = new Map<string, ReturnType<typeof createFactory>>()
export const pagesMap = new Map<string, ReturnType<typeof createFactory>>()
export function definePage(
pagePath: string,
......
......@@ -57,12 +57,14 @@ export function initScope(
vm: ComponentPublicInstance,
pageInstance: Page.PageInstance['$page']
) {
const $getAppWebview = () => {
return plus.webview.getWebviewById(pageId + '')
}
vm.$getAppWebview = $getAppWebview
;(vm.$ as any).ctx!.$scope = {
$getAppWebview,
if (!__X__) {
const $getAppWebview = () => {
return plus.webview.getWebviewById(pageId + '')
}
vm.$getAppWebview = $getAppWebview
;(vm.$ as any).ctx!.$scope = {
$getAppWebview,
}
}
vm.getOpenerEventChannel = () => {
if (!pageInstance.eventChannel) {
......
import { stringifyQuery } from '@dcloudio/uni-shared'
let id = 2
let id = __X__ ? 1 : 2
export function getWebviewId() {
return id
......
import { EventChannel, ON_HIDE, parseUrl } from '@dcloudio/uni-shared'
import { getRouteMeta, invokeHook } from '@dcloudio/uni-core'
import {
API_NAVIGATE_TO,
API_TYPE_NAVIGATE_TO,
defineAsyncApi,
DefineAsyncApiFn,
NavigateToOptions,
NavigateToProtocol,
} from '@dcloudio/uni-api'
import { ANI_DURATION, ANI_SHOW } from '../../../service/constants'
import {
// navigate,
RouteOptions,
} from '../../../service/api/route/utils'
import { showWebview } from './webview'
import { registerPage } from '../../framework/page'
import { getWebviewId } from '../../../service/framework/webview/utils'
// import { setStatusBarStyle } from '../../statusBar'
export const $navigateTo: DefineAsyncApiFn<API_TYPE_NAVIGATE_TO> = (
args,
{ resolve, reject }
) => {
const { url, events, animationType, animationDuration } = args
const { path, query } = parseUrl(url)
const [aniType, aniDuration] = initAnimation(
path,
animationType,
animationDuration
)
_navigateTo({
url,
path,
query,
events,
aniType,
aniDuration,
})
.then(resolve)
.catch(reject)
}
export const navigateTo = defineAsyncApi<API_TYPE_NAVIGATE_TO>(
API_NAVIGATE_TO,
$navigateTo,
NavigateToProtocol,
NavigateToOptions
)
interface NavigateToOptions extends RouteOptions {
events: Record<string, any>
aniType: string
aniDuration: number
}
function _navigateTo({
url,
path,
query,
events,
aniType,
aniDuration,
}: NavigateToOptions): Promise<void | { eventChannel: EventChannel }> {
// 当前页面触发 onHide
invokeHook(ON_HIDE)
const eventChannel = new EventChannel(getWebviewId() + 1, events)
return new Promise((resolve) => {
showWebview(
registerPage({ url, path, query, openType: 'navigateTo', eventChannel }),
aniType,
aniDuration,
() => {
resolve({ eventChannel })
}
)
// TODO uni-app x
// setStatusBarStyle()
})
}
function initAnimation(
path: string,
animationType?: string,
animationDuration?: number
) {
const { globalStyle } = __uniConfig
const meta = getRouteMeta(path)!
return [
animationType ||
meta.animationType ||
globalStyle.animationType ||
ANI_SHOW,
animationDuration ||
meta.animationDuration ||
globalStyle.animationDuration ||
ANI_DURATION,
] as const
}
import { IPage } from '@dcloudio/uni-app-x/types/native'
export function showWebview(
webview: IPage,
animationType: string,
animationDuration: number,
showCallback: Function,
delay?: number
) {
// TODO options
webview.startRender()
webview.show()
}
import { ComponentPublicInstance } from 'vue'
import { extend } from '@vue/shared'
import { formatLog } from '@dcloudio/uni-shared'
import {
// initAppVm,
// initService,
defineGlobalData,
} from '@dcloudio/uni-core'
// import { initEntry } from './initEntry'
// import { initTabBar } from './initTabBar'
// import { initGlobalEvent } from './initGlobalEvent'
import { initAppLaunch } from './initAppLaunch'
// import { clearTempFile } from './clearTempFile'
import { initSubscribeHandlers } from './subscriber'
import { initVueApp } from '../../../service/framework/app/vueApp'
// import { initKeyboardEvent } from '../dom/keyboard'
let appCtx: ComponentPublicInstance
const defaultApp = {
globalData: {},
}
export function getApp({ allowDefault = false } = {}) {
if (appCtx) {
// 真实的 App 已初始化
return appCtx
}
if (allowDefault) {
// 返回默认实现
return defaultApp
}
console.error(
'[warn]: getApp() failed. Learn more: https://uniapp.dcloud.io/collocation/frame/window?id=getapp.'
)
}
export function registerApp(appVm: ComponentPublicInstance) {
if (__DEV__) {
console.log(formatLog('registerApp'))
}
// // 定制 useStore (主要是为了 nvue 共享)
// if ((uni as any).Vuex && (appVm as any).$store) {
// const { useStore } = (uni as any).Vuex
// ; (uni as any).Vuex.useStore = (key: string) => {
// if (!key) {
// return (appVm as any).$store
// }
// return useStore(key)
// }
// }
initVueApp(appVm)
appCtx = appVm
// initAppVm(appCtx)
extend(appCtx, defaultApp) // 拷贝默认实现
defineGlobalData(appCtx, defaultApp.globalData)
// initService()
// initEntry()
// initTabBar()
// initGlobalEvent()
// initKeyboardEvent()
initSubscribeHandlers()
initAppLaunch(appVm)
// // 10s后清理临时文件
// setTimeout(clearTempFile, 10000)
__uniConfig.ready = true
// nav
}
import { invokeHook } from '@dcloudio/uni-core'
import { injectAppHooks } from '@dcloudio/uni-api'
import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared'
import { ComponentPublicInstance } from 'vue'
import { initLaunchOptions } from '../../../service/framework/app/utils'
export function initAppLaunch(appVm: ComponentPublicInstance) {
injectAppHooks(appVm.$)
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig
const args = initLaunchOptions({
path: entryPagePath,
query: entryPageQuery,
referrerInfo: referrerInfo,
})
invokeHook(appVm, ON_LAUNCH, args)
invokeHook(appVm, ON_SHOW, args)
// TODO uni-app x
// // https://tower.im/teams/226535/todos/16905/
// const getAppState = weex.requireModule('plus').getAppState
// const appState = getAppState && Number(getAppState())
// if (appState === 2) {
// invokeHook(appVm, ON_HIDE, args)
// }
}
import { getRouteOptions, subscribeServiceMethod } from '@dcloudio/uni-core'
import {
addLeadingSlash,
ON_WXS_INVOKE_CALL_METHOD,
WEB_INVOKE_APPSERVICE,
} from '@dcloudio/uni-shared'
import {
ON_WEBVIEW_READY,
VD_SYNC,
WEBVIEW_INSERTED,
WEBVIEW_REMOVED,
} from '../../../../constants'
import { subscribeWebviewReady } from './webviewReady'
export function initSubscribeHandlers() {
// const { subscribe, subscribeHandler, publishHandler } = UniServiceJSBridge
// onPlusMessage<{ type: string; data: Record<string, any>; pageId: number }>(
// 'subscribeHandler',
// ({ type, data, pageId }) => {
// subscribeHandler(type, data, pageId)
// }
// )
// onPlusMessage<{
// data: Parameters<WebInvokeAppService>[0]
// webviewIds: string[]
// }>(WEB_INVOKE_APPSERVICE, ({ data, webviewIds }) => {
// onWebInvokeAppService(data, webviewIds)
// })
// subscribe(ON_WEBVIEW_READY, subscribeWebviewReady)
// subscribe(VD_SYNC, onVdSync)
// subscribeServiceMethod()
// subscribeAd()
// subscribeNavigator()
// subscribe(WEBVIEW_INSERTED, onWebviewInserted)
// subscribe(WEBVIEW_REMOVED, onWebviewRemoved)
// subscribe(ON_WXS_INVOKE_CALL_METHOD, onWxsInvokeCallMethod)
// publishHandler(ON_WEBVIEW_READY, {}, 1)
subscribeWebviewReady({}, '1')
}
import { getRouteOptions } from '@dcloudio/uni-core'
import { addLeadingSlash } from '@dcloudio/uni-shared'
import { ON_WEBVIEW_READY } from '../../../../constants'
import { $navigateTo } from '../../../api/route/navigateTo'
// import { $switchTab } from '../../../api/route/switchTab'
let isLaunchWebviewReady = false // 目前首页双向确定 ready,可能会导致触发两次 onWebviewReady(主要是 Android)
export function subscribeWebviewReady(_data: unknown, pageId: string) {
const isLaunchWebview = pageId === '1'
if (isLaunchWebview && isLaunchWebviewReady) {
if (__DEV__) {
console.log('[uni-app] onLaunchWebviewReady.prevent')
}
return
}
if (isLaunchWebview) {
// 首页
isLaunchWebviewReady = true
}
// UniServiceJSBridge.emit(ON_WEBVIEW_READY + '.' + pageId)
isLaunchWebview && onLaunchWebviewReady()
}
function onLaunchWebviewReady() {
// TODO uni-app x
// const { autoclose, alwaysShowBeforeRender } = __uniConfig.splashscreen
// if (autoclose && !alwaysShowBeforeRender) {
// plus.navigator.closeSplashscreen()
// }
const entryPagePath = addLeadingSlash(__uniConfig.entryPagePath!)
const routeOptions = getRouteOptions(entryPagePath)!
const args = {
url: entryPagePath + (__uniConfig.entryPageQuery || ''),
openType: 'appLaunch',
}
const handler = { resolve() {}, reject() {} }
// TODO uni-app x
// if (routeOptions.meta.isTabBar) {
// return $switchTab(args, handler)
// }
return $navigateTo(args, handler)
}
export { registerPage } from './register'
import { isPromise } from '@vue/shared'
import { ComponentPublicInstance } from 'vue'
import { IPage } from '@dcloudio/uni-app-x/types/native'
import { EventChannel, formatLog } from '@dcloudio/uni-shared'
import {
initPageInternalInstance,
initPageVm,
invokeHook,
} from '@dcloudio/uni-core'
import { genWebviewId } from '../../../service/framework/webview/utils'
import { initRouteOptions } from '../../../service/framework/page/routeOptions'
import { pagesMap } from '../../../service/framework/page/define'
import { getVueApp } from '../../../service/framework/app/vueApp'
import { VuePageComponent } from '../../../service/framework/page/define'
type PageNodeOptions = {}
export interface RegisterPageOptions {
url: string
path: string
query: Record<string, string>
openType: UniApp.OpenType
webview?: IPage
nvuePageVm?: ComponentPublicInstance
eventChannel?: EventChannel
}
export function registerPage({
url,
path,
query,
openType,
webview,
nvuePageVm,
eventChannel,
}: RegisterPageOptions) {
const id = genWebviewId()
const routeOptions = initRouteOptions(path, openType)
const nativePage = __pageManager.createPage(url, id.toString(), new Map())
if (__DEV__) {
console.log(formatLog('registerPage', path, nativePage.pageId))
}
// TODO initWebview
// initWebview(webview, path, query, routeOptions.meta)
const route = path.slice(1)
// ;(webview as any).__uniapp_route = route
const pageInstance = initPageInternalInstance(
openType,
url,
query,
routeOptions.meta,
eventChannel,
// TODO ThemeMode
'light'
)
createVuePage(id, route, query, pageInstance, {}, nativePage)
return nativePage
}
function createVuePage(
__pageId: number,
__pagePath: string,
__pageQuery: Record<string, any>,
__pageInstance: Page.PageInstance['$page'],
pageOptions: PageNodeOptions,
nativePage: IPage
) {
const pageNode = nativePage.document.body
const app = getVueApp()
const component = pagesMap.get(__pagePath)!()
const mountPage = (component: VuePageComponent) =>
app.mountPage(
component,
{
__pageId,
__pagePath,
__pageQuery,
__pageInstance,
},
// @ts-ignore
pageNode
)
if (isPromise(component)) {
return component.then((component) => mountPage(component))
}
return mountPage(component)
}
import { getApp, registerApp as __registerApp } from './framework/app'
import {
getCurrentPages,
definePage as __definePage,
} from '../service/framework/page'
export default {
getApp,
getCurrentPages,
__definePage,
__registerApp,
}
import { IPageManager } from '@dcloudio/uni-app-x/types/native'
declare global {
var __pageManager: IPageManager
}
......@@ -26,6 +26,9 @@ importers:
'@dcloudio/uni-app':
specifier: 3.0.0-alpha-3090920231127001
version: link:packages/uni-app
'@dcloudio/uni-app-x':
specifier: ^0.6.1
version: 0.6.1
'@jest/types':
specifier: ^29.0.3
version: 29.0.3
......@@ -2780,6 +2783,10 @@ packages:
/@dcloudio/types@3.3.2:
resolution: {integrity: sha512-O+7M55RXqYJMCTh3MC86IGJvDPTR+v214yUeaoz1YUIHa2gJdgObs4RRwfAwZoLMtdoZ9J5BElZZqRy5oi+UTg==}
/@dcloudio/uni-app-x@0.6.1:
resolution: {integrity: sha512-ToZtMxX5E9uXYXj9uVPq7GzYfqRdBLV4GckvGfkrh0iwTq4XwRQRze58+UfuczopTNOqKH8gSatB83vazEC87Q==}
dev: true
/@dcloudio/uni-ui@1.4.28:
resolution: {integrity: sha512-e/lSbvR79KH9+d3D4ueNbvD6szigjO/5IyjBNmiTqaj0PTS324fBV3L6f3s1qpkYonM4rdOl000hVOcAg6Gh/A==}
dev: false
......
......@@ -30,6 +30,7 @@
"packages/shims-uni-app.d.ts",
"packages/shims-vue-runtime.d.ts",
"packages/shims-vue.d.ts",
"packages/uni-app-x.d.ts",
"packages/*/src",
"packages/*/__tests__",
"test-dts",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册