@mpxjs/webpack-plugin 2.10.17-beta.4 → 2.10.17-beta.7
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/global.d.ts +240 -11
- package/lib/index.js +7 -0
- package/lib/loader.js +4 -0
- package/lib/platform/style/wx/index.js +1 -17
- package/lib/platform/template/wx/component-config/button.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +34 -30
- package/lib/runtime/components/react/animationHooks/utils.ts +3 -2
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +0 -1
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +0 -1
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +38 -33
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +0 -1
- package/lib/runtime/components/react/dist/animationHooks/utils.js +3 -2
- package/lib/runtime/components/react/dist/context.d.ts +0 -1
- package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +49 -28
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +20 -6
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/parser.d.ts +0 -1
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts +2 -2
- package/lib/runtime/components/react/dist/utils.jsx +15 -21
- package/lib/runtime/components/react/mpx-image.tsx +2 -2
- package/lib/runtime/components/react/mpx-input.tsx +1 -1
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper.tsx +49 -27
- package/lib/runtime/components/react/mpx-view.tsx +23 -7
- package/lib/runtime/components/react/tsconfig.json +26 -0
- package/lib/runtime/components/react/utils.tsx +18 -23
- package/lib/style-compiler/strip-conditional-loader.js +45 -29
- package/package.json +5 -4
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
|
@@ -72,6 +72,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
72
72
|
marginBottom: dotSpacing,
|
|
73
73
|
zIndex: 98
|
|
74
74
|
};
|
|
75
|
+
const displayMultipleItems = props['display-multiple-items'] || 1;
|
|
75
76
|
const easeingFunc = props['easing-function'] || 'default';
|
|
76
77
|
const easeDuration = props.duration || 500;
|
|
77
78
|
const horizontal = props.vertical !== undefined ? !props.vertical : true;
|
|
@@ -97,18 +98,19 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
97
98
|
const preMarginShared = useSharedValue(preMargin);
|
|
98
99
|
const nextMarginShared = useSharedValue(nextMargin);
|
|
99
100
|
const autoplayShared = useSharedValue(autoplay);
|
|
101
|
+
const children = Array.isArray(props.children) ? props.children.filter(child => child) : (props.children ? [props.children] : []);
|
|
100
102
|
// 默认前后补位的元素个数
|
|
101
|
-
const patchElmNum = circular
|
|
103
|
+
const patchElmNum = (circular && children.length > 1) ? displayMultipleItems + 1 : 0;
|
|
102
104
|
const patchElmNumShared = useSharedValue(patchElmNum);
|
|
105
|
+
const displayMultipleItemsShared = useSharedValue(displayMultipleItems);
|
|
103
106
|
const circularShared = useSharedValue(circular);
|
|
104
|
-
const children = Array.isArray(props.children) ? props.children.filter(child => child) : (props.children ? [props.children] : []);
|
|
105
107
|
// 对有变化的变量,在worklet中只能使用sharedValue变量,useRef不能更新
|
|
106
108
|
const childrenLength = useSharedValue(children.length);
|
|
107
109
|
const initWidth = typeof normalStyle?.width === 'number' ? normalStyle.width - preMargin - nextMargin : normalStyle.width;
|
|
108
110
|
const initHeight = typeof normalStyle?.height === 'number' ? normalStyle.height - preMargin - nextMargin : normalStyle.height;
|
|
109
111
|
const dir = horizontal === false ? 'y' : 'x';
|
|
110
112
|
const pstep = dir === 'x' ? initWidth : initHeight;
|
|
111
|
-
const initStep = isNaN(pstep) ? 0 : pstep;
|
|
113
|
+
const initStep = isNaN(pstep) ? 0 : pstep / displayMultipleItems;
|
|
112
114
|
// 每个元素的宽度 or 高度,有固定值直接初始化无则0
|
|
113
115
|
const step = useSharedValue(initStep);
|
|
114
116
|
// 记录选中元素的索引值
|
|
@@ -126,6 +128,8 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
126
128
|
const moveTranstion = useSharedValue(0);
|
|
127
129
|
const timerId = useRef(0);
|
|
128
130
|
const intervalTimer = props.interval || 500;
|
|
131
|
+
// 记录是否首次
|
|
132
|
+
const isFirstRef = useRef(true);
|
|
129
133
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
130
134
|
const waitForHandlers = flatGesture(waitFor);
|
|
131
135
|
// 判断gesture手势是否需要协同处理、等待手势失败响应
|
|
@@ -168,7 +172,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
168
172
|
const { width, height } = e.nativeEvent.layout;
|
|
169
173
|
const realWidth = dir === 'x' ? width - preMargin - nextMargin : width;
|
|
170
174
|
const realHeight = dir === 'y' ? height - preMargin - nextMargin : height;
|
|
171
|
-
const iStep = dir === 'x' ? realWidth : realHeight;
|
|
175
|
+
const iStep = (dir === 'x' ? realWidth : realHeight) / displayMultipleItems;
|
|
172
176
|
if (iStep !== step.value) {
|
|
173
177
|
step.value = iStep;
|
|
174
178
|
updateCurrent(propCurrent, iStep);
|
|
@@ -224,19 +228,35 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
224
228
|
function renderItems() {
|
|
225
229
|
const intLen = children.length;
|
|
226
230
|
let renderChild = children.slice();
|
|
231
|
+
// if (circular && intLen > 1) {
|
|
232
|
+
// // 最前面加最后一个元素
|
|
233
|
+
// const lastChild = React.cloneElement(children[intLen - 1] as ReactElement, { key: 'clone0' })
|
|
234
|
+
// // 最后面加第一个元素
|
|
235
|
+
// const firstChild = React.cloneElement(children[0] as ReactElement, { key: 'clone1' })
|
|
236
|
+
// if (preMargin) {
|
|
237
|
+
// const lastChild1 = React.cloneElement(children[intLen - 2] as ReactElement, { key: 'clone2' })
|
|
238
|
+
// const firstChild1 = React.cloneElement(children[1] as ReactElement, { key: 'clone3' })
|
|
239
|
+
// renderChild = [lastChild1, lastChild].concat(renderChild).concat([firstChild, firstChild1])
|
|
240
|
+
// } else {
|
|
241
|
+
// renderChild = [lastChild].concat(renderChild).concat([firstChild])
|
|
242
|
+
// }
|
|
243
|
+
// }
|
|
227
244
|
if (circular && intLen > 1) {
|
|
228
|
-
//
|
|
229
|
-
const
|
|
230
|
-
//
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
245
|
+
// 动态生成前置补位元素
|
|
246
|
+
const frontClones = [];
|
|
247
|
+
// 计算补位序列的起始索引。例如 len=3, patch=2 -> start=1 (即从B开始)
|
|
248
|
+
const startIndex = intLen - (patchElmNum % intLen);
|
|
249
|
+
for (let i = 0; i < patchElmNum; i++) {
|
|
250
|
+
const sourceIndex = (startIndex + i) % intLen;
|
|
251
|
+
frontClones.push(React.cloneElement(children[sourceIndex], { key: `clone_front_${i}` }));
|
|
252
|
+
}
|
|
253
|
+
// 动态生成后置补位元素
|
|
254
|
+
const backClones = [];
|
|
255
|
+
for (let i = 0; i < patchElmNum; i++) {
|
|
256
|
+
const sourceIndex = i % intLen;
|
|
257
|
+
backClones.push(React.cloneElement(children[sourceIndex], { key: `clone_back_${i}` }));
|
|
258
|
+
}
|
|
259
|
+
renderChild = [...frontClones, ...renderChild, ...backClones];
|
|
240
260
|
}
|
|
241
261
|
const arrChildren = renderChild.map((child, index) => {
|
|
242
262
|
const extraStyle = {};
|
|
@@ -271,7 +291,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
271
291
|
let nextIndex = currentIndex.value;
|
|
272
292
|
if (!circularShared.value) {
|
|
273
293
|
// 获取下一个位置的坐标, 循环到最后一个元素,直接停止, 取消定时器
|
|
274
|
-
if (currentIndex.value === childrenLength.value -
|
|
294
|
+
if (currentIndex.value === childrenLength.value - displayMultipleItemsShared.value) {
|
|
275
295
|
pauseLoop();
|
|
276
296
|
return;
|
|
277
297
|
}
|
|
@@ -337,10 +357,8 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
337
357
|
};
|
|
338
358
|
}, []);
|
|
339
359
|
function handleSwiperChange(current, pCurrent) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
bindchange && bindchange(eventData);
|
|
343
|
-
}
|
|
360
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
|
|
361
|
+
bindchange && bindchange(eventData);
|
|
344
362
|
}
|
|
345
363
|
const runOnJSCallbackRef = useRef({
|
|
346
364
|
loop,
|
|
@@ -390,9 +408,10 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
390
408
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
391
409
|
useAnimatedReaction(() => currentIndex.value, (newIndex, preIndex) => {
|
|
392
410
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
393
|
-
if (newIndex !== preIndex && bindchange) {
|
|
411
|
+
if (newIndex !== preIndex && bindchange && !isFirstRef.current) {
|
|
394
412
|
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent);
|
|
395
413
|
}
|
|
414
|
+
isFirstRef.current = false;
|
|
396
415
|
});
|
|
397
416
|
useEffect(() => {
|
|
398
417
|
let patchStep = 0;
|
|
@@ -438,12 +457,13 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
438
457
|
};
|
|
439
458
|
}, [autoplay]);
|
|
440
459
|
useEffect(() => {
|
|
441
|
-
if (circular !== circularShared.value) {
|
|
460
|
+
if (circular !== circularShared.value || patchElmNum !== patchElmNumShared.value || displayMultipleItems !== displayMultipleItemsShared.value) {
|
|
442
461
|
circularShared.value = circular;
|
|
443
|
-
patchElmNumShared.value =
|
|
462
|
+
patchElmNumShared.value = patchElmNum;
|
|
463
|
+
displayMultipleItemsShared.value = displayMultipleItems;
|
|
444
464
|
offset.value = getOffset(currentIndex.value, step.value);
|
|
445
465
|
}
|
|
446
|
-
}, [circular,
|
|
466
|
+
}, [circular, patchElmNum, displayMultipleItems]);
|
|
447
467
|
const { gestureHandler } = useMemo(() => {
|
|
448
468
|
function getTargetPosition(eventData) {
|
|
449
469
|
'worklet';
|
|
@@ -461,7 +481,8 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
461
481
|
const moveToIndex = transdir < 0 ? Math.ceil(computedIndex) : Math.floor(computedIndex);
|
|
462
482
|
// 实际应该定位的索引值
|
|
463
483
|
if (!circularShared.value) {
|
|
464
|
-
|
|
484
|
+
const maxIndex = Math.max(0, childrenLength.value - displayMultipleItemsShared.value);
|
|
485
|
+
selectedIndex = Math.min(Math.max(moveToIndex, 0), maxIndex);
|
|
465
486
|
moveToTargetPos = selectedIndex * step.value;
|
|
466
487
|
}
|
|
467
488
|
else {
|
|
@@ -497,7 +518,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
497
518
|
const gestureMovePos = offset.value + translation;
|
|
498
519
|
if (!circularShared.value) {
|
|
499
520
|
// 如果只判断区间,中间非滑动状态(handleResistanceMove)向左滑动,突然改为向右滑动,但是还在非滑动态,本应该可滑动判断为了不可滑动
|
|
500
|
-
const posEnd = -step.value * (childrenLength.value -
|
|
521
|
+
const posEnd = -step.value * (childrenLength.value - displayMultipleItemsShared.value);
|
|
501
522
|
if (transdir < 0) {
|
|
502
523
|
return gestureMovePos > posEnd;
|
|
503
524
|
}
|
|
@@ -627,7 +648,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
627
648
|
const { translation, transdir } = eventData;
|
|
628
649
|
const moveToOffset = offset.value + translation;
|
|
629
650
|
const maxOverDrag = Math.floor(step.value / 2);
|
|
630
|
-
const maxOffset = translation < 0 ? -(childrenLength.value -
|
|
651
|
+
const maxOffset = translation < 0 ? -(childrenLength.value - displayMultipleItemsShared.value) * step.value : 0;
|
|
631
652
|
let resistance = 0.1;
|
|
632
653
|
let overDrag = 0;
|
|
633
654
|
let finalOffset = 0;
|
|
@@ -5,4 +5,3 @@ import { HandlerRef } from './useNodesRef';
|
|
|
5
5
|
export type TextareProps = Omit<InputProps & PrivateInputProps, 'type' | 'password' | 'multiline' | 'confirm-hold'>;
|
|
6
6
|
declare const Textarea: import("react").ForwardRefExoticComponent<TextareProps & import("react").RefAttributes<HandlerRef<TextInput, TextareProps>>>;
|
|
7
7
|
export default Textarea;
|
|
8
|
-
//# sourceMappingURL=mpx-textarea.d.ts.map
|
|
@@ -274,6 +274,18 @@ function normalizeBackgroundPosition(parts) {
|
|
|
274
274
|
let hOffset = 0;
|
|
275
275
|
let vStart = 'top';
|
|
276
276
|
let vOffset = 0;
|
|
277
|
+
if (!Array.isArray(parts)) {
|
|
278
|
+
// 模板 style 属性传入单个数值时不会和 class 一样转成数组,需要手动转换
|
|
279
|
+
parts = [parts];
|
|
280
|
+
}
|
|
281
|
+
// 模板 style 属性传入时, 需要额外转换处理单位 px/rpx/vh 以及 center 转化为 50%
|
|
282
|
+
parts = parts.map((part) => {
|
|
283
|
+
if (typeof part !== 'string')
|
|
284
|
+
return part;
|
|
285
|
+
if (part === 'center')
|
|
286
|
+
return '50%';
|
|
287
|
+
return global.__formatValue(part);
|
|
288
|
+
});
|
|
277
289
|
if (parts.length === 4)
|
|
278
290
|
return parts;
|
|
279
291
|
// 归一化
|
|
@@ -415,14 +427,16 @@ function normalizeBackgroundSize(backgroundSize, type) {
|
|
|
415
427
|
const sizeList = backgroundSize.slice();
|
|
416
428
|
if (sizeList.length === 1)
|
|
417
429
|
sizeList.push('auto');
|
|
418
|
-
|
|
430
|
+
return sizeList.map((val) => {
|
|
431
|
+
if (typeof val !== 'string')
|
|
432
|
+
return val;
|
|
419
433
|
// 处理当使用渐变的时候,background-size出现cover, contain, auto,当作100%处理
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
sizeList[i] = /^cover|contain|auto$/.test(val) ? '100%' : val;
|
|
434
|
+
if (type === 'linear' && /^cover|contain|auto$/.test(val)) {
|
|
435
|
+
val = '100%';
|
|
423
436
|
}
|
|
424
|
-
|
|
425
|
-
|
|
437
|
+
// 模板 style 属性传入时, 需要额外转换处理单位 px/rpx/vh
|
|
438
|
+
return global.__formatValue(val);
|
|
439
|
+
});
|
|
426
440
|
}
|
|
427
441
|
function preParseImage(imageStyle) {
|
|
428
442
|
const { backgroundImage = '', backgroundSize = ['auto'], backgroundPosition = [0, 0] } = normalizeStyle(imageStyle) || {};
|
|
@@ -20,4 +20,3 @@ interface WebViewProps {
|
|
|
20
20
|
}
|
|
21
21
|
declare const _WebView: import("react").ForwardRefExoticComponent<Omit<WebViewProps, "ref"> & import("react").RefAttributes<HandlerRef<WebView<{}>, WebViewProps>>>;
|
|
22
22
|
export default _WebView;
|
|
23
|
-
//# sourceMappingURL=mpx-web-view.d.ts.map
|
|
@@ -39,8 +39,9 @@ interface TransformStyleConfig {
|
|
|
39
39
|
parentFontSize?: number;
|
|
40
40
|
parentWidth?: number;
|
|
41
41
|
parentHeight?: number;
|
|
42
|
+
isTransformBorderRadiusPercent?: boolean;
|
|
42
43
|
}
|
|
43
|
-
export declare function useTransformStyle(styleObj: Record<string, any> | undefined, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig): {
|
|
44
|
+
export declare function useTransformStyle(styleObj: Record<string, any> | undefined, { enableVar, isTransformBorderRadiusPercent, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig): {
|
|
44
45
|
hasVarDec: boolean;
|
|
45
46
|
varContextRef: MutableRefObject<{}>;
|
|
46
47
|
setWidth: Dispatch<SetStateAction<number>>;
|
|
@@ -121,4 +122,3 @@ export declare function useHover({ enableHover, hoverStartTime, hoverStayTime, d
|
|
|
121
122
|
};
|
|
122
123
|
export declare function useRunOnJSCallback(callbackMapRef: MutableRefObject<Record<string, AnyFunc>>): (key: string, ...args: any) => any;
|
|
123
124
|
export {};
|
|
124
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement, createElement } from 'react';
|
|
2
2
|
import { Image } from 'react-native';
|
|
3
|
-
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn
|
|
3
|
+
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils';
|
|
4
4
|
import { VarContext, ScrollViewContext, RouteContext } from './context';
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
@@ -110,15 +110,17 @@ export function splitStyle(styleObj) {
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
const
|
|
114
|
-
translateX: 'width',
|
|
115
|
-
translateY: 'height',
|
|
113
|
+
const radiusPercentRule = {
|
|
116
114
|
borderTopLeftRadius: 'width',
|
|
117
115
|
borderBottomLeftRadius: 'width',
|
|
118
116
|
borderBottomRightRadius: 'width',
|
|
119
117
|
borderTopRightRadius: 'width',
|
|
120
118
|
borderRadius: 'width'
|
|
121
119
|
};
|
|
120
|
+
const selfPercentRule = Object.assign({
|
|
121
|
+
translateX: 'width',
|
|
122
|
+
translateY: 'height'
|
|
123
|
+
}, radiusPercentRule);
|
|
122
124
|
const parentHeightPercentRule = {
|
|
123
125
|
height: true,
|
|
124
126
|
minHeight: true,
|
|
@@ -193,7 +195,7 @@ function transformVar(styleObj, varKeyPaths, varContext, visitOther) {
|
|
|
193
195
|
const resolved = resolveVar(value, varContext);
|
|
194
196
|
if (resolved === undefined) {
|
|
195
197
|
delete target[key];
|
|
196
|
-
|
|
198
|
+
error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`);
|
|
197
199
|
return;
|
|
198
200
|
}
|
|
199
201
|
target[key] = resolved;
|
|
@@ -343,15 +345,7 @@ function transformBoxShadow(styleObj) {
|
|
|
343
345
|
return `${res}${idx === 0 ? '' : ' '}${global.__formatValue(i)}`;
|
|
344
346
|
}, '');
|
|
345
347
|
}
|
|
346
|
-
function
|
|
347
|
-
if (!styleObj.zIndex || typeof styleObj.zIndex === 'number')
|
|
348
|
-
return;
|
|
349
|
-
if (styleObj.zIndex === 'auto') {
|
|
350
|
-
error('Property [z-index] does not supported [auto], please check again!');
|
|
351
|
-
styleObj.zIndex = 0;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
348
|
+
export function useTransformStyle(styleObj = {}, { enableVar, isTransformBorderRadiusPercent, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
355
349
|
const varStyle = {};
|
|
356
350
|
const unoVarStyle = {};
|
|
357
351
|
const normalStyle = {};
|
|
@@ -403,7 +397,7 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
403
397
|
function calcVisitor({ key, value, keyPath }) {
|
|
404
398
|
if (calcUseRegExp.test(value)) {
|
|
405
399
|
// calc translate & border-radius 的百分比计算
|
|
406
|
-
if (hasOwn(selfPercentRule, key) &&
|
|
400
|
+
if (hasOwn(selfPercentRule, key) && /calc\(\d+%/.test(value)) {
|
|
407
401
|
hasSelfPercent = true;
|
|
408
402
|
percentKeyPaths.push(keyPath.slice());
|
|
409
403
|
}
|
|
@@ -412,7 +406,12 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
412
406
|
}
|
|
413
407
|
function percentVisitor({ key, value, keyPath }) {
|
|
414
408
|
// fixme 去掉 translate & border-radius 的百分比计算
|
|
415
|
-
|
|
409
|
+
// fixme Image 组件 borderRadius 仅支持 number
|
|
410
|
+
if (isTransformBorderRadiusPercent && hasOwn(radiusPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
411
|
+
hasSelfPercent = true;
|
|
412
|
+
percentKeyPaths.push(keyPath.slice());
|
|
413
|
+
}
|
|
414
|
+
else if ((key === 'fontSize' || key === 'lineHeight') && PERCENT_REGEX.test(value)) {
|
|
416
415
|
percentKeyPaths.push(keyPath.slice());
|
|
417
416
|
}
|
|
418
417
|
}
|
|
@@ -485,11 +484,6 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
485
484
|
transformStringify(normalStyle);
|
|
486
485
|
// transform rpx to px
|
|
487
486
|
transformBoxShadow(normalStyle);
|
|
488
|
-
// transform z-index auto to 0
|
|
489
|
-
transformZIndex(normalStyle);
|
|
490
|
-
if (Array.isArray(normalStyle.transform)) {
|
|
491
|
-
normalStyle.transform = normalStyle.transform.filter(item => !isEmptyObject(item));
|
|
492
|
-
}
|
|
493
487
|
return {
|
|
494
488
|
hasVarDec,
|
|
495
489
|
varContextRef,
|
|
@@ -26,7 +26,7 @@ import { noop } from '@mpxjs/utils'
|
|
|
26
26
|
import { SvgCssUri } from 'react-native-svg/css'
|
|
27
27
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
28
28
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
29
|
-
import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject } from './utils'
|
|
29
|
+
import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject, isAndroid } from './utils'
|
|
30
30
|
import Portal from './mpx-portal'
|
|
31
31
|
|
|
32
32
|
export type Mode =
|
|
@@ -190,7 +190,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
190
190
|
normalStyle,
|
|
191
191
|
setWidth,
|
|
192
192
|
setHeight
|
|
193
|
-
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
193
|
+
} = useTransformStyle(styleObj, { enableVar, isTransformBorderRadiusPercent: isAndroid && !isSvg && !isLayoutMode, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
194
194
|
|
|
195
195
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({
|
|
196
196
|
props,
|
|
@@ -285,11 +285,11 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
285
285
|
|
|
286
286
|
const setKeyboardAvoidContext = () => {
|
|
287
287
|
if (keyboardAvoid) {
|
|
288
|
-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition, holdKeyboard }
|
|
289
288
|
keyboardAvoid.current = {
|
|
290
289
|
cursorSpacing,
|
|
291
290
|
ref: nodeRef,
|
|
292
291
|
adjustPosition,
|
|
292
|
+
holdKeyboard,
|
|
293
293
|
// fix: iOS 会在 onFocus 之前触发 keyboardWillShow 并且赋值 keyboardHeight
|
|
294
294
|
// 这里手动同步下 keyboardHeight,防止 onFocus setKeyboardAvoidContext 删掉 keyboardHeight
|
|
295
295
|
keyboardHeight: keyboardAvoid?.current?.keyboardHeight
|
|
@@ -25,8 +25,10 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
25
25
|
const isShow = useRef<boolean>(false)
|
|
26
26
|
|
|
27
27
|
const animatedStyle = useAnimatedStyle(() => ({
|
|
28
|
-
// translate/position top
|
|
29
|
-
|
|
28
|
+
// translate/position top+ overflow hidden 在 android 上时因为键盘顶起让页面高度变小,同时元素位置上移
|
|
29
|
+
// 此时最底部的区域是超出了页面高度的,hidden生效就被隐藏掉,因此需要 android 配置聚焦时禁用高度缩小
|
|
30
|
+
// margin-top 因为在 react-native 上和 flex 1 同时存在时,负值只会让容器高度整体变高,不会让元素上移
|
|
31
|
+
transform: [{ translateY: -offset.value }],
|
|
30
32
|
flexBasis: basic.value as DimensionValue
|
|
31
33
|
}))
|
|
32
34
|
|
|
@@ -73,6 +73,7 @@ interface SwiperProps {
|
|
|
73
73
|
'wait-for'?: Array<GestureHandler>
|
|
74
74
|
'simultaneous-handlers'?: Array<GestureHandler>
|
|
75
75
|
disableGesture?: boolean
|
|
76
|
+
'display-multiple-items'?: number
|
|
76
77
|
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -167,6 +168,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
167
168
|
marginBottom: dotSpacing,
|
|
168
169
|
zIndex: 98
|
|
169
170
|
}
|
|
171
|
+
const displayMultipleItems = props['display-multiple-items'] || 1
|
|
170
172
|
const easeingFunc = props['easing-function'] || 'default'
|
|
171
173
|
const easeDuration = props.duration || 500
|
|
172
174
|
const horizontal = props.vertical !== undefined ? !props.vertical : true
|
|
@@ -200,18 +202,19 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
200
202
|
const preMarginShared = useSharedValue(preMargin)
|
|
201
203
|
const nextMarginShared = useSharedValue(nextMargin)
|
|
202
204
|
const autoplayShared = useSharedValue(autoplay)
|
|
205
|
+
const children = Array.isArray(props.children) ? props.children.filter(child => child) : (props.children ? [props.children] : [])
|
|
203
206
|
// 默认前后补位的元素个数
|
|
204
|
-
const patchElmNum = circular
|
|
207
|
+
const patchElmNum = (circular && children.length > 1) ? displayMultipleItems + 1 : 0
|
|
205
208
|
const patchElmNumShared = useSharedValue(patchElmNum)
|
|
209
|
+
const displayMultipleItemsShared = useSharedValue(displayMultipleItems)
|
|
206
210
|
const circularShared = useSharedValue(circular)
|
|
207
|
-
const children = Array.isArray(props.children) ? props.children.filter(child => child) : (props.children ? [props.children] : [])
|
|
208
211
|
// 对有变化的变量,在worklet中只能使用sharedValue变量,useRef不能更新
|
|
209
212
|
const childrenLength = useSharedValue(children.length)
|
|
210
213
|
const initWidth = typeof normalStyle?.width === 'number' ? normalStyle.width - preMargin - nextMargin : normalStyle.width
|
|
211
214
|
const initHeight = typeof normalStyle?.height === 'number' ? normalStyle.height - preMargin - nextMargin : normalStyle.height
|
|
212
215
|
const dir = horizontal === false ? 'y' : 'x'
|
|
213
216
|
const pstep = dir === 'x' ? initWidth : initHeight
|
|
214
|
-
const initStep: number = isNaN(pstep) ? 0 : pstep
|
|
217
|
+
const initStep: number = isNaN(pstep) ? 0 : pstep / displayMultipleItems
|
|
215
218
|
// 每个元素的宽度 or 高度,有固定值直接初始化无则0
|
|
216
219
|
const step = useSharedValue(initStep)
|
|
217
220
|
// 记录选中元素的索引值
|
|
@@ -229,6 +232,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
229
232
|
const moveTranstion = useSharedValue(0)
|
|
230
233
|
const timerId = useRef(0 as number | ReturnType<typeof setTimeout>)
|
|
231
234
|
const intervalTimer = props.interval || 500
|
|
235
|
+
// 记录是否首次
|
|
236
|
+
const isFirstRef = useRef(true)
|
|
232
237
|
|
|
233
238
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
|
|
234
239
|
const waitForHandlers = flatGesture(waitFor)
|
|
@@ -285,7 +290,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
285
290
|
const { width, height } = e.nativeEvent.layout
|
|
286
291
|
const realWidth = dir === 'x' ? width - preMargin - nextMargin : width
|
|
287
292
|
const realHeight = dir === 'y' ? height - preMargin - nextMargin : height
|
|
288
|
-
const iStep = dir === 'x' ? realWidth : realHeight
|
|
293
|
+
const iStep = (dir === 'x' ? realWidth : realHeight) / displayMultipleItems
|
|
289
294
|
if (iStep !== step.value) {
|
|
290
295
|
step.value = iStep
|
|
291
296
|
updateCurrent(propCurrent, iStep)
|
|
@@ -344,18 +349,35 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
344
349
|
function renderItems () {
|
|
345
350
|
const intLen = children.length
|
|
346
351
|
let renderChild = children.slice()
|
|
352
|
+
// if (circular && intLen > 1) {
|
|
353
|
+
// // 最前面加最后一个元素
|
|
354
|
+
// const lastChild = React.cloneElement(children[intLen - 1] as ReactElement, { key: 'clone0' })
|
|
355
|
+
// // 最后面加第一个元素
|
|
356
|
+
// const firstChild = React.cloneElement(children[0] as ReactElement, { key: 'clone1' })
|
|
357
|
+
// if (preMargin) {
|
|
358
|
+
// const lastChild1 = React.cloneElement(children[intLen - 2] as ReactElement, { key: 'clone2' })
|
|
359
|
+
// const firstChild1 = React.cloneElement(children[1] as ReactElement, { key: 'clone3' })
|
|
360
|
+
// renderChild = [lastChild1, lastChild].concat(renderChild).concat([firstChild, firstChild1])
|
|
361
|
+
// } else {
|
|
362
|
+
// renderChild = [lastChild].concat(renderChild).concat([firstChild])
|
|
363
|
+
// }
|
|
364
|
+
// }
|
|
347
365
|
if (circular && intLen > 1) {
|
|
348
|
-
//
|
|
349
|
-
const
|
|
350
|
-
//
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
renderChild = [lastChild1, lastChild].concat(renderChild).concat([firstChild, firstChild1])
|
|
356
|
-
} else {
|
|
357
|
-
renderChild = [lastChild].concat(renderChild).concat([firstChild])
|
|
366
|
+
// 动态生成前置补位元素
|
|
367
|
+
const frontClones = []
|
|
368
|
+
// 计算补位序列的起始索引。例如 len=3, patch=2 -> start=1 (即从B开始)
|
|
369
|
+
const startIndex = intLen - (patchElmNum % intLen)
|
|
370
|
+
for (let i = 0; i < patchElmNum; i++) {
|
|
371
|
+
const sourceIndex = (startIndex + i) % intLen
|
|
372
|
+
frontClones.push(React.cloneElement(children[sourceIndex], { key: `clone_front_${i}` }))
|
|
358
373
|
}
|
|
374
|
+
// 动态生成后置补位元素
|
|
375
|
+
const backClones = []
|
|
376
|
+
for (let i = 0; i < patchElmNum; i++) {
|
|
377
|
+
const sourceIndex = i % intLen
|
|
378
|
+
backClones.push(React.cloneElement(children[sourceIndex], { key: `clone_back_${i}` }))
|
|
379
|
+
}
|
|
380
|
+
renderChild = [...frontClones, ...renderChild, ...backClones]
|
|
359
381
|
}
|
|
360
382
|
const arrChildren = renderChild.map((child, index) => {
|
|
361
383
|
const extraStyle = {} as { [key: string]: any }
|
|
@@ -390,7 +412,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
390
412
|
let nextIndex = currentIndex.value
|
|
391
413
|
if (!circularShared.value) {
|
|
392
414
|
// 获取下一个位置的坐标, 循环到最后一个元素,直接停止, 取消定时器
|
|
393
|
-
if (currentIndex.value === childrenLength.value -
|
|
415
|
+
if (currentIndex.value === childrenLength.value - displayMultipleItemsShared.value) {
|
|
394
416
|
pauseLoop()
|
|
395
417
|
return
|
|
396
418
|
}
|
|
@@ -457,10 +479,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
457
479
|
}, [])
|
|
458
480
|
|
|
459
481
|
function handleSwiperChange (current: number, pCurrent: number) {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
bindchange && bindchange(eventData)
|
|
463
|
-
}
|
|
482
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
|
|
483
|
+
bindchange && bindchange(eventData)
|
|
464
484
|
}
|
|
465
485
|
|
|
466
486
|
const runOnJSCallbackRef = useRef({
|
|
@@ -509,9 +529,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
509
529
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
510
530
|
useAnimatedReaction(() => currentIndex.value, (newIndex: number, preIndex: number) => {
|
|
511
531
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
512
|
-
if (newIndex !== preIndex && bindchange) {
|
|
532
|
+
if (newIndex !== preIndex && bindchange && !isFirstRef.current) {
|
|
513
533
|
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
|
|
514
534
|
}
|
|
535
|
+
isFirstRef.current = false
|
|
515
536
|
})
|
|
516
537
|
|
|
517
538
|
useEffect(() => {
|
|
@@ -560,14 +581,14 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
560
581
|
}
|
|
561
582
|
}
|
|
562
583
|
}, [autoplay])
|
|
563
|
-
|
|
564
584
|
useEffect(() => {
|
|
565
|
-
if (circular !== circularShared.value) {
|
|
585
|
+
if (circular !== circularShared.value || patchElmNum !== patchElmNumShared.value || displayMultipleItems !== displayMultipleItemsShared.value) {
|
|
566
586
|
circularShared.value = circular
|
|
567
|
-
patchElmNumShared.value =
|
|
587
|
+
patchElmNumShared.value = patchElmNum
|
|
588
|
+
displayMultipleItemsShared.value = displayMultipleItems
|
|
568
589
|
offset.value = getOffset(currentIndex.value, step.value)
|
|
569
590
|
}
|
|
570
|
-
}, [circular,
|
|
591
|
+
}, [circular, patchElmNum, displayMultipleItems])
|
|
571
592
|
const { gestureHandler } = useMemo(() => {
|
|
572
593
|
function getTargetPosition (eventData: EventDataType) {
|
|
573
594
|
'worklet'
|
|
@@ -585,7 +606,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
585
606
|
const moveToIndex = transdir < 0 ? Math.ceil(computedIndex) : Math.floor(computedIndex)
|
|
586
607
|
// 实际应该定位的索引值
|
|
587
608
|
if (!circularShared.value) {
|
|
588
|
-
|
|
609
|
+
const maxIndex = Math.max(0, childrenLength.value - displayMultipleItemsShared.value)
|
|
610
|
+
selectedIndex = Math.min(Math.max(moveToIndex, 0), maxIndex)
|
|
589
611
|
moveToTargetPos = selectedIndex * step.value
|
|
590
612
|
} else {
|
|
591
613
|
if (moveToIndex >= childrenLength.value + patchElmNumShared.value) {
|
|
@@ -618,7 +640,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
618
640
|
const gestureMovePos = offset.value + translation
|
|
619
641
|
if (!circularShared.value) {
|
|
620
642
|
// 如果只判断区间,中间非滑动状态(handleResistanceMove)向左滑动,突然改为向右滑动,但是还在非滑动态,本应该可滑动判断为了不可滑动
|
|
621
|
-
const posEnd = -step.value * (childrenLength.value -
|
|
643
|
+
const posEnd = -step.value * (childrenLength.value - displayMultipleItemsShared.value)
|
|
622
644
|
if (transdir < 0) {
|
|
623
645
|
return gestureMovePos > posEnd
|
|
624
646
|
} else {
|
|
@@ -742,7 +764,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
742
764
|
const { translation, transdir } = eventData
|
|
743
765
|
const moveToOffset = offset.value + translation
|
|
744
766
|
const maxOverDrag = Math.floor(step.value / 2)
|
|
745
|
-
const maxOffset = translation < 0 ? -(childrenLength.value -
|
|
767
|
+
const maxOffset = translation < 0 ? -(childrenLength.value - displayMultipleItemsShared.value) * step.value : 0
|
|
746
768
|
let resistance = 0.1
|
|
747
769
|
let overDrag = 0
|
|
748
770
|
let finalOffset = 0
|