@mpxjs/webpack-plugin 2.9.69-beta.4 → 2.9.69-beta.5
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/runtime/components/react/context.ts +1 -1
- package/lib/runtime/components/react/mpx-button.tsx +12 -13
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +18 -2
- package/lib/runtime/components/react/mpx-portal/portal-consumer.tsx +1 -1
- package/lib/runtime/components/react/mpx-portal/portal-host.tsx +14 -45
- package/lib/runtime/components/react/mpx-portal.tsx +1 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +13 -7
- package/lib/runtime/components/react/mpx-swiper.tsx +377 -330
- package/lib/runtime/components/react/mpx-view.tsx +17 -14
- package/lib/runtime/components/react/mpx-web-view.tsx +19 -32
- package/lib/runtime/components/react/pickerFaces.ts +1 -6
- package/lib/runtime/components/react/types/global.d.ts +4 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +14 -10
- package/lib/runtime/components/react/utils.tsx +64 -0
- package/lib/wxss/loader.js +15 -2
- package/package.json +1 -1
|
@@ -42,7 +42,7 @@ export interface PortalManagerContextValue {
|
|
|
42
42
|
export interface PortalContextValue {
|
|
43
43
|
mount: (children: React.ReactNode, key?: number, pageId?: number|null) => number| undefined
|
|
44
44
|
update: (key: number, children: React.ReactNode, pageId?: number|null) => void
|
|
45
|
-
unmount: (key: number
|
|
45
|
+
unmount: (key: number) => void
|
|
46
46
|
manager?: PortalManagerContextValue
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -45,8 +45,8 @@ import {
|
|
|
45
45
|
NativeSyntheticEvent
|
|
46
46
|
} from 'react-native'
|
|
47
47
|
import { warn } from '@mpxjs/utils'
|
|
48
|
-
import { GestureDetector } from 'react-native-gesture-handler'
|
|
49
|
-
import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject,
|
|
48
|
+
import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
|
|
49
|
+
import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils'
|
|
50
50
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
51
51
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
52
52
|
import { RouteContext, FormContext } from './context'
|
|
@@ -223,7 +223,8 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
223
223
|
|
|
224
224
|
const formContext = useContext(FormContext)
|
|
225
225
|
|
|
226
|
-
const
|
|
226
|
+
const enableHover = hoverClass !== 'none'
|
|
227
|
+
const { isHover, gesture } = useHover({ enableHover, hoverStartTime, hoverStayTime, disabled })
|
|
227
228
|
|
|
228
229
|
let submitFn: () => void | undefined
|
|
229
230
|
let resetFn: () => void | undefined
|
|
@@ -235,15 +236,13 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
235
236
|
|
|
236
237
|
const isMiniSize = size === 'mini'
|
|
237
238
|
|
|
238
|
-
const applyHoverEffect = isHover && hoverClass !== 'none'
|
|
239
|
-
|
|
240
239
|
const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type]
|
|
241
240
|
|
|
242
|
-
const normalBackgroundColor = disabled ? disabledColor :
|
|
241
|
+
const normalBackgroundColor = disabled ? disabledColor : isHover || loading ? hoverColor : color
|
|
243
242
|
|
|
244
243
|
const plainBorderColor = disabled
|
|
245
244
|
? 'rgba(0, 0, 0, .2)'
|
|
246
|
-
:
|
|
245
|
+
: isHover
|
|
247
246
|
? `rgba(${plainColor},.6)`
|
|
248
247
|
: `rgb(${plainColor})`
|
|
249
248
|
|
|
@@ -251,14 +250,14 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
251
250
|
|
|
252
251
|
const plainTextColor = disabled
|
|
253
252
|
? 'rgba(0, 0, 0, .2)'
|
|
254
|
-
:
|
|
253
|
+
: isHover
|
|
255
254
|
? `rgba(${plainColor}, .6)`
|
|
256
255
|
: `rgb(${plainColor})`
|
|
257
256
|
|
|
258
257
|
const normalTextColor =
|
|
259
258
|
type === 'default'
|
|
260
|
-
? `rgba(0, 0, 0, ${disabled ? 0.3 :
|
|
261
|
-
: `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})`
|
|
262
261
|
|
|
263
262
|
const viewStyle = {
|
|
264
263
|
borderWidth: 1,
|
|
@@ -287,7 +286,7 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
287
286
|
{},
|
|
288
287
|
defaultStyle,
|
|
289
288
|
style,
|
|
290
|
-
|
|
289
|
+
isHover ? hoverStyle : {}
|
|
291
290
|
)
|
|
292
291
|
|
|
293
292
|
const {
|
|
@@ -414,8 +413,8 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
414
413
|
)
|
|
415
414
|
)
|
|
416
415
|
|
|
417
|
-
return
|
|
418
|
-
? createElement(GestureDetector, { gesture }, baseButton)
|
|
416
|
+
return enableHover
|
|
417
|
+
? createElement(GestureDetector, { gesture: gesture as PanGesture }, baseButton)
|
|
419
418
|
: baseButton
|
|
420
419
|
})
|
|
421
420
|
|
|
@@ -44,8 +44,8 @@ const _PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
|
|
|
44
44
|
return {
|
|
45
45
|
opacity: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.opacity), Extrapolation.CLAMP),
|
|
46
46
|
transform: [
|
|
47
|
-
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
|
|
48
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
49
|
{ scale: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.scale), Extrapolation.EXTEND) }
|
|
50
50
|
]
|
|
51
51
|
}
|
|
@@ -69,6 +69,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
69
69
|
const prevScrollingInfo = useRef({ index: initialIndex, y: 0 })
|
|
70
70
|
const touching = useRef(false)
|
|
71
71
|
const scrolling = useRef(false)
|
|
72
|
+
const timerScrollTo = useRef<NodeJS.Timeout | null>(null)
|
|
72
73
|
const activeIndex = useRef(initialIndex)
|
|
73
74
|
const prevIndex = usePrevious(initialIndex)
|
|
74
75
|
const prevMaxIndex = usePrevious(maxIndex)
|
|
@@ -125,6 +126,19 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
125
126
|
})
|
|
126
127
|
const debounceResetScrollPosition = useDebounceCallback(stableResetScrollPosition, 10)
|
|
127
128
|
|
|
129
|
+
const clearTimerScrollTo = () => {
|
|
130
|
+
if (timerScrollTo.current) {
|
|
131
|
+
clearTimeout(timerScrollTo.current)
|
|
132
|
+
timerScrollTo.current = null
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
return () => {
|
|
138
|
+
clearTimerScrollTo()
|
|
139
|
+
}
|
|
140
|
+
}, [])
|
|
141
|
+
|
|
128
142
|
useEffect(() => {
|
|
129
143
|
if (
|
|
130
144
|
!scrollViewRef.current ||
|
|
@@ -138,7 +152,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
138
152
|
) {
|
|
139
153
|
return
|
|
140
154
|
}
|
|
141
|
-
|
|
155
|
+
clearTimerScrollTo()
|
|
156
|
+
timerScrollTo.current = setTimeout(() => {
|
|
142
157
|
scrollViewRef.current?.scrollTo({
|
|
143
158
|
x: 0,
|
|
144
159
|
y: getYofIndex(initialIndex),
|
|
@@ -151,7 +166,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
151
166
|
const onContentSizeChange = (_w: number, h: number) => {
|
|
152
167
|
const y = getYofIndex(initialIndex)
|
|
153
168
|
if (y <= h) {
|
|
154
|
-
|
|
169
|
+
clearTimerScrollTo()
|
|
170
|
+
timerScrollTo.current = setTimeout(() => {
|
|
155
171
|
scrollViewRef.current?.scrollTo({ x: 0, y, animated: false })
|
|
156
172
|
}, 0)
|
|
157
173
|
}
|
|
@@ -23,7 +23,7 @@ const PortalConsumer = ({ manager, children } :PortalConsumerProps): JSX.Element
|
|
|
23
23
|
const curPageId = navigation?.pageId
|
|
24
24
|
keyRef.current = manager.mount(children, undefined, curPageId)
|
|
25
25
|
return () => {
|
|
26
|
-
manager.unmount(keyRef.current
|
|
26
|
+
manager.unmount(keyRef.current)
|
|
27
27
|
}
|
|
28
28
|
}, [])
|
|
29
29
|
return null
|
|
@@ -26,6 +26,7 @@ export type Operation =
|
|
|
26
26
|
// events
|
|
27
27
|
const addType = 'MPX_RN_ADD_PORTAL'
|
|
28
28
|
const removeType = 'MPX_RN_REMOVE_PORTAL'
|
|
29
|
+
const updateType = 'MPX_RN_UPDATE_PORTAL'
|
|
29
30
|
// fix react native web does not support DeviceEventEmitter
|
|
30
31
|
const TopViewEventEmitter = DeviceEventEmitter || new NativeEventEmitter()
|
|
31
32
|
|
|
@@ -46,6 +47,10 @@ class PortalGuard {
|
|
|
46
47
|
remove = (key: number) => {
|
|
47
48
|
TopViewEventEmitter.emit(removeType, key)
|
|
48
49
|
}
|
|
50
|
+
|
|
51
|
+
update = (key: number, e: ReactNode) => {
|
|
52
|
+
TopViewEventEmitter.emit(updateType, key, e)
|
|
53
|
+
}
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
56
|
* portal
|
|
@@ -57,6 +62,7 @@ const PortalHost = ({ children } :PortalHostProps): JSX.Element => {
|
|
|
57
62
|
const _queue = useRef<Operation[]>([])
|
|
58
63
|
const _addType = useRef<EventSubscription | null>(null)
|
|
59
64
|
const _removeType = useRef<EventSubscription | null>(null)
|
|
65
|
+
const _updateType = useRef<EventSubscription | null>(null)
|
|
60
66
|
const manager = useRef<PortalManagerContextValue | null>(null)
|
|
61
67
|
let currentPageId: number | undefined
|
|
62
68
|
const _mount = (children: ReactNode, _key?: number, curPageId?: number) => {
|
|
@@ -68,26 +74,17 @@ const PortalHost = ({ children } :PortalHostProps): JSX.Element => {
|
|
|
68
74
|
const key = _key || _nextKey.current++
|
|
69
75
|
if (manager.current) {
|
|
70
76
|
manager.current.mount(key, children)
|
|
71
|
-
} else {
|
|
72
|
-
_queue.current.push({ type: 'mount', key, children })
|
|
73
77
|
}
|
|
74
78
|
return key
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
const _unmount = (key: number
|
|
78
|
-
const navigation = getFocusedNavigation()
|
|
79
|
-
const pageId = navigation?.pageId
|
|
80
|
-
if (pageId !== (curPageId ?? currentPageId)) {
|
|
81
|
-
return
|
|
82
|
-
}
|
|
81
|
+
const _unmount = (key: number) => {
|
|
83
82
|
if (manager.current) {
|
|
84
83
|
manager.current.unmount(key)
|
|
85
|
-
} else {
|
|
86
|
-
_queue.current.push({ type: 'unmount', key })
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
const _update = (key: number, children
|
|
87
|
+
const _update = (key: number, children?: ReactNode, curPageId?: number) => {
|
|
91
88
|
const navigation = getFocusedNavigation()
|
|
92
89
|
const pageId = navigation?.pageId
|
|
93
90
|
if (pageId !== (curPageId ?? currentPageId)) {
|
|
@@ -95,17 +92,6 @@ const PortalHost = ({ children } :PortalHostProps): JSX.Element => {
|
|
|
95
92
|
}
|
|
96
93
|
if (manager.current) {
|
|
97
94
|
manager.current.update(key, children)
|
|
98
|
-
} else {
|
|
99
|
-
const op: Operation = { type: 'mount', key, children }
|
|
100
|
-
const index = _queue.current.findIndex(
|
|
101
|
-
(o) => o.type === 'mount' || (o.type === 'update' && o.key === key)
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
if (index > -1) {
|
|
105
|
-
_queue.current[index] = op
|
|
106
|
-
} else {
|
|
107
|
-
_queue.current.push(op)
|
|
108
|
-
}
|
|
109
95
|
}
|
|
110
96
|
}
|
|
111
97
|
|
|
@@ -113,29 +99,13 @@ const PortalHost = ({ children } :PortalHostProps): JSX.Element => {
|
|
|
113
99
|
const navigation = getFocusedNavigation()
|
|
114
100
|
currentPageId = navigation?.pageId
|
|
115
101
|
_addType.current = TopViewEventEmitter.addListener(addType, _mount)
|
|
116
|
-
_removeType.current = TopViewEventEmitter.addListener(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
102
|
+
_removeType.current = TopViewEventEmitter.addListener(removeType, _unmount)
|
|
103
|
+
_updateType.current = TopViewEventEmitter.addListener(updateType, _update)
|
|
104
|
+
|
|
120
105
|
return () => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
continue
|
|
125
|
-
}
|
|
126
|
-
// tslint:disable-next-line:switch-default
|
|
127
|
-
switch (action.type) {
|
|
128
|
-
case 'mount':
|
|
129
|
-
manager.current?.mount(action.key, action.children)
|
|
130
|
-
break
|
|
131
|
-
case 'update':
|
|
132
|
-
manager.current?.update(action.key, action.children)
|
|
133
|
-
break
|
|
134
|
-
case 'unmount':
|
|
135
|
-
manager.current?.unmount(action.key)
|
|
136
|
-
break
|
|
137
|
-
}
|
|
138
|
-
}
|
|
106
|
+
_addType.current?.remove()
|
|
107
|
+
_removeType.current?.remove()
|
|
108
|
+
_updateType.current?.remove()
|
|
139
109
|
}
|
|
140
110
|
}, [])
|
|
141
111
|
return (
|
|
@@ -146,7 +116,6 @@ const PortalHost = ({ children } :PortalHostProps): JSX.Element => {
|
|
|
146
116
|
unmount: _unmount
|
|
147
117
|
}}
|
|
148
118
|
>
|
|
149
|
-
{/* Need collapsable=false here to clip the elevations, otherwise they appear above Portal components */}
|
|
150
119
|
<View style={styles.container} collapsable={false}>
|
|
151
120
|
{children}
|
|
152
121
|
</View>
|
|
@@ -16,7 +16,7 @@ interface SwiperItemProps {
|
|
|
16
16
|
'parent-height'?: number;
|
|
17
17
|
children?: ReactNode;
|
|
18
18
|
style?: Object;
|
|
19
|
-
customStyle:
|
|
19
|
+
customStyle: Object;
|
|
20
20
|
itemIndex: number;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -24,6 +24,7 @@ interface ContextType {
|
|
|
24
24
|
offset: SharedValue<number>;
|
|
25
25
|
step: SharedValue<number>;
|
|
26
26
|
scale: boolean;
|
|
27
|
+
dir: string;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
|
|
@@ -39,6 +40,7 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
|
|
|
39
40
|
const offset = contextValue.offset || 0
|
|
40
41
|
const step = contextValue.step || 0
|
|
41
42
|
const scale = contextValue.scale || false
|
|
43
|
+
const dir = contextValue.dir || 'x'
|
|
42
44
|
const { textProps } = splitProps(props)
|
|
43
45
|
const nodeRef = useRef(null)
|
|
44
46
|
|
|
@@ -70,22 +72,26 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
|
|
|
70
72
|
'enable-offset',
|
|
71
73
|
'style'
|
|
72
74
|
], { layoutRef })
|
|
73
|
-
|
|
74
75
|
const itemAnimatedStyle = useAnimatedStyle(() => {
|
|
75
76
|
if (!step.value) return {}
|
|
76
77
|
const inputRange = [step.value, 0]
|
|
77
78
|
const outputRange = [0.7, 1]
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
// 实现元素的宽度跟随step从0到真实宽度,且不能触发重新渲染整个组件,通过AnimatedStyle的方式实现
|
|
80
|
+
const outerLayoutStyle = dir === 'x' ? { width: step.value, height: '100%' } : { width: '100%', height: step.value }
|
|
81
|
+
const transformStyle = []
|
|
82
|
+
if (scale) {
|
|
83
|
+
transformStyle.push({
|
|
80
84
|
scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
|
|
81
|
-
}
|
|
85
|
+
})
|
|
82
86
|
}
|
|
87
|
+
return Object.assign(outerLayoutStyle, {
|
|
88
|
+
transform: transformStyle
|
|
89
|
+
})
|
|
83
90
|
})
|
|
84
|
-
const mergeStyle = [innerStyle, layoutStyle, { width: '100%', height: '100%' }, scale ? itemAnimatedStyle : {}].concat(customStyle)
|
|
85
91
|
return (
|
|
86
92
|
<Animated.View
|
|
87
93
|
{...innerProps}
|
|
88
|
-
style={
|
|
94
|
+
style={[innerStyle, layoutStyle, itemAnimatedStyle, customStyle]}
|
|
89
95
|
data-itemId={props['item-id']}>
|
|
90
96
|
{
|
|
91
97
|
wrapChildren(
|