@mpxjs/webpack-plugin 2.9.67 → 2.9.70-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/ResolveDependency.js +5 -0
- package/lib/index.js +51 -15
- package/lib/json-compiler/helper.js +3 -3
- package/lib/loader.js +53 -0
- package/lib/platform/template/wx/component-config/button.js +14 -2
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +5 -1
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +6 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +127 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolve-loader.js +4 -1
- package/lib/resolver/AddModePlugin.js +8 -8
- package/lib/runtime/components/react/context.ts +6 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
- 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 +13 -13
- 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 +160 -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 +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -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 +65 -61
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
- 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 +35 -9
- package/lib/runtime/components/react/dist/utils.jsx +70 -23
- package/lib/runtime/components/react/getInnerListeners.ts +36 -43
- package/lib/runtime/components/react/mpx-button.tsx +95 -43
- 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 +302 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
- package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
- package/lib/runtime/components/react/mpx-form.tsx +10 -8
- package/lib/runtime/components/react/mpx-icon.tsx +10 -15
- package/lib/runtime/components/react/mpx-image.tsx +396 -0
- package/lib/runtime/components/react/mpx-input.tsx +61 -33
- package/lib/runtime/components/react/mpx-label.tsx +14 -13
- package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
- package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
- 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.tsx +236 -104
- package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
- package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
- package/lib/runtime/components/react/mpx-radio.tsx +26 -29
- package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +10 -8
- package/lib/runtime/components/react/mpx-text.tsx +6 -2
- package/lib/runtime/components/react/mpx-view.tsx +81 -59
- package/lib/runtime/components/react/mpx-web-view.tsx +46 -19
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +3 -16
- package/lib/runtime/components/react/utils.tsx +98 -27
- package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
- package/lib/runtime/components/tenon/tenon-button.vue +309 -0
- package/lib/runtime/components/tenon/tenon-image.vue +66 -0
- package/lib/runtime/components/tenon/tenon-input.vue +171 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
- package/lib/runtime/components/tenon/tenon-text.vue +70 -0
- package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- 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 +162 -162
- package/lib/runtime/optionProcessor.js +7 -16
- package/lib/runtime/optionProcessor.tenon.js +84 -0
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/hm.js +20 -0
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +70 -42
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/lib/tenon/index.js +117 -0
- package/lib/tenon/processJSON.js +352 -0
- package/lib/tenon/processScript.js +203 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +126 -0
- package/lib/tenon/script-helper.js +223 -0
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-relative-path.js +25 -0
- package/package.json +9 -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
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* swiper 实现
|
|
3
|
-
*/
|
|
4
|
-
import { Animated, View, Dimensions, Platform } from 'react-native';
|
|
5
|
-
import { forwardRef, useState, useRef, useEffect } from 'react';
|
|
6
|
-
import { getCustomEvent } from '../getInnerListeners';
|
|
7
|
-
import useNodesRef from '../useNodesRef'; // 引入辅助函数
|
|
8
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from '../utils';
|
|
9
|
-
/**
|
|
10
|
-
* 默认的Style类型
|
|
11
|
-
*/
|
|
12
|
-
const styles = {
|
|
13
|
-
slide: {
|
|
14
|
-
backgroundColor: 'transparent'
|
|
15
|
-
},
|
|
16
|
-
container_x: {
|
|
17
|
-
position: 'relative'
|
|
18
|
-
},
|
|
19
|
-
container_y: {
|
|
20
|
-
position: 'relative'
|
|
21
|
-
},
|
|
22
|
-
pagination_x: {
|
|
23
|
-
position: 'absolute',
|
|
24
|
-
bottom: 25,
|
|
25
|
-
left: 0,
|
|
26
|
-
right: 0,
|
|
27
|
-
flexDirection: 'row',
|
|
28
|
-
flex: 1,
|
|
29
|
-
justifyContent: 'center',
|
|
30
|
-
alignItems: 'center'
|
|
31
|
-
},
|
|
32
|
-
pagination_y: {
|
|
33
|
-
position: 'absolute',
|
|
34
|
-
right: 15,
|
|
35
|
-
top: 0,
|
|
36
|
-
bottom: 0,
|
|
37
|
-
flexDirection: 'column',
|
|
38
|
-
flex: 1,
|
|
39
|
-
justifyContent: 'center',
|
|
40
|
-
alignItems: 'center'
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const _Carouse = forwardRef((props, ref) => {
|
|
44
|
-
// 默认取水平方向的width
|
|
45
|
-
const { width } = Dimensions.get('window');
|
|
46
|
-
const { style, previousMargin = 0, nextMargin = 0, enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight } = props;
|
|
47
|
-
// 计算transfrom之类的
|
|
48
|
-
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, {
|
|
49
|
-
enableVar,
|
|
50
|
-
externalVarContext,
|
|
51
|
-
parentFontSize,
|
|
52
|
-
parentWidth,
|
|
53
|
-
parentHeight
|
|
54
|
-
});
|
|
55
|
-
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
56
|
-
const { textProps } = splitProps(props);
|
|
57
|
-
const newChild = Array.isArray(props.children) ? props.children.filter(child => child) : props.children;
|
|
58
|
-
const totalElements = Array.isArray(newChild) ? newChild.length : (newChild ? 1 : 0);
|
|
59
|
-
const defaultHeight = (normalStyle?.height || 150);
|
|
60
|
-
const defaultWidth = (normalStyle?.width || width || 375);
|
|
61
|
-
const dir = props.horizontal === false ? 'y' : 'x';
|
|
62
|
-
// state的offset默认值
|
|
63
|
-
// const initIndex = props.circular ? props.current + 1: (props.current || 0)
|
|
64
|
-
// 记录真正的下标索引, 不包括循环前后加入的索引, 游标
|
|
65
|
-
const initIndex = props.current || 0;
|
|
66
|
-
// 这里要排除超过元素个数的设置
|
|
67
|
-
const initOffsetIndex = initIndex + (props.circular && totalElements > 1 ? 1 : 0);
|
|
68
|
-
const defaultX = (defaultWidth * initOffsetIndex) || 0;
|
|
69
|
-
const defaultY = (defaultHeight * initOffsetIndex) || 0;
|
|
70
|
-
// 主动scorllTo时是否要出发onScrollEnd
|
|
71
|
-
const needTriggerScrollEnd = useRef(true);
|
|
72
|
-
// 内部存储上一次的offset值
|
|
73
|
-
const autoplayTimerRef = useRef(null);
|
|
74
|
-
const scrollViewRef = useRef(null);
|
|
75
|
-
useNodesRef(props, ref, scrollViewRef, {});
|
|
76
|
-
const {
|
|
77
|
-
// 存储layout布局信息
|
|
78
|
-
layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout: onWrapperLayout });
|
|
79
|
-
// 内部存储上一次的偏移量
|
|
80
|
-
const internalsRef = useRef({
|
|
81
|
-
offset: {
|
|
82
|
-
x: 0,
|
|
83
|
-
y: 0
|
|
84
|
-
},
|
|
85
|
-
isScrolling: false
|
|
86
|
-
});
|
|
87
|
-
const isDragRef = useRef(false);
|
|
88
|
-
const [state, setState] = useState({
|
|
89
|
-
width: dir === 'x' && typeof defaultWidth === 'number' ? defaultWidth - previousMargin - nextMargin : defaultWidth,
|
|
90
|
-
height: dir === 'y' && typeof defaultHeight === 'number' ? defaultHeight - previousMargin - nextMargin : defaultHeight,
|
|
91
|
-
// 真正的游标索引, 从0开始
|
|
92
|
-
index: initIndex,
|
|
93
|
-
total: totalElements,
|
|
94
|
-
offset: {
|
|
95
|
-
x: 0,
|
|
96
|
-
y: 0
|
|
97
|
-
},
|
|
98
|
-
dir
|
|
99
|
-
});
|
|
100
|
-
/**
|
|
101
|
-
* @desc: 开启下一次自动轮播
|
|
102
|
-
*/
|
|
103
|
-
function createAutoPlay() {
|
|
104
|
-
autoplayTimerRef.current && clearTimeout(autoplayTimerRef.current);
|
|
105
|
-
autoplayTimerRef.current = setTimeout(() => {
|
|
106
|
-
startAutoPlay();
|
|
107
|
-
}, props.interval || 500);
|
|
108
|
-
}
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
// 确认这个是变化的props变化的时候才执行,还是初始化的时候就执行
|
|
111
|
-
if (props.autoplay) {
|
|
112
|
-
createAutoPlay();
|
|
113
|
-
}
|
|
114
|
-
}, [props.autoplay, props.current, state.index, state.width, state.height]);
|
|
115
|
-
useEffect(() => {
|
|
116
|
-
// 确认这个是变化的props变化的时候才执行,还是初始化的时候就执行
|
|
117
|
-
if (!props.autoplay && props.current !== undefined && props.current !== state.index) {
|
|
118
|
-
const initIndex = props.current || 0;
|
|
119
|
-
// 这里要排除超过元素个数的设置
|
|
120
|
-
const { nextIndex, nextOffset } = getMultiNextConfig(props.current);
|
|
121
|
-
// 1. 安卓需要主动更新下内部状态, 2. IOS不能触发完wcrollTo之后立即updateState, 会造成滑动两次
|
|
122
|
-
// 2. setTimeout 是fix 当再渲染过程中触发scrollTo失败的问题
|
|
123
|
-
if (Platform.OS === 'ios') {
|
|
124
|
-
needTriggerScrollEnd.current = false;
|
|
125
|
-
setTimeout(() => {
|
|
126
|
-
scrollViewRef.current?.scrollTo({
|
|
127
|
-
...nextOffset,
|
|
128
|
-
animated: true
|
|
129
|
-
});
|
|
130
|
-
}, 50);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
updateState(nextIndex, nextOffset);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}, [props.current, state.width, state.height]);
|
|
137
|
-
function getMultiNextConfig(target) {
|
|
138
|
-
const step = state.dir === 'x' ? state.width : state.height;
|
|
139
|
-
const targetPos = step * props.current;
|
|
140
|
-
const targetOffset = {
|
|
141
|
-
x: dir === 'x' ? targetPos : 0,
|
|
142
|
-
y: dir === 'y' ? targetPos : 0
|
|
143
|
-
};
|
|
144
|
-
return {
|
|
145
|
-
nextIndex: target,
|
|
146
|
-
nextOffset: targetOffset
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @desc: 更新状态: index和offset, 并响应索引变化的事件
|
|
151
|
-
* scrollViewOffset: 移动到的目标位置
|
|
152
|
-
*/
|
|
153
|
-
function updateIndex(scrollViewOffset, useIndex = false) {
|
|
154
|
-
const { nextIndex, nextOffset } = getNextConfig(scrollViewOffset);
|
|
155
|
-
updateState(nextIndex, nextOffset);
|
|
156
|
-
// 更新完状态之后, 开启新的loop
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* 更新索引状态
|
|
160
|
-
*/
|
|
161
|
-
function updateState(index, offset) {
|
|
162
|
-
internalsRef.current.offset = offset;
|
|
163
|
-
setState((preState) => {
|
|
164
|
-
const newState = {
|
|
165
|
-
...preState,
|
|
166
|
-
index: index,
|
|
167
|
-
// offset用来指示当前scrollView的偏移量
|
|
168
|
-
offset: offset
|
|
169
|
-
};
|
|
170
|
-
return newState;
|
|
171
|
-
});
|
|
172
|
-
internalsRef.current.isScrolling = false;
|
|
173
|
-
// getCustomEvent
|
|
174
|
-
const eventData = getCustomEvent('change', {}, { detail: { current: index, source: 'touch' }, layoutRef: layoutRef });
|
|
175
|
-
props.bindchange && props.bindchange(eventData);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* @desc: 获取下一个位置的索引、scrollView的contentOffset、scrollTo到的offset
|
|
179
|
-
* @desc: 包括正循环、反向循环、不循环
|
|
180
|
-
* 其中循环模式为了实现无缝链接, 会将结合contentOffset, 和 scrollTo的offset,
|
|
181
|
-
* 先scrollTo一个位置的坐标, 然后通过updateIndex设置真正的index和内容的offset,视觉上是无缝
|
|
182
|
-
*/
|
|
183
|
-
function getNextConfig(scrollViewOffset) {
|
|
184
|
-
const step = state.dir === 'x' ? state.width : state.height;
|
|
185
|
-
const currentOffset = state.offset;
|
|
186
|
-
let nextIndex = state.index + 1;
|
|
187
|
-
let nextOffset = currentOffset;
|
|
188
|
-
// autoMoveOffset scrollView 滚动到前后增加的位置
|
|
189
|
-
let autoMoveOffset = currentOffset;
|
|
190
|
-
let isBack = false;
|
|
191
|
-
let isAutoEnd = false;
|
|
192
|
-
// 如果是循环反向的
|
|
193
|
-
if (scrollViewOffset?.[state.dir] < currentOffset[state.dir]) {
|
|
194
|
-
isBack = true;
|
|
195
|
-
nextIndex = isBack ? nextIndex - 2 : nextIndex;
|
|
196
|
-
}
|
|
197
|
-
if (!props.circular) {
|
|
198
|
-
nextOffset = Object.assign({}, currentOffset, { [state.dir]: step * nextIndex });
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
if (isBack) {
|
|
202
|
-
if (nextIndex < 0) {
|
|
203
|
-
// 反向: scollView 滚动到虚拟的位置
|
|
204
|
-
autoMoveOffset = Object.assign({}, currentOffset, { [state.dir]: 0 });
|
|
205
|
-
nextIndex = state.total - 1;
|
|
206
|
-
// 反向: 数组最后一个index
|
|
207
|
-
nextOffset = Object.assign({}, currentOffset, { [state.dir]: step * state.total });
|
|
208
|
-
isAutoEnd = true;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
// 反向非最后一个
|
|
212
|
-
nextOffset = Object.assign({}, currentOffset, { [state.dir]: (nextIndex + 1) * step });
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
if (nextIndex > state.total - 1) {
|
|
217
|
-
autoMoveOffset = Object.assign({}, currentOffset, { [state.dir]: step * (nextIndex + 1) });
|
|
218
|
-
nextIndex = 0;
|
|
219
|
-
nextOffset = Object.assign({}, currentOffset, { [state.dir]: step });
|
|
220
|
-
isAutoEnd = true;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
// nextIndex = nextIndex,
|
|
224
|
-
nextOffset = Object.assign({}, currentOffset, { [state.dir]: (nextIndex + 1) * step });
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
// 下一个要滚动到的实际元素的索引
|
|
230
|
-
nextIndex,
|
|
231
|
-
// 下一个要滚动到实际元素的offset
|
|
232
|
-
nextOffset,
|
|
233
|
-
// scrollTo一个位置的坐标, 虚拟元素的位置
|
|
234
|
-
autoMoveOffset,
|
|
235
|
-
isAutoEnd
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* @desc: 开启自动轮播
|
|
240
|
-
*/
|
|
241
|
-
function startAutoPlay() {
|
|
242
|
-
if (state.width && isNaN(+state.width)) {
|
|
243
|
-
createAutoPlay();
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (!Array.isArray(props.children)) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const step = state.dir === 'x' ? state.width : state.height;
|
|
250
|
-
const { nextOffset, autoMoveOffset, isAutoEnd } = getNextConfig(state.offset);
|
|
251
|
-
// 这里可以scroll到下一个元素, 但是把scrollView的偏移量在设置为content,视觉效果就没了吧
|
|
252
|
-
if (Platform.OS === 'ios') {
|
|
253
|
-
if (!isAutoEnd) {
|
|
254
|
-
scrollViewRef.current?.scrollTo({ x: nextOffset.x, y: nextOffset.y, animated: true });
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
if (state.dir === 'x') {
|
|
258
|
-
scrollViewRef.current?.scrollTo({ x: autoMoveOffset.x, y: autoMoveOffset.x, animated: true });
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
scrollViewRef.current?.scrollTo({ x: autoMoveOffset.y, y: autoMoveOffset.y, animated: true });
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
if (!isAutoEnd) {
|
|
267
|
-
scrollViewRef.current?.scrollTo({ x: nextOffset.x, y: nextOffset.y, animated: true });
|
|
268
|
-
onScrollEnd({
|
|
269
|
-
nativeEvent: {
|
|
270
|
-
contentOffset: {
|
|
271
|
-
x: +nextOffset.x,
|
|
272
|
-
y: +nextOffset.y
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
// 安卓无法实现视觉的无缝连接, 只能回到真正的位置, 且安卓调用scrollTo不能触发onMomentumScrollEnd,还未找到为啥
|
|
279
|
-
if (state.dir === 'x') {
|
|
280
|
-
scrollViewRef.current?.scrollTo({ x: step, y: step, animated: true });
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
scrollViewRef.current?.scrollTo({ x: autoMoveOffset.x, y: step, animated: true });
|
|
284
|
-
}
|
|
285
|
-
updateState(0, nextOffset);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* 当用户开始拖动此视图时调用此函数, 更新当前在滚动态
|
|
291
|
-
*/
|
|
292
|
-
function onScrollBegin() {
|
|
293
|
-
internalsRef.current.isScrolling = true;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* 当用户开始拖动结束
|
|
297
|
-
* 注意: 当手动调用scrollTo的时候, 安卓不会触发onMomentumScrollEnd, IOS会触发onMomentumScrollEnd
|
|
298
|
-
*/
|
|
299
|
-
function onScrollEnd(event) {
|
|
300
|
-
if (Platform.OS === 'ios' && !needTriggerScrollEnd.current) {
|
|
301
|
-
const { nextIndex, nextOffset } = getMultiNextConfig(props.current);
|
|
302
|
-
updateState(nextIndex, nextOffset);
|
|
303
|
-
needTriggerScrollEnd.current = true;
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
if (totalElements === 1) {
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
internalsRef.current.isScrolling = false;
|
|
310
|
-
// 用户手动滑动更新索引后,如果开启了自动轮播等重新开始
|
|
311
|
-
updateIndex(event.nativeEvent.contentOffset, true);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* 当拖拽结束时,检测是否可滚动
|
|
315
|
-
*/
|
|
316
|
-
function onScrollEndDrag(event) {
|
|
317
|
-
const { contentOffset } = event.nativeEvent;
|
|
318
|
-
const { index, total } = state;
|
|
319
|
-
isDragRef.current = true;
|
|
320
|
-
const internalOffset = internalsRef.current.offset;
|
|
321
|
-
const previousOffset = props.horizontal ? internalOffset.x : internalOffset.y;
|
|
322
|
-
const moveOffset = props.horizontal ? contentOffset.x : contentOffset.y;
|
|
323
|
-
if (previousOffset === moveOffset && (index === 0 || index === total - 1)) {
|
|
324
|
-
internalsRef.current.isScrolling = false;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* @desc: 水平方向时,获取元素的布局,更新, 其中如果传递100%时需要依赖measure计算元算的宽高
|
|
329
|
-
*/
|
|
330
|
-
function onWrapperLayout(e) {
|
|
331
|
-
scrollViewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
332
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
333
|
-
const isWDiff = state.width !== width;
|
|
334
|
-
const isHDiff = state.height !== height;
|
|
335
|
-
if (isWDiff || isHDiff) {
|
|
336
|
-
const changeState = {
|
|
337
|
-
width: isWDiff ? width : state.width,
|
|
338
|
-
height: isHDiff ? height : state.height
|
|
339
|
-
};
|
|
340
|
-
const attr = state.dir === 'x' ? 'width' : 'height';
|
|
341
|
-
changeState[attr] = changeState[attr] - previousMargin - nextMargin;
|
|
342
|
-
const correctOffset = Object.assign({}, state.offset, {
|
|
343
|
-
[state.dir]: initOffsetIndex * (state.dir === 'x' ? changeState.width : changeState.height)
|
|
344
|
-
});
|
|
345
|
-
state.width = changeState.width;
|
|
346
|
-
state.height = changeState.height;
|
|
347
|
-
// 这里setState之后,会再触发重新渲染, renderScrollView会再次触发onScrollEnd,
|
|
348
|
-
setState((preState) => {
|
|
349
|
-
return {
|
|
350
|
-
...preState,
|
|
351
|
-
width: changeState.width,
|
|
352
|
-
height: changeState.height
|
|
353
|
-
};
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
props.getInnerLayout && props.getInnerLayout(layoutRef);
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
function getOffset() {
|
|
360
|
-
const step = state.dir === 'x' ? state.width : state.height;
|
|
361
|
-
if (!step || Number.isNaN(+step))
|
|
362
|
-
return [];
|
|
363
|
-
const offsetArray = [];
|
|
364
|
-
for (let i = 0; i < totalElements; i++) {
|
|
365
|
-
offsetArray.push(i * step);
|
|
366
|
-
}
|
|
367
|
-
return offsetArray;
|
|
368
|
-
}
|
|
369
|
-
function renderScrollView(pages) {
|
|
370
|
-
const offsetsArray = getOffset();
|
|
371
|
-
const scrollElementProps = {
|
|
372
|
-
ref: scrollViewRef,
|
|
373
|
-
horizontal: props.horizontal,
|
|
374
|
-
pagingEnabled: true,
|
|
375
|
-
snapToOffsets: offsetsArray,
|
|
376
|
-
decelerationRate: 0.99,
|
|
377
|
-
showsHorizontalScrollIndicator: false,
|
|
378
|
-
showsVerticalScrollIndicator: false,
|
|
379
|
-
bounces: false,
|
|
380
|
-
scrollsToTop: false,
|
|
381
|
-
removeClippedSubviews: true,
|
|
382
|
-
automaticallyAdjustContentInsets: false
|
|
383
|
-
};
|
|
384
|
-
const layoutStyle = dir === 'x' ? { width: defaultWidth, height: defaultHeight } : { width: defaultWidth };
|
|
385
|
-
return (<Animated.ScrollView {...scrollElementProps} style={[layoutStyle]} overScrollMode="always" contentOffset={state.offset} onScrollBeginDrag={onScrollBegin} onMomentumScrollEnd={onScrollEnd} onScrollEndDrag={onScrollEndDrag}>
|
|
386
|
-
{pages}
|
|
387
|
-
</Animated.ScrollView>);
|
|
388
|
-
}
|
|
389
|
-
function renderPagination() {
|
|
390
|
-
if (state.total <= 1)
|
|
391
|
-
return null;
|
|
392
|
-
const dots = [];
|
|
393
|
-
const activeDotStyle = [{
|
|
394
|
-
backgroundColor: props.activeDotColor || '#007aff',
|
|
395
|
-
width: 8,
|
|
396
|
-
height: 8,
|
|
397
|
-
borderRadius: 4,
|
|
398
|
-
marginLeft: 3,
|
|
399
|
-
marginRight: 3,
|
|
400
|
-
marginTop: 3,
|
|
401
|
-
marginBottom: 3
|
|
402
|
-
}];
|
|
403
|
-
const dotStyle = [{
|
|
404
|
-
backgroundColor: props.dotColor || 'rgba(0,0,0,.2)',
|
|
405
|
-
width: 8,
|
|
406
|
-
height: 8,
|
|
407
|
-
borderRadius: 4,
|
|
408
|
-
marginLeft: 3,
|
|
409
|
-
marginRight: 3,
|
|
410
|
-
marginTop: 3,
|
|
411
|
-
marginBottom: 3
|
|
412
|
-
}];
|
|
413
|
-
for (let i = 0; i < state.total; i++) {
|
|
414
|
-
if (i === state.index) {
|
|
415
|
-
dots.push(<View style={activeDotStyle} key={i}></View>);
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
dots.push(<View style={dotStyle} key={i}></View>);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return (<View pointerEvents="none" style={[styles['pagination_' + state.dir]]}>
|
|
422
|
-
{dots}
|
|
423
|
-
</View>);
|
|
424
|
-
}
|
|
425
|
-
function renderPages() {
|
|
426
|
-
const { width, height } = state;
|
|
427
|
-
const { children } = props;
|
|
428
|
-
const { circular } = props;
|
|
429
|
-
const pageStyle = { width: width, height: height };
|
|
430
|
-
// 设置了previousMargin或者nextMargin,
|
|
431
|
-
// 1. 元素的宽度是减去这两个数目之和
|
|
432
|
-
// 2. previousMargin设置marginLeft正值, nextmargin设置marginRight负值
|
|
433
|
-
// 3. 第一个元素设置previousMargin 和 nextMargin, 最后一个元素
|
|
434
|
-
if (totalElements > 1 && Array.isArray(children)) {
|
|
435
|
-
let arrElements = [];
|
|
436
|
-
// pages = ["2", "0", "1", "2", "0"]
|
|
437
|
-
const pages = Array.isArray(children) ? Object.keys(children) : [];
|
|
438
|
-
/* 无限循环的时候 */
|
|
439
|
-
if (circular) {
|
|
440
|
-
pages.unshift(totalElements - 1 + '');
|
|
441
|
-
pages.push('0');
|
|
442
|
-
}
|
|
443
|
-
arrElements = pages.map((page, i) => {
|
|
444
|
-
const extraStyle = {};
|
|
445
|
-
if (i === 0 && dir === 'x' && typeof width === 'number') {
|
|
446
|
-
previousMargin && (extraStyle.marginLeft = previousMargin);
|
|
447
|
-
}
|
|
448
|
-
else if (i === pages.length - 1 && typeof width === 'number') {
|
|
449
|
-
nextMargin && (extraStyle.marginRight = nextMargin);
|
|
450
|
-
}
|
|
451
|
-
return (<View style={[pageStyle, styles.slide, extraStyle]} key={'page' + i}>
|
|
452
|
-
{wrapChildren({
|
|
453
|
-
children: children[+page]
|
|
454
|
-
}, {
|
|
455
|
-
hasVarDec,
|
|
456
|
-
varContext: varContextRef.current,
|
|
457
|
-
textStyle,
|
|
458
|
-
textProps
|
|
459
|
-
})}
|
|
460
|
-
</View>);
|
|
461
|
-
});
|
|
462
|
-
return arrElements;
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
const realElement = (<View style={pageStyle} key={0}>
|
|
466
|
-
{children}
|
|
467
|
-
</View>);
|
|
468
|
-
return realElement;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
const pages = renderPages();
|
|
472
|
-
return (<View style={[normalStyle, innerStyle, layoutStyle]} {...layoutProps}>
|
|
473
|
-
{renderScrollView(pages)}
|
|
474
|
-
{props.showsPagination && renderPagination()}
|
|
475
|
-
</View>);
|
|
476
|
-
});
|
|
477
|
-
_Carouse.displayName = 'MpxCarouse';
|
|
478
|
-
export default _Carouse;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useRef } from 'react';
|
|
2
|
-
import Carouse from './carouse';
|
|
3
|
-
import useInnerProps from '../getInnerListeners';
|
|
4
|
-
import useNodesRef from '../useNodesRef'; // 引入辅助函数
|
|
5
|
-
/**
|
|
6
|
-
* ✔ indicator-dots
|
|
7
|
-
* ✔ indicator-color
|
|
8
|
-
* ✔ indicator-active-color
|
|
9
|
-
* ✔ autoplay
|
|
10
|
-
* ✔ current
|
|
11
|
-
* ✔ interval
|
|
12
|
-
* ✔ duration
|
|
13
|
-
* ✔ circular
|
|
14
|
-
* ✔ vertical
|
|
15
|
-
* ✘ display-multiple-items
|
|
16
|
-
* ✘ previous-margin
|
|
17
|
-
* ✘ next-margin
|
|
18
|
-
* ✔ easing-function ="easeOutCubic"
|
|
19
|
-
* ✘ snap-to-edge
|
|
20
|
-
*/
|
|
21
|
-
const _SwiperWrapper = forwardRef((props, ref) => {
|
|
22
|
-
const { children } = props;
|
|
23
|
-
const innerLayout = useRef({});
|
|
24
|
-
const swiperProp = {
|
|
25
|
-
circular: props.circular || false,
|
|
26
|
-
current: props.current || 0,
|
|
27
|
-
autoplay: props.autoplay || false,
|
|
28
|
-
duration: props.duration || 500,
|
|
29
|
-
interval: props.interval || 5000,
|
|
30
|
-
showsPagination: props['indicator-dots'],
|
|
31
|
-
dotColor: props['indicator-color'] || 'rgba(0, 0, 0, .3)',
|
|
32
|
-
activeDotColor: props['indicator-active-color'] || '#000000',
|
|
33
|
-
horizontal: props.vertical !== undefined ? !props.vertical : true,
|
|
34
|
-
previousMargin: props['previous-margin'] ? parseInt(props['previous-margin']) : 0,
|
|
35
|
-
nextMargin: props['next-margin'] ? parseInt(props['next-margin']) : 0,
|
|
36
|
-
enableOffset: props['enable-offset'] || true,
|
|
37
|
-
enableVar: props['enable-var'] || false,
|
|
38
|
-
parentFontSize: props['parent-font-size'],
|
|
39
|
-
parentWidth: props['parent-width'],
|
|
40
|
-
parentHeight: props['parent-height'],
|
|
41
|
-
style: props.style || {},
|
|
42
|
-
externalVarContext: props['external-var-context'],
|
|
43
|
-
bindchange: props.bindchange,
|
|
44
|
-
easingFunction: props['easing-function'] || 'default'
|
|
45
|
-
};
|
|
46
|
-
const nodeRef = useRef(null);
|
|
47
|
-
useNodesRef(props, ref, nodeRef, {});
|
|
48
|
-
const innerProps = useInnerProps(props, {
|
|
49
|
-
ref: nodeRef
|
|
50
|
-
}, [
|
|
51
|
-
'indicator-dots',
|
|
52
|
-
'indicator-color',
|
|
53
|
-
'indicator-active-color',
|
|
54
|
-
'previous-margin',
|
|
55
|
-
'vertical',
|
|
56
|
-
'previous-margin',
|
|
57
|
-
'next-margin',
|
|
58
|
-
'easing-function'
|
|
59
|
-
], { layoutRef: innerLayout });
|
|
60
|
-
const getInnerLayout = (layout) => {
|
|
61
|
-
innerLayout.current = layout.current;
|
|
62
|
-
};
|
|
63
|
-
return <Carouse getInnerLayout={getInnerLayout} innerProps={innerProps} {...innerProps} {...swiperProp}>
|
|
64
|
-
{children}
|
|
65
|
-
</Carouse>;
|
|
66
|
-
});
|
|
67
|
-
_SwiperWrapper.displayName = 'MpxSwiper';
|
|
68
|
-
export default _SwiperWrapper;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|