@mpxjs/webpack-plugin 2.8.25-alpha.21 → 2.8.25-alpha.22
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/runtime/components/react/dist/KeyboardAvoidingView.jsx +89 -0
- package/lib/runtime/components/react/dist/context.js +14 -0
- package/lib/runtime/components/react/dist/event.config.js +27 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +262 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +271 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +341 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +90 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +131 -0
- package/lib/runtime/components/react/dist/mpx-form.jsx +68 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/cancel.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/clear.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/download.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/info.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/search.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/success.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/success_no_circle.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/waiting.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/icons/warn.png +0 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +50 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +292 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +292 -0
- package/lib/runtime/components/react/dist/mpx-label.jsx +52 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +32 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +468 -0
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +33 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +74 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +141 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +147 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +99 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +81 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +242 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +193 -0
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +125 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +30 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +112 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +86 -0
- package/lib/runtime/components/react/dist/mpx-radio.jsx +140 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +17 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +372 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +59 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +671 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +97 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +40 -0
- package/lib/runtime/components/react/dist/mpx-video.jsx +248 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +611 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +289 -0
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/pickerFaces.js +76 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +14 -0
- package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +23 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +346 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +16 -0
- package/lib/runtime/components/react/dist/utils.jsx +599 -0
- package/package.json +6 -3
- package/LICENSE +0 -433
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ scroll-x
|
|
3
|
+
* ✔ scroll-y
|
|
4
|
+
* ✔ upper-threshold
|
|
5
|
+
* ✔ lower-threshold
|
|
6
|
+
* ✔ scroll-top
|
|
7
|
+
* ✔ scroll-left
|
|
8
|
+
* ✔ scroll-into-view
|
|
9
|
+
* ✔ scroll-with-animation
|
|
10
|
+
* ✔ enable-back-to-top
|
|
11
|
+
* ✘ enable-passive
|
|
12
|
+
* ✔ refresher-enabled
|
|
13
|
+
* ✘ refresher-threshold
|
|
14
|
+
* ✔ refresher-default-style(仅 android 支持)
|
|
15
|
+
* ✔ refresher-background(仅 android 支持)
|
|
16
|
+
* ✔ refresher-triggered
|
|
17
|
+
* ✘ enable-flex(scroll-x,rn 默认支持)
|
|
18
|
+
* ✘ scroll-anchoring
|
|
19
|
+
* ✔ paging-enabled
|
|
20
|
+
* ✘ using-sticky
|
|
21
|
+
* ✔ show-scrollbar
|
|
22
|
+
* ✘ fast-deceleration
|
|
23
|
+
* ✔ binddragstart
|
|
24
|
+
* ✔ binddragging
|
|
25
|
+
* ✔ binddragend
|
|
26
|
+
* ✔ bindrefresherrefresh
|
|
27
|
+
* ✘ bindrefresherpulling
|
|
28
|
+
* ✘ bindrefresherrestore
|
|
29
|
+
* ✘ bindrefresherabort
|
|
30
|
+
* ✔ bindscrolltoupper
|
|
31
|
+
* ✔ bindscrolltolower
|
|
32
|
+
* ✔ bindscroll
|
|
33
|
+
*/
|
|
34
|
+
import { ScrollView } from 'react-native-gesture-handler';
|
|
35
|
+
import { RefreshControl } from 'react-native';
|
|
36
|
+
import { useRef, useState, useEffect, forwardRef, useContext, createElement, useMemo } from 'react';
|
|
37
|
+
import { useAnimatedRef } from 'react-native-reanimated';
|
|
38
|
+
import { warn } from '@mpxjs/utils';
|
|
39
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
40
|
+
import useNodesRef from './useNodesRef';
|
|
41
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
|
|
42
|
+
import { IntersectionObserverContext, ScrollViewContext } from './context';
|
|
43
|
+
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
44
|
+
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
45
|
+
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchstart, bindtouchmove, bindtouchend, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, __selectRef } = props;
|
|
46
|
+
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
47
|
+
const waitForHandlers = flatGesture(waitFor);
|
|
48
|
+
const [refreshing, setRefreshing] = useState(true);
|
|
49
|
+
const snapScrollTop = useRef(0);
|
|
50
|
+
const snapScrollLeft = useRef(0);
|
|
51
|
+
const scrollOptions = useRef({
|
|
52
|
+
contentLength: 0,
|
|
53
|
+
offset: 0,
|
|
54
|
+
scrollLeft: 0,
|
|
55
|
+
scrollTop: 0,
|
|
56
|
+
visibleLength: 0
|
|
57
|
+
});
|
|
58
|
+
const scrollEventThrottle = 50;
|
|
59
|
+
const hasCallScrollToUpper = useRef(true);
|
|
60
|
+
const hasCallScrollToLower = useRef(false);
|
|
61
|
+
const initialTimeout = useRef(null);
|
|
62
|
+
const intersectionObservers = useContext(IntersectionObserverContext);
|
|
63
|
+
const firstScrollIntoViewChange = useRef(false);
|
|
64
|
+
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
65
|
+
const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
|
|
66
|
+
const scrollViewRef = useAnimatedRef();
|
|
67
|
+
useNodesRef(props, ref, scrollViewRef, {
|
|
68
|
+
style: normalStyle,
|
|
69
|
+
scrollOffset: scrollOptions,
|
|
70
|
+
node: {
|
|
71
|
+
scrollEnabled: scrollX || scrollY,
|
|
72
|
+
bounces,
|
|
73
|
+
showScrollbar,
|
|
74
|
+
pagingEnabled,
|
|
75
|
+
fastDeceleration: false,
|
|
76
|
+
decelerationDisabled: false,
|
|
77
|
+
scrollTo: scrollToOffset
|
|
78
|
+
},
|
|
79
|
+
gestureRef: scrollViewRef
|
|
80
|
+
});
|
|
81
|
+
const contextValue = useMemo(() => {
|
|
82
|
+
return {
|
|
83
|
+
gestureRef: scrollViewRef
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
86
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
|
|
87
|
+
if (scrollX && scrollY) {
|
|
88
|
+
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');
|
|
89
|
+
}
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (snapScrollTop.current !== scrollTop || snapScrollLeft.current !== scrollLeft) {
|
|
92
|
+
initialTimeout.current = setTimeout(() => {
|
|
93
|
+
scrollToOffset(scrollLeft, scrollTop);
|
|
94
|
+
}, 0);
|
|
95
|
+
return () => {
|
|
96
|
+
initialTimeout.current && clearTimeout(initialTimeout.current);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}, [scrollTop, scrollLeft]);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (refreshing !== refresherTriggered) {
|
|
102
|
+
setRefreshing(!!refresherTriggered);
|
|
103
|
+
}
|
|
104
|
+
}, [refresherTriggered]);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (scrollIntoView && __selectRef) {
|
|
107
|
+
if (!firstScrollIntoViewChange.current) {
|
|
108
|
+
setTimeout(handleScrollIntoView);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
handleScrollIntoView();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
firstScrollIntoViewChange.current = true;
|
|
115
|
+
}, [scrollIntoView]);
|
|
116
|
+
function handleScrollIntoView() {
|
|
117
|
+
const refs = __selectRef(`#${scrollIntoView}`, 'node');
|
|
118
|
+
if (!refs)
|
|
119
|
+
return;
|
|
120
|
+
const { nodeRef } = refs.getNodeInstance();
|
|
121
|
+
nodeRef.current?.measureLayout(scrollViewRef.current, (left, top) => {
|
|
122
|
+
scrollToOffset(left, top);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function selectLength(size) {
|
|
126
|
+
return !scrollX ? size.height : size.width;
|
|
127
|
+
}
|
|
128
|
+
function selectOffset(position) {
|
|
129
|
+
return !scrollX ? position.y : position.x;
|
|
130
|
+
}
|
|
131
|
+
function onStartReached(e) {
|
|
132
|
+
const { bindscrolltoupper } = props;
|
|
133
|
+
const { offset } = scrollOptions.current;
|
|
134
|
+
if (bindscrolltoupper && (offset <= upperThreshold)) {
|
|
135
|
+
if (!hasCallScrollToUpper.current) {
|
|
136
|
+
bindscrolltoupper(getCustomEvent('scrolltoupper', e, {
|
|
137
|
+
detail: {
|
|
138
|
+
direction: scrollX ? 'left' : 'top'
|
|
139
|
+
},
|
|
140
|
+
layoutRef
|
|
141
|
+
}, props));
|
|
142
|
+
hasCallScrollToUpper.current = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
hasCallScrollToUpper.current = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function onEndReached(e) {
|
|
150
|
+
const { bindscrolltolower } = props;
|
|
151
|
+
const { contentLength, visibleLength, offset } = scrollOptions.current;
|
|
152
|
+
const distanceFromEnd = contentLength - visibleLength - offset;
|
|
153
|
+
if (bindscrolltolower && (distanceFromEnd < lowerThreshold)) {
|
|
154
|
+
if (!hasCallScrollToLower.current) {
|
|
155
|
+
hasCallScrollToLower.current = true;
|
|
156
|
+
bindscrolltolower(getCustomEvent('scrolltolower', e, {
|
|
157
|
+
detail: {
|
|
158
|
+
direction: scrollX ? 'right' : 'botttom'
|
|
159
|
+
},
|
|
160
|
+
layoutRef
|
|
161
|
+
}, props));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
hasCallScrollToLower.current = false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function onContentSizeChange(width, height) {
|
|
169
|
+
scrollOptions.current.contentLength = selectLength({ height, width });
|
|
170
|
+
}
|
|
171
|
+
function onLayout(e) {
|
|
172
|
+
const layout = e.nativeEvent.layout || {};
|
|
173
|
+
scrollOptions.current.visibleLength = selectLength(layout);
|
|
174
|
+
}
|
|
175
|
+
function updateScrollOptions(e, position) {
|
|
176
|
+
const visibleLength = selectLength(e.nativeEvent.layoutMeasurement);
|
|
177
|
+
const contentLength = selectLength(e.nativeEvent.contentSize);
|
|
178
|
+
const offset = selectOffset(e.nativeEvent.contentOffset);
|
|
179
|
+
extendObject(scrollOptions.current, {
|
|
180
|
+
contentLength,
|
|
181
|
+
offset,
|
|
182
|
+
scrollLeft: position.scrollLeft,
|
|
183
|
+
scrollTop: position.scrollTop,
|
|
184
|
+
visibleLength
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function onScroll(e) {
|
|
188
|
+
const { bindscroll } = props;
|
|
189
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
190
|
+
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize;
|
|
191
|
+
bindscroll &&
|
|
192
|
+
bindscroll(getCustomEvent('scroll', e, {
|
|
193
|
+
detail: {
|
|
194
|
+
scrollLeft,
|
|
195
|
+
scrollTop,
|
|
196
|
+
scrollHeight,
|
|
197
|
+
scrollWidth,
|
|
198
|
+
deltaX: scrollLeft - scrollOptions.current.scrollLeft,
|
|
199
|
+
deltaY: scrollTop - scrollOptions.current.scrollTop
|
|
200
|
+
},
|
|
201
|
+
layoutRef
|
|
202
|
+
}, props));
|
|
203
|
+
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
204
|
+
onStartReached(e);
|
|
205
|
+
onEndReached(e);
|
|
206
|
+
updateIntersection();
|
|
207
|
+
}
|
|
208
|
+
function onScrollEnd(e) {
|
|
209
|
+
const { bindscrollend } = props;
|
|
210
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
211
|
+
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize;
|
|
212
|
+
bindscrollend &&
|
|
213
|
+
bindscrollend(getCustomEvent('scrollend', e, {
|
|
214
|
+
detail: {
|
|
215
|
+
scrollLeft,
|
|
216
|
+
scrollTop,
|
|
217
|
+
scrollHeight,
|
|
218
|
+
scrollWidth
|
|
219
|
+
},
|
|
220
|
+
layoutRef
|
|
221
|
+
}, props));
|
|
222
|
+
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
223
|
+
onStartReached(e);
|
|
224
|
+
onEndReached(e);
|
|
225
|
+
updateIntersection();
|
|
226
|
+
}
|
|
227
|
+
function updateIntersection() {
|
|
228
|
+
if (enableTriggerIntersectionObserver && intersectionObservers) {
|
|
229
|
+
for (const key in intersectionObservers) {
|
|
230
|
+
intersectionObservers[key].throttleMeasure();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function scrollToOffset(x = 0, y = 0) {
|
|
235
|
+
if (scrollViewRef.current) {
|
|
236
|
+
scrollViewRef.current.scrollTo({ x, y, animated: !!scrollWithAnimation });
|
|
237
|
+
scrollOptions.current.scrollLeft = x;
|
|
238
|
+
scrollOptions.current.scrollTop = y;
|
|
239
|
+
snapScrollLeft.current = x;
|
|
240
|
+
snapScrollTop.current = y;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function onRefresh() {
|
|
244
|
+
const { bindrefresherrefresh } = props;
|
|
245
|
+
bindrefresherrefresh &&
|
|
246
|
+
bindrefresherrefresh(getCustomEvent('refresherrefresh', {}, { layoutRef }, props));
|
|
247
|
+
}
|
|
248
|
+
function onScrollTouchStart(e) {
|
|
249
|
+
const { bindtouchstart } = props;
|
|
250
|
+
bindtouchstart && bindtouchstart(e);
|
|
251
|
+
if (enhanced) {
|
|
252
|
+
binddragstart &&
|
|
253
|
+
binddragstart(getCustomEvent('dragstart', e, {
|
|
254
|
+
detail: {
|
|
255
|
+
scrollLeft: scrollOptions.current.scrollLeft,
|
|
256
|
+
scrollTop: scrollOptions.current.scrollTop
|
|
257
|
+
},
|
|
258
|
+
layoutRef
|
|
259
|
+
}, props));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function onScrollTouchMove(e) {
|
|
263
|
+
bindtouchmove && bindtouchmove(e);
|
|
264
|
+
if (enhanced) {
|
|
265
|
+
binddragging &&
|
|
266
|
+
binddragging(getCustomEvent('dragging', e, {
|
|
267
|
+
detail: {
|
|
268
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
269
|
+
scrollTop: scrollOptions.current.scrollTop || 0
|
|
270
|
+
},
|
|
271
|
+
layoutRef
|
|
272
|
+
}, props));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function onScrollTouchEnd(e) {
|
|
276
|
+
bindtouchend && bindtouchend(e);
|
|
277
|
+
if (enhanced) {
|
|
278
|
+
binddragend &&
|
|
279
|
+
binddragend(getCustomEvent('dragend', e, {
|
|
280
|
+
detail: {
|
|
281
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
282
|
+
scrollTop: scrollOptions.current.scrollTop || 0
|
|
283
|
+
},
|
|
284
|
+
layoutRef
|
|
285
|
+
}, props));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function onScrollDrag(e) {
|
|
289
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
290
|
+
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
291
|
+
updateIntersection();
|
|
292
|
+
}
|
|
293
|
+
function onScrollDragStart(e) {
|
|
294
|
+
hasCallScrollToLower.current = false;
|
|
295
|
+
hasCallScrollToUpper.current = false;
|
|
296
|
+
onScrollDrag(e);
|
|
297
|
+
}
|
|
298
|
+
const scrollAdditionalProps = extendObject({
|
|
299
|
+
style: extendObject({}, innerStyle, layoutStyle),
|
|
300
|
+
pinchGestureEnabled: false,
|
|
301
|
+
alwaysBounceVertical: false,
|
|
302
|
+
alwaysBounceHorizontal: false,
|
|
303
|
+
horizontal: scrollX && !scrollY,
|
|
304
|
+
scrollEventThrottle: scrollEventThrottle,
|
|
305
|
+
scrollsToTop: enableBackToTop,
|
|
306
|
+
showsHorizontalScrollIndicator: scrollX && showScrollbar,
|
|
307
|
+
showsVerticalScrollIndicator: scrollY && showScrollbar,
|
|
308
|
+
scrollEnabled: scrollX || scrollY,
|
|
309
|
+
ref: scrollViewRef,
|
|
310
|
+
onScroll: onScroll,
|
|
311
|
+
onContentSizeChange: onContentSizeChange,
|
|
312
|
+
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
|
|
313
|
+
bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
|
|
314
|
+
bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
|
|
315
|
+
onScrollBeginDrag: onScrollDragStart,
|
|
316
|
+
onScrollEndDrag: onScrollDrag,
|
|
317
|
+
onMomentumScrollEnd: onScrollEnd
|
|
318
|
+
}, (simultaneousHandlers ? { simultaneousHandlers } : {}), (waitForHandlers ? { waitFor: waitForHandlers } : {}), layoutProps);
|
|
319
|
+
if (enhanced) {
|
|
320
|
+
Object.assign(scrollAdditionalProps, {
|
|
321
|
+
bounces,
|
|
322
|
+
pagingEnabled
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
326
|
+
'id',
|
|
327
|
+
'scroll-x',
|
|
328
|
+
'scroll-y',
|
|
329
|
+
'enable-back-to-top',
|
|
330
|
+
'enable-trigger-intersection-observer',
|
|
331
|
+
'paging-enabled',
|
|
332
|
+
'show-scrollbar',
|
|
333
|
+
'upper-threshold',
|
|
334
|
+
'lower-threshold',
|
|
335
|
+
'scroll-top',
|
|
336
|
+
'scroll-left',
|
|
337
|
+
'scroll-with-animation',
|
|
338
|
+
'refresher-triggered',
|
|
339
|
+
'refresher-enabled',
|
|
340
|
+
'refresher-default-style',
|
|
341
|
+
'refresher-background',
|
|
342
|
+
'children',
|
|
343
|
+
'enhanced',
|
|
344
|
+
'binddragstart',
|
|
345
|
+
'binddragging',
|
|
346
|
+
'binddragend',
|
|
347
|
+
'bindscroll',
|
|
348
|
+
'bindscrolltoupper',
|
|
349
|
+
'bindscrolltolower',
|
|
350
|
+
'bindrefresherrefresh'
|
|
351
|
+
], { layoutRef });
|
|
352
|
+
const refreshColor = {
|
|
353
|
+
black: ['#000'],
|
|
354
|
+
white: ['#fff']
|
|
355
|
+
};
|
|
356
|
+
return createElement(ScrollView, extendObject({}, innerProps, {
|
|
357
|
+
refreshControl: refresherEnabled
|
|
358
|
+
? createElement(RefreshControl, extendObject({
|
|
359
|
+
progressBackgroundColor: refresherBackground,
|
|
360
|
+
refreshing: refreshing,
|
|
361
|
+
onRefresh: onRefresh
|
|
362
|
+
}, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
|
|
363
|
+
: undefined
|
|
364
|
+
}), createElement(ScrollViewContext.Provider, { value: contextValue }, wrapChildren(props, {
|
|
365
|
+
hasVarDec,
|
|
366
|
+
varContext: varContextRef.current,
|
|
367
|
+
textStyle,
|
|
368
|
+
textProps
|
|
369
|
+
})));
|
|
370
|
+
});
|
|
371
|
+
_ScrollView.displayName = 'MpxScrollView';
|
|
372
|
+
export default _ScrollView;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Text } from 'react-native';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { extendObject } from './utils';
|
|
4
|
+
const _Text2 = (props) => {
|
|
5
|
+
const { allowFontScaling = false } = props;
|
|
6
|
+
return createElement(Text, extendObject({}, props, {
|
|
7
|
+
allowFontScaling
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
_Text2.displayName = 'MpxSimpleText';
|
|
11
|
+
export default _Text2;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import Animated, { useAnimatedStyle, interpolate } from 'react-native-reanimated';
|
|
2
|
+
import { forwardRef, useRef, useContext } from 'react';
|
|
3
|
+
import useInnerProps from './getInnerListeners';
|
|
4
|
+
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
5
|
+
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils';
|
|
6
|
+
import { SwiperContext } from './context';
|
|
7
|
+
const _SwiperItem = forwardRef((props, ref) => {
|
|
8
|
+
const { 'enable-var': enableVar, 'external-var-context': externalVarContext, style, customStyle, itemIndex } = props;
|
|
9
|
+
const contextValue = useContext(SwiperContext);
|
|
10
|
+
const offset = contextValue.offset || 0;
|
|
11
|
+
const step = contextValue.step || 0;
|
|
12
|
+
const scale = contextValue.scale || false;
|
|
13
|
+
const dir = contextValue.dir || 'x';
|
|
14
|
+
const { textProps } = splitProps(props);
|
|
15
|
+
const nodeRef = useRef(null);
|
|
16
|
+
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
17
|
+
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
18
|
+
useNodesRef(props, ref, nodeRef, {
|
|
19
|
+
style: normalStyle
|
|
20
|
+
});
|
|
21
|
+
const {
|
|
22
|
+
// 存储layout布局信息
|
|
23
|
+
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
|
|
24
|
+
const innerProps = useInnerProps(props, {
|
|
25
|
+
ref: nodeRef,
|
|
26
|
+
...layoutProps
|
|
27
|
+
}, [
|
|
28
|
+
'children',
|
|
29
|
+
'enable-offset',
|
|
30
|
+
'style'
|
|
31
|
+
], { layoutRef });
|
|
32
|
+
const itemAnimatedStyle = useAnimatedStyle(() => {
|
|
33
|
+
if (!step.value)
|
|
34
|
+
return {};
|
|
35
|
+
const inputRange = [step.value, 0];
|
|
36
|
+
const outputRange = [0.7, 1];
|
|
37
|
+
// 实现元素的宽度跟随step从0到真实宽度,且不能触发重新渲染整个组件,通过AnimatedStyle的方式实现
|
|
38
|
+
const outerLayoutStyle = dir === 'x' ? { width: step.value, height: '100%' } : { width: '100%', height: step.value };
|
|
39
|
+
const transformStyle = [];
|
|
40
|
+
if (scale) {
|
|
41
|
+
transformStyle.push({
|
|
42
|
+
scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return Object.assign(outerLayoutStyle, {
|
|
46
|
+
transform: transformStyle
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return (<Animated.View {...innerProps} style={[innerStyle, layoutStyle, itemAnimatedStyle, customStyle]} data-itemId={props['item-id']}>
|
|
50
|
+
{wrapChildren(props, {
|
|
51
|
+
hasVarDec,
|
|
52
|
+
varContext: varContextRef.current,
|
|
53
|
+
textStyle,
|
|
54
|
+
textProps
|
|
55
|
+
})}
|
|
56
|
+
</Animated.View>);
|
|
57
|
+
});
|
|
58
|
+
_SwiperItem.displayName = 'MpxSwiperItem';
|
|
59
|
+
export default _SwiperItem;
|