pixuireactcomponents 1.4.13 → 1.5.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/index.d.ts +1 -1
- package/index.js +3 -1
- package/package.json +1 -1
- package/src/components/react/app/button/Button.d.ts +1 -0
- package/src/components/react/app/button/Button.js +57 -1
- package/src/components/react/app/carousel/Carousel.d.ts +3 -3
- package/src/components/react/app/carouselMulti/CarouselMulti.d.ts +5 -7
- package/src/components/react/app/carouselMulti/CarouselMulti.js +69 -44
- package/src/components/react/app/checkBox/CheckBox.d.ts +17 -8
- package/src/components/react/app/checkBox/CheckBox.js +95 -12
- package/src/components/react/app/checkBox/CheckBoxGroup.d.ts +19 -0
- package/src/components/react/app/checkBox/CheckBoxGroup.js +56 -0
- package/src/components/react/app/dropDown/DropDown.d.ts +18 -25
- package/src/components/react/app/dropDown/DropDown.js +85 -32
- package/src/components/react/app/scratchCard/ScratchCard.d.ts +4 -3
- package/src/components/react/app/scratchCard/ScratchCard.js +10 -17
- package/src/components/react/app/scrollBar/ScrollBar.d.ts +17 -2
- package/src/components/react/app/scrollBar/ScrollBar.js +71 -39
- package/src/components/react/app/slider/Slider.d.ts +22 -93
- package/src/components/react/app/slider/Slider.js +149 -358
- package/src/components/react/app/videoPlayer/VideoPlayer.d.ts +13 -11
- package/src/components/react/app/videoPlayer/VideoPlayer.js +118 -62
- package/src/components/react/app/wheelPicker/WheelPicker.d.ts +17 -9
- package/src/components/react/app/wheelPicker/WheelPicker.js +86 -28
|
@@ -37,6 +37,45 @@ var VideoStatus;
|
|
|
37
37
|
VideoStatus[VideoStatus["Pause"] = 2] = "Pause";
|
|
38
38
|
VideoStatus[VideoStatus["End"] = 3] = "End";
|
|
39
39
|
})(VideoStatus || (VideoStatus = {}));
|
|
40
|
+
var defaultIconStyle = [
|
|
41
|
+
{
|
|
42
|
+
position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/new_video_play.png)', backgroundSize: '100% 100%'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/new_video_pause.png)', backgroundSize: '100% 100%'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/video_loading.png)', backgroundSize: '100% 100%'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
position: 'relative', left: '-45%', top: '42%', width: '5%', paddingTop: '5%', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/new_video_reload.png)', backgroundSize: '100% 100%'
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
var defaultSliderStyle = {
|
|
55
|
+
rail: {
|
|
56
|
+
backgroundColor: 'rgb(240,240,240)',
|
|
57
|
+
width: '90%',
|
|
58
|
+
height: '30%',
|
|
59
|
+
border: '0px solid #000',
|
|
60
|
+
borderRadius: '10',
|
|
61
|
+
left: '0%'
|
|
62
|
+
},
|
|
63
|
+
track: {
|
|
64
|
+
position: 'relative',
|
|
65
|
+
backgroundColor: '#91caff',
|
|
66
|
+
width: '100%',
|
|
67
|
+
height: '100%',
|
|
68
|
+
border: '0px solid #000',
|
|
69
|
+
borderRadius: '10'
|
|
70
|
+
},
|
|
71
|
+
handle: {
|
|
72
|
+
position: 'absolute',
|
|
73
|
+
backgroundColor: '#1677ff',
|
|
74
|
+
borderRadius: '50%',
|
|
75
|
+
width: '200%',
|
|
76
|
+
height: '200%',
|
|
77
|
+
},
|
|
78
|
+
};
|
|
40
79
|
var openLog = false;
|
|
41
80
|
var videoLog = function () {
|
|
42
81
|
var msg = [];
|
|
@@ -48,16 +87,16 @@ var videoLog = function () {
|
|
|
48
87
|
}
|
|
49
88
|
};
|
|
50
89
|
export var VideoPlayer = function (props) {
|
|
51
|
-
var _a;
|
|
52
|
-
var _b = props.playUrl, playUrl = _b === void 0 ? '' : _b, _c = props.autoPlay, autoPlay = _c === void 0 ? true : _c, playEvent = props.playEvent, elementClass = props.elementClass, _d = props.hideSliderDuration, hideSliderDuration = _d === void 0 ? 3000 : _d, sliderBG = props.sliderBG, videoDuration = props.videoDuration, compRef = props.compRef, rootClassName = props.rootClassName;
|
|
90
|
+
var rootId = props.rootId, rootClassName = props.rootClassName, _a = props.playUrl, playUrl = _a === void 0 ? '' : _a, _b = props.autoPlay, autoPlay = _b === void 0 ? true : _b, playEvent = props.playEvent, iconElement = props.iconElement, _c = props.hideSliderDuration, hideSliderDuration = _c === void 0 ? 3000 : _c, sliderElement = props.sliderElement, videoDuration = props.videoDuration, compRef = props.compRef;
|
|
53
91
|
var isStreaming = !playUrl.endsWith('.mp4');
|
|
54
92
|
var refVideo = useRef(null);
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
93
|
+
var _d = useState(VideoStatus.Loading), videoStatus = _d[0], setVideoStatus = _d[1];
|
|
94
|
+
var _e = useState(0), currentTime = _e[0], setCurrentTime = _e[1];
|
|
95
|
+
var _f = useState(0), totalTime = _f[0], setTotalTime = _f[1];
|
|
96
|
+
var _g = useState(false), showSlider = _g[0], setShowSlider = _g[1];
|
|
59
97
|
var sliderTimmer = useRef(null);
|
|
60
98
|
var rootRef = useRef();
|
|
99
|
+
var isDragingRef = useRef(false);
|
|
61
100
|
var updatePlayTime = function () {
|
|
62
101
|
if (videoStatus != VideoStatus.Playing || isStreaming)
|
|
63
102
|
return;
|
|
@@ -113,15 +152,19 @@ export var VideoPlayer = function (props) {
|
|
|
113
152
|
// 开始拖就长显Bar
|
|
114
153
|
var onSliderDragStart = function () {
|
|
115
154
|
videoLog('onDragStart-----------------');
|
|
155
|
+
isDragingRef.current = true;
|
|
116
156
|
clearTimeout(sliderTimmer.current);
|
|
117
157
|
refVideo.current.pause();
|
|
118
158
|
};
|
|
119
159
|
var onSliderDrag = function (value) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
160
|
+
// console.warn('isDragingRef: ', isDragingRef.current)
|
|
161
|
+
if (isDragingRef.current) {
|
|
162
|
+
console.log('value: ', value, getDuration());
|
|
163
|
+
var totalTime_1 = value * getDuration();
|
|
164
|
+
var playSeconds = Math.floor(totalTime_1 / 1000 + 0.5);
|
|
165
|
+
videoLog('onSliderDrag, set currentTime:', playSeconds);
|
|
166
|
+
setCurrentTime(playSeconds);
|
|
167
|
+
}
|
|
125
168
|
};
|
|
126
169
|
var setShowUI = function (show, direct) {
|
|
127
170
|
if (direct === void 0) { direct = false; }
|
|
@@ -131,15 +174,20 @@ export var VideoPlayer = function (props) {
|
|
|
131
174
|
setShowSlider(show);
|
|
132
175
|
};
|
|
133
176
|
// 结束拖就3秒隐藏Bar
|
|
134
|
-
var onSliderDragEnd = function () {
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
177
|
+
var onSliderDragEnd = function (value) {
|
|
178
|
+
console.log('onSliderDragEnd======');
|
|
179
|
+
if (isDragingRef.current) {
|
|
180
|
+
isDragingRef.current = false;
|
|
181
|
+
videoLog('onDragEnd-----------------, ', value * getDuration());
|
|
182
|
+
if (hideSliderDuration > 0) {
|
|
183
|
+
clearTimeout(sliderTimmer.current);
|
|
184
|
+
sliderTimmer.current = setTimeout(function () {
|
|
185
|
+
setShowUI(false);
|
|
186
|
+
}, hideSliderDuration);
|
|
187
|
+
}
|
|
188
|
+
refVideo.current.seek(currentTime);
|
|
189
|
+
refVideo.current.play();
|
|
141
190
|
}
|
|
142
|
-
refVideo.current.play();
|
|
143
191
|
};
|
|
144
192
|
var onplaying = function () {
|
|
145
193
|
// 加载第一帧画面
|
|
@@ -210,7 +258,6 @@ export var VideoPlayer = function (props) {
|
|
|
210
258
|
};
|
|
211
259
|
if (compRef) {
|
|
212
260
|
compRef.current = {
|
|
213
|
-
switchPlayState: switchPlayState,
|
|
214
261
|
setShowUI: function (show) {
|
|
215
262
|
setShowUI(show, true);
|
|
216
263
|
},
|
|
@@ -226,10 +273,43 @@ export var VideoPlayer = function (props) {
|
|
|
226
273
|
getPlayStatus: function () {
|
|
227
274
|
return videoStatus;
|
|
228
275
|
},
|
|
276
|
+
currentTime: currentTime,
|
|
277
|
+
totalTime: totalTime
|
|
229
278
|
};
|
|
230
279
|
}
|
|
231
|
-
videoLog('currentTime', currentTime, 'totalTime', totalTime);
|
|
232
|
-
|
|
280
|
+
// videoLog('currentTime', currentTime, 'totalTime', totalTime);
|
|
281
|
+
var getIconStyleOrClass = function (videoStatus) {
|
|
282
|
+
if (iconElement == undefined) {
|
|
283
|
+
switch (videoStatus) {
|
|
284
|
+
case VideoStatus.Playing:
|
|
285
|
+
return defaultIconStyle[1];
|
|
286
|
+
case VideoStatus.Pause:
|
|
287
|
+
return defaultIconStyle[0];
|
|
288
|
+
case VideoStatus.Loading:
|
|
289
|
+
return defaultIconStyle[2];
|
|
290
|
+
case VideoStatus.End:
|
|
291
|
+
return defaultIconStyle[3];
|
|
292
|
+
default:
|
|
293
|
+
return {};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
switch (videoStatus) {
|
|
298
|
+
case VideoStatus.Playing:
|
|
299
|
+
return iconElement === null || iconElement === void 0 ? void 0 : iconElement.pauseIcon;
|
|
300
|
+
case VideoStatus.Pause:
|
|
301
|
+
return iconElement === null || iconElement === void 0 ? void 0 : iconElement.playIcon;
|
|
302
|
+
case VideoStatus.Loading:
|
|
303
|
+
return iconElement === null || iconElement === void 0 ? void 0 : iconElement.loadingIcon;
|
|
304
|
+
case VideoStatus.End:
|
|
305
|
+
return iconElement === null || iconElement === void 0 ? void 0 : iconElement.reloadIcon;
|
|
306
|
+
default:
|
|
307
|
+
return '' || {};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
var iconStyleOrClass = getIconStyleOrClass(videoStatus);
|
|
312
|
+
return (h("div", { id: rootId, className: rootClassName, ref: rootRef },
|
|
233
313
|
h("video", { ref: refVideo, src: playUrl, "object-fit": "no", autoPlay: autoPlay, style: { width: '100%', height: '100%' }, onPlaying: onplaying, onPlay: onplaying, onError: onerror, onEnded: onended, onPause: onpause, onWaiting: onwaiting, onLoadStart: function () {
|
|
234
314
|
console.warn('onloadstart');
|
|
235
315
|
}, onLoadedData: function () {
|
|
@@ -241,51 +321,27 @@ export var VideoPlayer = function (props) {
|
|
|
241
321
|
videoLog('screenClickerStyle click');
|
|
242
322
|
e.stopPropagation();
|
|
243
323
|
onScreenClick();
|
|
244
|
-
} },
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
} })) : null),
|
|
254
|
-
showSlider && !isStreaming ? (h("div", { style: {
|
|
255
|
-
width: '100%',
|
|
256
|
-
height: '15px',
|
|
257
|
-
fontSize: '18px',
|
|
324
|
+
} },
|
|
325
|
+
h("div", { className: typeof iconStyleOrClass === 'string' ? iconStyleOrClass : '', style: __assign(__assign({}, (typeof iconStyleOrClass === 'object' ? iconStyleOrClass : undefined)), { visibility: showSlider ? 'visible' : 'hidden' }), onClick: function (e) {
|
|
326
|
+
e.stopPropagation();
|
|
327
|
+
switchPlayState();
|
|
328
|
+
} })),
|
|
329
|
+
!isStreaming ? (h("div", { style: {
|
|
330
|
+
width: '90%',
|
|
331
|
+
height: '10%',
|
|
332
|
+
fontSize: '5%',
|
|
258
333
|
color: '#FFFFFF',
|
|
259
334
|
flexDirection: 'row',
|
|
260
|
-
justifyContent: '
|
|
335
|
+
justifyContent: 'flex-start',
|
|
261
336
|
alignItems: 'center',
|
|
262
337
|
position: 'absolute',
|
|
263
|
-
bottom: '
|
|
264
|
-
|
|
265
|
-
|
|
338
|
+
bottom: '3%',
|
|
339
|
+
right: '2%',
|
|
340
|
+
visibility: showSlider ? 'visible' : 'hidden'
|
|
266
341
|
} },
|
|
267
|
-
h(
|
|
268
|
-
h("div", { style: {
|
|
269
|
-
h(
|
|
270
|
-
h("text", null, FormatSecondCountDownTime(totalTime)))) : null));
|
|
271
|
-
};
|
|
272
|
-
var progressData = {
|
|
273
|
-
percent: 0,
|
|
274
|
-
wrapperHeight: 15,
|
|
275
|
-
wrapperWidth: window.innerWidth - 180,
|
|
276
|
-
height: 3,
|
|
277
|
-
dotWidth: 12,
|
|
278
|
-
dotHeight: 12,
|
|
279
|
-
dotWrapperWidth: 42,
|
|
280
|
-
dotWrapperHeight: 42,
|
|
281
|
-
isDiscrete: true,
|
|
282
|
-
maxDiscrete: 100,
|
|
283
|
-
outerBg: '',
|
|
284
|
-
innerBg: '',
|
|
285
|
-
dotBg: '',
|
|
286
|
-
onDragStart: null,
|
|
287
|
-
onDrag: null,
|
|
288
|
-
onDragEnd: null,
|
|
342
|
+
h(Slider, { element: sliderElement != undefined ? sliderElement : defaultSliderStyle, min: 0, max: 1, step: 0.001, value: totalTime > 0 ? currentTime / totalTime : 0, onChangeStart: onSliderDragStart, onChange: onSliderDrag, onChangeComplete: onSliderDragEnd }),
|
|
343
|
+
h("div", { className: typeof (sliderElement === null || sliderElement === void 0 ? void 0 : sliderElement.time) === 'string' ? sliderElement.time : '', style: __assign(__assign({}, (typeof (sliderElement === null || sliderElement === void 0 ? void 0 : sliderElement.time) === 'object' ? sliderElement.time : null)), { flexShrink: 0, right: '1%' }) },
|
|
344
|
+
h("text", null, "".concat(FormatSecondCountDownTime(currentTime), "/").concat(FormatSecondCountDownTime(totalTime)))))) : null));
|
|
289
345
|
};
|
|
290
346
|
var FormatSecondCountDownTime = function (seconds) {
|
|
291
347
|
var minutes = Math.floor(seconds / 60);
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { CSSProperties, h } from 'preact';
|
|
2
|
+
export interface wheelPickerElement {
|
|
3
|
+
itemTextStyle?: string | CSSProperties;
|
|
4
|
+
selectedTextStyle?: string | CSSProperties;
|
|
5
|
+
AboveMaskAreaStyle?: string | CSSProperties;
|
|
6
|
+
BelowMaskAreaStyle?: string | CSSProperties;
|
|
7
|
+
selectedAreaStyle?: string | CSSProperties;
|
|
8
|
+
}
|
|
9
|
+
export interface wheelPickerOption {
|
|
10
|
+
value: string;
|
|
11
|
+
label?: h.JSX.Element;
|
|
12
|
+
}
|
|
2
13
|
export interface WheelPickerProps {
|
|
3
|
-
|
|
4
|
-
|
|
14
|
+
rootId?: string;
|
|
15
|
+
rootClassName?: string;
|
|
16
|
+
options: string[];
|
|
17
|
+
defaultOption?: string;
|
|
5
18
|
visibleAbove?: number;
|
|
6
19
|
visibleBelow?: number;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
AboveMaskAreaStyle?: CSSProperties;
|
|
10
|
-
BelowMaskAreaStyle?: CSSProperties;
|
|
11
|
-
selectedAreaStyle?: CSSProperties;
|
|
12
|
-
firstSelectIndex?: number;
|
|
13
|
-
onChange?: (index: number) => void;
|
|
20
|
+
onChange?: (value: string) => void;
|
|
21
|
+
element?: wheelPickerElement;
|
|
14
22
|
}
|
|
15
23
|
export declare const WheelPicker: (props: WheelPickerProps) => h.JSX.Element;
|
|
@@ -17,7 +17,6 @@ var defaulWrapperStyle = {
|
|
|
17
17
|
alignItems: 'center'
|
|
18
18
|
};
|
|
19
19
|
var defaultItemTextStyle = {
|
|
20
|
-
fontFamily: 'Font_FounderZZ',
|
|
21
20
|
fontStyle: 'normal',
|
|
22
21
|
fontSize: '24px',
|
|
23
22
|
lineHeight: '32px',
|
|
@@ -27,14 +26,13 @@ var defaultItemTextStyle = {
|
|
|
27
26
|
color: '#000000'
|
|
28
27
|
};
|
|
29
28
|
var defaultSelectedTextStyle = {
|
|
30
|
-
fontFamily: 'Font_FounderZZ',
|
|
31
29
|
fontStyle: 'normal',
|
|
32
30
|
fontSize: '24px',
|
|
33
31
|
lineHeight: '32px',
|
|
34
32
|
display: 'flex',
|
|
35
33
|
alignItems: 'center',
|
|
36
34
|
textAlign: 'center',
|
|
37
|
-
color: '
|
|
35
|
+
color: 'white',
|
|
38
36
|
};
|
|
39
37
|
var defaultScrollStyle = {
|
|
40
38
|
width: '100%',
|
|
@@ -46,7 +44,7 @@ var defaultScrollStyle = {
|
|
|
46
44
|
alignItems: 'center',
|
|
47
45
|
overflowStyle: 'none',
|
|
48
46
|
};
|
|
49
|
-
var
|
|
47
|
+
var maskAreaStyle = {
|
|
50
48
|
position: 'absolute',
|
|
51
49
|
pointerEvents: 'none'
|
|
52
50
|
};
|
|
@@ -56,8 +54,65 @@ var defaultItemStyle = {
|
|
|
56
54
|
alignItems: 'center',
|
|
57
55
|
width: '100%'
|
|
58
56
|
};
|
|
57
|
+
var defaultMaskAreaStyle = {
|
|
58
|
+
width: '100%',
|
|
59
|
+
backgroundColor: 'rgba(5, 5, 5, 0.06)'
|
|
60
|
+
};
|
|
61
|
+
var defaultSelectedAreaStyle = {
|
|
62
|
+
borderBottom: '1px solid black',
|
|
63
|
+
borderTop: '1px solid black',
|
|
64
|
+
width: '100%',
|
|
65
|
+
backgroundColor: '#1677ff'
|
|
66
|
+
};
|
|
59
67
|
export var WheelPicker = function (props) {
|
|
60
|
-
var
|
|
68
|
+
var rootId = props.rootId, rootClassName = props.rootClassName, options = props.options, _a = props.visibleAbove, visibleAbove = _a === void 0 ? 1 : _a, _b = props.visibleBelow, visibleBelow = _b === void 0 ? 1 : _b, _c = props.defaultOption, defaultOption = _c === void 0 ? options[0] : _c, element = props.element, onChange = props.onChange;
|
|
69
|
+
var getElementStyleOrClass = function () {
|
|
70
|
+
if (element == undefined) {
|
|
71
|
+
return {
|
|
72
|
+
itemTextStyle: defaultItemTextStyle,
|
|
73
|
+
selectedTextStyle: defaultSelectedTextStyle,
|
|
74
|
+
AboveMaskAreaStyle: defaultMaskAreaStyle,
|
|
75
|
+
BelowMaskAreaStyle: defaultMaskAreaStyle,
|
|
76
|
+
selectedAreaStyle: defaultSelectedAreaStyle
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return element;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var elementStyleOrClass = getElementStyleOrClass();
|
|
84
|
+
var rootRef = useRef(null);
|
|
85
|
+
var getSelectedStyle = function (index) {
|
|
86
|
+
if (elementStyleOrClass.selectedTextStyle) {
|
|
87
|
+
if (index === selectIndex) {
|
|
88
|
+
return typeof elementStyleOrClass.selectedTextStyle === 'object' ? elementStyleOrClass.selectedTextStyle : undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return typeof elementStyleOrClass.itemTextStyle === 'object' ? elementStyleOrClass.itemTextStyle : undefined;
|
|
92
|
+
};
|
|
93
|
+
var getSelectedClass = function (index) {
|
|
94
|
+
if (elementStyleOrClass.selectedTextStyle) {
|
|
95
|
+
if (index === selectIndex) {
|
|
96
|
+
return typeof elementStyleOrClass.selectedTextStyle === 'string' ? elementStyleOrClass.selectedTextStyle : '';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return typeof elementStyleOrClass.itemTextStyle === 'string' ? elementStyleOrClass.itemTextStyle : '';
|
|
100
|
+
};
|
|
101
|
+
useEffect(function () {
|
|
102
|
+
if (rootRef.current) {
|
|
103
|
+
var _a = rootRef.current.getBoundingClientRect(), width = _a.width, height = _a.height;
|
|
104
|
+
var calcuItemHeight_1 = height / (visibleAbove + visibleBelow + 1);
|
|
105
|
+
setItemHeight(calcuItemHeight_1);
|
|
106
|
+
var defaultIndex_1 = options.indexOf(defaultOption || options[0]);
|
|
107
|
+
setSelectIndex(defaultIndex_1 + visibleAbove);
|
|
108
|
+
var timer_1 = setTimeout(function () {
|
|
109
|
+
if (scrollRef.current) {
|
|
110
|
+
scrollRef.current.scrollTop = defaultIndex_1 * calcuItemHeight_1;
|
|
111
|
+
}
|
|
112
|
+
}, 0);
|
|
113
|
+
return function () { return clearTimeout(timer_1); };
|
|
114
|
+
}
|
|
115
|
+
}, [rootRef.current]); // 依赖 rootRef.current,当它变化时重新执行
|
|
61
116
|
var scrollRef = useRef(null);
|
|
62
117
|
var _d = useState(0), itemHeight = _d[0], setItemHeight = _d[1];
|
|
63
118
|
var _e = useState([]), itemList = _e[0], setItemList = _e[1];
|
|
@@ -65,26 +120,26 @@ export var WheelPicker = function (props) {
|
|
|
65
120
|
var _g = useState(0), selectIndex = _g[0], setSelectIndex = _g[1];
|
|
66
121
|
var scrollTimmer = useRef(null);
|
|
67
122
|
useEffect(function () {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
setSelectIndex(firstSelectIndex + visibleAbove);
|
|
71
|
-
setItemList(fillBlankItems());
|
|
72
|
-
var timer = setTimeout(function () {
|
|
73
|
-
if (scrollRef.current) {
|
|
74
|
-
scrollRef.current.scrollTop = firstSelectIndex * calcuItemHeight;
|
|
75
|
-
}
|
|
76
|
-
}, 0);
|
|
77
|
-
return function () { return clearTimeout(timer); };
|
|
78
|
-
}, []);
|
|
79
|
-
useEffect(function () {
|
|
80
|
-
if (onChange) {
|
|
81
|
-
onChange(selectIndex - visibleAbove);
|
|
123
|
+
if (onChange && selectIndex - visibleAbove >= 0 && selectIndex - visibleAbove < options.length) {
|
|
124
|
+
onChange(options[selectIndex - visibleAbove]);
|
|
82
125
|
}
|
|
83
126
|
}, [selectIndex]);
|
|
127
|
+
useEffect(function () {
|
|
128
|
+
setItemList(fillBlankItems());
|
|
129
|
+
}, [props.options]);
|
|
84
130
|
var fillBlankItems = function () {
|
|
85
131
|
var startPadding = new Array(visibleAbove).fill('');
|
|
86
132
|
var endPadding = new Array(visibleBelow).fill('');
|
|
87
|
-
return startPadding.concat(
|
|
133
|
+
return startPadding.concat(options, endPadding);
|
|
134
|
+
};
|
|
135
|
+
// 创建一个函数来获取当前时间戳
|
|
136
|
+
var getCurrentTime = function () {
|
|
137
|
+
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
|
|
138
|
+
return performance.now();
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return Date.now();
|
|
142
|
+
}
|
|
88
143
|
};
|
|
89
144
|
var onScroll = function (e) {
|
|
90
145
|
// console.log('onScroll: ', scrollRef.current.scrollTop)
|
|
@@ -95,7 +150,7 @@ export var WheelPicker = function (props) {
|
|
|
95
150
|
scrollTimmer.current = window.setTimeout(function () {
|
|
96
151
|
var finalPos = (selectIndex - visibleAbove) * itemHeight;
|
|
97
152
|
if (!isDraging && scrollRef.current.scrollTop < finalPos - 1 || scrollRef.current.scrollTop > finalPos + 1) {
|
|
98
|
-
animateScroll(scrollRef.current.scrollTop, finalPos,
|
|
153
|
+
animateScroll(scrollRef.current.scrollTop, finalPos, getCurrentTime(), 100);
|
|
99
154
|
}
|
|
100
155
|
if (scrollTimmer.current) {
|
|
101
156
|
clearTimeout(scrollTimmer.current);
|
|
@@ -109,7 +164,7 @@ export var WheelPicker = function (props) {
|
|
|
109
164
|
};
|
|
110
165
|
var animateScroll = function (currentPos, targetPos, startTime, duration) {
|
|
111
166
|
var step = function () {
|
|
112
|
-
var currentTime =
|
|
167
|
+
var currentTime = getCurrentTime();
|
|
113
168
|
var time = Math.min(1, (currentTime - startTime) / duration);
|
|
114
169
|
var timeFunction = time * (2 - time);
|
|
115
170
|
var newPos = currentPos + (targetPos - currentPos) * timeFunction;
|
|
@@ -128,7 +183,7 @@ export var WheelPicker = function (props) {
|
|
|
128
183
|
setIsDraging(false);
|
|
129
184
|
if (!scrollTimmer.current) {
|
|
130
185
|
var finalPos = (selectIndex - visibleAbove) * itemHeight;
|
|
131
|
-
animateScroll(scrollRef.current.scrollTop, finalPos,
|
|
186
|
+
animateScroll(scrollRef.current.scrollTop, finalPos, getCurrentTime(), 100);
|
|
132
187
|
var nowSelectIndex = Math.round((scrollRef.current.scrollTop + visibleAbove * itemHeight) / itemHeight);
|
|
133
188
|
if (selectIndex !== nowSelectIndex) {
|
|
134
189
|
setSelectIndex(nowSelectIndex);
|
|
@@ -136,12 +191,15 @@ export var WheelPicker = function (props) {
|
|
|
136
191
|
}
|
|
137
192
|
}
|
|
138
193
|
};
|
|
139
|
-
return (h("div", { style: __assign(
|
|
194
|
+
return (h("div", { id: rootId, className: rootClassName, style: __assign({}, defaulWrapperStyle), ref: rootRef },
|
|
195
|
+
elementStyleOrClass.selectedAreaStyle &&
|
|
196
|
+
h("div", { className: typeof elementStyleOrClass.selectedAreaStyle === 'string' ? elementStyleOrClass.selectedAreaStyle : '', style: __assign(__assign(__assign({}, (typeof elementStyleOrClass.selectedAreaStyle === 'object' ? elementStyleOrClass.selectedAreaStyle : undefined)), maskAreaStyle), { height: "".concat(itemHeight, "px"), top: "".concat(itemHeight * visibleAbove, "px") }) }),
|
|
197
|
+
elementStyleOrClass.AboveMaskAreaStyle &&
|
|
198
|
+
h("div", { className: typeof elementStyleOrClass.AboveMaskAreaStyle === 'string' ? elementStyleOrClass.AboveMaskAreaStyle : '', style: __assign(__assign(__assign({}, (typeof elementStyleOrClass.AboveMaskAreaStyle === 'object' ? elementStyleOrClass.AboveMaskAreaStyle : undefined)), maskAreaStyle), { height: "".concat(itemHeight * visibleAbove, "px"), top: '0px' }) }),
|
|
199
|
+
elementStyleOrClass.BelowMaskAreaStyle &&
|
|
200
|
+
h("div", { className: typeof elementStyleOrClass.BelowMaskAreaStyle === 'string' ? elementStyleOrClass.BelowMaskAreaStyle : '', style: __assign(__assign(__assign({}, (typeof elementStyleOrClass.BelowMaskAreaStyle === 'object' ? elementStyleOrClass.BelowMaskAreaStyle : undefined)), maskAreaStyle), { height: "".concat(itemHeight * visibleBelow, "px"), top: "".concat(itemHeight * (visibleAbove + 1), "px") }) }),
|
|
140
201
|
h("div", { style: __assign({}, defaultScrollStyle),
|
|
141
202
|
// movement-type={'clamped'}
|
|
142
203
|
ref: scrollRef, onScroll: function (e) { onScroll(e); }, onMouseDown: function () { onMouseEvent(true); }, onMouseUp: function () { onMouseEvent(false); } }, itemList.map(function (item, index) { return (h("div", { style: __assign(__assign({}, defaultItemStyle), { minHeight: "".concat(itemHeight, "px") }) },
|
|
143
|
-
h("
|
|
144
|
-
selectedAreaStyle && h("div", { style: __assign(__assign(__assign({}, selectedAreaStyle), defaultMaskAreaStyle), { height: "".concat(itemHeight, "px"), top: "".concat(itemHeight * visibleAbove, "px") }) }),
|
|
145
|
-
AboveMaskAreaStyle && h("div", { style: __assign(__assign(__assign({}, AboveMaskAreaStyle), defaultMaskAreaStyle), { height: "".concat(itemHeight * visibleAbove, "px"), top: '0px' }) }),
|
|
146
|
-
BelowMaskAreaStyle && h("div", { style: __assign(__assign(__assign({}, BelowMaskAreaStyle), defaultMaskAreaStyle), { height: "".concat(itemHeight * visibleBelow, "px"), top: "".concat(itemHeight * (visibleAbove + 1), "px") }) })));
|
|
204
|
+
h("div", { className: getSelectedClass(index), style: getSelectedStyle(index) }, item))); }))));
|
|
147
205
|
};
|