@mpxjs/core 2.10.18-beta.1 → 2.10.19-fixrpx.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/index.d.ts +31 -1
- package/package.json +1 -1
- package/src/platform/builtInMixins/index.js +2 -1
- package/src/platform/builtInMixins/pageScrollMixin.ios.js +142 -0
- package/src/platform/builtInMixins/styleHelperMixin.ios.js +1 -1
- package/src/platform/createApp.ios.js +1 -4
- package/src/platform/env/vuePlugin.js +12 -1
- package/src/platform/patch/getDefaultOptions.ios.js +3 -6
package/@types/index.d.ts
CHANGED
|
@@ -387,7 +387,37 @@ export interface RnConfig {
|
|
|
387
387
|
* @platform android
|
|
388
388
|
* @default true
|
|
389
389
|
*/
|
|
390
|
-
enableNativeKeyboardAvoiding?: boolean
|
|
390
|
+
enableNativeKeyboardAvoiding?: boolean,
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 自定义蓝牙权限检查函数,用于在调用 openBluetoothAdapter 时替代默认的权限检查逻辑。
|
|
394
|
+
*
|
|
395
|
+
* Mpx 在 iOS 上默认返回 true(假定权限由系统弹窗处理),在 Android 上会请求 ACCESS_FINE_LOCATION 或 BLUETOOTH_SCAN/CONNECT 权限。
|
|
396
|
+
* 如果需要自定义权限申请逻辑(例如在某些定制 Android 设备上),可配置此函数。
|
|
397
|
+
*
|
|
398
|
+
* @returns Promise<boolean> Resolves 为 true 表示权限获取成功,false 表示失败。
|
|
399
|
+
*/
|
|
400
|
+
bluetoothPermission?: () => Promise<boolean>
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* 自定义 Wi-Fi 权限检查函数,用于在调用 startWifi 时替代默认的权限检查逻辑。
|
|
404
|
+
*
|
|
405
|
+
* Mpx 在 Android 上默认会请求 ACCESS_FINE_LOCATION 权限。
|
|
406
|
+
* 如果需要自定义权限申请逻辑,可配置此函数。
|
|
407
|
+
*
|
|
408
|
+
* @returns Promise<boolean> Resolves 为 true 表示权限获取成功,false 表示失败。
|
|
409
|
+
*/
|
|
410
|
+
wifiPermission?: () => Promise<boolean>
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* 自定义相机权限检查函数,用于在渲染 Camera 组件前进行权限检查。
|
|
414
|
+
*
|
|
415
|
+
* 默认情况下,Mpx 会直接渲染 Camera 组件。
|
|
416
|
+
* 如果配置了此函数,Camera 组件会等待该函数返回 true 后再进行渲染。
|
|
417
|
+
*
|
|
418
|
+
* @returns Promise<boolean> Resolves 为 true 表示权限获取成功,false 表示失败。
|
|
419
|
+
*/
|
|
420
|
+
cameraPermission?: () => Promise<boolean>
|
|
391
421
|
}
|
|
392
422
|
|
|
393
423
|
interface MpxConfig {
|
package/package.json
CHANGED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { warn } from '@mpxjs/utils'
|
|
2
|
+
import { CREATED } from '../../core/innerLifecycle'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* React Native 页面滚动 Mixin
|
|
6
|
+
* 提供页面级别的 pageScrollTo 方法
|
|
7
|
+
* 使用该功能需在页面的 scroll-view 组件上声明 wx:ref="pageScrollView"
|
|
8
|
+
*/
|
|
9
|
+
export default function pageScrollMixin (mixinType) {
|
|
10
|
+
if (mixinType !== 'page') {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
[CREATED] () {
|
|
16
|
+
this.__registerPageScrollTo()
|
|
17
|
+
},
|
|
18
|
+
beforeUnmount () {
|
|
19
|
+
const navigation = this.__props?.navigation
|
|
20
|
+
if (navigation && navigation.pageScrollTo) {
|
|
21
|
+
delete navigation.pageScrollTo
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
methods: {
|
|
25
|
+
/**
|
|
26
|
+
* 注册 pageScrollTo 方法到 navigation 对象
|
|
27
|
+
*/
|
|
28
|
+
__registerPageScrollTo () {
|
|
29
|
+
const navigation = this.__props?.navigation
|
|
30
|
+
|
|
31
|
+
// navigation.pageScrollTo 不存在时才注册,避免重复
|
|
32
|
+
if (navigation && !navigation.pageScrollTo) {
|
|
33
|
+
navigation.pageScrollTo = (options) => {
|
|
34
|
+
this.__pageScrollTo(options)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 获取页面滚动视图节点(通过固定 ref 名称 pageScrollView)
|
|
41
|
+
* @returns {Object|null} 滚动视图的节点实例
|
|
42
|
+
*/
|
|
43
|
+
__findScrollableNode () {
|
|
44
|
+
const ref = this.__refs?.pageScrollView?.[0]
|
|
45
|
+
if (!ref || ref.type !== 'node' || !ref.instance?.getNodeInstance) return null
|
|
46
|
+
return ref.instance.getNodeInstance()
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 页面滚动到指定位置
|
|
51
|
+
* @param {Object} options - 配置选项
|
|
52
|
+
* @param {number} options.scrollTop - 滚动到页面的目标位置(单位 px)
|
|
53
|
+
* @param {number} options.duration - 滚动动画的时长(单位 ms)
|
|
54
|
+
* @param {string} options.selector - 选择器
|
|
55
|
+
* @param {number} options.offsetTop - 偏移距离
|
|
56
|
+
* @param {Function} options.onSuccess - 成功回调
|
|
57
|
+
* @param {Function} options.onFail - 失败回调
|
|
58
|
+
*/
|
|
59
|
+
__pageScrollTo (options = {}) {
|
|
60
|
+
const {
|
|
61
|
+
scrollTop,
|
|
62
|
+
duration = 300,
|
|
63
|
+
selector,
|
|
64
|
+
offsetTop = 0,
|
|
65
|
+
onSuccess,
|
|
66
|
+
onFail
|
|
67
|
+
} = options
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const nodeInstance = this.__findScrollableNode()
|
|
71
|
+
|
|
72
|
+
if (nodeInstance) {
|
|
73
|
+
this.__executeScroll(nodeInstance, scrollTop, duration, selector, offsetTop, onSuccess, onFail)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 没找到可滚动视图
|
|
78
|
+
const errMsg = 'pageScrollTo:fail scrollable view not found. Please add wx:ref="pageScrollView" to the scroll-view component in your page'
|
|
79
|
+
warn(errMsg)
|
|
80
|
+
onFail && onFail(errMsg)
|
|
81
|
+
} catch (e) {
|
|
82
|
+
const errMsg = `pageScrollTo:fail ${e.message}`
|
|
83
|
+
warn(errMsg)
|
|
84
|
+
onFail && onFail(errMsg)
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 执行滚动操作
|
|
90
|
+
*/
|
|
91
|
+
__executeScroll (scrollViewNodeInstance, scrollTop, duration, selector, offsetTop, onSuccess, onFail) {
|
|
92
|
+
try {
|
|
93
|
+
const scrollViewNode = scrollViewNodeInstance.instance.node
|
|
94
|
+
|
|
95
|
+
// 如果提供了 selector,使用 scrollIntoView
|
|
96
|
+
if (selector) {
|
|
97
|
+
if (scrollViewNode.scrollIntoView) {
|
|
98
|
+
scrollViewNode.scrollIntoView(selector, {
|
|
99
|
+
offset: offsetTop,
|
|
100
|
+
animated: duration > 0,
|
|
101
|
+
duration
|
|
102
|
+
})
|
|
103
|
+
onSuccess && onSuccess()
|
|
104
|
+
} else {
|
|
105
|
+
const errMsg = 'pageScrollTo:fail scrollIntoView method not available'
|
|
106
|
+
warn(errMsg)
|
|
107
|
+
onFail && onFail(errMsg)
|
|
108
|
+
}
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 使用 scrollTop 进行滚动
|
|
113
|
+
if (scrollTop !== undefined) {
|
|
114
|
+
if (scrollViewNode.scrollTo) {
|
|
115
|
+
scrollViewNode.scrollTo({
|
|
116
|
+
top: scrollTop,
|
|
117
|
+
left: 0,
|
|
118
|
+
animated: duration > 0,
|
|
119
|
+
duration
|
|
120
|
+
})
|
|
121
|
+
onSuccess && onSuccess()
|
|
122
|
+
} else {
|
|
123
|
+
const errMsg = 'pageScrollTo:fail scrollTo method not available'
|
|
124
|
+
warn(errMsg)
|
|
125
|
+
onFail && onFail(errMsg)
|
|
126
|
+
}
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 既没有 scrollTop 也没有 selector
|
|
131
|
+
const errMsg = 'pageScrollTo:fail scrollTop or selector is required'
|
|
132
|
+
warn(errMsg)
|
|
133
|
+
onFail && onFail(errMsg)
|
|
134
|
+
} catch (e) {
|
|
135
|
+
const errMsg = `pageScrollTo:fail ${e.message}`
|
|
136
|
+
warn(errMsg)
|
|
137
|
+
onFail && onFail(errMsg)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -257,7 +257,7 @@ export default function styleHelperMixin () {
|
|
|
257
257
|
const isNativeStaticStyle = staticStyle && isNativeStyle(staticStyle)
|
|
258
258
|
let result = isNativeStaticStyle ? [] : {}
|
|
259
259
|
const mergeResult = isNativeStaticStyle ? (...args) => result.push(...args) : (...args) => Object.assign(result, ...args)
|
|
260
|
-
|
|
260
|
+
// 使用一下 __getSizeCount 触发其 get
|
|
261
261
|
this.__getSizeCount()
|
|
262
262
|
|
|
263
263
|
if (staticClass || dynamicClass) {
|
|
@@ -76,6 +76,7 @@ export default function createApp (options) {
|
|
|
76
76
|
return createElement(Stack.Screen, {
|
|
77
77
|
name: key,
|
|
78
78
|
getComponent,
|
|
79
|
+
initialParams,
|
|
79
80
|
layout: headerLayout
|
|
80
81
|
})
|
|
81
82
|
}
|
|
@@ -210,10 +211,6 @@ export default function createApp (options) {
|
|
|
210
211
|
}, [])
|
|
211
212
|
|
|
212
213
|
const { initialRouteName, initialParams } = initialRouteRef.current
|
|
213
|
-
if (!global.__mpxAppHotLaunched) {
|
|
214
|
-
global.__mpxInitialRouteName = initialRouteName
|
|
215
|
-
global.__mpxInitialRunParams = initialParams
|
|
216
|
-
}
|
|
217
214
|
const navScreenOpts = {
|
|
218
215
|
headerShown: false,
|
|
219
216
|
statusBarTranslucent: Mpx.config.rnConfig.statusBarTranslucent ?? true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { walkChildren, parseSelector, error, hasOwn, collectDataset } from '@mpxjs/utils'
|
|
1
|
+
import { walkChildren, parseSelector, error, hasOwn, collectDataset, getByPath } from '@mpxjs/utils'
|
|
2
2
|
import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
|
|
3
3
|
import { EffectScope } from 'vue'
|
|
4
4
|
import { PausedState } from '../../helper/const'
|
|
@@ -56,6 +56,17 @@ const hackEffectScope = () => {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export default function install (Vue) {
|
|
59
|
+
const originalWatch = Vue.prototype.$watch
|
|
60
|
+
Vue.prototype.$watch = function (expOrFn, cb, options) {
|
|
61
|
+
if (typeof expOrFn === 'string' && expOrFn.indexOf(',') > -1) {
|
|
62
|
+
const keys = expOrFn.split(',').map(key => key.trim())
|
|
63
|
+
expOrFn = function () {
|
|
64
|
+
return keys.map(key => getByPath(this, key))
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return originalWatch.call(this, expOrFn, cb, options)
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
Object.defineProperties(Vue.prototype, {
|
|
60
71
|
data: {
|
|
61
72
|
get () {
|
|
@@ -295,17 +295,13 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
295
295
|
instance[key] = method.bind(instance)
|
|
296
296
|
})
|
|
297
297
|
}
|
|
298
|
-
|
|
298
|
+
|
|
299
299
|
if (type === 'page') {
|
|
300
300
|
const props = propsRef.current
|
|
301
301
|
instance.route = props.route.name
|
|
302
302
|
global.__mpxPagesMap = global.__mpxPagesMap || {}
|
|
303
303
|
global.__mpxPagesMap[props.route.key] = [instance, props.navigation]
|
|
304
304
|
setFocusedNavigation(props.navigation)
|
|
305
|
-
|
|
306
|
-
if (!global.__mpxAppHotLaunched && global.__mpxInitialRunParams) {
|
|
307
|
-
Object.assign(loadParams, global.__mpxInitialRunParams)
|
|
308
|
-
}
|
|
309
305
|
set(global.__mpxPageSizeCountMap, pageId, global.__mpxSizeCount)
|
|
310
306
|
// App onLaunch 在 Page created 之前执行
|
|
311
307
|
if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
|
|
@@ -315,10 +311,11 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
|
|
|
315
311
|
|
|
316
312
|
const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
|
|
317
313
|
proxy.created()
|
|
314
|
+
|
|
318
315
|
if (type === 'page') {
|
|
319
316
|
const props = propsRef.current
|
|
320
317
|
const decodedQuery = {}
|
|
321
|
-
const rawQuery =
|
|
318
|
+
const rawQuery = props.route.params || {}
|
|
322
319
|
if (isObject(rawQuery)) {
|
|
323
320
|
for (const key in rawQuery) {
|
|
324
321
|
decodedQuery[key] = decodeURIComponent(rawQuery[key])
|