@mpxjs/core 2.10.17-beta.8 → 2.10.17-unocss.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.17-beta.8",
3
+ "version": "2.10.17-unocss.1",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -19,14 +19,14 @@
19
19
  ],
20
20
  "main": "src/index.js",
21
21
  "dependencies": {
22
- "@mpxjs/utils": "^2.10.17-beta.0",
22
+ "@mpxjs/utils": "^2.10.17",
23
23
  "lodash": "^4.1.1",
24
24
  "miniprogram-api-typings": "^3.10.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@d11/react-native-fast-image": "*",
28
- "@mpxjs/api-proxy": "^2.10.17-beta.0",
29
- "@mpxjs/store": "^2.10.0",
28
+ "@mpxjs/api-proxy": "^2.9.0",
29
+ "@mpxjs/store": "^2.9.0",
30
30
  "@react-navigation/native": "*",
31
31
  "@react-navigation/native-stack": "*",
32
32
  "react": "*",
@@ -101,35 +101,6 @@ function formatValue (value, unitType) {
101
101
 
102
102
  global.__formatValue = formatValue
103
103
 
104
- const escapeReg = /[()[\]{}#!.:,%'"+$]/g
105
- const escapeMap = {
106
- '(': '_pl_',
107
- ')': '_pr_',
108
- '[': '_bl_',
109
- ']': '_br_',
110
- '{': '_cl_',
111
- '}': '_cr_',
112
- '#': '_h_',
113
- '!': '_i_',
114
- '/': '_s_',
115
- '.': '_d_',
116
- ':': '_c_',
117
- ',': '_2c_',
118
- '%': '_p_',
119
- '\'': '_q_',
120
- '"': '_dq_',
121
- '+': '_a_',
122
- $: '_si_'
123
- }
124
-
125
- const mpEscape = cached((str) => {
126
- return str.replace(escapeReg, function (match) {
127
- if (escapeMap[match]) return escapeMap[match]
128
- // unknown escaped
129
- return '_u_'
130
- })
131
- })
132
-
133
104
  function concat (a = '', b = '') {
134
105
  return a ? b ? (a + ' ' + b) : a : b
135
106
  }
@@ -244,6 +215,58 @@ function getMediaStyle (media) {
244
215
  }, {})
245
216
  }
246
217
 
218
+ const createLayer = (isNativeStyle) => {
219
+ const layerMap = {
220
+ preflight: isNativeStyle ? [] : {},
221
+ app: isNativeStyle ? [] : {},
222
+ uno: isNativeStyle ? [] : {},
223
+ normal: isNativeStyle ? [] : {},
224
+ important: isNativeStyle ? [] : {}
225
+ }
226
+
227
+ const genResult = () => {
228
+ if (isNativeStyle) {
229
+ return [
230
+ ...layerMap.preflight,
231
+ ...layerMap.app,
232
+ ...layerMap.uno,
233
+ ...layerMap.normal,
234
+ ...layerMap.important
235
+ ]
236
+ } else {
237
+ return Object.assign({}, layerMap.preflight, layerMap.app, layerMap.uno, layerMap.normal, layerMap.important)
238
+ }
239
+ }
240
+
241
+ const mergeToLayer = (name, ...classObjs) => {
242
+ const layer = layerMap[name] || layerMap.normal
243
+ return isNativeStyle ? layer.push(...classObjs) : Object.assign(layer, ...classObjs)
244
+ }
245
+
246
+ return {
247
+ mergeToLayer,
248
+ layerMap,
249
+ genResult
250
+ }
251
+ }
252
+
253
+ const HIDE_STYLE = {
254
+ // display: 'none'
255
+ // RN下display:'none'容易引发未知异常问题,使用布局样式模拟
256
+ flex: 0,
257
+ height: 0,
258
+ width: 0,
259
+ paddingTop: 0,
260
+ paddingRight: 0,
261
+ paddingBottom: 0,
262
+ paddingLeft: 0,
263
+ marginTop: 0,
264
+ marginRight: 0,
265
+ marginBottom: 0,
266
+ marginLeft: 0,
267
+ overflow: 'hidden'
268
+ }
269
+
247
270
  export default function styleHelperMixin () {
248
271
  return {
249
272
  methods: {
@@ -255,70 +278,73 @@ export default function styleHelperMixin () {
255
278
  },
256
279
  __getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, hide) {
257
280
  const isNativeStaticStyle = staticStyle && isNativeStyle(staticStyle)
258
- let result = isNativeStaticStyle ? [] : {}
259
- const mergeResult = isNativeStaticStyle ? (...args) => result.push(...args) : (...args) => Object.assign(result, ...args)
260
- // 使用一下 __getSizeCount 触发其 get
261
- this.__getSizeCount()
281
+
282
+ const { mergeToLayer, genResult } = createLayer(isNativeStaticStyle)
283
+
284
+ this.__getSizeCount()
262
285
 
263
286
  if (staticClass || dynamicClass) {
264
- // todo 当前为了复用小程序unocss产物,暂时进行mpEscape,等后续正式支持unocss后可不进行mpEscape
265
- const classString = mpEscape(concat(staticClass, stringifyDynamicClass(dynamicClass)))
287
+ const classString = concat(staticClass, stringifyDynamicClass(dynamicClass))
288
+
289
+ let needAddUnoPreflight = false
266
290
 
267
291
  classString.split(/\s+/).forEach((className) => {
268
- let localStyle, appStyle
292
+ let localStyle, appStyle, unoStyle, unoVarStyle
269
293
  if (localStyle = this.__getClassStyle?.(className)) {
270
294
  if (localStyle._media?.length) {
271
- mergeResult(localStyle._default, getMediaStyle(localStyle._media))
295
+ mergeToLayer(localStyle._layer || 'normal', localStyle._default, getMediaStyle(localStyle._media))
272
296
  } else {
273
- mergeResult(localStyle)
297
+ mergeToLayer(localStyle._layer || 'normal', localStyle)
274
298
  }
299
+ } else if (unoStyle = global.__getUnoStyle(className)) {
300
+ if (unoStyle._media?.length) {
301
+ mergeToLayer(unoStyle.__layer || 'uno', unoStyle._default, getMediaStyle(unoStyle._media))
302
+ } else {
303
+ mergeToLayer(unoStyle.__layer || 'uno', unoStyle)
304
+ }
305
+ if (unoStyle.transform || unoStyle.filter) needAddUnoPreflight = true
306
+ } else if (unoVarStyle = global.__getUnoVarStyle(className)) {
307
+ mergeToLayer('important', unoVarStyle)
275
308
  } else if (appStyle = global.__getAppClassStyle?.(className)) {
276
309
  if (appStyle._media?.length) {
277
- mergeResult(appStyle._default, getMediaStyle(appStyle._media))
310
+ mergeToLayer(appStyle._layer || 'app', appStyle._default, getMediaStyle(appStyle._media))
278
311
  } else {
279
- mergeResult(appStyle)
312
+ mergeToLayer(appStyle._layer || 'app', appStyle)
280
313
  }
281
314
  } else if (isObject(this.__props[className])) {
282
315
  // externalClasses必定以对象形式传递下来
283
- mergeResult(this.__props[className])
316
+ mergeToLayer('normal', this.__props[className])
284
317
  }
285
318
  })
319
+
320
+ if (needAddUnoPreflight) {
321
+ mergeToLayer('preflight', global.__getAppClassStyle?.('__uno_preflight'))
322
+ }
286
323
  }
287
324
 
288
325
  if (staticStyle || dynamicStyle) {
289
326
  const styleObj = {}
290
327
  if (isNativeStaticStyle) {
291
328
  if (Array.isArray(staticStyle)) {
292
- result = result.concat(staticStyle)
329
+ mergeToLayer('normal', ...staticStyle)
293
330
  } else {
294
- mergeResult(staticStyle)
331
+ mergeToLayer('normal', staticStyle)
295
332
  }
296
333
  } else {
297
334
  Object.assign(styleObj, parseStyleText(staticStyle))
298
335
  }
299
336
  Object.assign(styleObj, normalizeDynamicStyle(dynamicStyle))
300
- mergeResult(transformStyleObj(styleObj))
337
+ mergeToLayer('normal', transformStyleObj(styleObj))
301
338
  }
302
339
 
303
340
  if (hide) {
304
- mergeResult({
305
- // display: 'none'
306
- // RN下display:'none'容易引发未知异常问题,使用布局样式模拟
307
- flex: 0,
308
- height: 0,
309
- width: 0,
310
- paddingTop: 0,
311
- paddingRight: 0,
312
- paddingBottom: 0,
313
- paddingLeft: 0,
314
- marginTop: 0,
315
- marginRight: 0,
316
- marginBottom: 0,
317
- marginLeft: 0,
318
- overflow: 'hidden'
319
- })
341
+ mergeToLayer('important', HIDE_STYLE)
320
342
  }
343
+
344
+ const result = genResult()
345
+
321
346
  const isEmpty = isNativeStaticStyle ? !result.length : isEmptyObject(result)
347
+
322
348
  return isEmpty ? empty : result
323
349
  }
324
350
  }
@@ -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,
@@ -9,7 +9,6 @@ import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE, REACTHOOKSEXEC
9
9
  import mergeOptions from '../../core/mergeOptions'
10
10
  import { queueJob, hasPendingJob } from '../../observer/scheduler'
11
11
  import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
12
- import MpxKeyboardAvoidingView from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view'
13
12
  import {
14
13
  IntersectionObserverContext,
15
14
  KeyboardAvoidContext,
@@ -295,17 +294,13 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
295
294
  instance[key] = method.bind(instance)
296
295
  })
297
296
  }
298
- const loadParams = {}
297
+
299
298
  if (type === 'page') {
300
299
  const props = propsRef.current
301
300
  instance.route = props.route.name
302
301
  global.__mpxPagesMap = global.__mpxPagesMap || {}
303
302
  global.__mpxPagesMap[props.route.key] = [instance, props.navigation]
304
303
  setFocusedNavigation(props.navigation)
305
-
306
- if (!global.__mpxAppHotLaunched && global.__mpxInitialRunParams) {
307
- Object.assign(loadParams, global.__mpxInitialRunParams)
308
- }
309
304
  set(global.__mpxPageSizeCountMap, pageId, global.__mpxSizeCount)
310
305
  // App onLaunch 在 Page created 之前执行
311
306
  if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
@@ -315,10 +310,11 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
315
310
 
316
311
  const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
317
312
  proxy.created()
313
+
318
314
  if (type === 'page') {
319
315
  const props = propsRef.current
320
316
  const decodedQuery = {}
321
- const rawQuery = Object.assign({}, loadParams, props.route.params || {})
317
+ const rawQuery = props.route.params || {}
322
318
  if (isObject(rawQuery)) {
323
319
  for (const key in rawQuery) {
324
320
  decodedQuery[key] = decodeURIComponent(rawQuery[key])
@@ -509,15 +505,15 @@ function getLayoutData (headerHeight) {
509
505
  // 在横屏状态下 screen.height = window.height + bottomVirtualHeight
510
506
  // 在正常状态 screen.height = window.height + bottomVirtualHeight + statusBarHeight
511
507
  const isLandscape = screenDimensions.height < screenDimensions.width
512
- // const bottomVirtualHeight = isLandscape ? screenDimensions.height - windowDimensions.height : ((screenDimensions.height - windowDimensions.height - ReactNative.StatusBar.currentHeight) || 0)
513
508
  let bottomVirtualHeight = 0
514
- // 红米手机&魅族16T手机的screen.height = windowHeight + bottomVirtualHeight 导致计算出来的底部虚拟偏少。此部分端引擎同学进行修改中
515
- // mpx临时兼容 bottomVirtualHeight取 initialWindowMetrics.inset.bottom 和 反算出来的bottomVirtualHeight的更大的值
516
509
  if (ReactNative.Platform.OS === 'android') {
517
510
  if (isLandscape) {
518
511
  bottomVirtualHeight = screenDimensions.height - windowDimensions.height
519
512
  } else {
520
- bottomVirtualHeight = Math.max(screenDimensions.height - windowDimensions.height - ReactNative.StatusBar.currentHeight, initialWindowMetrics?.insets?.bottom || 0, 0)
513
+ bottomVirtualHeight = initialWindowMetrics?.insets?.bottom || 0
514
+ if (typeof mpxGlobal.__mpx.config?.rnConfig?.getBottomVirtualHeight === 'function') {
515
+ bottomVirtualHeight = mpxGlobal.__mpx.config?.rnConfig?.getBottomVirtualHeight() || 0
516
+ }
521
517
  }
522
518
  }
523
519
  return {
@@ -562,6 +558,8 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
562
558
  usePageStatus(navigation, currentPageId)
563
559
 
564
560
  const withKeyboardAvoidingView = (element) => {
561
+ if (currentPageConfig.disableKeyboardAvoiding) return element
562
+ const MpxKeyboardAvoidingView = require('@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view').default
565
563
  return createElement(KeyboardAvoidContext.Provider,
566
564
  {
567
565
  value: keyboardAvoidRef
@@ -582,36 +580,36 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
582
580
  // android存在第一次打开insets都返回为0情况,后续会触发第二次渲染后正确
583
581
  navigation.insets = useSafeAreaInsets()
584
582
  return withKeyboardAvoidingView(
585
- createElement(ReactNative.View,
583
+ createElement(ReactNative.View,
584
+ {
585
+ style: {
586
+ flex: 1,
587
+ // 页面容器背景色
588
+ backgroundColor: currentPageConfig?.backgroundColorContent || '#fff',
589
+ // 解决页面内有元素定位relative left为负值的时候,回退的时候还能看到对应元素问题
590
+ overflow: 'hidden'
591
+ }
592
+ },
593
+ createElement(RouteContext.Provider,
594
+ {
595
+ value: routeContextValRef.current
596
+ },
597
+ createElement(IntersectionObserverContext.Provider,
586
598
  {
587
- style: {
588
- flex: 1,
589
- // 页面容器背景色
590
- backgroundColor: currentPageConfig?.backgroundColorContent || '#fff',
591
- // 解决页面内有元素定位relative left为负值的时候,回退的时候还能看到对应元素问题
592
- overflow: 'hidden'
593
- }
599
+ value: intersectionObservers.current
594
600
  },
595
- createElement(RouteContext.Provider,
596
- {
597
- value: routeContextValRef.current
598
- },
599
- createElement(IntersectionObserverContext.Provider,
600
- {
601
- value: intersectionObservers.current
602
- },
603
- createElement(PortalHost,
604
- null,
605
- createElement(WrappedComponent, {
606
- ...props,
607
- navigation,
608
- route,
609
- id: currentPageId
610
- })
611
- )
612
- )
601
+ createElement(PortalHost,
602
+ null,
603
+ createElement(WrappedComponent, {
604
+ ...props,
605
+ navigation,
606
+ route,
607
+ id: currentPageId
608
+ })
613
609
  )
610
+ )
614
611
  )
612
+ )
615
613
  )
616
614
  }
617
615
  }
File without changes