@mpxjs/webpack-plugin 2.9.66 → 2.9.69-beta.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 (158) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +24 -18
  8. package/lib/platform/style/wx/index.js +49 -47
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  11. package/lib/platform/template/wx/component-config/index.js +1 -1
  12. package/lib/platform/template/wx/component-config/input.js +1 -1
  13. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  14. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  15. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  16. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  17. package/lib/react/index.js +4 -3
  18. package/lib/react/processJSON.js +5 -13
  19. package/lib/react/processMainScript.js +7 -3
  20. package/lib/react/processScript.js +3 -4
  21. package/lib/react/processStyles.js +14 -4
  22. package/lib/react/processTemplate.js +5 -2
  23. package/lib/resolver/AddModePlugin.js +20 -7
  24. package/lib/runtime/components/react/context.ts +6 -0
  25. package/lib/runtime/components/react/dist/context.js +2 -0
  26. package/lib/runtime/components/react/dist/event.config.js +24 -24
  27. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  28. package/lib/runtime/components/react/dist/mpx-button.jsx +78 -50
  29. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  38. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +41 -34
  39. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -39
  40. package/lib/runtime/components/react/dist/mpx-form.jsx +47 -41
  41. package/lib/runtime/components/react/dist/mpx-icon.jsx +9 -17
  42. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +95 -62
  44. package/lib/runtime/components/react/dist/mpx-label.jsx +24 -28
  45. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +20 -30
  46. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +377 -293
  47. package/lib/runtime/components/react/dist/mpx-navigator.jsx +3 -5
  48. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  49. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  50. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  51. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  52. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  53. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  54. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  56. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  57. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +39 -34
  58. package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
  59. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  60. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  61. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  62. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +77 -51
  63. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  64. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -3
  65. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  66. package/lib/runtime/components/react/dist/mpx-switch.jsx +28 -11
  67. package/lib/runtime/components/react/dist/mpx-text.jsx +12 -11
  68. package/lib/runtime/components/react/dist/mpx-textarea.jsx +9 -4
  69. package/lib/runtime/components/react/dist/mpx-view.jsx +66 -62
  70. package/lib/runtime/components/react/dist/mpx-web-view.jsx +113 -36
  71. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  72. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  73. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  74. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  75. package/lib/runtime/components/react/dist/useAnimationHooks.js +126 -12
  76. package/lib/runtime/components/react/dist/utils.jsx +80 -24
  77. package/lib/runtime/components/react/event.config.ts +25 -26
  78. package/lib/runtime/components/react/getInnerListeners.ts +237 -198
  79. package/lib/runtime/components/react/mpx-button.tsx +105 -58
  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 +296 -0
  88. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  89. package/lib/runtime/components/react/mpx-checkbox-group.tsx +77 -51
  90. package/lib/runtime/components/react/mpx-checkbox.tsx +49 -50
  91. package/lib/runtime/components/react/mpx-form.tsx +62 -57
  92. package/lib/runtime/components/react/mpx-icon.tsx +13 -18
  93. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  94. package/lib/runtime/components/react/mpx-input.tsx +139 -117
  95. package/lib/runtime/components/react/mpx-label.tsx +36 -34
  96. package/lib/runtime/components/react/mpx-movable-area.tsx +26 -39
  97. package/lib/runtime/components/react/mpx-movable-view.tsx +455 -337
  98. package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
  99. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  100. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  101. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  102. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  103. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  104. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  105. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  106. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  107. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  108. package/lib/runtime/components/react/mpx-radio-group.tsx +77 -54
  109. package/lib/runtime/components/react/mpx-radio.tsx +46 -55
  110. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  111. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  112. package/lib/runtime/components/react/mpx-root-portal.tsx +4 -6
  113. package/lib/runtime/components/react/mpx-scroll-view.tsx +122 -76
  114. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  115. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +6 -4
  116. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  117. package/lib/runtime/components/react/mpx-swiper-item.tsx +4 -3
  118. package/lib/runtime/components/react/mpx-switch.tsx +39 -25
  119. package/lib/runtime/components/react/mpx-text.tsx +15 -19
  120. package/lib/runtime/components/react/mpx-textarea.tsx +12 -11
  121. package/lib/runtime/components/react/mpx-view.tsx +93 -77
  122. package/lib/runtime/components/react/mpx-web-view.tsx +117 -55
  123. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  124. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  125. package/lib/runtime/components/react/types/common.ts +2 -0
  126. package/lib/runtime/components/react/types/global.d.ts +5 -17
  127. package/lib/runtime/components/react/useAnimationHooks.ts +127 -18
  128. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  129. package/lib/runtime/components/react/utils.tsx +113 -27
  130. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  131. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  132. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  133. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  134. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  135. package/lib/runtime/optionProcessor.js +7 -38
  136. package/lib/runtime/optionProcessorReact.js +0 -15
  137. package/lib/runtime/swanHelper.wxs +1 -1
  138. package/lib/runtime/utils.js +2 -0
  139. package/lib/style-compiler/index.js +1 -1
  140. package/lib/style-compiler/plugins/scope-id.js +31 -2
  141. package/lib/template-compiler/bind-this.js +7 -2
  142. package/lib/template-compiler/compiler.js +118 -56
  143. package/lib/template-compiler/gen-node-react.js +3 -3
  144. package/lib/template-compiler/index.js +4 -4
  145. package/lib/utils/pre-process-json.js +117 -0
  146. package/lib/web/index.js +5 -4
  147. package/lib/web/processJSON.js +5 -13
  148. package/lib/web/processTemplate.js +2 -2
  149. package/package.json +6 -4
  150. package/LICENSE +0 -433
  151. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  152. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  153. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  154. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  155. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  156. package/lib/runtime/components/react/mpx-image/index.tsx +0 -346
  157. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  158. package/lib/runtime/components/web/event.js +0 -105
@@ -0,0 +1,40 @@
1
+
2
+ export const generateHTML = (html: string) => {
3
+ return `<html><head>
4
+ <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no" name="viewport">
5
+ <style>
6
+ html {
7
+ -ms-content-zooming: none;
8
+ -ms-touch-action: pan-x pan-y;
9
+ }
10
+ body {
11
+ position: fixed;
12
+ top: 0;
13
+ right: 0;
14
+ bottom: 0;
15
+ left: 0;
16
+ overflow: hidden;
17
+ }
18
+ html,body {
19
+ margin: 0;
20
+ padding: 0;
21
+ }
22
+ * {
23
+ user-select: none;
24
+ -ms-user-select: none;
25
+ -moz-user-select: none;
26
+ -webkit-user-select: none;
27
+ }
28
+ </style>
29
+ </head>
30
+ <body><div id="rich-text">${html}</div>
31
+ <script>
32
+ function sendHeight() {
33
+ const dom = document.getElementById('rich-text')
34
+ window.ReactNativeWebView.postMessage(dom.scrollHeight);
35
+ }
36
+ window.onload = sendHeight;
37
+ </script>
38
+ </body
39
+ ></html>`
40
+ }
@@ -0,0 +1,121 @@
1
+
2
+ /**
3
+ * ✔ nodes
4
+ */
5
+ import { View, ViewProps, ViewStyle } from 'react-native'
6
+ import { useRef, forwardRef, JSX, useState } from 'react'
7
+ import useInnerProps from '../getInnerListeners'
8
+ import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
9
+ import { useTransformStyle, useLayout } 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, {
95
+ ref: nodeRef,
96
+ style: { ...normalStyle, ...layoutStyle },
97
+ ...layoutProps
98
+ }, [], {
99
+ layoutRef
100
+ })
101
+
102
+ const html: string = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes)
103
+
104
+ return (
105
+ <View
106
+ {...innerProps}
107
+ >
108
+ <WebView
109
+ source={{ html: generateHTML(html) }}
110
+ onMessage={(event: WebViewMessageEvent) => {
111
+ setWebViewHeight(+event.nativeEvent.data)
112
+ }}
113
+ >
114
+ </WebView>
115
+ </View>
116
+ )
117
+ })
118
+
119
+ _RichText.displayName = 'mpx-rich-text'
120
+
121
+ 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,12 +16,10 @@ 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
- _RootPortal.displayName = 'mpx-root-portal'
23
+ _RootPortal.displayName = 'MpxRootPortal'
26
24
 
27
25
  export default _RootPortal
@@ -5,7 +5,7 @@
5
5
  * ✔ lower-threshold
6
6
  * ✔ scroll-top
7
7
  * ✔ scroll-left
8
- * scroll-into-view
8
+ * scroll-into-view
9
9
  * ✔ scroll-with-animation
10
10
  * ✔ enable-back-to-top
11
11
  * ✘ enable-passive
@@ -33,12 +33,12 @@
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 } 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 } from './utils'
41
+ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler } from './utils'
42
42
  import { IntersectionObserverContext } from './context'
43
43
 
44
44
  interface ScrollViewProps {
@@ -61,12 +61,15 @@ interface ScrollViewProps {
61
61
  'scroll-top'?: number;
62
62
  'scroll-left'?: number;
63
63
  'enable-offset'?: boolean;
64
+ 'scroll-into-view'?: string;
64
65
  'enable-trigger-intersection-observer'?: boolean;
65
66
  'enable-var'?: boolean;
66
67
  'external-var-context'?: Record<string, any>;
67
68
  'parent-font-size'?: number;
68
69
  'parent-width'?: number;
69
70
  'parent-height'?: number;
71
+ 'wait-for'?: Array<GestureHandler>;
72
+ 'simultaneous-handlers'?: Array<GestureHandler>;
70
73
  bindscrolltoupper?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
71
74
  bindscrolltolower?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
72
75
  bindscroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
@@ -78,6 +81,7 @@ interface ScrollViewProps {
78
81
  bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
79
82
  bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
80
83
  bindscrollend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
84
+ __selectRef?: (selector: string, nodeType: 'node' | 'component', all?: boolean) => HandlerRef<any, any>
81
85
  }
82
86
  type ScrollAdditionalProps = {
83
87
  pinchGestureEnabled: boolean;
@@ -97,6 +101,7 @@ type ScrollAdditionalProps = {
97
101
  bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
98
102
  bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
99
103
  bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
104
+ onScrollBeginDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
100
105
  onScrollEndDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
101
106
  onMomentumScrollEnd?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
102
107
  };
@@ -106,6 +111,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
106
111
  enhanced = false,
107
112
  bounces = true,
108
113
  style = {},
114
+ binddragstart,
115
+ binddragging,
116
+ binddragend,
117
+ bindtouchstart,
118
+ bindtouchmove,
119
+ bindtouchend,
109
120
  'scroll-x': scrollX = false,
110
121
  'scroll-y': scrollY = false,
111
122
  'enable-back-to-top': enableBackToTop = false,
@@ -118,13 +129,23 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
118
129
  'refresher-default-style': refresherDefaultStyle,
119
130
  'refresher-background': refresherBackground,
120
131
  'show-scrollbar': showScrollbar = true,
132
+ 'scroll-into-view': scrollIntoView = '',
133
+ 'scroll-top': scrollTop = 0,
134
+ 'scroll-left': scrollLeft = 0,
135
+ 'refresher-triggered': refresherTriggered,
121
136
  'enable-var': enableVar,
122
137
  'external-var-context': externalVarContext,
123
138
  'parent-font-size': parentFontSize,
124
139
  'parent-width': parentWidth,
125
- 'parent-height': parentHeight
140
+ 'parent-height': parentHeight,
141
+ 'simultaneous-handlers': originSimultaneousHandlers,
142
+ 'wait-for': waitFor,
143
+ __selectRef
126
144
  } = props
127
145
 
146
+ const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
147
+ const waitForHandlers = flatGesture(waitFor)
148
+
128
149
  const [refreshing, setRefreshing] = useState(true)
129
150
 
130
151
  const snapScrollTop = useRef(0)
@@ -144,6 +165,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
144
165
  const initialTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
145
166
  const intersectionObservers = useContext(IntersectionObserverContext)
146
167
 
168
+ const firstScrollIntoViewChange = useRef<boolean>(false)
169
+
147
170
  const {
148
171
  normalStyle,
149
172
  hasVarDec,
@@ -153,10 +176,11 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
153
176
  setHeight
154
177
  } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
155
178
 
156
- const { textStyle, innerStyle } = splitStyle(normalStyle)
179
+ const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
157
180
 
158
181
  const scrollViewRef = useAnimatedRef<ScrollView>()
159
182
  useNodesRef(props, ref, scrollViewRef, {
183
+ style: normalStyle,
160
184
  scrollOffset: scrollOptions,
161
185
  node: {
162
186
  scrollEnabled: scrollX || scrollY,
@@ -166,7 +190,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
166
190
  fastDeceleration: false,
167
191
  decelerationDisabled: false,
168
192
  scrollTo: scrollToOffset
169
- }
193
+ },
194
+ gestureRef: scrollViewRef
170
195
  })
171
196
 
172
197
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
@@ -176,27 +201,46 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
176
201
  }
177
202
  useEffect(() => {
178
203
  if (
179
- snapScrollTop.current !== props['scroll-top'] ||
180
- snapScrollLeft.current !== props['scroll-left']
204
+ snapScrollTop.current !== scrollTop || snapScrollLeft.current !== scrollLeft
181
205
  ) {
182
- snapScrollTop.current = props['scroll-top'] || 0
183
- snapScrollLeft.current = props['scroll-left'] || 0
184
-
185
206
  initialTimeout.current = setTimeout(() => {
186
- scrollToOffset(snapScrollLeft.current, snapScrollTop.current)
207
+ scrollToOffset(scrollLeft, scrollTop)
187
208
  }, 0)
188
209
 
189
210
  return () => {
190
211
  initialTimeout.current && clearTimeout(initialTimeout.current)
191
212
  }
192
213
  }
193
- }, [props['scroll-top'], props['scroll-left']])
214
+ }, [scrollTop, scrollLeft])
215
+
216
+ useEffect(() => {
217
+ if (refreshing !== refresherTriggered) {
218
+ setRefreshing(!!refresherTriggered)
219
+ }
220
+ }, [refresherTriggered])
194
221
 
195
222
  useEffect(() => {
196
- if (refreshing !== props['refresher-triggered']) {
197
- setRefreshing(!!props['refresher-triggered'])
223
+ if (scrollIntoView && __selectRef) {
224
+ if (!firstScrollIntoViewChange.current) {
225
+ setTimeout(handleScrollIntoView)
226
+ } else {
227
+ handleScrollIntoView()
228
+ }
198
229
  }
199
- }, [props['refresher-triggered']])
230
+ firstScrollIntoViewChange.current = true
231
+ }, [scrollIntoView])
232
+
233
+ function handleScrollIntoView () {
234
+ const refs = __selectRef!(`#${scrollIntoView}`, 'node')
235
+ if (!refs) return
236
+ const { nodeRef } = refs.getNodeInstance()
237
+ nodeRef.current?.measureLayout(
238
+ scrollViewRef.current,
239
+ (left: number, top:number) => {
240
+ scrollToOffset(left, top)
241
+ }
242
+ )
243
+ }
200
244
 
201
245
  function selectLength (size: { height: number; width: number }) {
202
246
  return !scrollX ? size.height : size.width
@@ -260,14 +304,13 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
260
304
  const visibleLength = selectLength(e.nativeEvent.layoutMeasurement)
261
305
  const contentLength = selectLength(e.nativeEvent.contentSize)
262
306
  const offset = selectOffset(e.nativeEvent.contentOffset)
263
- scrollOptions.current = {
264
- ...scrollOptions.current,
307
+ extendObject(scrollOptions.current, {
265
308
  contentLength,
266
309
  offset,
267
310
  scrollLeft: position.scrollLeft,
268
311
  scrollTop: position.scrollTop,
269
312
  visibleLength
270
- }
313
+ })
271
314
  }
272
315
 
273
316
  function onScroll (e: NativeSyntheticEvent<NativeScrollEvent>) {
@@ -322,6 +365,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
322
365
  scrollViewRef.current.scrollTo({ x, y, animated: !!scrollWithAnimation })
323
366
  scrollOptions.current.scrollLeft = x
324
367
  scrollOptions.current.scrollTop = y
368
+ snapScrollLeft.current = x
369
+ snapScrollTop.current = y
325
370
  }
326
371
  }
327
372
 
@@ -334,7 +379,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
334
379
  }
335
380
 
336
381
  function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
337
- const { binddragstart, bindtouchstart, enhanced } = props
382
+ const { bindtouchstart } = props
338
383
  bindtouchstart && bindtouchstart(e)
339
384
  if (enhanced) {
340
385
  binddragstart &&
@@ -350,7 +395,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
350
395
  }
351
396
  }
352
397
  function onScrollTouchMove (e: NativeSyntheticEvent<TouchEvent>) {
353
- const { binddragging, bindtouchmove, enhanced } = props
354
398
  bindtouchmove && bindtouchmove(e)
355
399
  if (enhanced) {
356
400
  binddragging &&
@@ -366,53 +410,61 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
366
410
  }
367
411
  }
368
412
 
369
- function onScrollEndDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
370
- const { binddragend, enhanced } = props
413
+ function onScrollTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
414
+ bindtouchend && bindtouchend(e)
371
415
  if (enhanced) {
372
- const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
373
- const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize
374
416
  binddragend &&
375
417
  binddragend(
376
418
  getCustomEvent('dragend', e, {
377
419
  detail: {
378
- scrollLeft: scrollLeft,
379
- scrollTop: scrollTop,
380
- scrollHeight,
381
- scrollWidth
420
+ scrollLeft: scrollOptions.current.scrollLeft || 0,
421
+ scrollTop: scrollOptions.current.scrollTop || 0
382
422
  },
383
423
  layoutRef
384
424
  }, props)
385
425
  )
386
- updateScrollOptions(e, { scrollLeft, scrollTop })
387
426
  }
388
427
  }
389
428
 
390
- let scrollAdditionalProps: ScrollAdditionalProps = {
391
- style: { ...innerStyle, ...layoutStyle },
392
- pinchGestureEnabled: false,
393
- horizontal: scrollX && !scrollY,
394
- scrollEventThrottle: scrollEventThrottle,
395
- scrollsToTop: enableBackToTop,
396
- showsHorizontalScrollIndicator: scrollX && showScrollbar,
397
- showsVerticalScrollIndicator: scrollY && showScrollbar,
398
- scrollEnabled: scrollX || scrollY,
399
- ref: scrollViewRef,
400
- onScroll: onScroll,
401
- onContentSizeChange: onContentSizeChange,
402
- bindtouchstart: onScrollTouchStart,
403
- bindtouchmove: onScrollTouchMove,
404
- onScrollEndDrag,
405
- onMomentumScrollEnd: onScrollEnd,
406
- ...layoutProps
429
+ function onScrollDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
430
+ const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
431
+ updateScrollOptions(e, { scrollLeft, scrollTop })
407
432
  }
433
+
434
+ const scrollAdditionalProps: ScrollAdditionalProps = extendObject(
435
+ {
436
+ style: extendObject({}, innerStyle, layoutStyle),
437
+ pinchGestureEnabled: false,
438
+ horizontal: scrollX && !scrollY,
439
+ scrollEventThrottle: scrollEventThrottle,
440
+ scrollsToTop: enableBackToTop,
441
+ showsHorizontalScrollIndicator: scrollX && showScrollbar,
442
+ showsVerticalScrollIndicator: scrollY && showScrollbar,
443
+ scrollEnabled: scrollX || scrollY,
444
+ ref: scrollViewRef,
445
+ onScroll: onScroll,
446
+ onContentSizeChange: onContentSizeChange,
447
+ bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
448
+ bindtouchmove: ((enhanced && binddragging) || bindtouchend) && onScrollTouchMove,
449
+ bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
450
+ onScrollBeginDrag: onScrollDrag,
451
+ onScrollEndDrag: onScrollDrag,
452
+ onMomentumScrollEnd: onScrollEnd
453
+ },
454
+ (simultaneousHandlers ? { simultaneousHandlers } : {}),
455
+ (waitForHandlers ? { waitFor: waitForHandlers } : {}),
456
+ layoutProps
457
+ )
458
+
408
459
  if (enhanced) {
409
- scrollAdditionalProps = {
410
- ...scrollAdditionalProps,
460
+ Object.assign(scrollAdditionalProps, {
411
461
  bounces,
412
462
  pagingEnabled
413
- }
463
+ })
414
464
  }
465
+
415
466
  const innerProps = useInnerProps(props, scrollAdditionalProps, [
467
+ 'id',
416
468
  'scroll-x',
417
469
  'scroll-y',
418
470
  'enable-back-to-top',
@@ -444,35 +496,29 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
444
496
  white: ['#fff']
445
497
  }
446
498
 
447
- return (
448
- <ScrollView
449
- {...innerProps}
450
- refreshControl={refresherEnabled
451
- ? (
452
- <RefreshControl
453
- progressBackgroundColor={refresherBackground}
454
- refreshing={refreshing}
455
- onRefresh={onRefresh}
456
- {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}
457
- />
458
- )
459
- : undefined}
460
- >
461
- {
462
- wrapChildren(
463
- props,
464
- {
465
- hasVarDec,
466
- varContext: varContextRef.current,
467
- textStyle,
468
- textProps
469
- }
470
- )
499
+ return createElement(
500
+ ScrollView,
501
+ extendObject({}, innerProps, {
502
+ refreshControl: refresherEnabled
503
+ ? createElement(RefreshControl, extendObject({
504
+ progressBackgroundColor: refresherBackground,
505
+ refreshing: refreshing,
506
+ onRefresh: onRefresh
507
+ }, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
508
+ : undefined
509
+ }),
510
+ wrapChildren(
511
+ props,
512
+ {
513
+ hasVarDec,
514
+ varContext: varContextRef.current,
515
+ textStyle,
516
+ textProps
471
517
  }
472
- </ScrollView>
518
+ )
473
519
  )
474
520
  })
475
521
 
476
- _ScrollView.displayName = 'mpx-scroll-view'
522
+ _ScrollView.displayName = 'MpxScrollView'
477
523
 
478
524
  export default _ScrollView
@@ -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
@@ -57,7 +57,7 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
57
57
  parentWidth,
58
58
  parentHeight
59
59
  } = props
60
- // 计算transfrom之类的
60
+ // 计算transform之类的
61
61
  const {
62
62
  normalStyle,
63
63
  hasVarDec,
@@ -92,7 +92,9 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
92
92
  // 内部存储上一次的offset值
93
93
  const autoplayTimerRef = useRef<ReturnType <typeof setTimeout> | null>(null)
94
94
  const scrollViewRef = useRef<ScrollView & View>(null)
95
- useNodesRef<ScrollView & View, CarouseProps>(props, ref, scrollViewRef, {})
95
+ useNodesRef<ScrollView & View, CarouseProps>(props, ref, scrollViewRef, {
96
+ style: normalStyle
97
+ })
96
98
  const {
97
99
  // 存储layout布局信息
98
100
  layoutRef,
@@ -488,7 +490,7 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
488
490
  } else if (i === pages.length - 1 && typeof width === 'number') {
489
491
  nextMargin && (extraStyle.marginRight = nextMargin)
490
492
  }
491
- return (<View style={[pageStyle, styles.slide, extraStyle]} key={ 'page' + i}>
493
+ return (<View style={[pageStyle, styles.slide, extraStyle]} key={'page' + i}>
492
494
  {wrapChildren(
493
495
  {
494
496
  children: children[+page]
@@ -520,6 +522,6 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
520
522
  </View>)
521
523
  })
522
524
 
523
- _Carouse.displayName = '_Carouse'
525
+ _Carouse.displayName = 'MpxCarouse'
524
526
 
525
527
  export default _Carouse
@@ -74,6 +74,7 @@ const _SwiperWrapper = forwardRef<HandlerRef<ScrollView, SwiperProps>, SwiperPro
74
74
  {children}
75
75
  </Carouse>
76
76
  })
77
- _SwiperWrapper.displayName = 'mpx-swiper'
77
+
78
+ _SwiperWrapper.displayName = 'MpxSwiper'
78
79
 
79
80
  export default _SwiperWrapper
@@ -18,7 +18,6 @@ interface SwiperItemProps {
18
18
 
19
19
  const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
20
20
  const {
21
- 'enable-offset': enableOffset,
22
21
  'enable-var': enableVar,
23
22
  'external-var-context': externalVarContext,
24
23
  style
@@ -26,7 +25,6 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
26
25
 
27
26
  const { textProps } = splitProps(props)
28
27
  const nodeRef = useRef(null)
29
- useNodesRef(props, ref, nodeRef, {})
30
28
 
31
29
  const {
32
30
  normalStyle,
@@ -37,6 +35,9 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
37
35
  setHeight
38
36
  } = useTransformStyle(style, { enableVar, externalVarContext })
39
37
  const { textStyle, innerStyle } = splitStyle(normalStyle)
38
+ useNodesRef(props, ref, nodeRef, {
39
+ style: normalStyle
40
+ })
40
41
 
41
42
  const {
42
43
  // 存储layout布局信息
@@ -73,6 +74,6 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
73
74
  )
74
75
  })
75
76
 
76
- _SwiperItem.displayName = 'mpx-swiper-item'
77
+ _SwiperItem.displayName = 'MpxSwiperItem'
77
78
 
78
79
  export default _SwiperItem