@mpxjs/webpack-plugin 2.10.17 → 2.10.18

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 (238) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/file-loader.js +4 -1
  3. package/lib/global.d.ts +231 -0
  4. package/lib/index.js +58 -73
  5. package/lib/init.js +3 -0
  6. package/lib/json-compiler/index.js +13 -4
  7. package/lib/loader.js +4 -0
  8. package/lib/platform/json/wx/index.js +6 -0
  9. package/lib/platform/style/wx/index.js +102 -72
  10. package/lib/platform/template/wx/component-config/ad.js +5 -0
  11. package/lib/platform/template/wx/component-config/button.js +10 -3
  12. package/lib/platform/template/wx/component-config/camera.js +13 -3
  13. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  14. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  15. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  16. package/lib/platform/template/wx/component-config/form.js +27 -2
  17. package/lib/platform/template/wx/component-config/image.js +5 -0
  18. package/lib/platform/template/wx/component-config/input.js +10 -0
  19. package/lib/platform/template/wx/component-config/label.js +10 -2
  20. package/lib/platform/template/wx/component-config/map.js +11 -0
  21. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  22. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  23. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  24. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  25. package/lib/platform/template/wx/component-config/picker.js +3 -1
  26. package/lib/platform/template/wx/component-config/progress.js +11 -1
  27. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  28. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  29. package/lib/platform/template/wx/component-config/slider.js +8 -0
  30. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  31. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  32. package/lib/platform/template/wx/component-config/text.js +5 -0
  33. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  34. package/lib/platform/template/wx/component-config/unsupported.js +9 -0
  35. package/lib/platform/template/wx/component-config/video.js +10 -0
  36. package/lib/platform/template/wx/index.js +21 -1
  37. package/lib/react/LoadAsyncChunkModule.js +1 -1
  38. package/lib/react/processStyles.js +21 -9
  39. package/lib/react/script-helper.js +2 -2
  40. package/lib/react/style-helper.js +76 -13
  41. package/lib/resolver/AddModePlugin.js +17 -7
  42. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  43. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
  44. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  45. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  46. package/lib/runtime/components/react/context.ts +12 -3
  47. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  48. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  49. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  50. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
  51. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  52. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  53. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  54. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  55. package/lib/runtime/components/react/dist/context.d.ts +10 -3
  56. package/lib/runtime/components/react/dist/context.js +1 -2
  57. package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
  58. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
  59. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
  60. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
  61. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  62. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
  63. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
  64. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
  65. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
  67. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
  68. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  73. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  75. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  76. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  77. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
  79. package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
  80. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
  81. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
  82. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  83. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  84. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  85. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
  86. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
  87. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
  88. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
  89. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
  90. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
  91. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
  92. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
  93. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
  94. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
  95. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
  96. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
  97. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
  98. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  99. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
  100. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
  101. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
  102. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
  103. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
  104. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
  105. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
  106. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
  107. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
  108. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
  109. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  110. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  111. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  112. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  113. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
  114. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  115. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
  116. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  117. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
  118. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
  119. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  120. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  121. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  122. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
  123. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  124. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  125. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -1
  126. package/lib/runtime/components/react/dist/mpx-swiper.jsx +95 -61
  127. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  128. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  129. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
  130. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
  131. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  132. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
  133. package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
  134. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
  135. package/lib/runtime/components/react/dist/parser.d.ts +0 -1
  136. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
  137. package/lib/runtime/components/react/dist/utils.d.ts +10 -9
  138. package/lib/runtime/components/react/dist/utils.jsx +47 -24
  139. package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
  140. package/lib/runtime/components/react/mpx-image.tsx +2 -2
  141. package/lib/runtime/components/react/mpx-input.tsx +77 -54
  142. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
  143. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  144. package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
  145. package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
  146. package/lib/runtime/components/react/mpx-swiper.tsx +115 -60
  147. package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
  148. package/lib/runtime/components/react/mpx-view.tsx +27 -12
  149. package/lib/runtime/components/react/tsconfig.json +26 -0
  150. package/lib/runtime/components/react/types/global.d.ts +1 -0
  151. package/lib/runtime/components/react/utils.tsx +51 -27
  152. package/lib/runtime/optionProcessor.js +5 -0
  153. package/lib/runtime/optionProcessorReact.js +7 -0
  154. package/lib/runtime/stringify.wxs +2 -2
  155. package/lib/script-setup-compiler/index.js +1 -2
  156. package/lib/style-compiler/strip-conditional.js +243 -0
  157. package/lib/template-compiler/compiler.js +2 -5
  158. package/lib/utils/string.js +25 -1
  159. package/lib/wxss/loader.js +4 -1
  160. package/lib/wxss/utils.js +7 -2
  161. package/package.json +7 -14
  162. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  163. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  164. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  165. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  166. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  167. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  168. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  169. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  170. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  171. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  172. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  173. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  174. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  175. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  176. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  177. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  178. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  179. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  180. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  181. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  182. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  183. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  184. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  185. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  186. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  187. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  189. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  190. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  192. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  194. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  196. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  198. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  200. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  202. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  204. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  206. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  208. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  210. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  212. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  214. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  216. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  218. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  220. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  222. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  224. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  226. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  228. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  229. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  230. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  231. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  232. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  233. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  234. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  235. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  236. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  237. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  238. package/lib/style-compiler/strip-conditional-loader.js +0 -289
@@ -11,6 +11,11 @@ import Portal from './mpx-portal'
11
11
  /**
12
12
  * ✔ indicator-dots
13
13
  * ✔ indicator-color
14
+ * ✔ indicator-width
15
+ * ✔ indicator-height
16
+ * ✔ indicator-radius
17
+ * ✔ indicator-spacing
18
+ * ✔ indicator-margin
14
19
  * ✔ indicator-active-color
15
20
  * ✔ autoplay
16
21
  * ✔ current
@@ -33,6 +38,10 @@ type EventDataType = {
33
38
  // onUpdate时根据上一个判断方向,onFinalize根据transformStart判断
34
39
  transdir: number
35
40
  }
41
+ // 只基于方向 + offset 计算最终的索引
42
+ type EventEndType = {
43
+ transdir: number
44
+ }
36
45
 
37
46
  interface SwiperProps {
38
47
  children?: ReactNode
@@ -46,6 +55,11 @@ interface SwiperProps {
46
55
  scale?: boolean
47
56
  'indicator-dots'?: boolean
48
57
  'indicator-color'?: string
58
+ 'indicator-width'?: number
59
+ 'indicator-height'?: number
60
+ 'indicator-spacing'?: number
61
+ 'indicator-radius'?: number
62
+ 'indicator-margin'?: number
49
63
  'indicator-active-color'?: string
50
64
  vertical?: boolean
51
65
  style: {
@@ -72,23 +86,23 @@ interface SwiperProps {
72
86
  const styles: { [key: string]: Object } = {
73
87
  pagination_x: {
74
88
  position: 'absolute',
75
- bottom: 25,
89
+ bottom: 0,
76
90
  left: 0,
77
91
  right: 0,
78
92
  flexDirection: 'row',
79
93
  flex: 1,
80
94
  justifyContent: 'center',
81
- alignItems: 'center'
95
+ alignItems: 'flex-end'
82
96
  },
83
97
  pagination_y: {
84
98
  position: 'absolute',
85
- right: 15,
99
+ right: 0,
86
100
  top: 0,
87
101
  bottom: 0,
88
102
  flexDirection: 'column',
89
103
  flex: 1,
90
104
  justifyContent: 'center',
91
- alignItems: 'center'
105
+ alignItems: 'flex-end'
92
106
  },
93
107
  pagerWrapperx: {
94
108
  position: 'absolute',
@@ -109,16 +123,6 @@ const styles: { [key: string]: Object } = {
109
123
  }
110
124
  }
111
125
 
112
- const dotCommonStyle = {
113
- width: 8,
114
- height: 8,
115
- borderRadius: 4,
116
- marginLeft: 3,
117
- marginRight: 3,
118
- marginTop: 3,
119
- marginBottom: 3,
120
- zIndex: 98
121
- }
122
126
  const activeDotStyle = {
123
127
  zIndex: 99
124
128
  }
@@ -136,6 +140,11 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
136
140
  const {
137
141
  'indicator-dots': showPagination,
138
142
  'indicator-color': dotColor = 'rgba(0, 0, 0, .3)',
143
+ 'indicator-width': dotWidth = 8,
144
+ 'indicator-height': dotHeight = 8,
145
+ 'indicator-radius': dotRadius = 4,
146
+ 'indicator-spacing': dotSpacing = 4,
147
+ 'indicator-margin': paginationMargin = 10,
139
148
  'indicator-active-color': activeDotColor = '#000000',
140
149
  'enable-var': enableVar = false,
141
150
  'parent-font-size': parentFontSize,
@@ -151,6 +160,17 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
151
160
  current: propCurrent = 0,
152
161
  bindchange
153
162
  } = props
163
+
164
+ const dotCommonStyle = {
165
+ width: dotWidth,
166
+ height: dotHeight,
167
+ borderRadius: dotRadius,
168
+ marginLeft: dotSpacing,
169
+ marginRight: dotSpacing,
170
+ marginTop: dotSpacing,
171
+ marginBottom: dotSpacing,
172
+ zIndex: 98
173
+ }
154
174
  const easeingFunc = props['easing-function'] || 'default'
155
175
  const easeDuration = props.duration || 500
156
176
  const horizontal = props.vertical !== undefined ? !props.vertical : true
@@ -188,7 +208,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
188
208
  const patchElmNum = circular ? (preMargin ? 2 : 1) : 0
189
209
  const patchElmNumShared = useSharedValue(patchElmNum)
190
210
  const circularShared = useSharedValue(circular)
191
- const children = Array.isArray(props.children) ? props.children.filter(child => child) : (props.children ? [props.children] : [])
211
+ // 支持swiper-item 同时存在<swiper-item wx:for/>和<swiper-item>并列的情况
212
+ const children = React.Children.toArray(props.children) as ReactElement[]
192
213
  // 对有变化的变量,在worklet中只能使用sharedValue变量,useRef不能更新
193
214
  const childrenLength = useSharedValue(children.length)
194
215
  const initWidth = typeof normalStyle?.width === 'number' ? normalStyle.width - preMargin - nextMargin : normalStyle.width
@@ -211,8 +232,12 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
211
232
  const preAbsolutePos = useSharedValue(0)
212
233
  // 记录从onBegin 到 onTouchesUp 时移动的距离
213
234
  const moveTranstion = useSharedValue(0)
235
+ // 记录用户手滑动的方向
236
+ const moveDir = useSharedValue(0)
214
237
  const timerId = useRef(0 as number | ReturnType<typeof setTimeout>)
215
238
  const intervalTimer = props.interval || 500
239
+ // 记录是否首次,首次不能触发bindchange回调
240
+ const isFirstRef = useRef(true)
216
241
 
217
242
  const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
218
243
  const waitForHandlers = flatGesture(waitFor)
@@ -252,6 +277,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
252
277
  'style',
253
278
  'indicator-dots',
254
279
  'indicator-color',
280
+ 'indicator-width',
255
281
  'indicator-active-color',
256
282
  'previous-margin',
257
283
  'vertical',
@@ -294,8 +320,18 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
294
320
  for (let i = 0; i < children.length; i++) {
295
321
  dots.push(<View style={[dotCommonStyle, { backgroundColor: unActionColor }]} key={i}></View>)
296
322
  }
323
+ let paginationStyle = styles['pagination_' + dir]
324
+ if (paginationMargin) {
325
+ paginationStyle = {
326
+ ...paginationStyle,
327
+ marginBottom: paginationMargin,
328
+ marginLeft: paginationMargin,
329
+ marginRight: paginationMargin,
330
+ marginTop: paginationMargin
331
+ }
332
+ }
297
333
  return (
298
- <View pointerEvents="none" style={styles['pagination_' + dir]}>
334
+ <View pointerEvents="none" style={paginationStyle} key="pagination">
299
335
  <View style={[styles['pagerWrapper' + dir]]}>
300
336
  <Animated.View style={[
301
337
  dotCommonStyle,
@@ -429,11 +465,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
429
465
  }
430
466
  }, [])
431
467
 
432
- function handleSwiperChange (current: number, pCurrent: number) {
433
- if (pCurrent !== currentIndex.value) {
434
- const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
435
- bindchange && bindchange(eventData)
436
- }
468
+ function handleSwiperChange (current: number) {
469
+ const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
470
+ bindchange && bindchange(eventData)
437
471
  }
438
472
 
439
473
  const runOnJSCallbackRef = useRef({
@@ -482,9 +516,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
482
516
  // 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
483
517
  useAnimatedReaction(() => currentIndex.value, (newIndex: number, preIndex: number) => {
484
518
  // 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
485
- if (newIndex !== preIndex && bindchange) {
519
+ if (newIndex !== preIndex && bindchange && !isFirstRef.current) {
486
520
  runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
487
521
  }
522
+ isFirstRef.current = false
488
523
  })
489
524
 
490
525
  useEffect(() => {
@@ -542,7 +577,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
542
577
  }
543
578
  }, [circular, preMargin])
544
579
  const { gestureHandler } = useMemo(() => {
545
- function getTargetPosition (eventData: EventDataType) {
580
+ // 基于transdir + 当前offset计算索引
581
+ function getTargetPosition (eventData: EventEndType) {
546
582
  'worklet'
547
583
  // 移动的距离
548
584
  const { transdir } = eventData
@@ -601,7 +637,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
601
637
  return true
602
638
  }
603
639
  }
604
- function handleEnd (eventData: EventDataType) {
640
+ function handleEnd (eventData: EventEndType) {
605
641
  'worklet'
606
642
  const { isCriticalItem, targetOffset, resetOffset, selectedIndex } = getTargetPosition(eventData)
607
643
  if (isCriticalItem) {
@@ -627,7 +663,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
627
663
  })
628
664
  }
629
665
  }
630
- function handleBack (eventData: EventDataType) {
666
+ function handleBack (eventData: EventEndType) {
631
667
  'worklet'
632
668
  const { transdir } = eventData
633
669
  // 向右滑动的back:trans < 0, 向左滑动的back: trans < 0
@@ -648,10 +684,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
648
684
  }
649
685
  })
650
686
  }
651
- // 当前的offset和index多对应的offset进行对比,判断是否超过一半
652
- function computeHalf (eventData: EventDataType) {
687
+ function computeHalf () {
653
688
  'worklet'
654
- const { transdir } = eventData
655
689
  const currentOffset = Math.abs(offset.value)
656
690
  let preOffset = (currentIndex.value + patchElmNumShared.value) * step.value
657
691
  if (circularShared.value) {
@@ -660,32 +694,14 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
660
694
  // 正常事件中拿到的translation值(正向滑动<0,倒着滑>0)
661
695
  const diffOffset = preOffset - currentOffset
662
696
  const half = Math.abs(diffOffset) > step.value / 2
663
- const isTriggerUpdateHalf = (transdir < 0 && currentOffset < preOffset) || (transdir > 0 && currentOffset > preOffset)
664
- return {
665
- diffOffset,
666
- half,
667
- isTriggerUpdateHalf
668
- }
669
- }
670
- function handleLongPress (eventData: EventDataType) {
671
- 'worklet'
672
- const { diffOffset, half, isTriggerUpdateHalf } = computeHalf(eventData)
673
- if (+diffOffset === 0) {
674
- runOnJS(runOnJSCallback)('resumeLoop')
675
- } else if (isTriggerUpdateHalf) {
676
- // 如果触发了onUpdate时的索引变更
677
- handleEnd(eventData)
678
- } else if (half) {
679
- handleEnd(eventData)
680
- } else {
681
- handleBack(eventData)
682
- }
697
+ return half
683
698
  }
684
699
  function reachBoundary (eventData: EventDataType) {
685
700
  'worklet'
686
701
  // 1. 基于当前的offset和translation判断是否超过当前边界值
687
702
  const { translation } = eventData
688
- const boundaryStart = -patchElmNumShared.value * step.value
703
+ // 与终点的逻辑对齐,都是超过补位元素对应的起点offset
704
+ const boundaryStart = 0
689
705
  const boundaryEnd = -(childrenLength.value + patchElmNumShared.value) * step.value
690
706
  const moveToOffset = offset.value + translation
691
707
  let isBoundary = false
@@ -702,7 +718,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
702
718
  // 超过边界的距离
703
719
  const exceedLength = Math.abs(boundaryStart) - Math.abs(moveToOffset)
704
720
  // 计算对标正常元素所在的offset
705
- resetOffset = (patchElmNumShared.value + childrenLength.value - 1) * step.value + (step.value - exceedLength)
721
+ resetOffset = (patchElmNumShared.value + childrenLength.value - 1) * step.value - exceedLength
706
722
  }
707
723
  return {
708
724
  isBoundary,
@@ -739,6 +755,14 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
739
755
  }
740
756
  return finalOffset
741
757
  }
758
+ // 设置手势移动的方向
759
+ function setMoveDir (curAbsoPos: number) {
760
+ 'worklet'
761
+ const distance = curAbsoPos - preAbsolutePos.value
762
+ if (distance) {
763
+ moveDir.value = curAbsoPos - preAbsolutePos.value
764
+ }
765
+ }
742
766
  const gesturePan = Gesture.Pan()
743
767
  .onBegin((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
744
768
  'worklet'
@@ -758,9 +782,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
758
782
  transdir: moveDistance
759
783
  }
760
784
  // 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
761
- const { half } = computeHalf(eventData)
762
- if (childrenLength.value > 1 && half) {
763
- const { selectedIndex } = getTargetPosition(eventData)
785
+ const offsetHalf = computeHalf()
786
+ if (childrenLength.value > 1 && offsetHalf) {
787
+ const { selectedIndex } = getTargetPosition({ transdir: moveDistance } as EventEndType)
764
788
  currentIndex.value = selectedIndex
765
789
  }
766
790
  // 2. 非循环: 处理用户一直拖拽到临界点的场景,如果放到onFinalize无法阻止offset.value更新为越界的值
@@ -771,6 +795,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
771
795
  const finalOffset = handleResistanceMove(eventData)
772
796
  offset.value = finalOffset
773
797
  }
798
+ setMoveDir(e[strAbso])
774
799
  preAbsolutePos.value = e[strAbso]
775
800
  return
776
801
  }
@@ -778,6 +803,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
778
803
  if (circularShared.value && childrenLength.value === 1) {
779
804
  const finalOffset = handleResistanceMove(eventData)
780
805
  offset.value = finalOffset
806
+ setMoveDir(e[strAbso])
781
807
  preAbsolutePos.value = e[strAbso]
782
808
  return
783
809
  }
@@ -788,6 +814,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
788
814
  } else {
789
815
  offset.value = moveDistance + offset.value
790
816
  }
817
+ setMoveDir(e[strAbso])
791
818
  preAbsolutePos.value = e[strAbso]
792
819
  })
793
820
  .onFinalize((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
@@ -795,10 +822,21 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
795
822
  if (touchfinish.value) return
796
823
  touchfinish.value = true
797
824
  // 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
825
+ // 正常状态下基于onUpdate时的moveDir判断方向、未触发onUpdate的则基于onBegin的moveTranstion判断方向
798
826
  const moveDistance = e[strAbso] - preAbsolutePos.value
827
+ // 默认兜底方向: 以onBegin为起点,因一些原因未触发onUpdate但是触发了位移
828
+ const defaultDir = e[strAbso] - moveTranstion.value
829
+ // 实时方向:方向基于onUpdate时的方向,滑动的速度超过阈值时基于实时的滑动方向计算
830
+ const realtimeData = {
831
+ transdir: moveDir.value || defaultDir
832
+ }
833
+ // 起始方向:基于用户起始手势
834
+ const originData = {
835
+ transdir: defaultDir
836
+ }
799
837
  const eventData = {
800
838
  translation: moveDistance,
801
- transdir: moveDistance !== 0 ? moveDistance : e[strAbso] - moveTranstion.value
839
+ transdir: realtimeData.transdir
802
840
  }
803
841
  // 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
804
842
  if (childrenLength.value === 1) {
@@ -812,19 +850,35 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
812
850
  // 非循环支持最后元素可滑动能力后,向左快速移动未超过最大可移动范围一半,因为offset为正值,向左滑动handleBack,默认向上取整
813
851
  // 但是在offset大于0时,取0。[-100, 0](back取0), [0, 100](back取1), 所以handleLongPress里的处理逻辑需要兼容支持,因此这里直接单独处理,不耦合下方公共的判断逻辑。
814
852
  if (!circularShared.value && !canMove(eventData)) {
815
- if (eventData.transdir < 0) {
816
- handleBack(eventData)
853
+ if (realtimeData.transdir < 0) {
854
+ handleBack(realtimeData)
817
855
  } else {
818
- handleEnd(eventData)
856
+ handleEnd(realtimeData)
819
857
  }
820
858
  return
821
859
  }
822
860
  // 3. 非循环状态可移动态、循环状态, 正常逻辑处理
823
861
  const velocity = e[strVelocity]
824
- if (Math.abs(velocity) < longPressRatio) {
825
- handleLongPress(eventData)
862
+ // 用于判断是否超过一半,基于索引判断是否超过一半不可行(1.滑动过程中索引会变更导致计算反向, 2.边界场景会更新offset也会导致基于索引+offset判断实效)
863
+ const tmp = offset.value % step.value > step.value / 2
864
+ // 小于0手向左滑动
865
+ const offsetHalf = originData.transdir < 0 ? tmp : !tmp
866
+ if (offsetHalf) {
867
+ if (Math.abs(velocity) > longPressRatio) {
868
+ // 超过速度阈值,按照实时方向(快速来回滑动)
869
+ handleEnd(realtimeData)
870
+ } else {
871
+ // 超过速度阈值,按照起始方向(慢速长按)
872
+ handleEnd(originData)
873
+ }
826
874
  } else {
827
- handleEnd(eventData)
875
+ if (Math.abs(velocity) > longPressRatio) {
876
+ // 超过速度阈值,按照实时方向(快速来回滑动)
877
+ handleEnd(realtimeData)
878
+ } else {
879
+ // 超过速度阈值,按照起始方向(慢速长按)
880
+ handleBack(originData)
881
+ }
828
882
  }
829
883
  })
830
884
  .withRef(swiperGestureRef)
@@ -861,6 +915,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
861
915
  style: [normalStyle, layoutStyle, styles.swiper]
862
916
  }, layoutProps, innerProps)
863
917
  const animateComponent = createElement(Animated.View, {
918
+ key: 'swiperContainer',
864
919
  style: [{ flexDirection: dir === 'x' ? 'row' : 'column', width: '100%', height: '100%' }, animatedStyles]
865
920
  }, wrapChildren({
866
921
  children: arrPages
@@ -4,6 +4,7 @@
4
4
  * type, password, confirm-hold
5
5
  * Addition:
6
6
  * ✔ confirm-type
7
+ * ✘ confirm-hold
7
8
  * ✔ auto-height
8
9
  * ✘ fixed
9
10
  * ✘ show-confirm-bar
@@ -8,8 +8,8 @@ import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, StyleShee
8
8
  import { useRef, useState, useEffect, forwardRef, ReactNode, JSX, createElement } from 'react'
9
9
  import useInnerProps from './getInnerListeners'
10
10
  import Animated from 'react-native-reanimated'
11
- import useAnimationHooks from './useAnimationHooks'
12
- import type { AnimationProp } from './useAnimationHooks'
11
+ import useAnimationHooks, { AnimationType } from './animationHooks/index'
12
+ import type { AnimationProp } from './animationHooks/utils'
13
13
  import { ExtendedViewStyle } from './types/common'
14
14
  import useNodesRef, { HandlerRef } from './useNodesRef'
15
15
  import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject, useHover } from './utils'
@@ -32,7 +32,7 @@ export interface _ViewProps extends ViewProps {
32
32
  'parent-font-size'?: number
33
33
  'parent-width'?: number
34
34
  'parent-height'?: number
35
- 'enable-animation'?: boolean
35
+ 'enable-animation'?: boolean | AnimationType
36
36
  bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
37
37
  bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
38
38
  bindtouchend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
@@ -287,7 +287,7 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
287
287
  } else { // 数值类型 ImageStyle
288
288
  // 数值类型设置为 stretch
289
289
  imageProps.resizeMode = 'stretch'
290
- if (type === 'linear' && (!layoutWidth || !layoutHeight)) {
290
+ if (type === 'linear' && (!layoutWidth || !layoutHeight) && (isPercent(width) || isPercent(height))) {
291
291
  // ios 上 linear 组件只要重新触发渲染,在渲染过程中外层容器 width 或者 height 被设置为 0,通过设置 % 的方式会渲染不出来,即使后面再更新为正常宽高也渲染不出来
292
292
  // 所以 hack 手动先将 linear 宽高也设置为 0,后面再更新为正确的数值或 %。
293
293
  dimensions = {
@@ -369,6 +369,17 @@ function normalizeBackgroundPosition (parts: PositionVal[]): backgroundPositionL
369
369
  let vStart: 'top' | 'bottom' = 'top'
370
370
  let vOffset: PositionVal = 0
371
371
 
372
+ if (!Array.isArray(parts)) {
373
+ // 模板 style 属性传入单个数值时不会和 class 一样转成数组,需要手动转换
374
+ parts = [parts]
375
+ }
376
+ // 模板 style 属性传入时, 需要额外转换处理单位 px/rpx/vh 以及 center 转化为 50%
377
+ parts = (parts as (PositionVal | string)[]).map((part) => {
378
+ if (typeof part !== 'string') return part
379
+ if (part === 'center') return '50%'
380
+ return global.__formatValue(part) as PositionVal
381
+ })
382
+
372
383
  if (parts.length === 4) return parts as backgroundPositionList
373
384
 
374
385
  // 归一化
@@ -514,19 +525,24 @@ function parseBgImage (text: string): {
514
525
  }
515
526
  }
516
527
 
517
- function normalizeBackgroundSize (backgroundSize: Exclude<ExtendedViewStyle['backgroundSize'], undefined>, type: 'image' | 'linear' | undefined) {
528
+ function normalizeBackgroundSize (
529
+ backgroundSize: NonNullable<ExtendedViewStyle['backgroundSize']>,
530
+ type: 'image' | 'linear' | undefined
531
+ ): DimensionValue[] {
518
532
  const sizeList = backgroundSize.slice()
519
533
  if (sizeList.length === 1) sizeList.push('auto')
520
534
 
521
- if (type === 'linear') {
535
+ return sizeList.map((val) => {
536
+ if (typeof val !== 'string') return val
537
+
522
538
  // 处理当使用渐变的时候,background-size出现cover, contain, auto,当作100%处理
523
- for (const i in sizeList) {
524
- const val = sizeList[i]
525
- sizeList[i] = /^cover|contain|auto$/.test(val as string) ? '100%' : val
539
+ if (type === 'linear' && /^cover|contain|auto$/.test(val)) {
540
+ val = '100%'
526
541
  }
527
- }
528
542
 
529
- return sizeList
543
+ // 模板 style 属性传入时, 需要额外转换处理单位 px/rpx/vh
544
+ return global.__formatValue(val) as DimensionValue
545
+ })
530
546
  }
531
547
 
532
548
  function preParseImage (imageStyle?: ExtendedViewStyle) {
@@ -777,7 +793,6 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
777
793
  ref: nodeRef,
778
794
  style: enableStyleAnimation ? [viewStyle, animationStyle] : viewStyle
779
795
  }
780
-
781
796
  ),
782
797
  [
783
798
  'hover-start-time',
@@ -0,0 +1,26 @@
1
+ // 用于 react 生成
2
+ {
3
+ "include": [
4
+ "./"
5
+ ],
6
+ "exclude": ["./dist/"],
7
+ "compilerOptions": {
8
+ "target": "esnext",
9
+ "module": "esnext",
10
+ "outDir": "./dist",
11
+ "rootDir": "./",
12
+ "noImplicitThis": true,
13
+ "noImplicitAny": true,
14
+ "skipLibCheck": true,
15
+ "strictNullChecks": true,
16
+ "moduleResolution": "node",
17
+ "declaration": true,
18
+ "allowSyntheticDefaultImports": true,
19
+ "jsx": "preserve",
20
+ "lib": [
21
+ "esnext",
22
+ "dom",
23
+ "dom.iterable"
24
+ ],
25
+ }
26
+ }
@@ -34,6 +34,7 @@ declare module '@mpxjs/utils' {
34
34
  },
35
35
  setOptions: (params: Record<string, any>) => void
36
36
  } | undefined
37
+ export function dash2hump (str: string): string
37
38
  }
38
39
 
39
40
  declare let global: {