@mpxjs/webpack-plugin 2.9.59 → 2.9.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -3
- package/lib/platform/style/wx/index.js +344 -270
- package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
- package/lib/platform/template/wx/component-config/checkbox.js +8 -0
- package/lib/platform/template/wx/component-config/cover-image.js +15 -0
- package/lib/platform/template/wx/component-config/cover-view.js +9 -0
- package/lib/platform/template/wx/component-config/form.js +13 -1
- package/lib/platform/template/wx/component-config/icon.js +8 -0
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/label.js +15 -0
- package/lib/platform/template/wx/component-config/movable-area.js +18 -1
- package/lib/platform/template/wx/component-config/movable-view.js +18 -1
- package/lib/platform/template/wx/component-config/navigator.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view.js +18 -2
- package/lib/platform/template/wx/component-config/picker.js +14 -1
- package/lib/platform/template/wx/component-config/radio-group.js +8 -0
- package/lib/platform/template/wx/component-config/radio.js +8 -0
- package/lib/platform/template/wx/component-config/root-portal.js +15 -0
- package/lib/platform/template/wx/component-config/switch.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -3
- package/lib/react/processScript.js +2 -0
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +12 -7
- package/lib/runtime/components/react/context.ts +40 -0
- package/lib/runtime/components/react/dist/context.js +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
- package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
- package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
- package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
- package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/types/common.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
- package/lib/runtime/components/react/dist/utils.jsx +433 -0
- package/lib/runtime/components/react/getInnerListeners.ts +43 -21
- package/lib/runtime/components/react/mpx-button.tsx +129 -119
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
- package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
- package/lib/runtime/components/react/mpx-form.tsx +117 -0
- package/lib/runtime/components/react/mpx-icon.tsx +106 -0
- package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
- package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
- package/lib/runtime/components/react/mpx-input.tsx +90 -42
- package/lib/runtime/components/react/mpx-label.tsx +110 -0
- package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
- package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
- package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
- package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
- package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
- package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
- package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
- package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
- package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
- package/lib/runtime/components/react/mpx-radio.tsx +230 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
- package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
- package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
- package/lib/runtime/components/react/mpx-switch.tsx +148 -0
- package/lib/runtime/components/react/mpx-text.tsx +53 -77
- package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
- package/lib/runtime/components/react/mpx-view.tsx +576 -195
- package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +12 -0
- package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
- package/lib/runtime/components/react/types/global.d.ts +17 -1
- package/lib/runtime/components/react/useNodesRef.ts +4 -10
- package/lib/runtime/components/react/utils.tsx +505 -0
- package/lib/runtime/optionProcessor.js +19 -17
- package/lib/template-compiler/compiler.js +84 -61
- package/lib/template-compiler/gen-node-react.js +7 -9
- package/lib/web/processStyles.js +2 -5
- package/package.json +8 -3
- package/lib/runtime/components/react/dist/utils.js +0 -80
- package/lib/runtime/components/react/utils.ts +0 -92
|
@@ -31,14 +31,16 @@
|
|
|
31
31
|
* ✔ bindscrolltolower
|
|
32
32
|
* ✔ bindscroll
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
import { View,
|
|
36
|
-
import
|
|
37
|
-
import
|
|
34
|
+
import { ScrollView } from 'react-native-gesture-handler'
|
|
35
|
+
import { View, RefreshControl, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
|
|
36
|
+
import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef } from 'react'
|
|
37
|
+
import { warn } from '@mpxjs/utils'
|
|
38
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
38
39
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
40
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren } from './utils'
|
|
39
41
|
|
|
40
42
|
interface ScrollViewProps {
|
|
41
|
-
children?:
|
|
43
|
+
children?: ReactNode;
|
|
42
44
|
enhanced?: boolean;
|
|
43
45
|
bounces?: boolean;
|
|
44
46
|
style?: ViewStyle;
|
|
@@ -57,6 +59,11 @@ interface ScrollViewProps {
|
|
|
57
59
|
'scroll-top'?: number;
|
|
58
60
|
'scroll-left'?: number;
|
|
59
61
|
'enable-offset'?: boolean;
|
|
62
|
+
'enable-var'?: boolean;
|
|
63
|
+
'external-var-context'?: Record<string, any>;
|
|
64
|
+
'parent-font-size'?: number;
|
|
65
|
+
'parent-width'?: number;
|
|
66
|
+
'parent-height'?: number;
|
|
60
67
|
bindscrolltoupper?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
61
68
|
bindscrolltolower?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
62
69
|
bindscroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
@@ -67,6 +74,7 @@ interface ScrollViewProps {
|
|
|
67
74
|
bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
68
75
|
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
69
76
|
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
77
|
+
bindscrollend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
70
78
|
}
|
|
71
79
|
type ScrollAdditionalProps = {
|
|
72
80
|
pinchGestureEnabled: boolean;
|
|
@@ -79,19 +87,22 @@ type ScrollAdditionalProps = {
|
|
|
79
87
|
showsHorizontalScrollIndicator: boolean;
|
|
80
88
|
showsVerticalScrollIndicator: boolean;
|
|
81
89
|
scrollEnabled: boolean;
|
|
82
|
-
ref:
|
|
90
|
+
ref: RefObject<ScrollView>;
|
|
83
91
|
bounces?: boolean;
|
|
84
92
|
pagingEnabled?: boolean;
|
|
85
93
|
style?: ViewStyle;
|
|
86
94
|
bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
87
95
|
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
88
96
|
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
97
|
+
onScrollEndDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
98
|
+
onMomentumScrollEnd?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
89
99
|
};
|
|
90
|
-
const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, ScrollViewProps>((
|
|
100
|
+
const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, ScrollViewProps>((scrollViewProps: ScrollViewProps = {}, ref): JSX.Element => {
|
|
101
|
+
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps)
|
|
91
102
|
const {
|
|
92
|
-
children,
|
|
93
103
|
enhanced = false,
|
|
94
104
|
bounces = true,
|
|
105
|
+
style = {},
|
|
95
106
|
'scroll-x': scrollX = false,
|
|
96
107
|
'scroll-y': scrollY = false,
|
|
97
108
|
'enable-back-to-top': enableBackToTop = false,
|
|
@@ -102,31 +113,47 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
102
113
|
'refresher-enabled': refresherEnabled,
|
|
103
114
|
'refresher-default-style': refresherDefaultStyle,
|
|
104
115
|
'refresher-background': refresherBackground,
|
|
105
|
-
'
|
|
106
|
-
'
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
'show-scrollbar': showScrollbar = true,
|
|
117
|
+
'enable-var': enableVar,
|
|
118
|
+
'external-var-context': externalVarContext,
|
|
119
|
+
'parent-font-size': parentFontSize,
|
|
120
|
+
'parent-width': parentWidth,
|
|
121
|
+
'parent-height': parentHeight
|
|
122
|
+
} = props
|
|
123
|
+
|
|
124
|
+
const [refreshing, setRefreshing] = useState(true)
|
|
125
|
+
|
|
126
|
+
const snapScrollTop = useRef(0)
|
|
127
|
+
const snapScrollLeft = useRef(0)
|
|
128
|
+
|
|
113
129
|
const scrollOptions = useRef({
|
|
114
130
|
contentLength: 0,
|
|
115
131
|
offset: 0,
|
|
116
132
|
scrollLeft: 0,
|
|
117
133
|
scrollTop: 0,
|
|
118
|
-
visibleLength: 0
|
|
119
|
-
})
|
|
134
|
+
visibleLength: 0
|
|
135
|
+
})
|
|
120
136
|
|
|
121
|
-
const scrollEventThrottle = 50
|
|
122
|
-
const hasCallScrollToUpper = useRef(true)
|
|
123
|
-
const hasCallScrollToLower = useRef(false)
|
|
137
|
+
const scrollEventThrottle = 50
|
|
138
|
+
const hasCallScrollToUpper = useRef(true)
|
|
139
|
+
const hasCallScrollToLower = useRef(false)
|
|
124
140
|
const initialTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
125
141
|
|
|
142
|
+
const {
|
|
143
|
+
normalStyle,
|
|
144
|
+
hasVarDec,
|
|
145
|
+
varContextRef,
|
|
146
|
+
hasSelfPercent,
|
|
147
|
+
setWidth,
|
|
148
|
+
setHeight
|
|
149
|
+
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
150
|
+
|
|
151
|
+
const { textStyle, innerStyle } = splitStyle(normalStyle)
|
|
152
|
+
|
|
126
153
|
const { nodeRef: scrollViewRef } = useNodesRef(props, ref, {
|
|
127
154
|
scrollOffset: scrollOptions,
|
|
128
155
|
node: {
|
|
129
|
-
scrollEnabled,
|
|
156
|
+
scrollEnabled: scrollX || scrollY,
|
|
130
157
|
bounces,
|
|
131
158
|
showScrollbar,
|
|
132
159
|
pagingEnabled,
|
|
@@ -136,107 +163,110 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
136
163
|
}
|
|
137
164
|
})
|
|
138
165
|
|
|
166
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
|
|
167
|
+
|
|
168
|
+
if (scrollX && scrollY) {
|
|
169
|
+
warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion')
|
|
170
|
+
}
|
|
139
171
|
useEffect(() => {
|
|
140
172
|
if (
|
|
141
|
-
snapScrollTop !== props['scroll-top'] ||
|
|
142
|
-
snapScrollLeft !== props['scroll-left']
|
|
173
|
+
snapScrollTop.current !== props['scroll-top'] ||
|
|
174
|
+
snapScrollLeft.current !== props['scroll-left']
|
|
143
175
|
) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
}, [props['scroll-top'], props['scroll-left']]);
|
|
176
|
+
snapScrollTop.current = props['scroll-top'] || 0
|
|
177
|
+
snapScrollLeft.current = props['scroll-left'] || 0
|
|
148
178
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
}, [props['refresher-triggered']]);
|
|
179
|
+
initialTimeout.current = setTimeout(() => {
|
|
180
|
+
scrollToOffset(snapScrollLeft.current, snapScrollTop.current)
|
|
181
|
+
}, 0)
|
|
154
182
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
} else {
|
|
159
|
-
setScrollEnabled(true);
|
|
183
|
+
return () => {
|
|
184
|
+
initialTimeout.current && clearTimeout(initialTimeout.current)
|
|
185
|
+
}
|
|
160
186
|
}
|
|
161
|
-
}, [props['scroll-
|
|
187
|
+
}, [props['scroll-top'], props['scroll-left']])
|
|
162
188
|
|
|
163
189
|
useEffect(() => {
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
scrollToOffset(snapScrollLeft, snapScrollTop);
|
|
167
|
-
}, 0);
|
|
190
|
+
if (refreshing !== props['refresher-triggered']) {
|
|
191
|
+
setRefreshing(!!props['refresher-triggered'])
|
|
168
192
|
}
|
|
193
|
+
}, [props['refresher-triggered']])
|
|
169
194
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
};
|
|
173
|
-
}, [snapScrollTop, snapScrollLeft]);
|
|
174
|
-
|
|
175
|
-
function selectLength(size: { height: number; width: number }) {
|
|
176
|
-
return !scrollX ? size.height : size.width;
|
|
195
|
+
function selectLength (size: { height: number; width: number }) {
|
|
196
|
+
return !scrollX ? size.height : size.width
|
|
177
197
|
}
|
|
178
198
|
|
|
179
|
-
function selectOffset(position: { x: number; y: number }) {
|
|
180
|
-
return !scrollX ? position.y : position.x
|
|
199
|
+
function selectOffset (position: { x: number; y: number }) {
|
|
200
|
+
return !scrollX ? position.y : position.x
|
|
181
201
|
}
|
|
182
202
|
|
|
183
|
-
function onStartReached(e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
184
|
-
const { bindscrolltoupper } = props
|
|
185
|
-
const { offset } = scrollOptions.current
|
|
203
|
+
function onStartReached (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
204
|
+
const { bindscrolltoupper } = props
|
|
205
|
+
const { offset } = scrollOptions.current
|
|
186
206
|
if (bindscrolltoupper && (offset <= upperThreshold)) {
|
|
187
207
|
if (!hasCallScrollToUpper.current) {
|
|
188
208
|
bindscrolltoupper(
|
|
189
209
|
getCustomEvent('scrolltoupper', e, {
|
|
190
210
|
detail: {
|
|
191
|
-
direction: scrollX ? 'left' : 'top'
|
|
211
|
+
direction: scrollX ? 'left' : 'top'
|
|
192
212
|
},
|
|
193
213
|
layoutRef
|
|
194
|
-
}, props)
|
|
195
|
-
)
|
|
196
|
-
hasCallScrollToUpper.current = true
|
|
214
|
+
}, props)
|
|
215
|
+
)
|
|
216
|
+
hasCallScrollToUpper.current = true
|
|
197
217
|
}
|
|
198
218
|
} else {
|
|
199
|
-
hasCallScrollToUpper.current = false
|
|
219
|
+
hasCallScrollToUpper.current = false
|
|
200
220
|
}
|
|
201
221
|
}
|
|
202
222
|
|
|
203
|
-
function onEndReached(e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
204
|
-
const { bindscrolltolower } = props
|
|
205
|
-
const { contentLength, visibleLength, offset } = scrollOptions.current
|
|
206
|
-
const distanceFromEnd = contentLength - visibleLength - offset
|
|
223
|
+
function onEndReached (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
224
|
+
const { bindscrolltolower } = props
|
|
225
|
+
const { contentLength, visibleLength, offset } = scrollOptions.current
|
|
226
|
+
const distanceFromEnd = contentLength - visibleLength - offset
|
|
207
227
|
if (bindscrolltolower && (distanceFromEnd < lowerThreshold)) {
|
|
208
228
|
if (!hasCallScrollToLower.current) {
|
|
209
|
-
hasCallScrollToLower.current = true
|
|
229
|
+
hasCallScrollToLower.current = true
|
|
210
230
|
bindscrolltolower(
|
|
211
231
|
getCustomEvent('scrolltolower', e, {
|
|
212
232
|
detail: {
|
|
213
|
-
direction: scrollX ? 'right' : 'botttom'
|
|
233
|
+
direction: scrollX ? 'right' : 'botttom'
|
|
214
234
|
},
|
|
215
235
|
layoutRef
|
|
216
|
-
}, props)
|
|
217
|
-
)
|
|
236
|
+
}, props)
|
|
237
|
+
)
|
|
218
238
|
}
|
|
219
239
|
} else {
|
|
220
|
-
hasCallScrollToLower.current = false
|
|
240
|
+
hasCallScrollToLower.current = false
|
|
221
241
|
}
|
|
222
242
|
}
|
|
223
243
|
|
|
224
|
-
function onContentSizeChange(width: number, height: number) {
|
|
225
|
-
scrollOptions.current.contentLength = selectLength({ height, width })
|
|
244
|
+
function onContentSizeChange (width: number, height: number) {
|
|
245
|
+
scrollOptions.current.contentLength = selectLength({ height, width })
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function onLayout (e: LayoutChangeEvent) {
|
|
249
|
+
const layout = e.nativeEvent.layout || {}
|
|
250
|
+
scrollOptions.current.visibleLength = selectLength(layout)
|
|
226
251
|
}
|
|
227
252
|
|
|
228
|
-
function
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
253
|
+
function updateScrollOptions (e: NativeSyntheticEvent<NativeScrollEvent>, position: Record<string, any>) {
|
|
254
|
+
const visibleLength = selectLength(e.nativeEvent.layoutMeasurement)
|
|
255
|
+
const contentLength = selectLength(e.nativeEvent.contentSize)
|
|
256
|
+
const offset = selectOffset(e.nativeEvent.contentOffset)
|
|
257
|
+
scrollOptions.current = {
|
|
258
|
+
...scrollOptions.current,
|
|
259
|
+
contentLength,
|
|
260
|
+
offset,
|
|
261
|
+
scrollLeft: position.scrollLeft,
|
|
262
|
+
scrollTop: position.scrollTop,
|
|
263
|
+
visibleLength
|
|
234
264
|
}
|
|
235
265
|
}
|
|
236
266
|
|
|
237
|
-
function onScroll(e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
238
|
-
const { bindscroll } = props
|
|
239
|
-
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
267
|
+
function onScroll (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
268
|
+
const { bindscroll } = props
|
|
269
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
240
270
|
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize
|
|
241
271
|
bindscroll &&
|
|
242
272
|
bindscroll(
|
|
@@ -247,62 +277,69 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
247
277
|
scrollHeight,
|
|
248
278
|
scrollWidth,
|
|
249
279
|
deltaX: scrollLeft - scrollOptions.current.scrollLeft,
|
|
250
|
-
deltaY: scrollTop - scrollOptions.current.scrollTop
|
|
280
|
+
deltaY: scrollTop - scrollOptions.current.scrollTop
|
|
251
281
|
},
|
|
252
282
|
layoutRef
|
|
253
283
|
}, props)
|
|
254
|
-
)
|
|
284
|
+
)
|
|
285
|
+
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
286
|
+
}
|
|
255
287
|
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
288
|
+
function onScrollEnd (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
289
|
+
const { bindscrollend } = props
|
|
290
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
291
|
+
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize
|
|
292
|
+
bindscrollend &&
|
|
293
|
+
bindscrollend(
|
|
294
|
+
getCustomEvent('scrollend', e, {
|
|
295
|
+
detail: {
|
|
296
|
+
scrollLeft,
|
|
297
|
+
scrollTop,
|
|
298
|
+
scrollHeight,
|
|
299
|
+
scrollWidth
|
|
300
|
+
},
|
|
301
|
+
layoutRef
|
|
302
|
+
}, props)
|
|
303
|
+
)
|
|
304
|
+
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
305
|
+
onStartReached(e)
|
|
306
|
+
onEndReached(e)
|
|
269
307
|
}
|
|
270
308
|
|
|
271
|
-
function scrollToOffset(x = 0, y = 0) {
|
|
309
|
+
function scrollToOffset (x = 0, y = 0) {
|
|
272
310
|
if (scrollViewRef.current) {
|
|
273
|
-
scrollViewRef.current.scrollTo({ x, y, animated: !!scrollWithAnimation })
|
|
311
|
+
scrollViewRef.current.scrollTo({ x, y, animated: !!scrollWithAnimation })
|
|
274
312
|
scrollOptions.current.scrollLeft = x
|
|
275
313
|
scrollOptions.current.scrollTop = y
|
|
276
314
|
}
|
|
277
315
|
}
|
|
278
316
|
|
|
279
|
-
function onRefresh() {
|
|
280
|
-
const { bindrefresherrefresh } = props
|
|
317
|
+
function onRefresh () {
|
|
318
|
+
const { bindrefresherrefresh } = props
|
|
281
319
|
bindrefresherrefresh &&
|
|
282
320
|
bindrefresherrefresh(
|
|
283
|
-
getCustomEvent('refresherrefresh', {}, { layoutRef }, props)
|
|
284
|
-
)
|
|
321
|
+
getCustomEvent('refresherrefresh', {}, { layoutRef }, props)
|
|
322
|
+
)
|
|
285
323
|
}
|
|
286
324
|
|
|
287
|
-
function onScrollTouchStart(e: NativeSyntheticEvent<TouchEvent>) {
|
|
288
|
-
const { binddragstart, bindtouchstart, enhanced } = props
|
|
325
|
+
function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
|
|
326
|
+
const { binddragstart, bindtouchstart, enhanced } = props
|
|
289
327
|
bindtouchstart && bindtouchstart(e)
|
|
290
328
|
if (enhanced) {
|
|
291
329
|
binddragstart &&
|
|
292
330
|
binddragstart(
|
|
293
331
|
getCustomEvent('dragstart', e, {
|
|
294
332
|
detail: {
|
|
295
|
-
scrollLeft: scrollOptions.current.scrollLeft
|
|
296
|
-
scrollTop: scrollOptions.current.scrollTop
|
|
333
|
+
scrollLeft: scrollOptions.current.scrollLeft,
|
|
334
|
+
scrollTop: scrollOptions.current.scrollTop
|
|
297
335
|
},
|
|
298
336
|
layoutRef
|
|
299
337
|
}, props)
|
|
300
338
|
)
|
|
301
339
|
}
|
|
302
340
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const { binddragging, bindtouchmove, enhanced } = props;
|
|
341
|
+
function onScrollTouchMove (e: NativeSyntheticEvent<TouchEvent>) {
|
|
342
|
+
const { binddragging, bindtouchmove, enhanced } = props
|
|
306
343
|
bindtouchmove && bindtouchmove(e)
|
|
307
344
|
if (enhanced) {
|
|
308
345
|
binddragging &&
|
|
@@ -310,7 +347,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
310
347
|
getCustomEvent('dragging', e, {
|
|
311
348
|
detail: {
|
|
312
349
|
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
313
|
-
scrollTop: scrollOptions.current.scrollTop || 0
|
|
350
|
+
scrollTop: scrollOptions.current.scrollTop || 0
|
|
314
351
|
},
|
|
315
352
|
layoutRef
|
|
316
353
|
}, props)
|
|
@@ -318,48 +355,53 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
318
355
|
}
|
|
319
356
|
}
|
|
320
357
|
|
|
321
|
-
function
|
|
322
|
-
const { binddragend,
|
|
323
|
-
bindtouchend && bindtouchend(e);
|
|
358
|
+
function onScrollEndDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
359
|
+
const { binddragend, enhanced } = props
|
|
324
360
|
if (enhanced) {
|
|
361
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
362
|
+
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize
|
|
325
363
|
binddragend &&
|
|
326
364
|
binddragend(
|
|
327
365
|
getCustomEvent('dragend', e, {
|
|
328
366
|
detail: {
|
|
329
|
-
scrollLeft:
|
|
330
|
-
scrollTop:
|
|
367
|
+
scrollLeft: scrollLeft,
|
|
368
|
+
scrollTop: scrollTop,
|
|
369
|
+
scrollHeight,
|
|
370
|
+
scrollWidth
|
|
331
371
|
},
|
|
332
372
|
layoutRef
|
|
333
373
|
}, props)
|
|
334
374
|
)
|
|
375
|
+
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
335
376
|
}
|
|
336
377
|
}
|
|
337
378
|
|
|
338
379
|
let scrollAdditionalProps: ScrollAdditionalProps = {
|
|
380
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
339
381
|
pinchGestureEnabled: false,
|
|
340
|
-
horizontal: scrollX
|
|
382
|
+
horizontal: scrollX && !scrollY,
|
|
341
383
|
scrollEventThrottle: scrollEventThrottle,
|
|
342
384
|
scrollsToTop: enableBackToTop,
|
|
343
385
|
showsHorizontalScrollIndicator: scrollX && showScrollbar,
|
|
344
386
|
showsVerticalScrollIndicator: scrollY && showScrollbar,
|
|
345
|
-
scrollEnabled:
|
|
387
|
+
scrollEnabled: scrollX || scrollY,
|
|
346
388
|
ref: scrollViewRef,
|
|
347
389
|
onScroll: onScroll,
|
|
348
390
|
onContentSizeChange: onContentSizeChange,
|
|
349
391
|
bindtouchstart: onScrollTouchStart,
|
|
350
|
-
bindtouchend: onScrollTouchEnd,
|
|
351
392
|
bindtouchmove: onScrollTouchMove,
|
|
352
|
-
|
|
353
|
-
|
|
393
|
+
onScrollEndDrag,
|
|
394
|
+
onMomentumScrollEnd: onScrollEnd,
|
|
395
|
+
...layoutProps
|
|
396
|
+
}
|
|
354
397
|
if (enhanced) {
|
|
355
398
|
scrollAdditionalProps = {
|
|
356
399
|
...scrollAdditionalProps,
|
|
357
400
|
bounces,
|
|
358
|
-
pagingEnabled
|
|
359
|
-
}
|
|
401
|
+
pagingEnabled
|
|
402
|
+
}
|
|
360
403
|
}
|
|
361
404
|
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
362
|
-
'enable-offset',
|
|
363
405
|
'scroll-x',
|
|
364
406
|
'scroll-y',
|
|
365
407
|
'enable-back-to-top',
|
|
@@ -383,30 +425,42 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
383
425
|
'bindscrolltoupper',
|
|
384
426
|
'bindscrolltolower',
|
|
385
427
|
'bindrefresherrefresh'
|
|
386
|
-
], { layoutRef })
|
|
428
|
+
], { layoutRef })
|
|
387
429
|
|
|
388
430
|
const refreshColor = {
|
|
389
|
-
|
|
390
|
-
|
|
431
|
+
black: ['#000'],
|
|
432
|
+
white: ['#fff']
|
|
391
433
|
}
|
|
392
434
|
|
|
393
435
|
return (
|
|
394
436
|
<ScrollView
|
|
395
437
|
{...innerProps}
|
|
396
|
-
refreshControl={refresherEnabled
|
|
438
|
+
refreshControl={refresherEnabled
|
|
439
|
+
? (
|
|
397
440
|
<RefreshControl
|
|
398
441
|
progressBackgroundColor={refresherBackground}
|
|
399
442
|
refreshing={refreshing}
|
|
400
443
|
onRefresh={onRefresh}
|
|
401
444
|
{...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}
|
|
402
445
|
/>
|
|
403
|
-
|
|
446
|
+
)
|
|
447
|
+
: undefined}
|
|
404
448
|
>
|
|
405
|
-
|
|
449
|
+
{
|
|
450
|
+
wrapChildren(
|
|
451
|
+
props,
|
|
452
|
+
{
|
|
453
|
+
hasVarDec,
|
|
454
|
+
varContext: varContextRef.current,
|
|
455
|
+
textStyle,
|
|
456
|
+
textProps
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
}
|
|
406
460
|
</ScrollView>
|
|
407
|
-
)
|
|
461
|
+
)
|
|
408
462
|
})
|
|
409
463
|
|
|
410
|
-
_ScrollView.displayName = 'mpx-scroll-view'
|
|
464
|
+
_ScrollView.displayName = 'mpx-scroll-view'
|
|
411
465
|
|
|
412
466
|
export default _ScrollView
|