@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.
- package/lib/index.js +30 -9
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolver/AddEnvPlugin.js +1 -0
- package/lib/resolver/AddModePlugin.js +9 -8
- package/lib/runtime/components/react/context.ts +14 -0
- package/lib/runtime/components/react/dist/context.js +4 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
- package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
- 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 +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- 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 +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
- package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
- package/lib/runtime/components/react/dist/utils.jsx +129 -24
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -202
- package/lib/runtime/components/react/mpx-button.tsx +104 -57
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
- package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
- package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +93 -117
- package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
- package/lib/runtime/components/react/pickerFaces.ts +112 -0
- package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +7 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
- package/lib/runtime/components/react/utils.tsx +169 -29
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/index.js +3 -4
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/style-compiler/strip-conditional-loader.js +118 -0
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +66 -39
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/package.json +6 -4
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { ScrollView } from 'react-native-gesture-handler';
|
|
35
35
|
import { RefreshControl } from 'react-native';
|
|
36
|
-
import { useRef, useState, useEffect, forwardRef, useContext } from 'react';
|
|
36
|
+
import { 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 from './useNodesRef';
|
|
41
|
-
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, flatGesture } from './utils';
|
|
42
|
-
import { IntersectionObserverContext } from './context';
|
|
41
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
|
|
42
|
+
import { IntersectionObserverContext, ScrollViewContext } from './context';
|
|
43
43
|
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
44
44
|
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
45
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;
|
|
@@ -60,11 +60,12 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
60
60
|
const hasCallScrollToLower = useRef(false);
|
|
61
61
|
const initialTimeout = useRef(null);
|
|
62
62
|
const intersectionObservers = useContext(IntersectionObserverContext);
|
|
63
|
-
const
|
|
63
|
+
const firstScrollIntoViewChange = useRef(false);
|
|
64
64
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
65
|
-
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
65
|
+
const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
|
|
66
66
|
const scrollViewRef = useAnimatedRef();
|
|
67
67
|
useNodesRef(props, ref, scrollViewRef, {
|
|
68
|
+
style: normalStyle,
|
|
68
69
|
scrollOffset: scrollOptions,
|
|
69
70
|
node: {
|
|
70
71
|
scrollEnabled: scrollX || scrollY,
|
|
@@ -77,6 +78,11 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
77
78
|
},
|
|
78
79
|
gestureRef: scrollViewRef
|
|
79
80
|
});
|
|
81
|
+
const contextValue = useMemo(() => {
|
|
82
|
+
return {
|
|
83
|
+
gestureRef: scrollViewRef
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
80
86
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
|
|
81
87
|
if (scrollX && scrollY) {
|
|
82
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');
|
|
@@ -97,19 +103,25 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
97
103
|
}
|
|
98
104
|
}, [refresherTriggered]);
|
|
99
105
|
useEffect(() => {
|
|
100
|
-
if (scrollIntoView && __selectRef
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
scrollToOffset(left, top);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
106
|
+
if (scrollIntoView && __selectRef) {
|
|
107
|
+
if (!firstScrollIntoViewChange.current) {
|
|
108
|
+
setTimeout(handleScrollIntoView);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
handleScrollIntoView();
|
|
112
|
+
}
|
|
111
113
|
}
|
|
114
|
+
firstScrollIntoViewChange.current = true;
|
|
112
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
|
+
}
|
|
113
125
|
function selectLength(size) {
|
|
114
126
|
return !scrollX ? size.height : size.width;
|
|
115
127
|
}
|
|
@@ -164,14 +176,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
164
176
|
const visibleLength = selectLength(e.nativeEvent.layoutMeasurement);
|
|
165
177
|
const contentLength = selectLength(e.nativeEvent.contentSize);
|
|
166
178
|
const offset = selectOffset(e.nativeEvent.contentOffset);
|
|
167
|
-
scrollOptions.current
|
|
168
|
-
...scrollOptions.current,
|
|
179
|
+
extendObject(scrollOptions.current, {
|
|
169
180
|
contentLength,
|
|
170
181
|
offset,
|
|
171
182
|
scrollLeft: position.scrollLeft,
|
|
172
183
|
scrollTop: position.scrollTop,
|
|
173
184
|
visibleLength
|
|
174
|
-
};
|
|
185
|
+
});
|
|
175
186
|
}
|
|
176
187
|
function onScroll(e) {
|
|
177
188
|
const { bindscroll } = props;
|
|
@@ -272,8 +283,8 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
272
283
|
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
273
284
|
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
274
285
|
}
|
|
275
|
-
|
|
276
|
-
style: {
|
|
286
|
+
const scrollAdditionalProps = extendObject({
|
|
287
|
+
style: extendObject({}, innerStyle, layoutStyle),
|
|
277
288
|
pinchGestureEnabled: false,
|
|
278
289
|
horizontal: scrollX && !scrollY,
|
|
279
290
|
scrollEventThrottle: scrollEventThrottle,
|
|
@@ -284,22 +295,18 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
284
295
|
ref: scrollViewRef,
|
|
285
296
|
onScroll: onScroll,
|
|
286
297
|
onContentSizeChange: onContentSizeChange,
|
|
287
|
-
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart)
|
|
288
|
-
bindtouchmove: ((enhanced && binddragging) || bindtouchend)
|
|
289
|
-
bindtouchend: ((enhanced && binddragend) || bindtouchend)
|
|
298
|
+
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
|
|
299
|
+
bindtouchmove: ((enhanced && binddragging) || bindtouchend) && onScrollTouchMove,
|
|
300
|
+
bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
|
|
290
301
|
onScrollBeginDrag: onScrollDrag,
|
|
291
302
|
onScrollEndDrag: onScrollDrag,
|
|
292
|
-
onMomentumScrollEnd: onScrollEnd
|
|
293
|
-
|
|
294
|
-
...(simultaneousHandlers ? { simultaneousHandlers } : {}),
|
|
295
|
-
...(waitForHandlers ? { waitFor: waitForHandlers } : {})
|
|
296
|
-
};
|
|
303
|
+
onMomentumScrollEnd: onScrollEnd
|
|
304
|
+
}, (simultaneousHandlers ? { simultaneousHandlers } : {}), (waitForHandlers ? { waitFor: waitForHandlers } : {}), layoutProps);
|
|
297
305
|
if (enhanced) {
|
|
298
|
-
scrollAdditionalProps
|
|
299
|
-
...scrollAdditionalProps,
|
|
306
|
+
Object.assign(scrollAdditionalProps, {
|
|
300
307
|
bounces,
|
|
301
308
|
pagingEnabled
|
|
302
|
-
};
|
|
309
|
+
});
|
|
303
310
|
}
|
|
304
311
|
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
305
312
|
'id',
|
|
@@ -332,16 +339,20 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
332
339
|
black: ['#000'],
|
|
333
340
|
white: ['#fff']
|
|
334
341
|
};
|
|
335
|
-
return (
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
return createElement(ScrollView, extendObject({}, innerProps, {
|
|
343
|
+
refreshControl: refresherEnabled
|
|
344
|
+
? createElement(RefreshControl, extendObject({
|
|
345
|
+
progressBackgroundColor: refresherBackground,
|
|
346
|
+
refreshing: refreshing,
|
|
347
|
+
onRefresh: onRefresh
|
|
348
|
+
}, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
|
|
349
|
+
: undefined
|
|
350
|
+
}), createElement(ScrollViewContext.Provider, { value: contextValue }, wrapChildren(props, {
|
|
351
|
+
hasVarDec,
|
|
352
|
+
varContext: varContextRef.current,
|
|
353
|
+
textStyle,
|
|
354
|
+
textProps
|
|
355
|
+
})));
|
|
345
356
|
});
|
|
346
357
|
_ScrollView.displayName = 'MpxScrollView';
|
|
347
358
|
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;
|
|
@@ -1,34 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forwardRef, useRef } from 'react';
|
|
1
|
+
import Animated, { useAnimatedStyle, interpolate } from 'react-native-reanimated';
|
|
2
|
+
import { forwardRef, useRef, useContext } from 'react';
|
|
3
3
|
import useInnerProps from './getInnerListeners';
|
|
4
4
|
import useNodesRef from './useNodesRef'; // 引入辅助函数
|
|
5
5
|
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils';
|
|
6
|
+
import { SwiperContext } from './context';
|
|
6
7
|
const _SwiperItem = forwardRef((props, ref) => {
|
|
7
|
-
const { 'enable-
|
|
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;
|
|
8
13
|
const { textProps } = splitProps(props);
|
|
9
14
|
const nodeRef = useRef(null);
|
|
10
|
-
useNodesRef(props, ref, nodeRef, {});
|
|
11
15
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
|
|
12
16
|
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
17
|
+
useNodesRef(props, ref, nodeRef, {
|
|
18
|
+
style: normalStyle
|
|
19
|
+
});
|
|
13
20
|
const {
|
|
14
21
|
// 存储layout布局信息
|
|
15
22
|
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
|
|
16
23
|
const innerProps = useInnerProps(props, {
|
|
17
|
-
style: { ...innerStyle, ...layoutStyle },
|
|
18
24
|
ref: nodeRef,
|
|
19
25
|
...layoutProps
|
|
20
26
|
}, [
|
|
21
27
|
'children',
|
|
22
|
-
'enable-offset'
|
|
28
|
+
'enable-offset',
|
|
29
|
+
'style'
|
|
23
30
|
], { layoutRef });
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
const itemAnimatedStyle = useAnimatedStyle(() => {
|
|
32
|
+
if (!step.value)
|
|
33
|
+
return {};
|
|
34
|
+
const inputRange = [step.value, 0];
|
|
35
|
+
const outputRange = [0.7, 1];
|
|
36
|
+
return {
|
|
37
|
+
transform: [{
|
|
38
|
+
scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
|
|
39
|
+
}]
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
const mergeStyle = [innerStyle, layoutStyle, { width: '100%', height: '100%' }, scale ? itemAnimatedStyle : {}].concat(customStyle);
|
|
43
|
+
return (<Animated.View {...innerProps} style={mergeStyle} data-itemId={props['item-id']}>
|
|
44
|
+
{wrapChildren(props, {
|
|
26
45
|
hasVarDec,
|
|
27
46
|
varContext: varContextRef.current,
|
|
28
47
|
textStyle,
|
|
29
48
|
textProps
|
|
30
49
|
})}
|
|
31
|
-
</View>);
|
|
50
|
+
</Animated.View>);
|
|
32
51
|
});
|
|
33
52
|
_SwiperItem.displayName = 'MpxSwiperItem';
|
|
34
53
|
export default _SwiperItem;
|