@mpxjs/webpack-plugin 2.9.70 → 2.9.71
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/platform/template/wx/component-config/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/picker-view.js +1 -5
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/platform/template/wx/index.js +0 -4
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -31
- package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +93 -58
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +151 -127
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +38 -34
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +11 -4
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +670 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +15 -53
- package/lib/runtime/components/react/dist/pickerFaces.js +7 -6
- package/lib/runtime/components/react/dist/pickerVIewContext.js +14 -0
- package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +23 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +20 -2
- package/lib/runtime/components/react/dist/utils.jsx +74 -11
- package/lib/runtime/components/react/getInnerListeners.ts +43 -32
- package/lib/runtime/components/react/mpx-button.tsx +20 -57
- package/lib/runtime/components/react/mpx-movable-view.tsx +119 -74
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
- package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +12 -18
- package/lib/runtime/components/react/mpx-scroll-view.tsx +21 -10
- package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
- package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
- package/lib/runtime/components/react/mpx-view.tsx +18 -65
- package/lib/runtime/components/react/pickerFaces.ts +10 -7
- package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
- package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
- package/lib/runtime/components/react/types/global.d.ts +10 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +24 -3
- package/lib/runtime/components/react/utils.tsx +85 -12
- package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
- package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
- package/lib/template-compiler/compiler.js +61 -13
- package/lib/wxss/loader.js +15 -2
- package/package.json +3 -3
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -480
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +0 -21
- package/lib/runtime/components/react/dist/types/common.js +0 -1
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -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
- package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
- /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { View } from 'react-native'
|
|
2
|
-
import React, { forwardRef,
|
|
2
|
+
import React, { forwardRef, useRef } from 'react'
|
|
3
3
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
4
4
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
5
5
|
import {
|
|
@@ -7,35 +7,33 @@ import {
|
|
|
7
7
|
splitProps,
|
|
8
8
|
splitStyle,
|
|
9
9
|
wrapChildren,
|
|
10
|
-
parseInlineStyle,
|
|
11
10
|
useTransformStyle,
|
|
12
|
-
useDebounceCallback,
|
|
13
|
-
useStableCallback,
|
|
14
11
|
extendObject
|
|
15
12
|
} from './utils'
|
|
13
|
+
import { PickerViewStyleContext } from './pickerVIewContext'
|
|
16
14
|
import type { AnyFunc } from './types/common'
|
|
17
15
|
/**
|
|
18
16
|
* ✔ value
|
|
19
17
|
* ✔ bindchange
|
|
20
18
|
* ✘ bindpickstart
|
|
21
19
|
* ✘ bindpickend
|
|
22
|
-
*
|
|
20
|
+
* ✔ mask-class
|
|
23
21
|
* ✔ indicator-style: 优先级indicator-style.height > pick-view-column中的子元素设置的height
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* WebView Only:
|
|
23
|
+
* ✔ indicator-class
|
|
24
|
+
* ✔ mask-style
|
|
26
25
|
* ✘ immediate-change
|
|
27
26
|
*/
|
|
28
27
|
|
|
29
28
|
interface PickerViewProps {
|
|
30
29
|
children: React.ReactNode
|
|
31
|
-
// 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),
|
|
32
|
-
// 数字大于 picker-view-column 可选项长度时,选择最后一项。
|
|
33
30
|
value?: Array<number>
|
|
34
31
|
bindchange?: AnyFunc
|
|
35
32
|
style: {
|
|
36
33
|
[key: string]: any
|
|
37
34
|
}
|
|
38
|
-
'indicator-style'?: string
|
|
35
|
+
'indicator-style'?: Record<string, any>,
|
|
36
|
+
'mask-style'?: Record<string, any>,
|
|
39
37
|
'enable-var': boolean
|
|
40
38
|
'external-var-context'?: Record<string, any>,
|
|
41
39
|
'enable-offset': boolean
|
|
@@ -62,25 +60,25 @@ const styles: { [key: string]: Object } = {
|
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
|
|
63
|
+
const DefaultPickerItemH = 36
|
|
64
|
+
|
|
65
65
|
const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProps>((props: PickerViewProps, ref) => {
|
|
66
66
|
const {
|
|
67
67
|
children,
|
|
68
68
|
value = [],
|
|
69
69
|
bindchange,
|
|
70
70
|
style,
|
|
71
|
+
'indicator-style': indicatorStyle = {},
|
|
72
|
+
'mask-style': pickerMaskStyle = {},
|
|
71
73
|
'enable-var': enableVar,
|
|
72
74
|
'external-var-context': externalVarContext
|
|
73
75
|
} = props
|
|
74
|
-
|
|
75
|
-
// indicatorStyle 需要转换为rn的style
|
|
76
|
-
// 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
|
|
77
|
-
const indicatorStyle = parseInlineStyle(props['indicator-style'])
|
|
78
|
-
const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle
|
|
79
|
-
const [pickMaxH, setPickMaxH] = useState(0)
|
|
76
|
+
const { height: indicatorH, ...pickerIndicatorStyle } = indicatorStyle
|
|
80
77
|
const nodeRef = useRef(null)
|
|
81
78
|
const cloneRef = useRef(null)
|
|
82
79
|
const activeValueRef = useRef(value)
|
|
83
80
|
activeValueRef.current = value.slice()
|
|
81
|
+
const snapActiveValueRef = useRef<number[] | null>(null)
|
|
84
82
|
|
|
85
83
|
const {
|
|
86
84
|
normalStyle,
|
|
@@ -96,7 +94,6 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
96
94
|
})
|
|
97
95
|
|
|
98
96
|
const {
|
|
99
|
-
// 存储layout布局信息
|
|
100
97
|
layoutRef,
|
|
101
98
|
layoutProps,
|
|
102
99
|
layoutStyle
|
|
@@ -104,33 +101,32 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
104
101
|
const { textProps } = splitProps(props)
|
|
105
102
|
const { textStyle } = splitStyle(normalStyle)
|
|
106
103
|
|
|
107
|
-
const onColumnItemRawHChange = (height: number) => {
|
|
108
|
-
if (height > pickMaxH) {
|
|
109
|
-
setPickMaxH(height)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const bindchangeDebounce = useDebounceCallback(useStableCallback(bindchange), 300)
|
|
114
|
-
|
|
115
104
|
const onSelectChange = (columnIndex: number, selectedIndex: number) => {
|
|
116
|
-
bindchangeDebounce.clear()
|
|
117
105
|
const activeValue = activeValueRef.current
|
|
118
106
|
activeValue[columnIndex] = selectedIndex
|
|
119
107
|
const eventData = getCustomEvent(
|
|
120
108
|
'change',
|
|
121
109
|
{},
|
|
122
|
-
{ detail: { value: activeValue, source: 'change' }, layoutRef }
|
|
110
|
+
{ detail: { value: activeValue.slice(), source: 'change' }, layoutRef }
|
|
123
111
|
)
|
|
124
|
-
|
|
112
|
+
bindchange?.(eventData)
|
|
113
|
+
snapActiveValueRef.current = activeValueRef.current
|
|
125
114
|
}
|
|
126
115
|
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
)
|
|
133
|
-
|
|
116
|
+
const hasDiff = (a: number[] = [], b: number[]) => {
|
|
117
|
+
return a.some((v, i) => v !== b[i])
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const onInitialChange = (isInvalid: boolean, value: number[]) => {
|
|
121
|
+
if (isInvalid || !snapActiveValueRef.current || hasDiff(snapActiveValueRef.current, value)) {
|
|
122
|
+
const eventData = getCustomEvent(
|
|
123
|
+
'change',
|
|
124
|
+
{},
|
|
125
|
+
{ detail: { value: value.slice(), source: 'change' }, layoutRef }
|
|
126
|
+
)
|
|
127
|
+
bindchange?.(eventData)
|
|
128
|
+
snapActiveValueRef.current = value.slice()
|
|
129
|
+
}
|
|
134
130
|
}
|
|
135
131
|
|
|
136
132
|
const innerProps = useInnerProps(
|
|
@@ -148,12 +144,17 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
148
144
|
),
|
|
149
145
|
layoutProps
|
|
150
146
|
}),
|
|
151
|
-
[
|
|
147
|
+
[
|
|
148
|
+
'enable-offset',
|
|
149
|
+
'indicator-style',
|
|
150
|
+
'indicator-class',
|
|
151
|
+
'mask-style',
|
|
152
|
+
'mask-class'
|
|
153
|
+
],
|
|
152
154
|
{ layoutRef }
|
|
153
155
|
)
|
|
154
156
|
|
|
155
157
|
const renderColumn = (child: React.ReactElement, index: number, columnData: React.ReactNode[], initialIndex: number) => {
|
|
156
|
-
const extraProps = {}
|
|
157
158
|
const childProps = child?.props || {}
|
|
158
159
|
const wrappedProps = extendObject(
|
|
159
160
|
{},
|
|
@@ -164,15 +165,14 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
164
165
|
columnIndex: index,
|
|
165
166
|
key: `pick-view-${index}`,
|
|
166
167
|
wrapperStyle: {
|
|
167
|
-
height: normalStyle?.height ||
|
|
168
|
-
itemHeight: indicatorH ||
|
|
168
|
+
height: normalStyle?.height || DefaultPickerItemH,
|
|
169
|
+
itemHeight: indicatorH || DefaultPickerItemH
|
|
169
170
|
},
|
|
170
|
-
onColumnItemRawHChange,
|
|
171
171
|
onSelectChange: onSelectChange.bind(null, index),
|
|
172
172
|
initialIndex,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
pickerIndicatorStyle,
|
|
174
|
+
pickerMaskStyle
|
|
175
|
+
}
|
|
176
176
|
)
|
|
177
177
|
const realElement = React.cloneElement(child, wrappedProps)
|
|
178
178
|
return wrapChildren(
|
|
@@ -215,17 +215,18 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
215
215
|
validValue.push(validIndex)
|
|
216
216
|
renderColumns.push(renderColumn(item, index, columnData, validIndex))
|
|
217
217
|
})
|
|
218
|
-
isInvalid
|
|
218
|
+
onInitialChange(isInvalid, validValue)
|
|
219
219
|
return renderColumns
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
return (
|
|
223
|
-
<
|
|
224
|
-
<View
|
|
225
|
-
|
|
223
|
+
<PickerViewStyleContext.Provider value={textStyle}>
|
|
224
|
+
<View {...innerProps}>
|
|
225
|
+
<View style={[styles.wrapper]}>{renderPickerColumns()}</View>
|
|
226
|
+
</View>
|
|
227
|
+
</PickerViewStyleContext.Provider>
|
|
226
228
|
)
|
|
227
229
|
})
|
|
228
230
|
|
|
229
231
|
_PickerView.displayName = 'MpxPickerView'
|
|
230
|
-
|
|
231
232
|
export default _PickerView
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* ✔ nodes
|
|
4
4
|
*/
|
|
5
5
|
import { View, ViewProps, ViewStyle } from 'react-native'
|
|
6
|
-
import { useRef, forwardRef, JSX, useState } from 'react'
|
|
6
|
+
import { useRef, forwardRef, JSX, useState, createElement } from 'react'
|
|
7
7
|
import useInnerProps from '../getInnerListeners'
|
|
8
8
|
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
9
|
-
import { useTransformStyle, useLayout } from '../utils'
|
|
9
|
+
import { useTransformStyle, useLayout, extendObject } from '../utils'
|
|
10
10
|
import { WebView, WebViewMessageEvent } from 'react-native-webview'
|
|
11
11
|
import { generateHTML } from './html'
|
|
12
12
|
|
|
@@ -91,28 +91,22 @@ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((
|
|
|
91
91
|
layoutRef
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
const innerProps = useInnerProps(props, {
|
|
94
|
+
const innerProps = useInnerProps(props, extendObject({
|
|
95
95
|
ref: nodeRef,
|
|
96
|
-
style:
|
|
97
|
-
|
|
98
|
-
}, [], {
|
|
96
|
+
style: extendObject(normalStyle, layoutStyle)
|
|
97
|
+
}, layoutProps), [], {
|
|
99
98
|
layoutRef
|
|
100
99
|
})
|
|
101
100
|
|
|
102
101
|
const html: string = typeof nodes === 'string' ? nodes : jsonToHtmlStr(nodes)
|
|
103
102
|
|
|
104
|
-
return (
|
|
105
|
-
|
|
106
|
-
{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
setWebViewHeight(+event.nativeEvent.data)
|
|
112
|
-
}}
|
|
113
|
-
>
|
|
114
|
-
</WebView>
|
|
115
|
-
</View>
|
|
103
|
+
return createElement(View, innerProps,
|
|
104
|
+
createElement(WebView, {
|
|
105
|
+
source: { html: generateHTML(html) },
|
|
106
|
+
onMessage: (event: WebViewMessageEvent) => {
|
|
107
|
+
setWebViewHeight(+event.nativeEvent.data)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
116
110
|
)
|
|
117
111
|
})
|
|
118
112
|
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { ScrollView } from 'react-native-gesture-handler'
|
|
35
35
|
import { View, RefreshControl, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
|
|
36
|
-
import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, createElement } from 'react'
|
|
36
|
+
import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, createElement, useMemo } from 'react'
|
|
37
37
|
import { useAnimatedRef } from 'react-native-reanimated'
|
|
38
38
|
import { warn } from '@mpxjs/utils'
|
|
39
39
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
40
40
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
41
41
|
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler } from './utils'
|
|
42
|
-
import { IntersectionObserverContext } from './context'
|
|
42
|
+
import { IntersectionObserverContext, ScrollViewContext } from './context'
|
|
43
43
|
|
|
44
44
|
interface ScrollViewProps {
|
|
45
45
|
children?: ReactNode;
|
|
@@ -194,6 +194,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
194
194
|
gestureRef: scrollViewRef
|
|
195
195
|
})
|
|
196
196
|
|
|
197
|
+
const contextValue = useMemo(() => {
|
|
198
|
+
return {
|
|
199
|
+
gestureRef: scrollViewRef
|
|
200
|
+
}
|
|
201
|
+
}, [])
|
|
202
|
+
|
|
197
203
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
|
|
198
204
|
|
|
199
205
|
if (scrollX && scrollY) {
|
|
@@ -332,6 +338,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
332
338
|
}, props)
|
|
333
339
|
)
|
|
334
340
|
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
341
|
+
onStartReached(e)
|
|
342
|
+
onEndReached(e)
|
|
335
343
|
if (enableTriggerIntersectionObserver && intersectionObservers) {
|
|
336
344
|
for (const key in intersectionObservers) {
|
|
337
345
|
intersectionObservers[key].throttleMeasure()
|
|
@@ -507,14 +515,17 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
507
515
|
}, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
|
|
508
516
|
: undefined
|
|
509
517
|
}),
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
+
createElement(ScrollViewContext.Provider,
|
|
519
|
+
{ value: contextValue },
|
|
520
|
+
wrapChildren(
|
|
521
|
+
props,
|
|
522
|
+
{
|
|
523
|
+
hasVarDec,
|
|
524
|
+
varContext: varContextRef.current,
|
|
525
|
+
textStyle,
|
|
526
|
+
textProps
|
|
527
|
+
}
|
|
528
|
+
)
|
|
518
529
|
)
|
|
519
530
|
)
|
|
520
531
|
})
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { View
|
|
2
|
-
import {
|
|
1
|
+
import { View } from 'react-native'
|
|
2
|
+
import Animated, { useAnimatedStyle, interpolate, SharedValue } from 'react-native-reanimated'
|
|
3
|
+
import { ReactNode, forwardRef, useRef, useContext } from 'react'
|
|
3
4
|
import useInnerProps from './getInnerListeners'
|
|
4
5
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
5
6
|
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
|
|
7
|
+
import { SwiperContext } from './context'
|
|
6
8
|
|
|
7
9
|
interface SwiperItemProps {
|
|
8
10
|
'item-id'?: string;
|
|
@@ -14,15 +16,31 @@ interface SwiperItemProps {
|
|
|
14
16
|
'parent-height'?: number;
|
|
15
17
|
children?: ReactNode;
|
|
16
18
|
style?: Object;
|
|
19
|
+
customStyle: Object;
|
|
20
|
+
itemIndex: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ContextType {
|
|
24
|
+
offset: SharedValue<number>;
|
|
25
|
+
step: SharedValue<number>;
|
|
26
|
+
scale: boolean;
|
|
27
|
+
dir: string;
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
|
|
20
31
|
const {
|
|
21
32
|
'enable-var': enableVar,
|
|
22
33
|
'external-var-context': externalVarContext,
|
|
23
|
-
style
|
|
34
|
+
style,
|
|
35
|
+
customStyle,
|
|
36
|
+
itemIndex
|
|
24
37
|
} = props
|
|
25
38
|
|
|
39
|
+
const contextValue = useContext(SwiperContext) as ContextType
|
|
40
|
+
const offset = contextValue.offset || 0
|
|
41
|
+
const step = contextValue.step || 0
|
|
42
|
+
const scale = contextValue.scale || false
|
|
43
|
+
const dir = contextValue.dir || 'x'
|
|
26
44
|
const { textProps } = splitProps(props)
|
|
27
45
|
const nodeRef = useRef(null)
|
|
28
46
|
|
|
@@ -47,19 +65,35 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
|
|
|
47
65
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
|
|
48
66
|
|
|
49
67
|
const innerProps = useInnerProps(props, {
|
|
50
|
-
style: { ...innerStyle, ...layoutStyle },
|
|
51
68
|
ref: nodeRef,
|
|
52
69
|
...layoutProps
|
|
53
70
|
}, [
|
|
54
71
|
'children',
|
|
55
|
-
'enable-offset'
|
|
72
|
+
'enable-offset',
|
|
73
|
+
'style'
|
|
56
74
|
], { layoutRef })
|
|
57
|
-
|
|
75
|
+
const itemAnimatedStyle = useAnimatedStyle(() => {
|
|
76
|
+
if (!step.value) return {}
|
|
77
|
+
const inputRange = [step.value, 0]
|
|
78
|
+
const outputRange = [0.7, 1]
|
|
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({
|
|
84
|
+
scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
return Object.assign(outerLayoutStyle, {
|
|
88
|
+
transform: transformStyle
|
|
89
|
+
})
|
|
90
|
+
})
|
|
58
91
|
return (
|
|
59
|
-
<View
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
|
|
92
|
+
<Animated.View
|
|
93
|
+
{...innerProps}
|
|
94
|
+
style={[innerStyle, layoutStyle, itemAnimatedStyle, customStyle]}
|
|
95
|
+
data-itemId={props['item-id']}>
|
|
96
|
+
{
|
|
63
97
|
wrapChildren(
|
|
64
98
|
props,
|
|
65
99
|
{
|
|
@@ -70,7 +104,7 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
|
|
|
70
104
|
}
|
|
71
105
|
)
|
|
72
106
|
}
|
|
73
|
-
</View>
|
|
107
|
+
</Animated.View>
|
|
74
108
|
)
|
|
75
109
|
})
|
|
76
110
|
|