@mpxjs/webpack-plugin 2.10.4-beta.4 → 2.10.4-beta.6
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/index.js +5 -1
- package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
- package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
- package/lib/runtime/components/react/context.ts +12 -3
- package/lib/runtime/components/react/dist/context.js +4 -1
- package/lib/runtime/components/react/dist/event.config.js +0 -2
- package/lib/runtime/components/react/dist/getInnerListeners.js +127 -153
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +3 -4
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +3 -4
- package/lib/runtime/components/react/dist/mpx-label.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +18 -7
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +112 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -5
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -9
- package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -5
- package/lib/runtime/components/react/dist/mpx-text.jsx +4 -7
- package/lib/runtime/components/react/dist/mpx-video.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-view.jsx +2 -2
- package/lib/runtime/components/react/dist/utils.jsx +12 -1
- package/lib/runtime/components/react/event.config.ts +1 -8
- package/lib/runtime/components/react/getInnerListeners.ts +146 -192
- package/lib/runtime/components/react/mpx-button.tsx +4 -5
- package/lib/runtime/components/react/mpx-canvas/index.tsx +23 -15
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +4 -3
- package/lib/runtime/components/react/mpx-checkbox.tsx +8 -9
- package/lib/runtime/components/react/mpx-form.tsx +25 -19
- package/lib/runtime/components/react/mpx-icon/index.tsx +4 -3
- package/lib/runtime/components/react/mpx-image.tsx +4 -3
- package/lib/runtime/components/react/mpx-input.tsx +6 -7
- package/lib/runtime/components/react/mpx-label.tsx +4 -5
- package/lib/runtime/components/react/mpx-movable-area.tsx +22 -13
- package/lib/runtime/components/react/mpx-movable-view.tsx +47 -40
- package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
- package/lib/runtime/components/react/mpx-picker/index.tsx +7 -4
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +17 -14
- package/lib/runtime/components/react/mpx-radio-group.tsx +4 -3
- package/lib/runtime/components/react/mpx-radio.tsx +8 -9
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +15 -6
- package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -57
- package/lib/runtime/components/react/mpx-simple-text.tsx +10 -3
- package/lib/runtime/components/react/mpx-simple-view.tsx +10 -4
- package/lib/runtime/components/react/mpx-sticky-header.tsx +176 -0
- package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +31 -24
- package/lib/runtime/components/react/mpx-swiper.tsx +67 -61
- package/lib/runtime/components/react/mpx-switch.tsx +19 -14
- package/lib/runtime/components/react/mpx-text.tsx +16 -13
- package/lib/runtime/components/react/mpx-video.tsx +34 -33
- package/lib/runtime/components/react/mpx-view.tsx +15 -9
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +65 -35
- package/lib/runtime/components/react/utils.tsx +12 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
- package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
- package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Text, TextProps } from 'react-native'
|
|
2
2
|
import { JSX, createElement } from 'react'
|
|
3
3
|
import useInnerProps from './getInnerListeners'
|
|
4
|
+
import { extendObject } from './utils'
|
|
4
5
|
|
|
5
6
|
const SimpleText = (props: TextProps): JSX.Element => {
|
|
6
7
|
const {
|
|
@@ -8,9 +9,15 @@ const SimpleText = (props: TextProps): JSX.Element => {
|
|
|
8
9
|
children
|
|
9
10
|
} = props
|
|
10
11
|
|
|
11
|
-
const innerProps = useInnerProps(
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const innerProps = useInnerProps(
|
|
13
|
+
extendObject(
|
|
14
|
+
{},
|
|
15
|
+
props,
|
|
16
|
+
{
|
|
17
|
+
allowFontScaling
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
return createElement(Text, innerProps, children)
|
|
16
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { View, ViewProps, TextStyle } from 'react-native'
|
|
2
2
|
import { createElement } from 'react'
|
|
3
|
-
import { splitProps, splitStyle, wrapChildren } from './utils'
|
|
3
|
+
import { splitProps, splitStyle, wrapChildren, extendObject } from './utils'
|
|
4
4
|
import useInnerProps from './getInnerListeners'
|
|
5
5
|
|
|
6
6
|
const SimpleView = (simpleViewProps: ViewProps): JSX.Element => {
|
|
@@ -8,9 +8,15 @@ const SimpleView = (simpleViewProps: ViewProps): JSX.Element => {
|
|
|
8
8
|
|
|
9
9
|
const { textStyle, innerStyle = {} } = splitStyle(props.style || {})
|
|
10
10
|
|
|
11
|
-
const innerProps = useInnerProps(
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const innerProps = useInnerProps(
|
|
12
|
+
extendObject(
|
|
13
|
+
{},
|
|
14
|
+
props,
|
|
15
|
+
{
|
|
16
|
+
style: innerStyle
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
)
|
|
14
20
|
|
|
15
21
|
return createElement(View, innerProps, wrapChildren(
|
|
16
22
|
props,
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, useContext, forwardRef, useMemo, createElement, ReactNode, useId } from 'react'
|
|
2
|
+
import { Animated, StyleSheet, View, NativeSyntheticEvent, ViewStyle, LayoutChangeEvent } from 'react-native'
|
|
3
|
+
import { ScrollViewContext, StickyContext } from './context'
|
|
4
|
+
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
5
|
+
import { splitProps, splitStyle, useTransformStyle, wrapChildren, useLayout, extendObject } from './utils'
|
|
6
|
+
import { error } from '@mpxjs/utils'
|
|
7
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
8
|
+
|
|
9
|
+
interface StickyHeaderProps {
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
style?: ViewStyle;
|
|
12
|
+
padding?: [number, number, number, number];
|
|
13
|
+
'offset-top'?: number;
|
|
14
|
+
'enable-var'?: boolean;
|
|
15
|
+
'external-var-context'?: Record<string, any>;
|
|
16
|
+
'parent-font-size'?: number;
|
|
17
|
+
'parent-width'?: number;
|
|
18
|
+
'parent-height'?: number;
|
|
19
|
+
bindstickontopchange?: (e: NativeSyntheticEvent<unknown>) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const _StickyHeader = forwardRef<HandlerRef<View, StickyHeaderProps>, StickyHeaderProps>((stickyHeaderProps: StickyHeaderProps = {}, ref): JSX.Element => {
|
|
23
|
+
const { textProps, innerProps: props = {} } = splitProps(stickyHeaderProps)
|
|
24
|
+
const {
|
|
25
|
+
style,
|
|
26
|
+
bindstickontopchange,
|
|
27
|
+
padding = [0, 0, 0, 0],
|
|
28
|
+
'offset-top': offsetTop = 0,
|
|
29
|
+
'enable-var': enableVar,
|
|
30
|
+
'external-var-context': externalVarContext,
|
|
31
|
+
'parent-font-size': parentFontSize,
|
|
32
|
+
'parent-width': parentWidth,
|
|
33
|
+
'parent-height': parentHeight
|
|
34
|
+
} = props
|
|
35
|
+
|
|
36
|
+
const scrollViewContext = useContext(ScrollViewContext)
|
|
37
|
+
const stickyContext = useContext(StickyContext)
|
|
38
|
+
const { scrollOffset } = scrollViewContext
|
|
39
|
+
const { registerStickyHeader, unregisterStickyHeader } = stickyContext
|
|
40
|
+
const headerRef = useRef<View>(null)
|
|
41
|
+
const isStickOnTopRef = useRef(false)
|
|
42
|
+
const id = useId()
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
normalStyle,
|
|
46
|
+
hasVarDec,
|
|
47
|
+
varContextRef,
|
|
48
|
+
hasSelfPercent,
|
|
49
|
+
setWidth,
|
|
50
|
+
setHeight
|
|
51
|
+
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
52
|
+
|
|
53
|
+
const { layoutRef, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: headerRef, onLayout })
|
|
54
|
+
|
|
55
|
+
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
56
|
+
|
|
57
|
+
const headerTopAnimated = useRef(new Animated.Value(0)).current
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
registerStickyHeader({ key: id, updatePosition })
|
|
61
|
+
return () => {
|
|
62
|
+
unregisterStickyHeader(id)
|
|
63
|
+
}
|
|
64
|
+
}, [])
|
|
65
|
+
|
|
66
|
+
function updatePosition () {
|
|
67
|
+
if (headerRef.current) {
|
|
68
|
+
const scrollViewRef = scrollViewContext.gestureRef
|
|
69
|
+
if (scrollViewRef && scrollViewRef.current) {
|
|
70
|
+
headerRef.current.measureLayout(
|
|
71
|
+
scrollViewRef.current,
|
|
72
|
+
(left: number, top: number) => {
|
|
73
|
+
Animated.timing(headerTopAnimated, {
|
|
74
|
+
toValue: top,
|
|
75
|
+
duration: 0,
|
|
76
|
+
useNativeDriver: true
|
|
77
|
+
}).start()
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
} else {
|
|
81
|
+
error('StickyHeader measureLayout error: scrollViewRef is not a valid native component reference')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function onLayout (e: LayoutChangeEvent) {
|
|
87
|
+
updatePosition()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
useNodesRef(props, ref, headerRef, {
|
|
91
|
+
style: normalStyle
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!bindstickontopchange) return
|
|
96
|
+
|
|
97
|
+
const listener = scrollOffset.addListener((state: { value: number }) => {
|
|
98
|
+
const currentScrollValue = state.value
|
|
99
|
+
const newIsStickOnTop = currentScrollValue > (headerTopAnimated as any)._value
|
|
100
|
+
if (newIsStickOnTop !== isStickOnTopRef.current) {
|
|
101
|
+
isStickOnTopRef.current = newIsStickOnTop
|
|
102
|
+
bindstickontopchange(
|
|
103
|
+
getCustomEvent('stickontopchange', {}, {
|
|
104
|
+
detail: {
|
|
105
|
+
isStickOnTop: newIsStickOnTop
|
|
106
|
+
},
|
|
107
|
+
layoutRef
|
|
108
|
+
}, props))
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
return () => {
|
|
113
|
+
scrollOffset.removeListener(listener)
|
|
114
|
+
}
|
|
115
|
+
}, [])
|
|
116
|
+
|
|
117
|
+
const animatedStyle = useMemo(() => {
|
|
118
|
+
const translateY = Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
|
|
119
|
+
inputRange: [0, 1],
|
|
120
|
+
outputRange: [0, 1],
|
|
121
|
+
extrapolateLeft: 'clamp',
|
|
122
|
+
extrapolateRight: 'extend'
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
const finalTranslateY = offsetTop === 0
|
|
126
|
+
? translateY
|
|
127
|
+
: Animated.add(
|
|
128
|
+
translateY,
|
|
129
|
+
Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
|
|
130
|
+
inputRange: [0, 1],
|
|
131
|
+
outputRange: [0, offsetTop],
|
|
132
|
+
extrapolate: 'clamp'
|
|
133
|
+
})
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
transform: [{ translateY: finalTranslateY }]
|
|
138
|
+
}
|
|
139
|
+
}, [scrollOffset, headerTopAnimated, offsetTop])
|
|
140
|
+
|
|
141
|
+
const innerProps = useInnerProps(extendObject({}, props, {
|
|
142
|
+
ref: headerRef,
|
|
143
|
+
style: extendObject({}, styles.content, innerStyle, animatedStyle, {
|
|
144
|
+
paddingTop: padding[0] || 0,
|
|
145
|
+
paddingRight: padding[1] || 0,
|
|
146
|
+
paddingBottom: padding[2] || 0,
|
|
147
|
+
paddingLeft: padding[3] || 0
|
|
148
|
+
})
|
|
149
|
+
}, layoutProps), [], { layoutRef })
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
createElement(
|
|
153
|
+
Animated.View,
|
|
154
|
+
innerProps,
|
|
155
|
+
wrapChildren(
|
|
156
|
+
props,
|
|
157
|
+
{
|
|
158
|
+
hasVarDec,
|
|
159
|
+
varContext: varContextRef.current,
|
|
160
|
+
textStyle,
|
|
161
|
+
textProps
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const styles = StyleSheet.create({
|
|
169
|
+
content: {
|
|
170
|
+
width: '100%',
|
|
171
|
+
zIndex: 10
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
_StickyHeader.displayName = 'MpxStickyHeader'
|
|
176
|
+
export default _StickyHeader
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
import { useRef, forwardRef, createElement, ReactNode, useCallback, useMemo } from 'react'
|
|
3
|
+
import { View, ViewStyle } from 'react-native'
|
|
4
|
+
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
5
|
+
import { splitProps, splitStyle, useTransformStyle, wrapChildren, useLayout, extendObject } from './utils'
|
|
6
|
+
import { StickyContext } from './context'
|
|
7
|
+
import useInnerProps from './getInnerListeners'
|
|
8
|
+
|
|
9
|
+
interface StickySectionProps {
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
style?: ViewStyle;
|
|
12
|
+
'offset-top'?: number;
|
|
13
|
+
'enable-var'?: boolean;
|
|
14
|
+
'external-var-context'?: Record<string, any>;
|
|
15
|
+
'parent-font-size'?: number;
|
|
16
|
+
'parent-width'?: number;
|
|
17
|
+
'parent-height'?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const _StickySection = forwardRef<HandlerRef<View, StickySectionProps>, StickySectionProps>((stickySectionProps: StickySectionProps = {}, ref): JSX.Element => {
|
|
21
|
+
const { textProps, innerProps: props = {} } = splitProps(stickySectionProps)
|
|
22
|
+
const {
|
|
23
|
+
style,
|
|
24
|
+
'enable-var': enableVar,
|
|
25
|
+
'external-var-context': externalVarContext,
|
|
26
|
+
'parent-font-size': parentFontSize,
|
|
27
|
+
'parent-width': parentWidth,
|
|
28
|
+
'parent-height': parentHeight
|
|
29
|
+
} = props
|
|
30
|
+
const sectionRef = useRef<View>(null)
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
normalStyle,
|
|
34
|
+
hasVarDec,
|
|
35
|
+
varContextRef,
|
|
36
|
+
hasSelfPercent,
|
|
37
|
+
setWidth,
|
|
38
|
+
setHeight
|
|
39
|
+
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
40
|
+
|
|
41
|
+
const { layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: sectionRef, onLayout })
|
|
42
|
+
|
|
43
|
+
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
44
|
+
|
|
45
|
+
const stickyHeaders = useRef<Map<string, any>>(new Map())
|
|
46
|
+
|
|
47
|
+
const registerStickyHeader = useCallback((item: { id: string, updatePosition: Function }) => {
|
|
48
|
+
stickyHeaders.current.set(item.id, item)
|
|
49
|
+
}, [])
|
|
50
|
+
|
|
51
|
+
const unregisterStickyHeader = useCallback((id: string) => {
|
|
52
|
+
stickyHeaders.current.delete(id)
|
|
53
|
+
}, [])
|
|
54
|
+
|
|
55
|
+
const contextValue = useMemo(() => ({
|
|
56
|
+
registerStickyHeader,
|
|
57
|
+
unregisterStickyHeader
|
|
58
|
+
}), [])
|
|
59
|
+
|
|
60
|
+
useNodesRef(props, ref, sectionRef, {
|
|
61
|
+
style: normalStyle
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
function onLayout () {
|
|
65
|
+
stickyHeaders.current.forEach(item => {
|
|
66
|
+
item.updatePosition()
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const innerProps = useInnerProps(extendObject({}, props, {
|
|
71
|
+
style: extendObject(innerStyle, layoutStyle),
|
|
72
|
+
ref: sectionRef
|
|
73
|
+
}, layoutProps), [], { layoutRef })
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
createElement(
|
|
77
|
+
View,
|
|
78
|
+
innerProps,
|
|
79
|
+
createElement(
|
|
80
|
+
StickyContext.Provider,
|
|
81
|
+
{ value: contextValue },
|
|
82
|
+
wrapChildren(
|
|
83
|
+
props,
|
|
84
|
+
{
|
|
85
|
+
hasVarDec,
|
|
86
|
+
varContext: varContextRef.current,
|
|
87
|
+
textStyle,
|
|
88
|
+
textProps
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
))
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
_StickySection.displayName = 'MpxStickySection'
|
|
96
|
+
export default _StickySection
|
|
@@ -3,28 +3,28 @@ import Animated, { useAnimatedStyle, interpolate, SharedValue } from 'react-nati
|
|
|
3
3
|
import { ReactNode, forwardRef, useRef, useContext } from 'react'
|
|
4
4
|
import useInnerProps from './getInnerListeners'
|
|
5
5
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
6
|
-
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
|
|
6
|
+
import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, extendObject } from './utils'
|
|
7
7
|
import { SwiperContext } from './context'
|
|
8
8
|
|
|
9
9
|
interface SwiperItemProps {
|
|
10
|
-
'item-id'?: string
|
|
11
|
-
'enable-offset'?: boolean
|
|
12
|
-
'enable-var': boolean
|
|
13
|
-
'external-var-context'?: Record<string, any
|
|
14
|
-
'parent-font-size'?: number
|
|
15
|
-
'parent-width'?: number
|
|
16
|
-
'parent-height'?: number
|
|
17
|
-
children?: ReactNode
|
|
18
|
-
style?: Object
|
|
19
|
-
customStyle: Object
|
|
20
|
-
itemIndex: number
|
|
10
|
+
'item-id'?: string
|
|
11
|
+
'enable-offset'?: boolean
|
|
12
|
+
'enable-var': boolean
|
|
13
|
+
'external-var-context'?: Record<string, any>
|
|
14
|
+
'parent-font-size'?: number
|
|
15
|
+
'parent-width'?: number
|
|
16
|
+
'parent-height'?: number
|
|
17
|
+
children?: ReactNode
|
|
18
|
+
style?: Object
|
|
19
|
+
customStyle: Object
|
|
20
|
+
itemIndex: number
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
interface ContextType {
|
|
24
|
-
offset: SharedValue<number
|
|
25
|
-
step: SharedValue<number
|
|
26
|
-
scale: boolean
|
|
27
|
-
dir: string
|
|
24
|
+
offset: SharedValue<number>
|
|
25
|
+
step: SharedValue<number>
|
|
26
|
+
scale: boolean
|
|
27
|
+
dir: string
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
|
|
@@ -64,14 +64,21 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
|
|
|
64
64
|
layoutStyle
|
|
65
65
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
|
|
66
66
|
|
|
67
|
-
const innerProps = useInnerProps(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
const innerProps = useInnerProps(
|
|
68
|
+
extendObject(
|
|
69
|
+
{},
|
|
70
|
+
props,
|
|
71
|
+
layoutProps,
|
|
72
|
+
{
|
|
73
|
+
ref: nodeRef
|
|
74
|
+
}
|
|
75
|
+
),
|
|
76
|
+
[
|
|
77
|
+
'children',
|
|
78
|
+
'enable-offset',
|
|
79
|
+
'style'
|
|
80
|
+
],
|
|
81
|
+
{ layoutRef })
|
|
75
82
|
const itemAnimatedStyle = useAnimatedStyle(() => {
|
|
76
83
|
if (!step.value) return {}
|
|
77
84
|
const inputRange = [step.value, 0]
|
|
@@ -5,7 +5,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS
|
|
|
5
5
|
import React, { JSX, forwardRef, useRef, useEffect, ReactNode, ReactElement, useMemo } from 'react'
|
|
6
6
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
8
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from './utils'
|
|
8
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject } from './utils'
|
|
9
9
|
import { SwiperContext } from './context'
|
|
10
10
|
/**
|
|
11
11
|
* ✔ indicator-dots
|
|
@@ -30,32 +30,32 @@ type EventDataType = {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
interface SwiperProps {
|
|
33
|
-
children?: ReactNode
|
|
34
|
-
circular?: boolean
|
|
35
|
-
current?: number
|
|
36
|
-
interval?: number
|
|
37
|
-
autoplay?: boolean
|
|
33
|
+
children?: ReactNode
|
|
34
|
+
circular?: boolean
|
|
35
|
+
current?: number
|
|
36
|
+
interval?: number
|
|
37
|
+
autoplay?: boolean
|
|
38
38
|
// scrollView 只有安卓可以设
|
|
39
|
-
duration?: number
|
|
39
|
+
duration?: number
|
|
40
40
|
// 滑动过程中元素是否scale变化
|
|
41
|
-
scale?: boolean
|
|
42
|
-
'indicator-dots'?: boolean
|
|
43
|
-
'indicator-color'?: string
|
|
44
|
-
'indicator-active-color'?: string
|
|
45
|
-
vertical?: boolean
|
|
41
|
+
scale?: boolean
|
|
42
|
+
'indicator-dots'?: boolean
|
|
43
|
+
'indicator-color'?: string
|
|
44
|
+
'indicator-active-color'?: string
|
|
45
|
+
vertical?: boolean
|
|
46
46
|
style: {
|
|
47
47
|
[key: string]: any
|
|
48
|
-
}
|
|
49
|
-
'easing-function'?: EaseType
|
|
50
|
-
'previous-margin'?: string
|
|
51
|
-
'next-margin'?: string
|
|
52
|
-
'enable-offset'?: boolean
|
|
53
|
-
'enable-var': boolean
|
|
54
|
-
'parent-font-size'?: number
|
|
55
|
-
'parent-width'?: number
|
|
56
|
-
'parent-height'?: number
|
|
57
|
-
'external-var-context'?: Record<string, any
|
|
58
|
-
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
48
|
+
}
|
|
49
|
+
'easing-function'?: EaseType
|
|
50
|
+
'previous-margin'?: string
|
|
51
|
+
'next-margin'?: string
|
|
52
|
+
'enable-offset'?: boolean
|
|
53
|
+
'enable-var': boolean
|
|
54
|
+
'parent-font-size'?: number
|
|
55
|
+
'parent-width'?: number
|
|
56
|
+
'parent-height'?: number
|
|
57
|
+
'external-var-context'?: Record<string, any>
|
|
58
|
+
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
@@ -201,23 +201,29 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
201
201
|
layoutProps,
|
|
202
202
|
layoutStyle
|
|
203
203
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout: onWrapperLayout })
|
|
204
|
-
const innerProps = useInnerProps(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
204
|
+
const innerProps = useInnerProps(
|
|
205
|
+
extendObject(
|
|
206
|
+
{},
|
|
207
|
+
props,
|
|
208
|
+
{
|
|
209
|
+
ref: nodeRef
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
[
|
|
213
|
+
'style',
|
|
214
|
+
'indicator-dots',
|
|
215
|
+
'indicator-color',
|
|
216
|
+
'indicator-active-color',
|
|
217
|
+
'previous-margin',
|
|
218
|
+
'vertical',
|
|
219
|
+
'previous-margin',
|
|
220
|
+
'next-margin',
|
|
221
|
+
'easing-function',
|
|
222
|
+
'autoplay',
|
|
223
|
+
'circular',
|
|
224
|
+
'interval',
|
|
225
|
+
'easing-function'
|
|
226
|
+
], { layoutRef: layoutRef })
|
|
221
227
|
|
|
222
228
|
function onWrapperLayout (e: LayoutChangeEvent) {
|
|
223
229
|
const { width, height } = e.nativeEvent.layout
|
|
@@ -251,8 +257,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
251
257
|
dots.push(<View style={[dotCommonStyle, { backgroundColor: unActionColor }]} key={i}></View>)
|
|
252
258
|
}
|
|
253
259
|
return (
|
|
254
|
-
<View pointerEvents="none" style
|
|
255
|
-
<View style
|
|
260
|
+
<View pointerEvents="none" style={styles['pagination_' + dir]}>
|
|
261
|
+
<View style={[styles['pagerWrapper' + dir]]}>
|
|
256
262
|
<Animated.View style={[
|
|
257
263
|
dotCommonStyle,
|
|
258
264
|
activeDotStyle,
|
|
@@ -266,8 +272,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
266
272
|
]}
|
|
267
273
|
/>
|
|
268
274
|
{dots}
|
|
269
|
-
|
|
270
|
-
|
|
275
|
+
</View>
|
|
276
|
+
</View>)
|
|
271
277
|
}
|
|
272
278
|
|
|
273
279
|
function renderItems () {
|
|
@@ -392,7 +398,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
392
398
|
}
|
|
393
399
|
}
|
|
394
400
|
|
|
395
|
-
function getOffset (index:number, stepValue: number) {
|
|
401
|
+
function getOffset (index: number, stepValue: number) {
|
|
396
402
|
if (!stepValue) return 0
|
|
397
403
|
let targetOffset = 0
|
|
398
404
|
if (circular && children.length > 1) {
|
|
@@ -404,7 +410,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
404
410
|
return targetOffset
|
|
405
411
|
}
|
|
406
412
|
|
|
407
|
-
function updateCurrent (index:number, stepValue: number) {
|
|
413
|
+
function updateCurrent (index: number, stepValue: number) {
|
|
408
414
|
const targetOffset = getOffset(index || 0, stepValue)
|
|
409
415
|
if (targetOffset !== offset.value) {
|
|
410
416
|
// 内部基于props.current!==currentIndex.value决定是否使用动画及更新currentIndex.value
|
|
@@ -712,21 +718,21 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
712
718
|
function renderSwiper () {
|
|
713
719
|
const arrPages: Array<ReactNode> | ReactNode = renderItems()
|
|
714
720
|
return (<View style={[normalStyle, layoutStyle, styles.swiper]} {...layoutProps} {...innerProps}>
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
721
|
+
<Animated.View style={[{
|
|
722
|
+
flexDirection: dir === 'x' ? 'row' : 'column',
|
|
723
|
+
width: '100%',
|
|
724
|
+
height: '100%'
|
|
725
|
+
}, animatedStyles]}>
|
|
726
|
+
{wrapChildren({
|
|
727
|
+
children: arrPages
|
|
728
|
+
}, {
|
|
729
|
+
hasVarDec,
|
|
730
|
+
varContext: varContextRef.current,
|
|
731
|
+
textStyle,
|
|
732
|
+
textProps
|
|
733
|
+
})}
|
|
734
|
+
</Animated.View>
|
|
735
|
+
{showsPagination && renderPagination()}
|
|
730
736
|
</View>)
|
|
731
737
|
}
|
|
732
738
|
|
|
@@ -120,20 +120,25 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
|
|
|
120
120
|
}
|
|
121
121
|
}, [])
|
|
122
122
|
|
|
123
|
-
const innerProps = useInnerProps(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
const innerProps = useInnerProps(
|
|
124
|
+
extendObject(
|
|
125
|
+
{},
|
|
126
|
+
props,
|
|
127
|
+
layoutProps,
|
|
128
|
+
{
|
|
129
|
+
ref: nodeRef,
|
|
130
|
+
style: extendObject({}, normalStyle, layoutStyle)
|
|
131
|
+
},
|
|
132
|
+
!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
|
|
133
|
+
),
|
|
134
|
+
[
|
|
135
|
+
'checked',
|
|
136
|
+
'disabled',
|
|
137
|
+
'type',
|
|
138
|
+
'color'
|
|
139
|
+
],
|
|
140
|
+
{ layoutRef }
|
|
141
|
+
)
|
|
137
142
|
|
|
138
143
|
if (type === 'checkbox') {
|
|
139
144
|
return createElement(
|
|
@@ -8,7 +8,7 @@ import { Text, TextStyle, TextProps } from 'react-native'
|
|
|
8
8
|
import { useRef, forwardRef, ReactNode, JSX, createElement } from 'react'
|
|
9
9
|
import useInnerProps from './getInnerListeners'
|
|
10
10
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
11
|
-
import { useTransformStyle, wrapChildren } from './utils'
|
|
11
|
+
import { useTransformStyle, wrapChildren, extendObject } from './utils'
|
|
12
12
|
|
|
13
13
|
interface _TextProps extends TextProps {
|
|
14
14
|
style?: TextStyle
|
|
@@ -35,8 +35,6 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
|
|
|
35
35
|
'parent-height': parentHeight
|
|
36
36
|
} = props
|
|
37
37
|
|
|
38
|
-
const layoutRef = useRef({})
|
|
39
|
-
|
|
40
38
|
const {
|
|
41
39
|
normalStyle,
|
|
42
40
|
hasVarDec,
|
|
@@ -54,16 +52,21 @@ const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref):
|
|
|
54
52
|
style: normalStyle
|
|
55
53
|
})
|
|
56
54
|
|
|
57
|
-
const innerProps = useInnerProps(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
const innerProps = useInnerProps(
|
|
56
|
+
extendObject(
|
|
57
|
+
{},
|
|
58
|
+
props,
|
|
59
|
+
{
|
|
60
|
+
ref: nodeRef,
|
|
61
|
+
style: normalStyle,
|
|
62
|
+
selectable: !!selectable || !!userSelect,
|
|
63
|
+
allowFontScaling
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
[
|
|
67
|
+
'user-select'
|
|
68
|
+
]
|
|
69
|
+
)
|
|
67
70
|
|
|
68
71
|
return createElement(Text, innerProps, wrapChildren(
|
|
69
72
|
props,
|