@mpxjs/webpack-plugin 2.9.69-beta.0 → 2.9.69-beta.10
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/config.js +3 -1
- package/lib/index.js +17 -1
- package/lib/platform/style/wx/index.js +18 -18
- package/lib/platform/template/wx/component-config/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/platform/template/wx/index.js +3 -1
- package/lib/react/processScript.js +6 -4
- package/lib/resolver/AddEnvPlugin.js +1 -0
- package/lib/resolver/AddModePlugin.js +1 -0
- package/lib/runtime/components/react/context.ts +25 -0
- package/lib/runtime/components/react/dist/context.js +4 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +5 -6
- package/lib/runtime/components/react/dist/locale-provider.jsx +15 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
- package/lib/runtime/components/react/dist/mpx-image.jsx +13 -9
- package/lib/runtime/components/react/dist/mpx-input.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +72 -57
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-consumer.jsx +23 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +93 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +40 -0
- package/lib/runtime/components/react/dist/mpx-portal.jsx +13 -0
- package/lib/runtime/components/react/dist/mpx-provider.jsx +31 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +18 -9
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +437 -372
- package/lib/runtime/components/react/dist/mpx-view.jsx +18 -53
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +163 -49
- package/lib/runtime/components/react/dist/pickerFaces.js +3 -8
- package/lib/runtime/components/react/dist/useAnimationHooks.js +31 -14
- package/lib/runtime/components/react/dist/utils.jsx +120 -4
- package/lib/runtime/components/react/getInnerListeners.ts +5 -7
- package/lib/runtime/components/react/locale-provider.tsx +83 -0
- package/lib/runtime/components/react/mpx-button.tsx +20 -57
- package/lib/runtime/components/react/mpx-image.tsx +41 -25
- package/lib/runtime/components/react/mpx-input.tsx +1 -1
- package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker/time.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +196 -163
- package/lib/runtime/components/react/mpx-picker-view.tsx +35 -37
- package/lib/runtime/components/react/mpx-portal/portal-consumer.tsx +32 -0
- package/lib/runtime/components/react/mpx-portal/portal-host.tsx +127 -0
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +64 -0
- package/lib/runtime/components/react/mpx-portal.tsx +30 -0
- package/lib/runtime/components/react/mpx-provider.tsx +51 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +12 -18
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +29 -18
- package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
- package/lib/runtime/components/react/mpx-swiper.tsx +743 -0
- package/lib/runtime/components/react/mpx-view.tsx +22 -65
- package/lib/runtime/components/react/mpx-web-view.tsx +199 -47
- package/lib/runtime/components/react/pickerFaces.ts +10 -7
- package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/{pickerOverlay.tsx → pickerViewOverlay.tsx} +5 -3
- package/lib/runtime/components/react/types/global.d.ts +10 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +35 -15
- package/lib/runtime/components/react/utils.tsx +139 -5
- package/lib/style-compiler/index.js +3 -4
- package/lib/style-compiler/strip-conditional-loader.js +118 -0
- package/lib/template-compiler/compiler.js +10 -15
- package/lib/utils/pre-process-json.js +5 -9
- package/lib/wxss/loader.js +15 -2
- package/package.json +1 -1
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { useEffect, useCallback, useMemo, useRef, isValidElement, useContext, useState, Children, cloneElement } from 'react';
|
|
2
|
-
import { Image } from 'react-native';
|
|
2
|
+
import { Image, Platform } from 'react-native';
|
|
3
3
|
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils';
|
|
4
|
-
import { VarContext } from './context';
|
|
4
|
+
import { VarContext, ScrollViewContext } from './context';
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
7
7
|
import FastImage from '@d11/react-native-fast-image';
|
|
8
|
+
import { runOnJS } from 'react-native-reanimated';
|
|
9
|
+
import { Gesture } from 'react-native-gesture-handler';
|
|
8
10
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
|
|
9
11
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
|
|
10
12
|
export const URL_REGEX = /^\s*url\(["']?(.*?)["']?\)\s*$/;
|
|
@@ -15,6 +17,8 @@ export const DEFAULT_FONT_SIZE = 16;
|
|
|
15
17
|
export const HIDDEN_STYLE = {
|
|
16
18
|
opacity: 0
|
|
17
19
|
};
|
|
20
|
+
export const isIOS = Platform.OS === 'ios';
|
|
21
|
+
export const isAndroid = Platform.OS === 'android';
|
|
18
22
|
const varDecRegExp = /^--.*/;
|
|
19
23
|
const varUseRegExp = /var\(/;
|
|
20
24
|
const calcUseRegExp = /calc\(/;
|
|
@@ -447,13 +451,14 @@ export function wrapChildren(props = {}, { hasVarDec, varContext, textStyle, tex
|
|
|
447
451
|
export const debounce = (func, delay) => {
|
|
448
452
|
let timer;
|
|
449
453
|
const wrapper = (...args) => {
|
|
450
|
-
clearTimeout(timer);
|
|
454
|
+
timer && clearTimeout(timer);
|
|
451
455
|
timer = setTimeout(() => {
|
|
452
456
|
func(...args);
|
|
453
457
|
}, delay);
|
|
454
458
|
};
|
|
455
459
|
wrapper.clear = () => {
|
|
456
|
-
clearTimeout(timer);
|
|
460
|
+
timer && clearTimeout(timer);
|
|
461
|
+
timer = null;
|
|
457
462
|
};
|
|
458
463
|
return wrapper;
|
|
459
464
|
};
|
|
@@ -500,3 +505,114 @@ export function pickStyle(styleObj = {}, pickedKeys, callback) {
|
|
|
500
505
|
return acc;
|
|
501
506
|
}, {});
|
|
502
507
|
}
|
|
508
|
+
export function useHoverStyle({ hoverStyle, hoverStartTime, hoverStayTime, disabled }) {
|
|
509
|
+
const enableHoverStyle = !!hoverStyle;
|
|
510
|
+
const enableHoverStyleRef = useRef(enableHoverStyle);
|
|
511
|
+
if (enableHoverStyleRef.current !== enableHoverStyle) {
|
|
512
|
+
throw new Error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.');
|
|
513
|
+
}
|
|
514
|
+
if (!enableHoverStyle)
|
|
515
|
+
return { enableHoverStyle };
|
|
516
|
+
const gestureRef = useContext(ScrollViewContext).gestureRef;
|
|
517
|
+
const [isHover, setIsHover] = useState(false);
|
|
518
|
+
const dataRef = useRef({});
|
|
519
|
+
useEffect(() => {
|
|
520
|
+
return () => {
|
|
521
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
522
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
|
|
523
|
+
};
|
|
524
|
+
}, []);
|
|
525
|
+
const setStartTimer = () => {
|
|
526
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
527
|
+
dataRef.current.startTimer = setTimeout(() => {
|
|
528
|
+
setIsHover(true);
|
|
529
|
+
}, +hoverStartTime);
|
|
530
|
+
};
|
|
531
|
+
const setStayTimer = () => {
|
|
532
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
|
|
533
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
534
|
+
dataRef.current.stayTimer = setTimeout(() => {
|
|
535
|
+
setIsHover(false);
|
|
536
|
+
}, +hoverStayTime);
|
|
537
|
+
};
|
|
538
|
+
const gesture = useMemo(() => {
|
|
539
|
+
return Gesture.Pan()
|
|
540
|
+
.onTouchesDown(() => {
|
|
541
|
+
'worklet';
|
|
542
|
+
if (disabled)
|
|
543
|
+
return;
|
|
544
|
+
runOnJS(setStartTimer)();
|
|
545
|
+
})
|
|
546
|
+
.onTouchesUp(() => {
|
|
547
|
+
'worklet';
|
|
548
|
+
if (disabled)
|
|
549
|
+
return;
|
|
550
|
+
runOnJS(setStayTimer)();
|
|
551
|
+
});
|
|
552
|
+
}, [disabled]);
|
|
553
|
+
if (gestureRef) {
|
|
554
|
+
gesture.simultaneousWithExternalGesture(gestureRef);
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
isHover,
|
|
558
|
+
gesture,
|
|
559
|
+
enableHoverStyle
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
export function useHover({ enableHover, hoverStartTime, hoverStayTime, disabled }) {
|
|
563
|
+
const enableHoverRef = useRef(enableHover);
|
|
564
|
+
if (enableHoverRef.current !== enableHover) {
|
|
565
|
+
error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.');
|
|
566
|
+
}
|
|
567
|
+
if (!enableHoverRef.current)
|
|
568
|
+
return { isHover: false };
|
|
569
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
570
|
+
const gestureRef = useContext(ScrollViewContext).gestureRef;
|
|
571
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
572
|
+
const [isHover, setIsHover] = useState(false);
|
|
573
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
574
|
+
const dataRef = useRef({});
|
|
575
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
576
|
+
useEffect(() => {
|
|
577
|
+
return () => {
|
|
578
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
579
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
|
|
580
|
+
};
|
|
581
|
+
}, []);
|
|
582
|
+
const setStartTimer = () => {
|
|
583
|
+
if (disabled)
|
|
584
|
+
return;
|
|
585
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
586
|
+
dataRef.current.startTimer = setTimeout(() => {
|
|
587
|
+
setIsHover(true);
|
|
588
|
+
}, +hoverStartTime);
|
|
589
|
+
};
|
|
590
|
+
const setStayTimer = () => {
|
|
591
|
+
if (disabled)
|
|
592
|
+
return;
|
|
593
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer);
|
|
594
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer);
|
|
595
|
+
dataRef.current.stayTimer = setTimeout(() => {
|
|
596
|
+
setIsHover(false);
|
|
597
|
+
}, +hoverStayTime);
|
|
598
|
+
};
|
|
599
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
600
|
+
const gesture = useMemo(() => {
|
|
601
|
+
return Gesture.Pan()
|
|
602
|
+
.onTouchesDown(() => {
|
|
603
|
+
'worklet';
|
|
604
|
+
runOnJS(setStartTimer)();
|
|
605
|
+
})
|
|
606
|
+
.onTouchesUp(() => {
|
|
607
|
+
'worklet';
|
|
608
|
+
runOnJS(setStayTimer)();
|
|
609
|
+
});
|
|
610
|
+
}, []);
|
|
611
|
+
if (gestureRef) {
|
|
612
|
+
gesture.simultaneousWithExternalGesture(gestureRef);
|
|
613
|
+
}
|
|
614
|
+
return {
|
|
615
|
+
isHover,
|
|
616
|
+
gesture
|
|
617
|
+
};
|
|
618
|
+
}
|
|
@@ -126,8 +126,8 @@ function checkIsNeedPress (e: NativeTouchEvent, type: 'bubble' | 'capture', ref:
|
|
|
126
126
|
const currentPageX = nativeEvent.changedTouches[0].pageX
|
|
127
127
|
const currentPageY = nativeEvent.changedTouches[0].pageY
|
|
128
128
|
if (
|
|
129
|
-
Math.abs(currentPageX - tapDetailInfo.x) >
|
|
130
|
-
Math.abs(currentPageY - tapDetailInfo.y) >
|
|
129
|
+
Math.abs(currentPageX - tapDetailInfo.x) > 3 ||
|
|
130
|
+
Math.abs(currentPageY - tapDetailInfo.y) > 3
|
|
131
131
|
) {
|
|
132
132
|
ref.current!.needPress[type] = false
|
|
133
133
|
ref.current!.startTimer[type] &&
|
|
@@ -289,7 +289,6 @@ const useInnerProps = (
|
|
|
289
289
|
const eventConfig: { [key: string]: string[] } = {}
|
|
290
290
|
const config = rawConfig || {
|
|
291
291
|
layoutRef: { current: {} },
|
|
292
|
-
disableTouch: false,
|
|
293
292
|
disableTap: false
|
|
294
293
|
}
|
|
295
294
|
const removeProps = [
|
|
@@ -317,11 +316,10 @@ const useInnerProps = (
|
|
|
317
316
|
}
|
|
318
317
|
}
|
|
319
318
|
|
|
320
|
-
if (!rawEventKeys.length || config.disableTouch) {
|
|
321
|
-
return omit(propsRef.current, removeProps)
|
|
322
|
-
}
|
|
323
|
-
|
|
324
319
|
const events = useMemo(() => {
|
|
320
|
+
if (!rawEventKeys.length) {
|
|
321
|
+
return {}
|
|
322
|
+
}
|
|
325
323
|
const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => {
|
|
326
324
|
if (propsRef.current[key]) {
|
|
327
325
|
return acc.concat(eventConfig[key])
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createContext, useMemo, memo, ReactNode } from 'react'
|
|
2
|
+
import { extendObject } from './utils'
|
|
3
|
+
|
|
4
|
+
interface Locale {
|
|
5
|
+
/** zh_CN */
|
|
6
|
+
locale: string
|
|
7
|
+
DatePicker: {
|
|
8
|
+
/** 确定 */
|
|
9
|
+
okText: string
|
|
10
|
+
/** 取消 */
|
|
11
|
+
dismissText: string
|
|
12
|
+
/** 请选择 */
|
|
13
|
+
extra: string
|
|
14
|
+
DatePickerLocale: {
|
|
15
|
+
/** 年 */
|
|
16
|
+
year: string
|
|
17
|
+
/** 月 */
|
|
18
|
+
month: string
|
|
19
|
+
/** 日 */
|
|
20
|
+
day: string
|
|
21
|
+
/** 时 */
|
|
22
|
+
hour: string
|
|
23
|
+
/** 分 */
|
|
24
|
+
minute: string
|
|
25
|
+
/** 上午 */
|
|
26
|
+
am: string
|
|
27
|
+
/** 下午 */
|
|
28
|
+
pm: string
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
DatePickerView: {
|
|
32
|
+
/** 年 */
|
|
33
|
+
year: string
|
|
34
|
+
/** 月 */
|
|
35
|
+
month: string
|
|
36
|
+
/** 日 */
|
|
37
|
+
day: string
|
|
38
|
+
/** 时 */
|
|
39
|
+
hour: string
|
|
40
|
+
/** 分 */
|
|
41
|
+
minute: string
|
|
42
|
+
/** 上午 */
|
|
43
|
+
am: string
|
|
44
|
+
/** 下午 */
|
|
45
|
+
pm: string
|
|
46
|
+
}
|
|
47
|
+
Picker: {
|
|
48
|
+
/** 确定 */
|
|
49
|
+
okText: string
|
|
50
|
+
/** 取消 */
|
|
51
|
+
dismissText: string
|
|
52
|
+
/** 请选择 */
|
|
53
|
+
extra: string
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export type LocaleContextProps = {
|
|
57
|
+
antLocale: Partial<Locale & { exist: boolean }>
|
|
58
|
+
}
|
|
59
|
+
export interface LocaleProviderProps {
|
|
60
|
+
children?: ReactNode,
|
|
61
|
+
locale?: LocaleContextProps
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const LocaleContext = createContext<
|
|
65
|
+
LocaleContextProps | undefined
|
|
66
|
+
>(undefined)
|
|
67
|
+
|
|
68
|
+
const LocaleProvider = (props :LocaleProviderProps): JSX.Element => {
|
|
69
|
+
const locale = useMemo(() => {
|
|
70
|
+
return {
|
|
71
|
+
antLocale: extendObject({}, props.locale, { exist: true })
|
|
72
|
+
}
|
|
73
|
+
}, [props.locale])
|
|
74
|
+
return (
|
|
75
|
+
<LocaleContext.Provider value={locale}>
|
|
76
|
+
{props.children}
|
|
77
|
+
</LocaleContext.Provider>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
LocaleProvider.displayName = 'LocaleProvider'
|
|
82
|
+
|
|
83
|
+
export default memo(LocaleProvider)
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* ✘ bindagreeprivacyauthorization
|
|
35
35
|
* ✔ bindtap
|
|
36
36
|
*/
|
|
37
|
-
import { createElement, useEffect, useRef,
|
|
37
|
+
import { createElement, useEffect, useRef, ReactNode, forwardRef, useContext, JSX } from 'react'
|
|
38
38
|
import {
|
|
39
39
|
View,
|
|
40
40
|
StyleSheet,
|
|
@@ -45,10 +45,12 @@ import {
|
|
|
45
45
|
NativeSyntheticEvent
|
|
46
46
|
} from 'react-native'
|
|
47
47
|
import { warn } from '@mpxjs/utils'
|
|
48
|
-
import {
|
|
48
|
+
import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
|
|
49
|
+
import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils'
|
|
49
50
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
50
51
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
51
52
|
import { RouteContext, FormContext } from './context'
|
|
53
|
+
import type { ExtendedViewStyle } from './types/common'
|
|
52
54
|
|
|
53
55
|
export type Type = 'default' | 'primary' | 'warn'
|
|
54
56
|
|
|
@@ -68,7 +70,7 @@ export interface ButtonProps {
|
|
|
68
70
|
disabled?: boolean
|
|
69
71
|
loading?: boolean
|
|
70
72
|
'hover-class'?: string
|
|
71
|
-
'hover-style'?:
|
|
73
|
+
'hover-style'?: ExtendedViewStyle
|
|
72
74
|
'hover-start-time'?: number
|
|
73
75
|
'hover-stay-time'?: number
|
|
74
76
|
'open-type'?: OpenType
|
|
@@ -83,8 +85,6 @@ export interface ButtonProps {
|
|
|
83
85
|
children: ReactNode
|
|
84
86
|
bindgetuserinfo?: (userInfo: any) => void
|
|
85
87
|
bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
86
|
-
bindtouchstart?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
87
|
-
bindtouchend?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
const LOADING_IMAGE_URI =
|
|
@@ -216,15 +216,16 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
216
216
|
style = {},
|
|
217
217
|
children,
|
|
218
218
|
bindgetuserinfo,
|
|
219
|
-
bindtap
|
|
220
|
-
bindtouchstart,
|
|
221
|
-
bindtouchend
|
|
219
|
+
bindtap
|
|
222
220
|
} = props
|
|
223
221
|
|
|
224
222
|
const pageId = useContext(RouteContext)
|
|
225
223
|
|
|
226
224
|
const formContext = useContext(FormContext)
|
|
227
225
|
|
|
226
|
+
const enableHover = hoverClass !== 'none'
|
|
227
|
+
const { isHover, gesture } = useHover({ enableHover, hoverStartTime, hoverStayTime, disabled })
|
|
228
|
+
|
|
228
229
|
let submitFn: () => void | undefined
|
|
229
230
|
let resetFn: () => void | undefined
|
|
230
231
|
|
|
@@ -233,27 +234,15 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
233
234
|
resetFn = formContext.reset
|
|
234
235
|
}
|
|
235
236
|
|
|
236
|
-
const refs = useRef<{
|
|
237
|
-
hoverStartTimer: ReturnType<typeof setTimeout> | undefined
|
|
238
|
-
hoverStayTimer: ReturnType<typeof setTimeout> | undefined
|
|
239
|
-
}>({
|
|
240
|
-
hoverStartTimer: undefined,
|
|
241
|
-
hoverStayTimer: undefined
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
const [isHover, setIsHover] = useState(false)
|
|
245
|
-
|
|
246
237
|
const isMiniSize = size === 'mini'
|
|
247
238
|
|
|
248
|
-
const applyHoverEffect = isHover && hoverClass !== 'none'
|
|
249
|
-
|
|
250
239
|
const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type]
|
|
251
240
|
|
|
252
|
-
const normalBackgroundColor = disabled ? disabledColor :
|
|
241
|
+
const normalBackgroundColor = disabled ? disabledColor : isHover || loading ? hoverColor : color
|
|
253
242
|
|
|
254
243
|
const plainBorderColor = disabled
|
|
255
244
|
? 'rgba(0, 0, 0, .2)'
|
|
256
|
-
:
|
|
245
|
+
: isHover
|
|
257
246
|
? `rgba(${plainColor},.6)`
|
|
258
247
|
: `rgb(${plainColor})`
|
|
259
248
|
|
|
@@ -261,14 +250,14 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
261
250
|
|
|
262
251
|
const plainTextColor = disabled
|
|
263
252
|
? 'rgba(0, 0, 0, .2)'
|
|
264
|
-
:
|
|
253
|
+
: isHover
|
|
265
254
|
? `rgba(${plainColor}, .6)`
|
|
266
255
|
: `rgb(${plainColor})`
|
|
267
256
|
|
|
268
257
|
const normalTextColor =
|
|
269
258
|
type === 'default'
|
|
270
|
-
? `rgba(0, 0, 0, ${disabled ? 0.3 :
|
|
271
|
-
: `rgba(255 ,255 ,255 , ${disabled ||
|
|
259
|
+
? `rgba(0, 0, 0, ${disabled ? 0.3 : isHover || loading ? 0.6 : 1})`
|
|
260
|
+
: `rgba(255 ,255 ,255 , ${disabled || isHover || loading ? 0.6 : 1})`
|
|
272
261
|
|
|
273
262
|
const viewStyle = {
|
|
274
263
|
borderWidth: 1,
|
|
@@ -297,7 +286,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
297
286
|
{},
|
|
298
287
|
defaultStyle,
|
|
299
288
|
style,
|
|
300
|
-
|
|
289
|
+
isHover ? hoverStyle : {}
|
|
301
290
|
)
|
|
302
291
|
|
|
303
292
|
const {
|
|
@@ -366,34 +355,6 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
366
355
|
}
|
|
367
356
|
}
|
|
368
357
|
|
|
369
|
-
const setStayTimer = () => {
|
|
370
|
-
clearTimeout(refs.current.hoverStayTimer)
|
|
371
|
-
refs.current.hoverStayTimer = setTimeout(() => {
|
|
372
|
-
setIsHover(false)
|
|
373
|
-
clearTimeout(refs.current.hoverStayTimer)
|
|
374
|
-
}, hoverStayTime)
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const setStartTimer = () => {
|
|
378
|
-
clearTimeout(refs.current.hoverStartTimer)
|
|
379
|
-
refs.current.hoverStartTimer = setTimeout(() => {
|
|
380
|
-
setIsHover(true)
|
|
381
|
-
clearTimeout(refs.current.hoverStartTimer)
|
|
382
|
-
}, hoverStartTime)
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const onTouchStart = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
386
|
-
bindtouchstart && bindtouchstart(evt)
|
|
387
|
-
if (disabled) return
|
|
388
|
-
setStartTimer()
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const onTouchEnd = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
392
|
-
bindtouchend && bindtouchend(evt)
|
|
393
|
-
if (disabled) return
|
|
394
|
-
setStayTimer()
|
|
395
|
-
}
|
|
396
|
-
|
|
397
358
|
const handleFormTypeFn = () => {
|
|
398
359
|
if (formType === 'submit') {
|
|
399
360
|
submitFn && submitFn()
|
|
@@ -418,8 +379,6 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
418
379
|
},
|
|
419
380
|
layoutProps,
|
|
420
381
|
{
|
|
421
|
-
bindtouchstart: (bindtouchstart || !disabled) && onTouchStart,
|
|
422
|
-
bindtouchend: (bindtouchend || !disabled) && onTouchEnd,
|
|
423
382
|
bindtap: !disabled && onTap
|
|
424
383
|
}
|
|
425
384
|
),
|
|
@@ -442,7 +401,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
442
401
|
}
|
|
443
402
|
)
|
|
444
403
|
|
|
445
|
-
|
|
404
|
+
const baseButton = createElement(View, innerProps, loading && createElement(Loading, { alone: !children }),
|
|
446
405
|
wrapChildren(
|
|
447
406
|
props,
|
|
448
407
|
{
|
|
@@ -453,6 +412,10 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
453
412
|
}
|
|
454
413
|
)
|
|
455
414
|
)
|
|
415
|
+
|
|
416
|
+
return enableHover
|
|
417
|
+
? createElement(GestureDetector, { gesture: gesture as PanGesture }, baseButton)
|
|
418
|
+
: baseButton
|
|
456
419
|
})
|
|
457
420
|
|
|
458
421
|
Button.displayName = 'MpxButton'
|
|
@@ -403,32 +403,48 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
403
403
|
}
|
|
404
404
|
)
|
|
405
405
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
406
|
+
const createBaseImage = (innerProps = {}) => {
|
|
407
|
+
return renderImage(
|
|
408
|
+
extendObject(
|
|
409
|
+
{
|
|
410
|
+
source: { uri: src },
|
|
411
|
+
resizeMode: resizeMode,
|
|
412
|
+
onLoad: bindload && onImageLoad,
|
|
413
|
+
onError: binderror && onImageError,
|
|
414
|
+
style: extendObject(
|
|
415
|
+
{
|
|
416
|
+
transformOrigin: 'top left',
|
|
417
|
+
width: isCropMode ? imageWidth : '100%',
|
|
418
|
+
height: isCropMode ? imageHeight : '100%'
|
|
419
|
+
},
|
|
420
|
+
isCropMode ? modeStyle : {}
|
|
421
|
+
)
|
|
422
|
+
},
|
|
423
|
+
innerProps
|
|
424
|
+
),
|
|
425
|
+
enableFastImage
|
|
426
|
+
)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const SvgImage = createElement(
|
|
430
|
+
View,
|
|
431
|
+
innerProps,
|
|
432
|
+
createElement(SvgCssUri, {
|
|
433
|
+
uri: src,
|
|
434
|
+
onLayout: onSvgLoad,
|
|
435
|
+
onError: binderror && onSvgError,
|
|
436
|
+
style: extendObject(
|
|
437
|
+
{ transformOrigin: 'top left' },
|
|
438
|
+
modeStyle
|
|
439
|
+
)
|
|
440
|
+
})
|
|
431
441
|
)
|
|
442
|
+
|
|
443
|
+
const BaseImage = createBaseImage(innerProps)
|
|
444
|
+
|
|
445
|
+
const LayoutImage = createElement(View, innerProps, loaded && createBaseImage())
|
|
446
|
+
|
|
447
|
+
return isSvg ? SvgImage : isLayoutMode ? LayoutImage : BaseImage
|
|
432
448
|
})
|
|
433
449
|
|
|
434
450
|
Image.displayName = 'mpx-image'
|
|
@@ -149,7 +149,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
149
149
|
'parent-font-size': parentFontSize,
|
|
150
150
|
'parent-width': parentWidth,
|
|
151
151
|
'parent-height': parentHeight,
|
|
152
|
-
'adjust-position': adjustPosition =
|
|
152
|
+
'adjust-position': adjustPosition = false,
|
|
153
153
|
bindinput,
|
|
154
154
|
bindfocus,
|
|
155
155
|
bindblur,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { View, Text, Modal, TouchableWithoutFeedback } from 'react-native'
|
|
2
|
-
import
|
|
2
|
+
import Portal from '../mpx-portal'
|
|
3
|
+
import { PickerView } from '@ant-design/react-native'
|
|
3
4
|
import React, { forwardRef, useState, useRef, useEffect } from 'react'
|
|
4
5
|
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
5
6
|
import { TimeProps } from './type'
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
|
+
import { LayoutChangeEvent } from 'react-native'
|
|
3
|
+
import Reanimated, { Extrapolation, interpolate, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
|
|
4
|
+
import { wrapChildren, extendObject } from './utils'
|
|
5
|
+
import { createFaces } from './pickerFaces'
|
|
6
|
+
import { usePickerViewColumnAnimationContext } from './pickerVIewContext'
|
|
7
|
+
|
|
8
|
+
interface PickerColumnItemProps {
|
|
9
|
+
item: React.ReactElement
|
|
10
|
+
index: number
|
|
11
|
+
itemHeight: number
|
|
12
|
+
itemWidth?: number | '100%'
|
|
13
|
+
textStyleFromParent: Record<string, any>
|
|
14
|
+
textStyle: Record<string, any>
|
|
15
|
+
hasVarDec: boolean
|
|
16
|
+
varContext: Record<string, any>
|
|
17
|
+
visibleCount: number
|
|
18
|
+
textProps?: any
|
|
19
|
+
onItemLayout?: (e: LayoutChangeEvent) => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const _PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
|
|
23
|
+
item,
|
|
24
|
+
index,
|
|
25
|
+
itemHeight,
|
|
26
|
+
itemWidth = '100%',
|
|
27
|
+
textStyleFromParent,
|
|
28
|
+
textStyle,
|
|
29
|
+
hasVarDec,
|
|
30
|
+
varContext,
|
|
31
|
+
textProps,
|
|
32
|
+
visibleCount,
|
|
33
|
+
onItemLayout
|
|
34
|
+
}) => {
|
|
35
|
+
const offsetYShared = usePickerViewColumnAnimationContext()
|
|
36
|
+
const facesShared = useSharedValue(createFaces(itemHeight, visibleCount))
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
facesShared.value = createFaces(itemHeight, visibleCount)
|
|
40
|
+
}, [itemHeight])
|
|
41
|
+
|
|
42
|
+
const animatedStyles = useAnimatedStyle(() => {
|
|
43
|
+
const inputRange = facesShared.value.map((f) => itemHeight * (index + f.index))
|
|
44
|
+
return {
|
|
45
|
+
opacity: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.opacity), Extrapolation.CLAMP),
|
|
46
|
+
transform: [
|
|
47
|
+
{ translateY: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.offsetY), Extrapolation.EXTEND) },
|
|
48
|
+
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
|
|
49
|
+
{ scale: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.scale), Extrapolation.EXTEND) }
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const strKey = `picker-column-item-${index}`
|
|
55
|
+
const restProps = index === 0 ? { onLayout: onItemLayout } : {}
|
|
56
|
+
const itemProps = extendObject(
|
|
57
|
+
{
|
|
58
|
+
style: extendObject(
|
|
59
|
+
{ height: itemHeight, width: '100%' },
|
|
60
|
+
textStyleFromParent,
|
|
61
|
+
textStyle,
|
|
62
|
+
item.props.style
|
|
63
|
+
)
|
|
64
|
+
},
|
|
65
|
+
restProps
|
|
66
|
+
)
|
|
67
|
+
const realItem = React.cloneElement(item, itemProps)
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Reanimated.View
|
|
71
|
+
key={strKey}
|
|
72
|
+
style={[{ height: itemHeight, width: itemWidth }, animatedStyles]}
|
|
73
|
+
>
|
|
74
|
+
{wrapChildren(
|
|
75
|
+
{ children: realItem },
|
|
76
|
+
{
|
|
77
|
+
hasVarDec,
|
|
78
|
+
varContext,
|
|
79
|
+
textStyle,
|
|
80
|
+
textProps
|
|
81
|
+
}
|
|
82
|
+
)}
|
|
83
|
+
</Reanimated.View>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_PickerViewColumnItem.displayName = 'MpxPickerViewColumnItem'
|
|
88
|
+
export default _PickerViewColumnItem
|