@mpxjs/webpack-plugin 2.9.67 → 2.9.69-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.
Files changed (150) hide show
  1. package/lib/index.js +30 -9
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  4. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  9. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  10. package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
  11. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  12. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  13. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  14. package/lib/react/processStyles.js +14 -4
  15. package/lib/react/processTemplate.js +3 -0
  16. package/lib/resolver/AddEnvPlugin.js +1 -0
  17. package/lib/resolver/AddModePlugin.js +9 -8
  18. package/lib/runtime/components/react/context.ts +14 -0
  19. package/lib/runtime/components/react/dist/context.js +4 -0
  20. package/lib/runtime/components/react/dist/event.config.js +24 -24
  21. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
  22. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  23. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  32. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  33. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  34. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  35. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  36. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  37. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  38. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  40. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  41. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  42. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  48. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  53. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  55. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  56. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
  57. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  58. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  59. package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
  60. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  61. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  62. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  63. package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
  64. package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
  65. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  66. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  69. package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
  70. package/lib/runtime/components/react/dist/utils.jsx +129 -24
  71. package/lib/runtime/components/react/event.config.ts +25 -26
  72. package/lib/runtime/components/react/getInnerListeners.ts +238 -202
  73. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  74. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  75. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  76. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  77. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  78. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  79. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  80. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  81. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  82. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  83. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  84. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  85. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  86. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  87. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  88. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  89. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  90. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  91. package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
  92. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  93. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  95. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  96. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  97. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  98. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  99. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  100. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
  101. package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
  102. package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
  103. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  104. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  105. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  106. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  107. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  108. package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
  109. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  110. package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
  111. package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
  112. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  113. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  114. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  115. package/lib/runtime/components/react/mpx-view.tsx +93 -117
  116. package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
  117. package/lib/runtime/components/react/pickerFaces.ts +112 -0
  118. package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
  119. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  120. package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
  121. package/lib/runtime/components/react/types/common.ts +2 -0
  122. package/lib/runtime/components/react/types/global.d.ts +7 -17
  123. package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
  124. package/lib/runtime/components/react/utils.tsx +169 -29
  125. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  126. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  127. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  128. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  129. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  130. package/lib/runtime/optionProcessor.js +7 -38
  131. package/lib/runtime/utils.js +2 -0
  132. package/lib/style-compiler/index.js +3 -4
  133. package/lib/style-compiler/plugins/scope-id.js +30 -2
  134. package/lib/style-compiler/strip-conditional-loader.js +118 -0
  135. package/lib/template-compiler/bind-this.js +7 -2
  136. package/lib/template-compiler/compiler.js +66 -39
  137. package/lib/template-compiler/gen-node-react.js +3 -3
  138. package/package.json +6 -4
  139. package/LICENSE +0 -433
  140. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  141. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  142. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  143. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  144. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  145. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  146. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  147. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
  148. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  149. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  150. package/lib/runtime/components/web/event.js +0 -105
@@ -0,0 +1,115 @@
1
+
2
+ /**
3
+ * ✔ nodes
4
+ */
5
+ import { View, ViewProps, ViewStyle } from 'react-native'
6
+ import { useRef, forwardRef, JSX, useState, createElement } from 'react'
7
+ import useInnerProps from '../getInnerListeners'
8
+ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
9
+ import { useTransformStyle, useLayout, extendObject } from '../utils'
10
+ import { WebView, WebViewMessageEvent } from 'react-native-webview'
11
+ import { generateHTML } from './html'
12
+
13
+ type Node = {
14
+ type: 'node' | 'text'
15
+ name?: string
16
+ attrs?: any
17
+ children?: Array<Node>
18
+ text: string
19
+ }
20
+
21
+ interface _RichTextProps extends ViewProps {
22
+ style?: ViewStyle
23
+ nodes: string | Array<Node>
24
+ 'enable-var'?: boolean
25
+ 'external-var-context'?: Record<string, any>
26
+ 'parent-font-size'?: number
27
+ 'parent-width'?: number
28
+ 'parent-height'?: number
29
+ }
30
+
31
+ function jsonToHtmlStr (elements: Array<Node>) {
32
+ let htmlStr = ''
33
+
34
+ for (const element of elements) {
35
+ if (element.type === 'text') {
36
+ htmlStr += element.text
37
+ return htmlStr
38
+ }
39
+
40
+ const { name, attrs = {}, children = [] } = element
41
+
42
+ let attrStr = ''
43
+ for (const [key, value] of Object.entries(attrs)) attrStr += ` ${key}="${value}"`
44
+
45
+ let childrenStr = ''
46
+ for (const child of children) childrenStr += jsonToHtmlStr([child])
47
+
48
+ htmlStr += `<${name}${attrStr}>${childrenStr}</${name}>`
49
+ }
50
+
51
+ return htmlStr
52
+ }
53
+
54
+ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((props, ref): JSX.Element => {
55
+ const {
56
+ style = {},
57
+ nodes,
58
+ 'enable-var': enableVar,
59
+ 'external-var-context': externalVarContext,
60
+ 'parent-font-size': parentFontSize,
61
+ 'parent-width': parentWidth,
62
+ 'parent-height': parentHeight
63
+ } = props
64
+
65
+ const nodeRef = useRef(null)
66
+ const [webViewHeight, setWebViewHeight] = useState(0)
67
+
68
+ const {
69
+ normalStyle,
70
+ hasSelfPercent,
71
+ setWidth,
72
+ setHeight
73
+ } = useTransformStyle(Object.assign({
74
+ width: '100%',
75
+ height: webViewHeight
76
+ }, style), {
77
+ enableVar,
78
+ externalVarContext,
79
+ parentFontSize,
80
+ parentWidth,
81
+ parentHeight
82
+ })
83
+
84
+ const {
85
+ layoutRef,
86
+ layoutStyle,
87
+ layoutProps
88
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
89
+
90
+ useNodesRef<View, _RichTextProps>(props, ref, nodeRef, {
91
+ layoutRef
92
+ })
93
+
94
+ const innerProps = useInnerProps(props, extendObject({
95
+ ref: nodeRef,
96
+ style: extendObject(normalStyle, layoutStyle)
97
+ }, layoutProps), [], {
98
+ layoutRef
99
+ })
100
+
101
+ const html: string = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes)
102
+
103
+ return createElement(View, innerProps,
104
+ createElement(WebView, {
105
+ source: { html: generateHTML(html) },
106
+ onMessage: (event: WebViewMessageEvent) => {
107
+ setWebViewHeight(+event.nativeEvent.data)
108
+ }
109
+ })
110
+ )
111
+ })
112
+
113
+ _RichText.displayName = 'mpx-rich-text'
114
+
115
+ export default _RichText
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ✔ enable
3
3
  */
4
- import { ReactNode } from 'react'
4
+ import { ReactNode, createElement, Fragment } from 'react'
5
5
  import { Portal } from '@ant-design/react-native'
6
6
  import { warn } from '@mpxjs/utils'
7
7
  interface RootPortalProps {
@@ -16,10 +16,8 @@ const _RootPortal = (props: RootPortalProps) => {
16
16
  warn('The root-portal component does not support the style prop.')
17
17
  }
18
18
  return enable
19
- ? <Portal>
20
- {children}
21
- </Portal>
22
- : <>{children}</>
19
+ ? createElement(Portal, null, children)
20
+ : createElement(Fragment, null, children)
23
21
  }
24
22
 
25
23
  _RootPortal.displayName = 'MpxRootPortal'
@@ -33,13 +33,13 @@
33
33
  */
34
34
  import { ScrollView } from 'react-native-gesture-handler'
35
35
  import { View, RefreshControl, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
36
- import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext } from 'react'
36
+ import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, createElement, useMemo } from 'react'
37
37
  import { useAnimatedRef } from 'react-native-reanimated'
38
38
  import { warn } from '@mpxjs/utils'
39
39
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
40
40
  import useNodesRef, { HandlerRef } from './useNodesRef'
41
- import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, flatGesture, GestureHandler } from './utils'
42
- import { IntersectionObserverContext } from './context'
41
+ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler } from './utils'
42
+ import { IntersectionObserverContext, ScrollViewContext } from './context'
43
43
 
44
44
  interface ScrollViewProps {
45
45
  children?: ReactNode;
@@ -165,7 +165,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
165
165
  const initialTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
166
166
  const intersectionObservers = useContext(IntersectionObserverContext)
167
167
 
168
- const snapScrollIntoView = useRef<string>('')
168
+ const firstScrollIntoViewChange = useRef<boolean>(false)
169
169
 
170
170
  const {
171
171
  normalStyle,
@@ -176,10 +176,11 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
176
176
  setHeight
177
177
  } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
178
178
 
179
- const { textStyle, innerStyle } = splitStyle(normalStyle)
179
+ const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
180
180
 
181
181
  const scrollViewRef = useAnimatedRef<ScrollView>()
182
182
  useNodesRef(props, ref, scrollViewRef, {
183
+ style: normalStyle,
183
184
  scrollOffset: scrollOptions,
184
185
  node: {
185
186
  scrollEnabled: scrollX || scrollY,
@@ -193,6 +194,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
193
194
  gestureRef: scrollViewRef
194
195
  })
195
196
 
197
+ const contextValue = useMemo(() => {
198
+ return {
199
+ gestureRef: scrollViewRef
200
+ }
201
+ }, [])
202
+
196
203
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
197
204
 
198
205
  if (scrollX && scrollY) {
@@ -219,23 +226,28 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
219
226
  }, [refresherTriggered])
220
227
 
221
228
  useEffect(() => {
222
- if (scrollIntoView && __selectRef && snapScrollIntoView.current !== scrollIntoView) {
223
- snapScrollIntoView.current = scrollIntoView || ''
224
- setTimeout(() => {
225
- const refs = __selectRef(`#${scrollIntoView}`, 'node')
226
- if (refs) {
227
- const { nodeRef } = refs.getNodeInstance()
228
- nodeRef.current?.measureLayout(
229
- scrollViewRef.current,
230
- (left: number, top:number) => {
231
- scrollToOffset(left, top)
232
- }
233
- )
234
- }
235
- })
229
+ if (scrollIntoView && __selectRef) {
230
+ if (!firstScrollIntoViewChange.current) {
231
+ setTimeout(handleScrollIntoView)
232
+ } else {
233
+ handleScrollIntoView()
234
+ }
236
235
  }
236
+ firstScrollIntoViewChange.current = true
237
237
  }, [scrollIntoView])
238
238
 
239
+ function handleScrollIntoView () {
240
+ const refs = __selectRef!(`#${scrollIntoView}`, 'node')
241
+ if (!refs) return
242
+ const { nodeRef } = refs.getNodeInstance()
243
+ nodeRef.current?.measureLayout(
244
+ scrollViewRef.current,
245
+ (left: number, top:number) => {
246
+ scrollToOffset(left, top)
247
+ }
248
+ )
249
+ }
250
+
239
251
  function selectLength (size: { height: number; width: number }) {
240
252
  return !scrollX ? size.height : size.width
241
253
  }
@@ -298,14 +310,13 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
298
310
  const visibleLength = selectLength(e.nativeEvent.layoutMeasurement)
299
311
  const contentLength = selectLength(e.nativeEvent.contentSize)
300
312
  const offset = selectOffset(e.nativeEvent.contentOffset)
301
- scrollOptions.current = {
302
- ...scrollOptions.current,
313
+ extendObject(scrollOptions.current, {
303
314
  contentLength,
304
315
  offset,
305
316
  scrollLeft: position.scrollLeft,
306
317
  scrollTop: position.scrollTop,
307
318
  visibleLength
308
- }
319
+ })
309
320
  }
310
321
 
311
322
  function onScroll (e: NativeSyntheticEvent<NativeScrollEvent>) {
@@ -426,34 +437,36 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
426
437
  updateScrollOptions(e, { scrollLeft, scrollTop })
427
438
  }
428
439
 
429
- let scrollAdditionalProps: ScrollAdditionalProps = {
430
- style: { ...innerStyle, ...layoutStyle },
431
- pinchGestureEnabled: false,
432
- horizontal: scrollX && !scrollY,
433
- scrollEventThrottle: scrollEventThrottle,
434
- scrollsToTop: enableBackToTop,
435
- showsHorizontalScrollIndicator: scrollX && showScrollbar,
436
- showsVerticalScrollIndicator: scrollY && showScrollbar,
437
- scrollEnabled: scrollX || scrollY,
438
- ref: scrollViewRef,
439
- onScroll: onScroll,
440
- onContentSizeChange: onContentSizeChange,
441
- bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) ? onScrollTouchStart : undefined,
442
- bindtouchmove: ((enhanced && binddragging) || bindtouchend) ? onScrollTouchMove : undefined,
443
- bindtouchend: ((enhanced && binddragend) || bindtouchend) ? onScrollTouchEnd : undefined,
444
- onScrollBeginDrag: onScrollDrag,
445
- onScrollEndDrag: onScrollDrag,
446
- onMomentumScrollEnd: onScrollEnd,
447
- ...layoutProps,
448
- ...(simultaneousHandlers ? { simultaneousHandlers } : {}),
449
- ...(waitForHandlers ? { waitFor: waitForHandlers } : {})
450
- }
440
+ const scrollAdditionalProps: ScrollAdditionalProps = extendObject(
441
+ {
442
+ style: extendObject({}, innerStyle, layoutStyle),
443
+ pinchGestureEnabled: false,
444
+ horizontal: scrollX && !scrollY,
445
+ scrollEventThrottle: scrollEventThrottle,
446
+ scrollsToTop: enableBackToTop,
447
+ showsHorizontalScrollIndicator: scrollX && showScrollbar,
448
+ showsVerticalScrollIndicator: scrollY && showScrollbar,
449
+ scrollEnabled: scrollX || scrollY,
450
+ ref: scrollViewRef,
451
+ onScroll: onScroll,
452
+ onContentSizeChange: onContentSizeChange,
453
+ bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
454
+ bindtouchmove: ((enhanced && binddragging) || bindtouchend) && onScrollTouchMove,
455
+ bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
456
+ onScrollBeginDrag: onScrollDrag,
457
+ onScrollEndDrag: onScrollDrag,
458
+ onMomentumScrollEnd: onScrollEnd
459
+ },
460
+ (simultaneousHandlers ? { simultaneousHandlers } : {}),
461
+ (waitForHandlers ? { waitFor: waitForHandlers } : {}),
462
+ layoutProps
463
+ )
464
+
451
465
  if (enhanced) {
452
- scrollAdditionalProps = {
453
- ...scrollAdditionalProps,
466
+ Object.assign(scrollAdditionalProps, {
454
467
  bounces,
455
468
  pagingEnabled
456
- }
469
+ })
457
470
  }
458
471
 
459
472
  const innerProps = useInnerProps(props, scrollAdditionalProps, [
@@ -489,32 +502,29 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
489
502
  white: ['#fff']
490
503
  }
491
504
 
492
- return (
493
- <ScrollView
494
- {...innerProps}
495
- refreshControl={refresherEnabled
496
- ? (
497
- <RefreshControl
498
- progressBackgroundColor={refresherBackground}
499
- refreshing={refreshing}
500
- onRefresh={onRefresh}
501
- {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}
502
- />
503
- )
504
- : undefined}
505
- >
506
- {
507
- wrapChildren(
508
- props,
509
- {
510
- hasVarDec,
511
- varContext: varContextRef.current,
512
- textStyle,
513
- textProps
514
- }
515
- )
516
- }
517
- </ScrollView>
505
+ return createElement(
506
+ ScrollView,
507
+ extendObject({}, innerProps, {
508
+ refreshControl: refresherEnabled
509
+ ? createElement(RefreshControl, extendObject({
510
+ progressBackgroundColor: refresherBackground,
511
+ refreshing: refreshing,
512
+ onRefresh: onRefresh
513
+ }, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
514
+ : undefined
515
+ }),
516
+ createElement(ScrollViewContext.Provider,
517
+ { value: contextValue },
518
+ wrapChildren(
519
+ props,
520
+ {
521
+ hasVarDec,
522
+ varContext: varContextRef.current,
523
+ textStyle,
524
+ textProps
525
+ }
526
+ )
527
+ )
518
528
  )
519
529
  })
520
530
 
@@ -0,0 +1,18 @@
1
+ import { Text, TextProps } from 'react-native'
2
+ import { JSX, createElement } from 'react'
3
+
4
+ import { extendObject } from './utils'
5
+
6
+ const _Text2 = (props: TextProps): JSX.Element => {
7
+ const {
8
+ allowFontScaling = false
9
+ } = props
10
+
11
+ return createElement(Text, extendObject({}, props, {
12
+ allowFontScaling
13
+ }))
14
+ }
15
+
16
+ _Text2.displayName = 'MpxSimpleText'
17
+
18
+ export default _Text2
@@ -1,8 +1,10 @@
1
- import { View, LayoutChangeEvent } from 'react-native'
2
- import { ReactNode, forwardRef, useRef } from 'react'
1
+ import { View } from 'react-native'
2
+ import Animated, { useAnimatedStyle, interpolate, SharedValue } from 'react-native-reanimated'
3
+ import { ReactNode, forwardRef, useRef, useContext } from 'react'
3
4
  import useInnerProps from './getInnerListeners'
4
5
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
5
6
  import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
7
+ import { SwiperContext } from './context'
6
8
 
7
9
  interface SwiperItemProps {
8
10
  'item-id'?: string;
@@ -14,19 +16,31 @@ interface SwiperItemProps {
14
16
  'parent-height'?: number;
15
17
  children?: ReactNode;
16
18
  style?: Object;
19
+ customStyle: [];
20
+ itemIndex: number;
21
+ }
22
+
23
+ interface ContextType {
24
+ offset: SharedValue<number>;
25
+ step: SharedValue<number>;
26
+ scale: boolean;
17
27
  }
18
28
 
19
29
  const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
20
30
  const {
21
- 'enable-offset': enableOffset,
22
31
  'enable-var': enableVar,
23
32
  'external-var-context': externalVarContext,
24
- style
33
+ style,
34
+ customStyle,
35
+ itemIndex
25
36
  } = props
26
37
 
38
+ const contextValue = useContext(SwiperContext) as ContextType
39
+ const offset = contextValue.offset || 0
40
+ const step = contextValue.step || 0
41
+ const scale = contextValue.scale || false
27
42
  const { textProps } = splitProps(props)
28
43
  const nodeRef = useRef(null)
29
- useNodesRef(props, ref, nodeRef, {})
30
44
 
31
45
  const {
32
46
  normalStyle,
@@ -37,6 +51,9 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
37
51
  setHeight
38
52
  } = useTransformStyle(style, { enableVar, externalVarContext })
39
53
  const { textStyle, innerStyle } = splitStyle(normalStyle)
54
+ useNodesRef(props, ref, nodeRef, {
55
+ style: normalStyle
56
+ })
40
57
 
41
58
  const {
42
59
  // 存储layout布局信息
@@ -46,19 +63,31 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
46
63
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
47
64
 
48
65
  const innerProps = useInnerProps(props, {
49
- style: { ...innerStyle, ...layoutStyle },
50
66
  ref: nodeRef,
51
67
  ...layoutProps
52
68
  }, [
53
69
  'children',
54
- 'enable-offset'
70
+ 'enable-offset',
71
+ 'style'
55
72
  ], { layoutRef })
56
73
 
74
+ const itemAnimatedStyle = useAnimatedStyle(() => {
75
+ if (!step.value) return {}
76
+ const inputRange = [step.value, 0]
77
+ const outputRange = [0.7, 1]
78
+ return {
79
+ transform: [{
80
+ scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
81
+ }]
82
+ }
83
+ })
84
+ const mergeStyle = [innerStyle, layoutStyle, { width: '100%', height: '100%' }, scale ? itemAnimatedStyle : {}].concat(customStyle)
57
85
  return (
58
- <View
59
- data-itemId={props['item-id']}
60
- {...innerProps}>
61
- {
86
+ <Animated.View
87
+ {...innerProps}
88
+ style={mergeStyle}
89
+ data-itemId={props['item-id']}>
90
+ {
62
91
  wrapChildren(
63
92
  props,
64
93
  {
@@ -69,7 +98,7 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
69
98
  }
70
99
  )
71
100
  }
72
- </View>
101
+ </Animated.View>
73
102
  )
74
103
  })
75
104