@mpxjs/webpack-plugin 2.9.69-beta.2 → 2.9.69-beta.3
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/index.js +1 -17
- package/lib/platform/style/wx/index.js +18 -18
- package/lib/platform/template/wx/component-config/movable-view.js +1 -8
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/resolver/AddEnvPlugin.js +0 -1
- package/lib/resolver/AddModePlugin.js +0 -1
- package/lib/runtime/components/react/context.ts +0 -8
- package/lib/runtime/components/react/getInnerListeners.ts +5 -3
- 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-view-column.tsx +159 -177
- package/lib/runtime/components/react/mpx-picker-view.tsx +37 -35
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +18 -12
- package/lib/runtime/components/react/mpx-scroll-view.tsx +13 -30
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +527 -0
- package/lib/runtime/components/react/mpx-swiper/index.tsx +80 -0
- package/lib/runtime/components/react/mpx-swiper/type.ts +87 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +10 -38
- package/lib/runtime/components/react/mpx-view.tsx +51 -11
- package/lib/runtime/components/react/mpx-web-view.tsx +13 -57
- package/lib/runtime/components/react/pickerFaces.ts +7 -15
- package/lib/runtime/components/react/{pickerViewOverlay.tsx → pickerOverlay.tsx} +3 -5
- package/lib/runtime/components/react/types/global.d.ts +1 -3
- package/lib/runtime/components/react/useAnimationHooks.ts +1 -1
- package/lib/runtime/components/react/utils.tsx +5 -75
- package/lib/style-compiler/index.js +4 -3
- package/lib/template-compiler/compiler.js +14 -9
- package/lib/utils/hump-dash.js +1 -1
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +0 -88
- package/lib/runtime/components/react/mpx-swiper.tsx +0 -690
- package/lib/runtime/components/react/pickerVIewContext.ts +0 -18
- package/lib/runtime/components/react/pickerViewMask.tsx +0 -30
- package/lib/style-compiler/strip-conditional-loader.js +0 -118
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { View } from 'react-native'
|
|
2
|
-
import
|
|
3
|
-
import { ReactNode, forwardRef, useRef, useContext } from 'react'
|
|
1
|
+
import { View, LayoutChangeEvent } from 'react-native'
|
|
2
|
+
import { ReactNode, forwardRef, useRef } from 'react'
|
|
4
3
|
import useInnerProps from './getInnerListeners'
|
|
5
4
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
6
5
|
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
|
|
7
|
-
import { SwiperContext } from './context'
|
|
8
6
|
|
|
9
7
|
interface SwiperItemProps {
|
|
10
8
|
'item-id'?: string;
|
|
@@ -16,29 +14,15 @@ interface SwiperItemProps {
|
|
|
16
14
|
'parent-height'?: number;
|
|
17
15
|
children?: ReactNode;
|
|
18
16
|
style?: Object;
|
|
19
|
-
customStyle: [];
|
|
20
|
-
itemIndex: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface ContextType {
|
|
24
|
-
offset: SharedValue<number>;
|
|
25
|
-
step: SharedValue<number>;
|
|
26
|
-
scale: boolean;
|
|
27
17
|
}
|
|
28
18
|
|
|
29
19
|
const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
|
|
30
20
|
const {
|
|
31
21
|
'enable-var': enableVar,
|
|
32
22
|
'external-var-context': externalVarContext,
|
|
33
|
-
style
|
|
34
|
-
customStyle,
|
|
35
|
-
itemIndex
|
|
23
|
+
style
|
|
36
24
|
} = props
|
|
37
25
|
|
|
38
|
-
const contextValue = useContext(SwiperContext) as ContextType
|
|
39
|
-
const offset = contextValue.offset || 0
|
|
40
|
-
const step = contextValue.step || 0
|
|
41
|
-
const scale = contextValue.scale || false
|
|
42
26
|
const { textProps } = splitProps(props)
|
|
43
27
|
const nodeRef = useRef(null)
|
|
44
28
|
|
|
@@ -63,31 +47,19 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
|
|
|
63
47
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
|
|
64
48
|
|
|
65
49
|
const innerProps = useInnerProps(props, {
|
|
50
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
66
51
|
ref: nodeRef,
|
|
67
52
|
...layoutProps
|
|
68
53
|
}, [
|
|
69
54
|
'children',
|
|
70
|
-
'enable-offset'
|
|
71
|
-
'style'
|
|
55
|
+
'enable-offset'
|
|
72
56
|
], { layoutRef })
|
|
73
57
|
|
|
74
|
-
const itemAnimatedStyle = useAnimatedStyle(() => {
|
|
75
|
-
if (!step.value) return {}
|
|
76
|
-
const inputRange = [step.value, 0]
|
|
77
|
-
const outputRange = [0.7, 1]
|
|
78
|
-
return {
|
|
79
|
-
transform: [{
|
|
80
|
-
scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
|
|
81
|
-
}]
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
const mergeStyle = [innerStyle, layoutStyle, { width: '100%', height: '100%' }, scale ? itemAnimatedStyle : {}].concat(customStyle)
|
|
85
58
|
return (
|
|
86
|
-
<
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
{
|
|
59
|
+
<View
|
|
60
|
+
data-itemId={props['item-id']}
|
|
61
|
+
{...innerProps}>
|
|
62
|
+
{
|
|
91
63
|
wrapChildren(
|
|
92
64
|
props,
|
|
93
65
|
{
|
|
@@ -98,7 +70,7 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
|
|
|
98
70
|
}
|
|
99
71
|
)
|
|
100
72
|
}
|
|
101
|
-
</
|
|
73
|
+
</View>
|
|
102
74
|
)
|
|
103
75
|
})
|
|
104
76
|
|
|
@@ -12,10 +12,9 @@ import useAnimationHooks from './useAnimationHooks'
|
|
|
12
12
|
import type { AnimationProp } from './useAnimationHooks'
|
|
13
13
|
import { ExtendedViewStyle } from './types/common'
|
|
14
14
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
15
|
-
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject
|
|
15
|
+
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle, extendObject } from './utils'
|
|
16
16
|
import { error } from '@mpxjs/utils'
|
|
17
17
|
import LinearGradient from 'react-native-linear-gradient'
|
|
18
|
-
import { GestureDetector } from 'react-native-gesture-handler'
|
|
19
18
|
|
|
20
19
|
export interface _ViewProps extends ViewProps {
|
|
21
20
|
style?: ExtendedViewStyle
|
|
@@ -684,6 +683,8 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
684
683
|
animation
|
|
685
684
|
} = props
|
|
686
685
|
|
|
686
|
+
const [isHover, setIsHover] = useState(false)
|
|
687
|
+
|
|
687
688
|
// 默认样式
|
|
688
689
|
const defaultStyle: ExtendedViewStyle = style.display === 'flex'
|
|
689
690
|
? {
|
|
@@ -694,8 +695,6 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
694
695
|
}
|
|
695
696
|
: {}
|
|
696
697
|
|
|
697
|
-
const { isHover, enableHoverStyle, gesture } = useHoverStyle({ hoverStyle, hoverStartTime, hoverStayTime })
|
|
698
|
-
|
|
699
698
|
const styleObj: ExtendedViewStyle = extendObject({}, defaultStyle, style, isHover ? hoverStyle as ExtendedViewStyle : {})
|
|
700
699
|
|
|
701
700
|
const {
|
|
@@ -726,6 +725,45 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
726
725
|
style: normalStyle
|
|
727
726
|
})
|
|
728
727
|
|
|
728
|
+
const dataRef = useRef<{
|
|
729
|
+
startTimer?: ReturnType<typeof setTimeout>
|
|
730
|
+
stayTimer?: ReturnType<typeof setTimeout>
|
|
731
|
+
}>({})
|
|
732
|
+
|
|
733
|
+
useEffect(() => {
|
|
734
|
+
return () => {
|
|
735
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
736
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
|
|
737
|
+
}
|
|
738
|
+
}, [])
|
|
739
|
+
|
|
740
|
+
const setStartTimer = () => {
|
|
741
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
742
|
+
dataRef.current.startTimer = setTimeout(() => {
|
|
743
|
+
setIsHover(true)
|
|
744
|
+
}, +hoverStartTime)
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const setStayTimer = () => {
|
|
748
|
+
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
|
|
749
|
+
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
750
|
+
dataRef.current.stayTimer = setTimeout(() => {
|
|
751
|
+
setIsHover(false)
|
|
752
|
+
}, +hoverStayTime)
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function onTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
|
|
756
|
+
const { bindtouchstart } = props
|
|
757
|
+
bindtouchstart && bindtouchstart(e)
|
|
758
|
+
setStartTimer()
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function onTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
|
|
762
|
+
const { bindtouchend } = props
|
|
763
|
+
bindtouchend && bindtouchend(e)
|
|
764
|
+
setStayTimer()
|
|
765
|
+
}
|
|
766
|
+
|
|
729
767
|
const {
|
|
730
768
|
layoutRef,
|
|
731
769
|
layoutStyle,
|
|
@@ -751,7 +789,13 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
751
789
|
ref: nodeRef,
|
|
752
790
|
style: finalStyle
|
|
753
791
|
},
|
|
754
|
-
layoutProps
|
|
792
|
+
layoutProps,
|
|
793
|
+
hoverStyle
|
|
794
|
+
? {
|
|
795
|
+
bindtouchstart: onTouchStart,
|
|
796
|
+
bindtouchend: onTouchEnd
|
|
797
|
+
}
|
|
798
|
+
: {}
|
|
755
799
|
), [
|
|
756
800
|
'hover-start-time',
|
|
757
801
|
'hover-stay-time',
|
|
@@ -772,13 +816,9 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
772
816
|
enableFastImage
|
|
773
817
|
})
|
|
774
818
|
|
|
775
|
-
|
|
776
|
-
? createElement(Animated.View,
|
|
819
|
+
return enableAnimation
|
|
820
|
+
? createElement(Animated.View, innerProps, childNode)
|
|
777
821
|
: createElement(View, innerProps, childNode)
|
|
778
|
-
|
|
779
|
-
return enableHoverStyle
|
|
780
|
-
? createElement(GestureDetector, { gesture }, BaseComponent)
|
|
781
|
-
: BaseComponent
|
|
782
822
|
})
|
|
783
823
|
|
|
784
824
|
_View.displayName = 'MpxView'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, JSX, useRef, useContext, useMemo, createElement
|
|
1
|
+
import { forwardRef, JSX, useRef, useContext, useMemo, createElement } from 'react'
|
|
2
2
|
import { warn, getFocusedNavigation, isFunction } from '@mpxjs/utils'
|
|
3
3
|
import { Portal } from '@ant-design/react-native'
|
|
4
4
|
import { getCustomEvent } from './getInnerListeners'
|
|
@@ -6,9 +6,8 @@ import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab }
|
|
|
6
6
|
import { WebView } from 'react-native-webview'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
8
8
|
import { getCurrentPage, extendObject } from './utils'
|
|
9
|
-
import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation
|
|
9
|
+
import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation } from 'react-native-webview/lib/WebViewTypes'
|
|
10
10
|
import { RouteContext } from './context'
|
|
11
|
-
import { BackHandler } from 'react-native'
|
|
12
11
|
|
|
13
12
|
type OnMessageCallbackEvent = {
|
|
14
13
|
detail: {
|
|
@@ -57,35 +56,6 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
57
56
|
top: 0 as number,
|
|
58
57
|
bottom: 0 as number
|
|
59
58
|
}
|
|
60
|
-
const canGoBack = useRef<boolean>(false)
|
|
61
|
-
|
|
62
|
-
const onAndroidBackPress = useCallback(() => {
|
|
63
|
-
if (canGoBack.current) {
|
|
64
|
-
webViewRef.current?.goBack()
|
|
65
|
-
return true
|
|
66
|
-
}
|
|
67
|
-
return false
|
|
68
|
-
}, [canGoBack])
|
|
69
|
-
|
|
70
|
-
const beforeRemoveHandle = useCallback((e: Event) => {
|
|
71
|
-
if (canGoBack.current) {
|
|
72
|
-
webViewRef.current?.goBack()
|
|
73
|
-
e.preventDefault()
|
|
74
|
-
}
|
|
75
|
-
}, [canGoBack])
|
|
76
|
-
|
|
77
|
-
const navigation = getFocusedNavigation()
|
|
78
|
-
|
|
79
|
-
navigation?.addListener('beforeRemove', beforeRemoveHandle)
|
|
80
|
-
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
if (__mpx_mode__ === 'android') {
|
|
83
|
-
BackHandler.addEventListener('hardwareBackPress', onAndroidBackPress)
|
|
84
|
-
return () => {
|
|
85
|
-
BackHandler.removeEventListener('hardwareBackPress', onAndroidBackPress)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}, [])
|
|
89
59
|
|
|
90
60
|
useNodesRef<WebView, WebViewProps>(props, ref, webViewRef, {
|
|
91
61
|
style: defaultWebViewStyle
|
|
@@ -103,7 +73,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
103
73
|
src: res.nativeEvent?.url
|
|
104
74
|
}
|
|
105
75
|
}
|
|
106
|
-
bindload
|
|
76
|
+
bindload(result)
|
|
107
77
|
}
|
|
108
78
|
const _error = function (res: WebViewErrorEvent) {
|
|
109
79
|
const result = {
|
|
@@ -113,7 +83,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
113
83
|
src: ''
|
|
114
84
|
}
|
|
115
85
|
}
|
|
116
|
-
binderror
|
|
86
|
+
binderror(result)
|
|
117
87
|
}
|
|
118
88
|
const injectedJavaScript = `
|
|
119
89
|
if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
|
|
@@ -139,26 +109,12 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
139
109
|
}
|
|
140
110
|
});
|
|
141
111
|
}
|
|
142
|
-
true;
|
|
143
112
|
`
|
|
144
|
-
const sendMessage = function (params: string) {
|
|
145
|
-
return `
|
|
146
|
-
window.mpxWebviewMessageCallback(${params})
|
|
147
|
-
true;
|
|
148
|
-
`
|
|
149
|
-
}
|
|
150
113
|
const _changeUrl = function (navState: WebViewNavigation) {
|
|
151
114
|
if (navState.navigationType) { // navigationType这个事件在页面开始加载时和页面加载完成时都会被触发所以判断这个避免其他无效触发执行该逻辑
|
|
152
|
-
canGoBack.current = navState.canGoBack
|
|
153
115
|
currentPage.__webViewUrl = navState.url
|
|
154
116
|
}
|
|
155
117
|
}
|
|
156
|
-
|
|
157
|
-
const _onLoadProgress = function (event: WebViewProgressEvent) {
|
|
158
|
-
if (__mpx_mode__ === 'android') {
|
|
159
|
-
canGoBack.current = event.nativeEvent.canGoBack
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
118
|
const _message = function (res: WebViewMessageEvent) {
|
|
163
119
|
let data: MessageData = {}
|
|
164
120
|
let asyncCallback
|
|
@@ -178,6 +134,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
178
134
|
{ // case下不允许直接声明,包个块解决该问题
|
|
179
135
|
const title = postData._documentTitle
|
|
180
136
|
if (title) {
|
|
137
|
+
const navigation = getFocusedNavigation()
|
|
181
138
|
navigation && navigation.setOptions({ title })
|
|
182
139
|
}
|
|
183
140
|
}
|
|
@@ -224,21 +181,21 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
224
181
|
|
|
225
182
|
asyncCallback && asyncCallback.then((res: any) => {
|
|
226
183
|
if (webViewRef.current?.postMessage) {
|
|
227
|
-
const
|
|
184
|
+
const test = JSON.stringify({
|
|
228
185
|
type,
|
|
229
186
|
callbackId: data.callbackId,
|
|
230
187
|
result: res
|
|
231
188
|
})
|
|
232
|
-
webViewRef.current.
|
|
189
|
+
webViewRef.current.postMessage(test)
|
|
233
190
|
}
|
|
234
191
|
}).catch((error: any) => {
|
|
235
192
|
if (webViewRef.current?.postMessage) {
|
|
236
|
-
const
|
|
193
|
+
const test = JSON.stringify({
|
|
237
194
|
type,
|
|
238
195
|
callbackId: data.callbackId,
|
|
239
196
|
error
|
|
240
197
|
})
|
|
241
|
-
webViewRef.current.
|
|
198
|
+
webViewRef.current.postMessage(test)
|
|
242
199
|
}
|
|
243
200
|
})
|
|
244
201
|
}
|
|
@@ -254,17 +211,16 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
254
211
|
onError: _error
|
|
255
212
|
})
|
|
256
213
|
}
|
|
214
|
+
extendObject(events, {
|
|
215
|
+
onMessage: _message
|
|
216
|
+
})
|
|
257
217
|
|
|
258
218
|
return createElement(Portal, null, createElement(WebView, extendObject({
|
|
259
219
|
style: defaultWebViewStyle,
|
|
260
220
|
source: { uri: src },
|
|
261
221
|
ref: webViewRef,
|
|
262
222
|
javaScriptEnabled: true,
|
|
263
|
-
onNavigationStateChange: _changeUrl
|
|
264
|
-
onMessage: _message,
|
|
265
|
-
injectedJavaScript: injectedJavaScript,
|
|
266
|
-
onLoadProgress: _onLoadProgress,
|
|
267
|
-
allowsBackForwardNavigationGestures: true
|
|
223
|
+
onNavigationStateChange: _changeUrl
|
|
268
224
|
}, events)))
|
|
269
225
|
})
|
|
270
226
|
|
|
@@ -8,7 +8,6 @@ export type Faces = {
|
|
|
8
8
|
deg: number
|
|
9
9
|
offsetY: number
|
|
10
10
|
opacity: number
|
|
11
|
-
scale: number
|
|
12
11
|
screenHeight: number
|
|
13
12
|
}
|
|
14
13
|
|
|
@@ -34,7 +33,7 @@ export const createFaces = (
|
|
|
34
33
|
const maxStep = Math.trunc((visibleCount + 2) / 2) // + 2 because there are 2 more faces at 90 degrees
|
|
35
34
|
const stepDegree = 90 / maxStep
|
|
36
35
|
|
|
37
|
-
const result
|
|
36
|
+
const result = []
|
|
38
37
|
for (let i = 1; i <= maxStep; i++) {
|
|
39
38
|
result.push(i * stepDegree)
|
|
40
39
|
}
|
|
@@ -55,9 +54,6 @@ export const createFaces = (
|
|
|
55
54
|
for (let i = 0; i < index; i++) {
|
|
56
55
|
offset += freeSpaces[i]
|
|
57
56
|
}
|
|
58
|
-
if (index === 0) {
|
|
59
|
-
offset *= 0.6
|
|
60
|
-
}
|
|
61
57
|
return offset
|
|
62
58
|
}) as unknown as T
|
|
63
59
|
return [screenHeights, offsets]
|
|
@@ -66,19 +62,17 @@ export const createFaces = (
|
|
|
66
62
|
const getOpacity = (index: number) => {
|
|
67
63
|
const map: Record<number, number> = {
|
|
68
64
|
0: 0,
|
|
69
|
-
1: 0.
|
|
70
|
-
2: 0.
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
1: 0.2,
|
|
66
|
+
2: 0.35,
|
|
67
|
+
3: 0.45,
|
|
68
|
+
4: 0.5
|
|
73
69
|
}
|
|
74
|
-
return map[index] ?? Math.min(1, map[
|
|
70
|
+
return map[index] ?? Math.min(1, map[4] + index * 0.5)
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
const degrees = getDegreesRelativeCenter()
|
|
78
74
|
const [screenHeight, offsets] = getScreenHeightsAndOffsets(degrees)
|
|
79
75
|
|
|
80
|
-
const scales = [1, 0.925, 0.8]
|
|
81
|
-
|
|
82
76
|
return [
|
|
83
77
|
// top items
|
|
84
78
|
...degrees
|
|
@@ -88,14 +82,13 @@ export const createFaces = (
|
|
|
88
82
|
deg: degree,
|
|
89
83
|
opacity: getOpacity(degrees.length - 1 - index),
|
|
90
84
|
offsetY: -1 * offsets[index],
|
|
91
|
-
scale: scales[index],
|
|
92
85
|
screenHeight: screenHeight[index]
|
|
93
86
|
}
|
|
94
87
|
})
|
|
95
88
|
.reverse(),
|
|
96
89
|
|
|
97
90
|
// center item
|
|
98
|
-
{ index: 0, deg: 0, opacity: 1, offsetY: 0,
|
|
91
|
+
{ index: 0, deg: 0, opacity: 1, offsetY: 0, screenHeight: itemHeight },
|
|
99
92
|
|
|
100
93
|
// bottom items
|
|
101
94
|
...degrees.map<Faces>((degree, index) => {
|
|
@@ -104,7 +97,6 @@ export const createFaces = (
|
|
|
104
97
|
deg: -1 * degree,
|
|
105
98
|
opacity: getOpacity(degrees.length - 1 - index),
|
|
106
99
|
offsetY: offsets[index],
|
|
107
|
-
scale: scales[index],
|
|
108
100
|
screenHeight: screenHeight[index]
|
|
109
101
|
}
|
|
110
102
|
})
|
|
@@ -7,7 +7,7 @@ type OverlayProps = {
|
|
|
7
7
|
overlayContainerStyle?: StyleProp<ViewStyle>
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const Overlay = ({ itemHeight, overlayItemStyle, overlayContainerStyle }: OverlayProps) => {
|
|
11
11
|
return (
|
|
12
12
|
<View style={[styles.overlayContainer, overlayContainerStyle]} pointerEvents={'none'}>
|
|
13
13
|
<View style={[styles.selection, { height: itemHeight }, overlayItemStyle]} />
|
|
@@ -19,8 +19,7 @@ const styles = StyleSheet.create({
|
|
|
19
19
|
overlayContainer: {
|
|
20
20
|
...StyleSheet.absoluteFillObject,
|
|
21
21
|
justifyContent: 'center',
|
|
22
|
-
alignItems: 'center'
|
|
23
|
-
zIndex: 200
|
|
22
|
+
alignItems: 'center'
|
|
24
23
|
},
|
|
25
24
|
selection: {
|
|
26
25
|
borderTopWidth: 1,
|
|
@@ -30,5 +29,4 @@ const styles = StyleSheet.create({
|
|
|
30
29
|
}
|
|
31
30
|
})
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
export default _PickerViewOverlay
|
|
32
|
+
export default React.memo(Overlay)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios'
|
|
2
1
|
declare module '@mpxjs/utils' {
|
|
3
2
|
export function isEmptyObject (obj: Object): boolean
|
|
4
3
|
export function isFunction (fn: unknown): boolean
|
|
@@ -21,8 +20,7 @@ declare module '@mpxjs/utils' {
|
|
|
21
20
|
left: number
|
|
22
21
|
right: number
|
|
23
22
|
},
|
|
24
|
-
setOptions: (params: Record<string, any>) => void
|
|
25
|
-
addListener: (eventName: string, callback: (e: Event) => void) => void
|
|
23
|
+
setOptions: (params: Record<string, any>) => void
|
|
26
24
|
} | undefined
|
|
27
25
|
}
|
|
28
26
|
|
|
@@ -110,7 +110,7 @@ const parseTransform = (transformStr: string) => {
|
|
|
110
110
|
const values = parseValues(transformStr)
|
|
111
111
|
const transform: {[propName: string]: string|number|number[]}[] = []
|
|
112
112
|
values.forEach(item => {
|
|
113
|
-
const match = item.match(/([/\w]+)\((
|
|
113
|
+
const match = item.match(/([/\w]+)\(([^)]+)\)/)
|
|
114
114
|
if (match && match.length >= 3) {
|
|
115
115
|
let key = match[1]
|
|
116
116
|
const val = match[2]
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
|
|
2
|
-
import { LayoutChangeEvent, TextStyle, ImageProps, Image
|
|
2
|
+
import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
|
|
3
3
|
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils'
|
|
4
|
-
import { VarContext
|
|
4
|
+
import { VarContext } from './context'
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser'
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
7
7
|
import FastImage, { FastImageProps } from '@d11/react-native-fast-image'
|
|
8
|
-
import type { AnyFunc, ExtendedFunctionComponent
|
|
9
|
-
import { runOnJS } from 'react-native-reanimated'
|
|
10
|
-
import { Gesture } from 'react-native-gesture-handler'
|
|
8
|
+
import type { AnyFunc, ExtendedFunctionComponent } from './types/common'
|
|
11
9
|
|
|
12
10
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
|
|
13
11
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/
|
|
@@ -20,9 +18,6 @@ export const HIDDEN_STYLE = {
|
|
|
20
18
|
opacity: 0
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
export const isIOS = Platform.OS === 'ios'
|
|
24
|
-
export const isAndroid = Platform.OS === 'android'
|
|
25
|
-
|
|
26
21
|
const varDecRegExp = /^--.*/
|
|
27
22
|
const varUseRegExp = /var\(/
|
|
28
23
|
const calcUseRegExp = /calc\(/
|
|
@@ -502,7 +497,6 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
|
|
|
502
497
|
props.onLayout && props.onLayout(e)
|
|
503
498
|
}
|
|
504
499
|
}
|
|
505
|
-
|
|
506
500
|
return {
|
|
507
501
|
layoutRef,
|
|
508
502
|
layoutStyle,
|
|
@@ -540,14 +534,13 @@ export const debounce = <T extends AnyFunc> (
|
|
|
540
534
|
): ((...args: Parameters<T>) => void) & { clear: () => void } => {
|
|
541
535
|
let timer: any
|
|
542
536
|
const wrapper = (...args: ReadonlyArray<any>) => {
|
|
543
|
-
|
|
537
|
+
clearTimeout(timer)
|
|
544
538
|
timer = setTimeout(() => {
|
|
545
539
|
func(...args)
|
|
546
540
|
}, delay)
|
|
547
541
|
}
|
|
548
542
|
wrapper.clear = () => {
|
|
549
|
-
|
|
550
|
-
timer = null
|
|
543
|
+
clearTimeout(timer)
|
|
551
544
|
}
|
|
552
545
|
return wrapper
|
|
553
546
|
}
|
|
@@ -617,66 +610,3 @@ export function pickStyle (styleObj: Record<string, any> = {}, pickedKeys: Array
|
|
|
617
610
|
return acc
|
|
618
611
|
}, {})
|
|
619
612
|
}
|
|
620
|
-
|
|
621
|
-
export function useHoverStyle ({ hoverStyle, hoverStartTime, hoverStayTime, disabled } : { hoverStyle?: ExtendedViewStyle, hoverStartTime: number, hoverStayTime: number, disabled?: boolean }) {
|
|
622
|
-
const enableHoverStyle = !!hoverStyle
|
|
623
|
-
const enableHoverStyleRef = useRef(enableHoverStyle)
|
|
624
|
-
if (enableHoverStyleRef.current !== enableHoverStyle) {
|
|
625
|
-
throw new Error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.')
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
if (!enableHoverStyle) return { enableHoverStyle }
|
|
629
|
-
|
|
630
|
-
const gestureRef = useContext(ScrollViewContext).gestureRef
|
|
631
|
-
const [isHover, setIsHover] = useState(false)
|
|
632
|
-
const dataRef = useRef<{
|
|
633
|
-
startTimer?: ReturnType<typeof setTimeout>
|
|
634
|
-
stayTimer?: ReturnType<typeof setTimeout>
|
|
635
|
-
}>({})
|
|
636
|
-
|
|
637
|
-
useEffect(() => {
|
|
638
|
-
return () => {
|
|
639
|
-
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
640
|
-
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
|
|
641
|
-
}
|
|
642
|
-
}, [])
|
|
643
|
-
|
|
644
|
-
const setStartTimer = () => {
|
|
645
|
-
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
646
|
-
dataRef.current.startTimer = setTimeout(() => {
|
|
647
|
-
setIsHover(true)
|
|
648
|
-
}, +hoverStartTime)
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
const setStayTimer = () => {
|
|
652
|
-
dataRef.current.stayTimer && clearTimeout(dataRef.current.stayTimer)
|
|
653
|
-
dataRef.current.startTimer && clearTimeout(dataRef.current.startTimer)
|
|
654
|
-
dataRef.current.stayTimer = setTimeout(() => {
|
|
655
|
-
setIsHover(false)
|
|
656
|
-
}, +hoverStayTime)
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
const gesture = useMemo(() => {
|
|
660
|
-
return Gesture.Pan()
|
|
661
|
-
.onTouchesDown(() => {
|
|
662
|
-
'worklet'
|
|
663
|
-
if (disabled) return
|
|
664
|
-
runOnJS(setStartTimer)()
|
|
665
|
-
})
|
|
666
|
-
.onTouchesUp(() => {
|
|
667
|
-
'worklet'
|
|
668
|
-
if (disabled) return
|
|
669
|
-
runOnJS(setStayTimer)()
|
|
670
|
-
})
|
|
671
|
-
}, [disabled])
|
|
672
|
-
|
|
673
|
-
if (gestureRef) {
|
|
674
|
-
gesture.simultaneousWithExternalGesture(gestureRef)
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
return {
|
|
678
|
-
isHover,
|
|
679
|
-
gesture,
|
|
680
|
-
enableHoverStyle
|
|
681
|
-
}
|
|
682
|
-
}
|
|
@@ -4,6 +4,7 @@ const loadPostcssConfig = require('./load-postcss-config')
|
|
|
4
4
|
const { MPX_ROOT_VIEW, MPX_DISABLE_EXTRACTOR_CACHE } = require('../utils/const')
|
|
5
5
|
const rpx = require('./plugins/rpx')
|
|
6
6
|
const vw = require('./plugins/vw')
|
|
7
|
+
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
7
8
|
const scopeId = require('./plugins/scope-id')
|
|
8
9
|
const transSpecial = require('./plugins/trans-special')
|
|
9
10
|
const cssArrayList = require('./plugins/css-array-list')
|
|
@@ -57,9 +58,9 @@ module.exports = function (css, map) {
|
|
|
57
58
|
plugins.push(transSpecial({ id }))
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
plugins.push(pluginCondStrip({
|
|
62
|
+
defs
|
|
63
|
+
}))
|
|
63
64
|
|
|
64
65
|
for (const item of transRpxRules) {
|
|
65
66
|
const {
|
|
@@ -117,6 +117,7 @@ let hasOptionalChaining = false
|
|
|
117
117
|
let processingTemplate = false
|
|
118
118
|
const rulesResultMap = new Map()
|
|
119
119
|
let usingComponents = []
|
|
120
|
+
let usingComponentsInfo = {}
|
|
120
121
|
|
|
121
122
|
function updateForScopesMap () {
|
|
122
123
|
forScopesMap = {}
|
|
@@ -636,6 +637,7 @@ function parse (template, options) {
|
|
|
636
637
|
|
|
637
638
|
if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
|
|
638
639
|
usingComponents = Object.keys(options.usingComponentsInfo)
|
|
640
|
+
usingComponentsInfo = options.usingComponentsInfo
|
|
639
641
|
|
|
640
642
|
const _warn = content => {
|
|
641
643
|
const currentElementRuleResult = rulesResultMap.get(currentEl) || rulesResultMap.set(currentEl, {
|
|
@@ -1207,7 +1209,7 @@ function processEventReact (el) {
|
|
|
1207
1209
|
for (const type in eventConfigMap) {
|
|
1208
1210
|
const { configs } = eventConfigMap[type]
|
|
1209
1211
|
if (!configs.length) continue
|
|
1210
|
-
const needBind = configs.length > 1 || configs[0].hasArgs
|
|
1212
|
+
const needBind = configs.length > 1 || configs[0].hasArgs
|
|
1211
1213
|
if (needBind) {
|
|
1212
1214
|
configs.forEach(({ name }) => {
|
|
1213
1215
|
if (name) {
|
|
@@ -2185,16 +2187,20 @@ function isRealNode (el) {
|
|
|
2185
2187
|
return !virtualNodeTagMap[el.tag]
|
|
2186
2188
|
}
|
|
2187
2189
|
|
|
2188
|
-
function isComponentNode (el
|
|
2190
|
+
function isComponentNode (el) {
|
|
2189
2191
|
return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
|
|
2190
2192
|
}
|
|
2191
2193
|
|
|
2192
|
-
function
|
|
2193
|
-
return
|
|
2194
|
+
function getComponentInfo (el) {
|
|
2195
|
+
return usingComponentsInfo[el.tag] || {}
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
function isReactComponent (el) {
|
|
2199
|
+
return !isComponentNode(el) && isRealNode(el) && !el.isBuiltIn
|
|
2194
2200
|
}
|
|
2195
2201
|
|
|
2196
2202
|
function processExternalClasses (el, options) {
|
|
2197
|
-
const isComponent = isComponentNode(el
|
|
2203
|
+
const isComponent = isComponentNode(el)
|
|
2198
2204
|
const classLikeAttrNames = isComponent ? ['class'].concat(options.externalClasses) : ['class']
|
|
2199
2205
|
|
|
2200
2206
|
classLikeAttrNames.forEach((classLikeAttrName) => {
|
|
@@ -2308,8 +2314,7 @@ function postProcessAliComponentRootView (el, options, meta) {
|
|
|
2308
2314
|
{ condition: /^style$/, action: 'move' },
|
|
2309
2315
|
{ condition: /^slot$/, action: 'move' }
|
|
2310
2316
|
]
|
|
2311
|
-
const
|
|
2312
|
-
const mid = options.usingComponentsInfo[tagName]?.mid || moduleId
|
|
2317
|
+
const mid = getComponentInfo(el).mid
|
|
2313
2318
|
const processAppendAttrsRules = [
|
|
2314
2319
|
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${mid}` }
|
|
2315
2320
|
]
|
|
@@ -2416,7 +2421,7 @@ function processShow (el, options, root) {
|
|
|
2416
2421
|
show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}'
|
|
2417
2422
|
}
|
|
2418
2423
|
if (show === undefined) return
|
|
2419
|
-
if (isComponentNode(el
|
|
2424
|
+
if (isComponentNode(el) && getComponentInfo(el).hasVirtualHost) {
|
|
2420
2425
|
if (show === '') {
|
|
2421
2426
|
show = '{{false}}'
|
|
2422
2427
|
}
|
|
@@ -2715,7 +2720,7 @@ function closeElement (el, options, meta) {
|
|
|
2715
2720
|
}
|
|
2716
2721
|
})
|
|
2717
2722
|
}
|
|
2718
|
-
if (isComponentNode(el
|
|
2723
|
+
if (isComponentNode(el) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') {
|
|
2719
2724
|
postProcessAliComponentRootView(el, options, meta)
|
|
2720
2725
|
}
|
|
2721
2726
|
}
|