@mpxjs/core 2.10.18-beta.4 → 2.10.19-beta.1

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.18-beta.4",
3
+ "version": "2.10.19-beta.1",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -24,9 +24,8 @@
24
24
  "miniprogram-api-typings": "^3.10.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "@d11/react-native-fast-image": "*",
28
27
  "@mpxjs/api-proxy": "^2.9.0",
29
- "@mpxjs/store": "^2.9.0",
28
+ "@d11/react-native-fast-image": "*",
30
29
  "@react-navigation/native": "*",
31
30
  "@react-navigation/native-stack": "*",
32
31
  "react": "*",
@@ -38,22 +37,23 @@
38
37
  "react-native-screens": "*",
39
38
  "react-native-video": "*",
40
39
  "react-native-webview": "*",
40
+ "react-native-vision-camera": "*",
41
41
  "vue": "^2.7.10",
42
42
  "vue-demi": "^0.14.6",
43
43
  "vue-i18n": "^8.27.2",
44
44
  "vue-i18n-bridge": "^9.2.2"
45
45
  },
46
46
  "peerDependenciesMeta": {
47
- "vue": {
47
+ "@mpxjs/api-proxy": {
48
48
  "optional": true
49
49
  },
50
- "vue-demi": {
50
+ "@d11/react-native-fast-image": {
51
51
  "optional": true
52
52
  },
53
- "vue-i18n": {
53
+ "@react-navigation/native": {
54
54
  "optional": true
55
55
  },
56
- "vue-i18n-bridge": {
56
+ "@react-navigation/native-stack": {
57
57
  "optional": true
58
58
  },
59
59
  "react": {
@@ -62,13 +62,13 @@
62
62
  "react-native": {
63
63
  "optional": true
64
64
  },
65
- "react-native-reanimated": {
65
+ "react-native-gesture-handler": {
66
66
  "optional": true
67
67
  },
68
- "@react-navigation/native": {
68
+ "react-native-linear-gradient": {
69
69
  "optional": true
70
70
  },
71
- "@react-navigation/native-stack": {
71
+ "react-native-reanimated": {
72
72
  "optional": true
73
73
  },
74
74
  "react-native-safe-area-context": {
@@ -77,19 +77,25 @@
77
77
  "react-native-screens": {
78
78
  "optional": true
79
79
  },
80
+ "react-native-video": {
81
+ "optional": true
82
+ },
80
83
  "react-native-webview": {
81
84
  "optional": true
82
85
  },
83
- "react-native-gesture-handler": {
86
+ "react-native-vision-camera": {
84
87
  "optional": true
85
88
  },
86
- "react-native-linear-gradient": {
89
+ "vue": {
87
90
  "optional": true
88
91
  },
89
- "@d11/react-native-fast-image": {
92
+ "vue-demi": {
90
93
  "optional": true
91
94
  },
92
- "react-native-video": {
95
+ "vue-i18n": {
96
+ "optional": true
97
+ },
98
+ "vue-i18n-bridge": {
93
99
  "optional": true
94
100
  }
95
101
  },
package/src/index.js CHANGED
@@ -110,7 +110,6 @@ function use (plugin, options = {}) {
110
110
  extendProps(Mpx, proxyMpx, rawProps, options)
111
111
  extendProps(Mpx.prototype, proxyMpx.prototype, rawPrototypeProps, options)
112
112
  installedPlugins.push(plugin)
113
- plugin.__installed = true
114
113
  return this
115
114
  }
116
115
 
@@ -26,7 +26,8 @@ export default function getBuiltInMixins ({ type, rawOptions = {} }) {
26
26
  refsMixin(),
27
27
  i18nMixin(),
28
28
  relationsMixin(type),
29
- pageRouteMixin(type)
29
+ pageRouteMixin(type),
30
+ pageScrollMixin(type)
30
31
  ]
31
32
  } else if (isWeb) {
32
33
  bulitInMixins = [
@@ -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
+ }
@@ -27,8 +27,9 @@ export default function proxyEventMixin () {
27
27
  } catch (e) {}
28
28
  }
29
29
  const location = this.__mpxProxy.options.mpxFileResource
30
+ const isObjectEvent = rawEvent && typeof rawEvent === 'object'
30
31
 
31
- if (rawEvent.target && !rawEvent.target._datasetProcessed) {
32
+ if (isObjectEvent && rawEvent.target && !rawEvent.target._datasetProcessed) {
32
33
  const originalDataset = rawEvent.target.dataset
33
34
  Object.defineProperty(rawEvent.target, 'dataset', {
34
35
  get: () => parseDataset(originalDataset),
@@ -37,7 +38,7 @@ export default function proxyEventMixin () {
37
38
  })
38
39
  rawEvent.target._datasetProcessed = true
39
40
  }
40
- if (rawEvent.currentTarget && !rawEvent.currentTarget._datasetProcessed) {
41
+ if (isObjectEvent && rawEvent.currentTarget && !rawEvent.currentTarget._datasetProcessed) {
41
42
  const originalDataset = rawEvent.currentTarget.dataset
42
43
  Object.defineProperty(rawEvent.currentTarget, 'dataset', {
43
44
  get: () => parseDataset(originalDataset),
@@ -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) {
@@ -268,13 +268,13 @@ export default function styleHelperMixin () {
268
268
  let localStyle, appStyle
269
269
  if (localStyle = this.__getClassStyle?.(className)) {
270
270
  if (localStyle._media?.length) {
271
- mergeResult(localStyle._default, getMediaStyle(localStyle._media))
271
+ mergeResult(localStyle, getMediaStyle(localStyle._media))
272
272
  } else {
273
273
  mergeResult(localStyle)
274
274
  }
275
275
  } else if (appStyle = global.__getAppClassStyle?.(className)) {
276
276
  if (appStyle._media?.length) {
277
- mergeResult(appStyle._default, getMediaStyle(appStyle._media))
277
+ mergeResult(appStyle, getMediaStyle(appStyle._media))
278
278
  } else {
279
279
  mergeResult(appStyle)
280
280
  }
@@ -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
  }
@@ -119,7 +120,7 @@ export default function createApp (options) {
119
120
  const current = state.routes[state.index]
120
121
  options = {
121
122
  path: current.name,
122
- query: current.name === global.__mpxInitialRouteName ? global.__mpxInitialRunParams : current.params,
123
+ query: current.params,
123
124
  scene: 0,
124
125
  shareTicket: '',
125
126
  referrerInfo: {}
@@ -179,7 +180,7 @@ export default function createApp (options) {
179
180
  const current = state.routes[state.index]
180
181
  const options = {
181
182
  path: current.name,
182
- query: current.name === global.__mpxInitialRouteName ? global.__mpxInitialRunParams : current.params,
183
+ query: current.params,
183
184
  scene: 0,
184
185
  shareTicket: '',
185
186
  referrerInfo: {},
@@ -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
- const loadParams = {}
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 = Object.assign({}, loadParams, props.route.params || {})
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])