@mpxjs/webpack-plugin 2.9.67 → 2.9.70-alpha.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.
Files changed (161) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/ResolveDependency.js +5 -0
  5. package/lib/index.js +51 -15
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +53 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/image.js +4 -0
  11. package/lib/platform/template/wx/component-config/input.js +5 -1
  12. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  13. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  14. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  15. package/lib/platform/template/wx/component-config/switch.js +4 -0
  16. package/lib/platform/template/wx/component-config/text.js +4 -0
  17. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  18. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  19. package/lib/platform/template/wx/component-config/view.js +4 -0
  20. package/lib/platform/template/wx/index.js +127 -1
  21. package/lib/react/processStyles.js +14 -4
  22. package/lib/react/processTemplate.js +3 -0
  23. package/lib/resolve-loader.js +4 -1
  24. package/lib/resolver/AddModePlugin.js +8 -8
  25. package/lib/runtime/components/react/context.ts +6 -0
  26. package/lib/runtime/components/react/dist/context.js +2 -0
  27. package/lib/runtime/components/react/dist/event.config.js +24 -24
  28. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  29. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  30. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  38. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  39. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  40. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  41. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  42. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  43. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  44. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  45. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  46. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  47. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  48. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  49. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  50. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  51. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  52. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  53. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  54. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  56. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  57. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  58. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  59. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  60. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  61. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  62. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  63. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  64. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  65. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  66. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  67. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  68. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  69. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  70. package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
  71. package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
  72. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  73. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  74. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  75. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  76. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  77. package/lib/runtime/components/react/dist/utils.jsx +70 -23
  78. package/lib/runtime/components/react/getInnerListeners.ts +36 -43
  79. package/lib/runtime/components/react/mpx-button.tsx +95 -43
  80. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  81. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  82. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  83. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  84. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  85. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  86. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  87. package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
  88. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  89. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  90. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  91. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  92. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  93. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  94. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  95. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  96. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  97. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  98. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  99. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  100. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  101. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  102. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  103. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  104. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  105. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  106. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  107. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  108. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  109. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  110. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  111. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  112. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  113. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  114. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  115. package/lib/runtime/components/react/mpx-view.tsx +81 -59
  116. package/lib/runtime/components/react/mpx-web-view.tsx +46 -19
  117. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  118. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  119. package/lib/runtime/components/react/types/common.ts +2 -0
  120. package/lib/runtime/components/react/types/global.d.ts +3 -16
  121. package/lib/runtime/components/react/utils.tsx +98 -27
  122. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  123. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  124. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  125. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  126. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  127. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  128. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  129. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  130. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  131. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  132. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  133. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  134. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  135. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  136. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  137. package/lib/runtime/optionProcessor.js +7 -16
  138. package/lib/runtime/optionProcessor.tenon.js +84 -0
  139. package/lib/runtime/utils.js +2 -0
  140. package/lib/style-compiler/index.js +1 -1
  141. package/lib/style-compiler/plugins/hm.js +20 -0
  142. package/lib/template-compiler/bind-this.js +7 -2
  143. package/lib/template-compiler/compiler.js +70 -42
  144. package/lib/template-compiler/gen-node-react.js +3 -3
  145. package/lib/tenon/index.js +117 -0
  146. package/lib/tenon/processJSON.js +352 -0
  147. package/lib/tenon/processScript.js +203 -0
  148. package/lib/tenon/processStyles.js +21 -0
  149. package/lib/tenon/processTemplate.js +126 -0
  150. package/lib/tenon/script-helper.js +223 -0
  151. package/lib/utils/env.js +6 -1
  152. package/lib/utils/get-relative-path.js +25 -0
  153. package/package.json +9 -4
  154. package/LICENSE +0 -433
  155. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  156. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  157. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  158. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  159. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  160. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  161. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
@@ -12,7 +12,7 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners'
12
12
 
13
13
  import CheckBox from './mpx-checkbox'
14
14
  import { FormContext, FormFieldValue } from './context'
15
- import { useTransformStyle, useLayout } from './utils'
15
+ import { useTransformStyle, useLayout, extendObject } from './utils'
16
16
 
17
17
  interface _SwitchProps extends SwitchProps {
18
18
  style?: ViewStyle
@@ -42,7 +42,6 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
42
42
  'parent-font-size': parentFontSize,
43
43
  'parent-width': parentWidth,
44
44
  'parent-height': parentHeight,
45
-
46
45
  bindchange,
47
46
  catchchange
48
47
  } = props
@@ -77,7 +76,9 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
77
76
  }, [checked])
78
77
 
79
78
  const nodeRef = useRef(null)
80
- useNodesRef<Switch, _SwitchProps>(props, ref, nodeRef)
79
+ useNodesRef<Switch, _SwitchProps>(props, ref, nodeRef, {
80
+ style: normalStyle
81
+ })
81
82
 
82
83
  const {
83
84
  layoutRef,
@@ -119,12 +120,13 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
119
120
  }
120
121
  }, [])
121
122
 
122
- const innerProps = useInnerProps(props, {
123
+ const innerProps = useInnerProps(props, extendObject({
123
124
  ref: nodeRef,
124
- style: { ...normalStyle, ...layoutStyle },
125
- ...layoutProps,
126
- ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
127
- }, [
125
+ style: extendObject({}, normalStyle, layoutStyle)
126
+ },
127
+ layoutProps,
128
+ !disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {})
129
+ , [
128
130
  'checked',
129
131
  'disabled',
130
132
  'type',
@@ -25,6 +25,7 @@ interface _TextProps extends TextProps {
25
25
  const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
26
26
  const {
27
27
  style = {},
28
+ allowFontScaling = false,
28
29
  selectable,
29
30
  'enable-var': enableVar,
30
31
  'external-var-context': externalVarContext,
@@ -49,12 +50,15 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
49
50
  })
50
51
 
51
52
  const nodeRef = useRef(null)
52
- useNodesRef<Text, _TextProps>(props, ref, nodeRef)
53
+ useNodesRef<Text, _TextProps>(props, ref, nodeRef, {
54
+ style: normalStyle
55
+ })
53
56
 
54
57
  const innerProps = useInnerProps(props, {
55
58
  ref: nodeRef,
56
59
  style: normalStyle,
57
- selectable: !!selectable || !!userSelect
60
+ selectable: !!selectable || !!userSelect,
61
+ allowFontScaling
58
62
  }, [
59
63
  'user-select'
60
64
  ], {
@@ -4,15 +4,15 @@
4
4
  * ✔ hover-start-time
5
5
  * ✔ hover-stay-time
6
6
  */
7
- import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, ImageResizeMode, StyleSheet, Image, LayoutChangeEvent, Text } from 'react-native'
8
- import { useRef, useState, useEffect, forwardRef, ReactNode, JSX, Children, cloneElement } from 'react'
7
+ import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, StyleSheet, Image, LayoutChangeEvent } from 'react-native'
8
+ import { useRef, useState, useEffect, forwardRef, ReactNode, JSX } from 'react'
9
9
  import useInnerProps from './getInnerListeners'
10
10
  import Animated from 'react-native-reanimated'
11
11
  import useAnimationHooks from './useAnimationHooks'
12
12
  import type { AnimationProp } from './useAnimationHooks'
13
13
  import { ExtendedViewStyle } from './types/common'
14
14
  import useNodesRef, { HandlerRef } from './useNodesRef'
15
- import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout } from './utils'
15
+ import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject } from './utils'
16
16
  import LinearGradient from 'react-native-linear-gradient'
17
17
 
18
18
  export interface _ViewProps extends ViewProps {
@@ -24,6 +24,7 @@ export interface _ViewProps extends ViewProps {
24
24
  'hover-stay-time'?: number
25
25
  'enable-background'?: boolean
26
26
  'enable-var'?: boolean
27
+ 'enable-fast-image'?: boolean
27
28
  'external-var-context'?: Record<string, any>
28
29
  'parent-font-size'?: number
29
30
  'parent-width'?: number
@@ -76,9 +77,11 @@ type PreImageInfo = {
76
77
  type ImageProps = {
77
78
  style: ImageStyle,
78
79
  src?: string,
80
+ source?: {uri: string },
79
81
  colors: Array<string>,
80
82
  locations?: Array<number>
81
83
  angle?: number
84
+ resizeMode?: 'cover' | 'stretch'
82
85
  }
83
86
 
84
87
  const linearMap = new Map([
@@ -233,10 +236,7 @@ function backgroundPosition (imageProps: ImageProps, preImageInfo: PreImageInfo,
233
236
  }
234
237
  }
235
238
 
236
- imageProps.style = {
237
- ...imageProps.style as ImageStyle,
238
- ...style
239
- }
239
+ extendObject(imageProps.style, style)
240
240
  }
241
241
 
242
242
  // background-size 转换
@@ -280,24 +280,23 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
280
280
  if (!dimensions) return
281
281
  } else { // 数值类型 ImageStyle
282
282
  // 数值类型设置为 stretch
283
- (imageProps.style as ImageStyle).resizeMode = 'stretch'
283
+ imageProps.resizeMode = 'stretch'
284
284
  dimensions = {
285
285
  width: isPercent(width) ? width : +width,
286
286
  height: isPercent(height) ? height : +height
287
287
  } as { width: NumberVal, height: NumberVal }
288
288
  }
289
289
  }
290
+
290
291
  // 样式合并
291
- imageProps.style = {
292
- ...imageProps.style as ImageStyle,
293
- ...dimensions
294
- }
292
+ extendObject(imageProps.style, dimensions)
295
293
  }
296
294
 
297
295
  // background-image转换为source
298
296
  function backgroundImage (imageProps: ImageProps, preImageInfo: PreImageInfo) {
299
- if (preImageInfo.src) {
300
- imageProps.src = preImageInfo.src
297
+ const src = preImageInfo.src
298
+ if (src) {
299
+ imageProps.source = { uri: src }
301
300
  }
302
301
  }
303
302
 
@@ -326,8 +325,8 @@ function linearGradient (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
326
325
  const imageStyleToProps = (preImageInfo: PreImageInfo, imageSize: Size, layoutInfo: Size) => {
327
326
  // 初始化
328
327
  const imageProps: ImageProps = {
328
+ resizeMode: 'cover',
329
329
  style: {
330
- resizeMode: 'cover' as ImageResizeMode,
331
330
  position: 'absolute'
332
331
  // ...StyleSheet.absoluteFillObject
333
332
  },
@@ -476,10 +475,9 @@ function parseLinearGradient (text: string): LinearInfo | undefined {
476
475
  return prev
477
476
  }, { colors: [], locations: [] })
478
477
 
479
- return {
480
- ...linearInfo,
478
+ return extendObject({}, linearInfo, {
481
479
  direction: direction.trim()
482
- }
480
+ })
483
481
  }
484
482
 
485
483
  function parseBgImage (text: string): {
@@ -533,7 +531,26 @@ function isDiagonalAngle (linearInfo?: LinearInfo): boolean {
533
531
  return !!(linearInfo?.direction && diagonalAngleMap[linearInfo.direction])
534
532
  }
535
533
 
536
- function wrapImage (imageStyle?: ExtendedViewStyle) {
534
+ function inheritStyle (innerStyle: ExtendedViewStyle = {}) {
535
+ const { borderWidth, borderRadius } = innerStyle
536
+ const borderStyles = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius']
537
+ return pickStyle(innerStyle,
538
+ borderStyles,
539
+ borderWidth && borderRadius
540
+ ? (key, val) => {
541
+ // 盒子内圆角borderWith与borderRadius的关系
542
+ // 当borderRadius 小于 当borderWith 内边框为直角
543
+ // 当borderRadius 大于等于 当borderWith 内边框为圆角
544
+ if (borderStyles.includes(key)) {
545
+ const borderVal = +val - borderWidth
546
+ return borderVal > 0 ? borderVal : 0
547
+ }
548
+ return val
549
+ }
550
+ : undefined)
551
+ }
552
+
553
+ function wrapImage (imageStyle?: ExtendedViewStyle, innerStyle?: Record<string, any>, enableFastImage?: boolean) {
537
554
  // 预处理数据
538
555
  const preImageInfo: PreImageInfo = preParseImage(imageStyle)
539
556
  // 预解析
@@ -616,9 +633,9 @@ function wrapImage (imageStyle?: ExtendedViewStyle) {
616
633
  }
617
634
  }
618
635
 
619
- return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
636
+ return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...inheritStyle(innerStyle), ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
620
637
  {show && type === 'linear' && <LinearGradient useAngle={true} {...imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size)} /> }
621
- {show && type === 'image' && <Image {...imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size)} />}
638
+ {show && type === 'image' && (renderImage(imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size), enableFastImage))}
622
639
  </View>
623
640
  }
624
641
 
@@ -629,9 +646,11 @@ interface WrapChildrenConfig {
629
646
  backgroundStyle?: ExtendedViewStyle
630
647
  varContext?: Record<string, any>
631
648
  textProps?: Record<string, any>
649
+ innerStyle?: Record<string, any>
650
+ enableFastImage?: boolean
632
651
  }
633
652
 
634
- function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps }: WrapChildrenConfig) {
653
+ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps, innerStyle, enableFastImage }: WrapChildrenConfig) {
635
654
  const children = wrapChildren(props, {
636
655
  hasVarDec,
637
656
  varContext,
@@ -640,7 +659,7 @@ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, tex
640
659
  })
641
660
 
642
661
  return [
643
- enableBackground ? wrapImage(backgroundStyle) : null,
662
+ enableBackground ? wrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
644
663
  children
645
664
  ]
646
665
  }
@@ -655,6 +674,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
655
674
  'enable-var': enableVar,
656
675
  'external-var-context': externalVarContext,
657
676
  'enable-background': enableBackground,
677
+ 'enable-fast-image': enableFastImage,
658
678
  'enable-animation': enableAnimation,
659
679
  'parent-font-size': parentFontSize,
660
680
  'parent-width': parentWidth,
@@ -665,21 +685,16 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
665
685
  const [isHover, setIsHover] = useState(false)
666
686
 
667
687
  // 默认样式
668
- const defaultStyle: ExtendedViewStyle = {
669
- // flex 布局相关的默认样式
670
- ...style.display === 'flex' && {
671
- flexDirection: 'row',
672
- flexBasis: 'auto',
673
- flexShrink: 1,
674
- flexWrap: 'nowrap'
675
- }
676
- }
688
+ const defaultStyle: ExtendedViewStyle = style.display === 'flex'
689
+ ? {
690
+ flexDirection: 'row',
691
+ flexBasis: 'auto',
692
+ flexShrink: 1,
693
+ flexWrap: 'nowrap'
694
+ }
695
+ : {}
677
696
 
678
- const styleObj: ExtendedViewStyle = {
679
- ...defaultStyle,
680
- ...style,
681
- ...(isHover ? hoverStyle : null)
682
- }
697
+ const styleObj: ExtendedViewStyle = extendObject({}, defaultStyle, style, isHover ? hoverStyle as ExtendedViewStyle : {})
683
698
 
684
699
  const {
685
700
  normalStyle,
@@ -696,7 +711,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
696
711
  parentHeight
697
712
  })
698
713
 
699
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
714
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
700
715
 
701
716
  enableBackground = enableBackground || !!backgroundStyle
702
717
  const enableBackgroundRef = useRef(enableBackground)
@@ -706,7 +721,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
706
721
 
707
722
  const nodeRef = useRef(null)
708
723
  useNodesRef<View, _ViewProps>(props, ref, nodeRef, {
709
- defaultStyle
724
+ style: normalStyle
710
725
  })
711
726
 
712
727
  const dataRef = useRef<{
@@ -754,23 +769,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
754
769
  layoutProps
755
770
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
756
771
 
757
- const viewStyle = Object.assign({}, innerStyle, layoutStyle)
758
- const innerProps = useInnerProps(props, {
759
- ref: nodeRef,
760
- style: viewStyle,
761
- ...layoutProps,
762
- ...(hoverStyle && {
763
- bindtouchstart: onTouchStart,
764
- bindtouchend: onTouchEnd
765
- })
766
- }, [
767
- 'hover-start-time',
768
- 'hover-stay-time',
769
- 'hover-style',
770
- 'hover-class'
771
- ], {
772
- layoutRef
773
- })
772
+ const viewStyle = extendObject({}, innerStyle, layoutStyle)
774
773
 
775
774
  enableAnimation = enableAnimation || !!animation
776
775
  const enableAnimationRef = useRef(enableAnimation)
@@ -783,18 +782,41 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
783
782
  style: viewStyle
784
783
  })
785
784
  : viewStyle
785
+ const innerProps = useInnerProps(
786
+ props,
787
+ extendObject({
788
+ ref: nodeRef,
789
+ style: finalStyle
790
+ },
791
+ layoutProps,
792
+ hoverStyle
793
+ ? {
794
+ bindtouchstart: onTouchStart,
795
+ bindtouchend: onTouchEnd
796
+ }
797
+ : {}
798
+ ), [
799
+ 'hover-start-time',
800
+ 'hover-stay-time',
801
+ 'hover-style',
802
+ 'hover-class'
803
+ ], {
804
+ layoutRef
805
+ })
806
+
786
807
  const childNode = wrapWithChildren(props, {
787
808
  hasVarDec,
788
809
  enableBackground: enableBackgroundRef.current,
789
810
  textStyle,
790
811
  backgroundStyle,
791
812
  varContext: varContextRef.current,
792
- textProps
813
+ textProps,
814
+ innerStyle,
815
+ enableFastImage
793
816
  })
794
- return animation?.actions?.length
817
+ return enableAnimation
795
818
  ? (<Animated.View
796
819
  {...innerProps}
797
- style={finalStyle}
798
820
  >
799
821
  {childNode}
800
822
  </Animated.View>)
@@ -1,11 +1,14 @@
1
- import { forwardRef, JSX, useEffect, useRef } from 'react'
1
+ import { forwardRef, JSX, useEffect, useRef, useContext, useMemo } from 'react'
2
2
  import { noop, warn } from '@mpxjs/utils'
3
+ import { View } from 'react-native'
3
4
  import { Portal } from '@ant-design/react-native'
4
5
  import { getCustomEvent } from './getInnerListeners'
5
6
  import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
6
7
  import { WebView } from 'react-native-webview'
7
8
  import useNodesRef, { HandlerRef } from './useNodesRef'
8
- import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent } from 'react-native-webview/lib/WebViewTypes'
9
+ import { getCurrentPage, extendObject } from './utils'
10
+ import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation } from 'react-native-webview/lib/WebViewTypes'
11
+ import { RouteContext } from './context'
9
12
 
10
13
  type OnMessageCallbackEvent = {
11
14
  detail: {
@@ -37,20 +40,17 @@ type MessageData = {
37
40
  callbackId?: number
38
41
  }
39
42
 
40
- interface NativeEvent {
41
- url: string,
42
- data: string
43
- }
44
-
45
- interface FormRef {
46
- postMessage: (value: any) => void;
47
- }
48
-
49
43
  const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element => {
50
- const { src = '', bindmessage = noop, bindload = noop, binderror = noop } = props
44
+ const { src, bindmessage = noop, bindload = noop, binderror = noop } = props
45
+ if (!src) {
46
+ return (<View></View>)
47
+ }
51
48
  if (props.style) {
52
49
  warn('The web-view component does not support the style prop.')
53
50
  }
51
+ const pageId = useContext(RouteContext)
52
+ const currentPage = useMemo(() => getCurrentPage(pageId), [pageId])
53
+
54
54
  const defaultWebViewStyle = {
55
55
  position: 'absolute' as 'absolute' | 'relative' | 'static',
56
56
  left: 0 as number,
@@ -61,20 +61,26 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
61
61
 
62
62
  const webViewRef = useRef<WebView>(null)
63
63
  useNodesRef<WebView, WebViewProps>(props, ref, webViewRef, {
64
- defaultStyle: defaultWebViewStyle
64
+ style: defaultWebViewStyle
65
65
  })
66
66
 
67
- const _messageList: any[] = []
67
+ const _messageList = useRef<any[]>([])
68
68
  const handleUnload = () => {
69
69
  // 这里是 WebView 销毁前执行的逻辑
70
70
  bindmessage(getCustomEvent('messsage', {}, {
71
71
  detail: {
72
- data: _messageList
72
+ data: _messageList.current
73
73
  },
74
74
  layoutRef: webViewRef
75
75
  }))
76
76
  }
77
77
 
78
+ useEffect(() => {
79
+ if (currentPage) {
80
+ currentPage.__webViewUrl = src
81
+ }
82
+ }, [src, currentPage])
83
+
78
84
  useEffect(() => {
79
85
  // 组件卸载时执行
80
86
  return () => {
@@ -101,6 +107,11 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
101
107
  }
102
108
  binderror(result)
103
109
  }
110
+ const _changeUrl = function (navState: WebViewNavigation) {
111
+ if (currentPage) {
112
+ currentPage.__webViewUrl = navState.url
113
+ }
114
+ }
104
115
  const _message = function (res: WebViewMessageEvent) {
105
116
  let data: MessageData = {}
106
117
  let asyncCallback
@@ -116,7 +127,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
116
127
  const postData: PayloadData = data.payload || {}
117
128
  switch (data.type) {
118
129
  case 'postMessage':
119
- _messageList.push(postData.data)
130
+ _messageList.current.push(postData.data)
120
131
  asyncCallback = Promise.resolve({
121
132
  errMsg: 'invokeWebappApi:ok'
122
133
  })
@@ -149,14 +160,30 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
149
160
  }
150
161
  })
151
162
  }
163
+ const events = {}
164
+
165
+ if (bindload) {
166
+ extendObject(events, {
167
+ onLoad: _load
168
+ })
169
+ }
170
+ if (binderror) {
171
+ extendObject(events, {
172
+ onError: _error
173
+ })
174
+ }
175
+ if (bindmessage) {
176
+ extendObject(events, {
177
+ onMessage: _message
178
+ })
179
+ }
152
180
  return (<Portal>
153
181
  <WebView
154
182
  style={defaultWebViewStyle}
155
183
  source={{ uri: src }}
156
184
  ref={webViewRef}
157
- onLoad={_load}
158
- onError={_error}
159
- onMessage={_message}
185
+ {...events}
186
+ onNavigationStateChange={_changeUrl}
160
187
  javaScriptEnabled={true}
161
188
  ></WebView>
162
189
  </Portal>)
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Borrowed from open-source code: https://github.com/quidone/react-native-wheel-picker
3
+ * Special thanks to the authors for their contribution to the open-source community.
4
+ */
5
+
6
+ export type Faces = {
7
+ index: number
8
+ deg: number
9
+ offsetY: number
10
+ opacity: number
11
+ screenHeight: number
12
+ }
13
+
14
+ export const degToRad = (deg: number) => (Math.PI * deg) / 180
15
+
16
+ // Calculates the height of the element after rotating it relative to the user's screen.
17
+ const calcHeight = (degree: number, itemHeight: number) =>
18
+ itemHeight * Math.cos(degToRad(degree))
19
+
20
+ export const calcPickerHeight = (faces: Faces[], itemHeight: number) => {
21
+ if (faces.length === 7) {
22
+ return itemHeight * 5
23
+ }
24
+ return faces.reduce((r, v) => r + calcHeight(Math.abs(v.deg), itemHeight), 0)
25
+ }
26
+
27
+ export const createFaces = (
28
+ itemHeight: number,
29
+ visibleCount: number
30
+ ): Faces[] => {
31
+ // e.g [30, 60, 90]
32
+ const getDegreesRelativeCenter = () => {
33
+ const maxStep = Math.trunc((visibleCount + 2) / 2) // + 2 because there are 2 more faces at 90 degrees
34
+ const stepDegree = 90 / maxStep
35
+
36
+ const result = []
37
+ for (let i = 1; i <= maxStep; i++) {
38
+ result.push(i * stepDegree)
39
+ }
40
+ return result
41
+ }
42
+
43
+ const getScreenHeightsAndOffsets = <T extends readonly number[]>(
44
+ degrees: T
45
+ ): [T, T] => {
46
+ const screenHeights = degrees.map((deg) =>
47
+ calcHeight(deg, itemHeight)
48
+ ) as unknown as T
49
+ const freeSpaces = screenHeights.map(
50
+ (screenHeight) => itemHeight - screenHeight
51
+ )
52
+ const offsets = freeSpaces.map((freeSpace, index) => {
53
+ let offset = freeSpace / 2
54
+ for (let i = 0; i < index; i++) {
55
+ offset += freeSpaces[i]
56
+ }
57
+ return offset
58
+ }) as unknown as T
59
+ return [screenHeights, offsets]
60
+ }
61
+
62
+ const getOpacity = (index: number) => {
63
+ const map: Record<number, number> = {
64
+ 0: 0,
65
+ 1: 0.2,
66
+ 2: 0.35,
67
+ 3: 0.45,
68
+ 4: 0.5
69
+ }
70
+ return map[index] ?? Math.min(1, map[4] + index * 0.5)
71
+ }
72
+
73
+ const degrees = getDegreesRelativeCenter()
74
+ const [screenHeight, offsets] = getScreenHeightsAndOffsets(degrees)
75
+
76
+ return [
77
+ // top items
78
+ ...degrees
79
+ .map<Faces>((degree, index) => {
80
+ return {
81
+ index: -1 * (index + 1),
82
+ deg: degree,
83
+ opacity: getOpacity(degrees.length - 1 - index),
84
+ offsetY: -1 * offsets[index],
85
+ screenHeight: screenHeight[index]
86
+ }
87
+ })
88
+ .reverse(),
89
+
90
+ // center item
91
+ { index: 0, deg: 0, opacity: 1, offsetY: 0, screenHeight: itemHeight },
92
+
93
+ // bottom items
94
+ ...degrees.map<Faces>((degree, index) => {
95
+ return {
96
+ index: index + 1,
97
+ deg: -1 * degree,
98
+ opacity: getOpacity(degrees.length - 1 - index),
99
+ offsetY: offsets[index],
100
+ screenHeight: screenHeight[index]
101
+ }
102
+ })
103
+ ]
104
+ }
@@ -0,0 +1,32 @@
1
+ import React from 'react'
2
+ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
3
+
4
+ type OverlayProps = {
5
+ itemHeight: number
6
+ overlayItemStyle?: StyleProp<ViewStyle>
7
+ overlayContainerStyle?: StyleProp<ViewStyle>
8
+ }
9
+
10
+ const Overlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }: OverlayProps) => {
11
+ return (
12
+ <View style={[styles.overlayContainer, overlayContainerStyle]} pointerEvents={'none'}>
13
+ <View style={[styles.selection, { height: itemHeight }, overlayItemStyle]} />
14
+ </View>
15
+ )
16
+ }
17
+
18
+ const styles = StyleSheet.create({
19
+ overlayContainer: {
20
+ ...StyleSheet.absoluteFillObject,
21
+ justifyContent: 'center',
22
+ alignItems: 'center'
23
+ },
24
+ selection: {
25
+ borderTopWidth: 1,
26
+ borderBottomWidth: 1,
27
+ borderColor: 'rgba(0, 0, 0, 0.05)',
28
+ alignSelf: 'stretch'
29
+ }
30
+ })
31
+
32
+ export default React.memo(Overlay)
@@ -16,3 +16,5 @@ export type ExtendedViewStyle = ViewStyle & {
16
16
  export type ExtendedFunctionComponent = FunctionComponent & {
17
17
  isCustomText?: boolean
18
18
  }
19
+
20
+ export type AnyFunc = (...args: ReadonlyArray<any>) => any
@@ -1,21 +1,7 @@
1
- declare module 'react-native-svg/css' {
2
- import type { ImageSourcePropType, StyleProp, ImageStyle } from 'react-native'
3
- import type { SvgProps as SvgCssUriProps } from 'react-native-svg'
4
-
5
- export const SvgCssUri: React.ComponentType<SvgCssUriProps & { uri?: string }>
6
-
7
- export interface WithLocalSvgProps {
8
- asset: ImageSourcePropType
9
- style?: StyleProp<ImageStyle>
10
- width?: string | number
11
- height?: string | number
12
- }
13
-
14
- export const WithLocalSvg: React.ComponentType<WithLocalSvgProps>
15
- }
16
-
17
1
  declare module '@mpxjs/utils' {
18
2
  export function isEmptyObject (obj: Object): boolean
3
+ export function isFunction (fn: unknown): boolean
4
+ export function isNumber (num: unknown): boolean
19
5
  export function hasOwn (obj: Object, key: string): boolean
20
6
  export function noop (...arg: any): void
21
7
  export function diffAndCloneA<A, B> (a: A, b?: B): {
@@ -26,6 +12,7 @@ declare module '@mpxjs/utils' {
26
12
  export function isObject (value): value is Object
27
13
  export function error (msg: string, location?: string, e?: any): void
28
14
  export function warn (msg: string, location?: string, e?: any): void
15
+ export function collectDataset (props: Record<string, any>, needParse?: boolean): Record<string, any>
29
16
  export function getFocusedNavigation (): {
30
17
  insets: {
31
18
  top: number