@mpxjs/webpack-plugin 2.10.3-beta.6 → 2.10.4-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/lib/index.js +1 -1
  2. package/lib/platform/json/wx/index.js +0 -1
  3. package/lib/platform/style/wx/index.js +22 -21
  4. package/lib/platform/template/wx/component-config/button.js +1 -1
  5. package/lib/platform/template/wx/component-config/index.js +5 -1
  6. package/lib/platform/template/wx/component-config/input.js +2 -2
  7. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  8. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  9. package/lib/platform/template/wx/component-config/text.js +18 -3
  10. package/lib/platform/template/wx/component-config/view.js +0 -2
  11. package/lib/platform/template/wx/index.js +41 -93
  12. package/lib/react/processJSON.js +7 -6
  13. package/lib/react/processScript.js +1 -18
  14. package/lib/runtime/components/react/context.ts +12 -3
  15. package/lib/runtime/components/react/dist/context.js +4 -1
  16. package/lib/runtime/components/react/dist/event.config.js +0 -1
  17. package/lib/runtime/components/react/dist/getInnerListeners.js +127 -142
  18. package/lib/runtime/components/react/dist/mpx-button.jsx +4 -5
  19. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +4 -5
  20. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -2
  21. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -3
  22. package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
  23. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
  24. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  25. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
  26. package/lib/runtime/components/react/dist/mpx-input.jsx +6 -10
  27. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
  28. package/lib/runtime/components/react/dist/mpx-label.jsx +2 -3
  29. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +2 -2
  30. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
  31. package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
  32. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
  33. package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
  34. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +180 -98
  35. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
  36. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
  37. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
  38. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
  39. package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +5 -6
  40. package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +64 -16
  41. package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
  42. package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
  43. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
  44. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
  45. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -2
  46. package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -3
  47. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +2 -2
  48. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +207 -29
  49. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +7 -5
  50. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
  51. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
  52. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  53. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -5
  54. package/lib/runtime/components/react/dist/mpx-swiper.jsx +11 -11
  55. package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -5
  56. package/lib/runtime/components/react/dist/mpx-text.jsx +4 -7
  57. package/lib/runtime/components/react/dist/mpx-video.jsx +5 -5
  58. package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
  59. package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -17
  60. package/lib/runtime/components/react/dist/useAnimationHooks.js +26 -4
  61. package/lib/runtime/components/react/dist/utils.jsx +13 -2
  62. package/lib/runtime/components/react/event.config.ts +1 -6
  63. package/lib/runtime/components/react/getInnerListeners.ts +148 -191
  64. package/lib/runtime/components/react/mpx-button.tsx +7 -7
  65. package/lib/runtime/components/react/mpx-canvas/index.tsx +25 -17
  66. package/lib/runtime/components/react/mpx-checkbox-group.tsx +4 -3
  67. package/lib/runtime/components/react/mpx-checkbox.tsx +8 -9
  68. package/lib/runtime/components/react/mpx-form.tsx +25 -19
  69. package/lib/runtime/components/react/mpx-icon/index.tsx +4 -3
  70. package/lib/runtime/components/react/mpx-image.tsx +4 -3
  71. package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
  72. package/lib/runtime/components/react/mpx-input.tsx +8 -14
  73. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +2 -2
  74. package/lib/runtime/components/react/mpx-label.tsx +4 -5
  75. package/lib/runtime/components/react/mpx-movable-area.tsx +22 -13
  76. package/lib/runtime/components/react/mpx-movable-view.tsx +47 -40
  77. package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
  78. package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
  79. package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
  80. package/lib/runtime/components/react/mpx-picker/index.tsx +242 -118
  81. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
  82. package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
  83. package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
  84. package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
  85. package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
  86. package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +24 -21
  87. package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +70 -19
  88. package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
  89. package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
  90. package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
  91. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
  92. package/lib/runtime/components/react/mpx-radio-group.tsx +4 -3
  93. package/lib/runtime/components/react/mpx-radio.tsx +8 -9
  94. package/lib/runtime/components/react/mpx-rich-text/index.tsx +15 -6
  95. package/lib/runtime/components/react/mpx-scroll-view.tsx +326 -96
  96. package/lib/runtime/components/react/mpx-simple-text.tsx +17 -8
  97. package/lib/runtime/components/react/mpx-simple-view.tsx +17 -16
  98. package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
  99. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  100. package/lib/runtime/components/react/mpx-swiper-item.tsx +31 -24
  101. package/lib/runtime/components/react/mpx-swiper.tsx +69 -65
  102. package/lib/runtime/components/react/mpx-switch.tsx +19 -14
  103. package/lib/runtime/components/react/mpx-text.tsx +16 -13
  104. package/lib/runtime/components/react/mpx-video.tsx +36 -35
  105. package/lib/runtime/components/react/mpx-view.tsx +41 -17
  106. package/lib/runtime/components/react/mpx-web-view.tsx +16 -16
  107. package/lib/runtime/components/react/types/getInnerListeners.d.ts +69 -35
  108. package/lib/runtime/components/react/useAnimationHooks.ts +29 -9
  109. package/lib/runtime/components/react/utils.tsx +13 -2
  110. package/lib/runtime/components/web/mpx-input.vue +1 -1
  111. package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
  112. package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
  113. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  114. package/lib/runtime/stringify.wxs +2 -2
  115. package/lib/template-compiler/compiler.js +7 -7
  116. package/package.json +3 -4
  117. /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
  118. /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
  119. /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
  120. /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
  121. /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
  122. /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
@@ -0,0 +1,179 @@
1
+ import { useEffect, useRef, useContext, forwardRef, useMemo, createElement, ReactNode, useId } from 'react'
2
+ import { Animated, StyleSheet, View, NativeSyntheticEvent, ViewStyle, LayoutChangeEvent, useAnimatedValue } 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 = useAnimatedValue(0)
58
+ // harmony animatedValue 不支持通过 _value 访问
59
+ const headerTopRef = useRef(0)
60
+
61
+ useEffect(() => {
62
+ registerStickyHeader({ key: id, updatePosition })
63
+ return () => {
64
+ unregisterStickyHeader(id)
65
+ }
66
+ }, [])
67
+
68
+ function updatePosition () {
69
+ if (headerRef.current) {
70
+ const scrollViewRef = scrollViewContext.gestureRef
71
+ if (scrollViewRef && scrollViewRef.current) {
72
+ headerRef.current.measureLayout(
73
+ scrollViewRef.current,
74
+ (left: number, top: number) => {
75
+ Animated.timing(headerTopAnimated, {
76
+ toValue: top,
77
+ duration: 0,
78
+ useNativeDriver: true
79
+ }).start()
80
+ headerTopRef.current = top
81
+ }
82
+ )
83
+ } else {
84
+ error('StickyHeader measureLayout error: scrollViewRef is not a valid native component reference')
85
+ }
86
+ }
87
+ }
88
+
89
+ function onLayout (e: LayoutChangeEvent) {
90
+ updatePosition()
91
+ }
92
+
93
+ useNodesRef(props, ref, headerRef, {
94
+ style: normalStyle
95
+ })
96
+
97
+ useEffect(() => {
98
+ if (!bindstickontopchange) return
99
+
100
+ const listener = scrollOffset.addListener((state: { value: number }) => {
101
+ const currentScrollValue = state.value
102
+ const newIsStickOnTop = currentScrollValue > headerTopRef.current
103
+ if (newIsStickOnTop !== isStickOnTopRef.current) {
104
+ isStickOnTopRef.current = newIsStickOnTop
105
+ bindstickontopchange(
106
+ getCustomEvent('stickontopchange', {}, {
107
+ detail: {
108
+ isStickOnTop: newIsStickOnTop
109
+ },
110
+ layoutRef
111
+ }, props))
112
+ }
113
+ })
114
+
115
+ return () => {
116
+ scrollOffset.removeListener(listener)
117
+ }
118
+ }, [])
119
+
120
+ const animatedStyle = useMemo(() => {
121
+ const translateY = Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
122
+ inputRange: [0, 1],
123
+ outputRange: [0, 1],
124
+ extrapolateLeft: 'clamp',
125
+ extrapolateRight: 'extend'
126
+ })
127
+
128
+ const finalTranslateY = offsetTop === 0
129
+ ? translateY
130
+ : Animated.add(
131
+ translateY,
132
+ Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
133
+ inputRange: [0, 1],
134
+ outputRange: [0, offsetTop],
135
+ extrapolate: 'clamp'
136
+ })
137
+ )
138
+
139
+ return {
140
+ transform: [{ translateY: finalTranslateY }]
141
+ }
142
+ }, [scrollOffset, headerTopAnimated, offsetTop])
143
+
144
+ const innerProps = useInnerProps(extendObject({}, props, {
145
+ ref: headerRef,
146
+ style: extendObject({}, styles.content, innerStyle, animatedStyle, {
147
+ paddingTop: padding[0] || 0,
148
+ paddingRight: padding[1] || 0,
149
+ paddingBottom: padding[2] || 0,
150
+ paddingLeft: padding[3] || 0
151
+ })
152
+ }, layoutProps), [], { layoutRef })
153
+
154
+ return (
155
+ createElement(
156
+ Animated.View,
157
+ innerProps,
158
+ wrapChildren(
159
+ props,
160
+ {
161
+ hasVarDec,
162
+ varContext: varContextRef.current,
163
+ textStyle,
164
+ textProps
165
+ }
166
+ )
167
+ )
168
+ )
169
+ })
170
+
171
+ const styles = StyleSheet.create({
172
+ content: {
173
+ width: '100%',
174
+ zIndex: 10
175
+ }
176
+ })
177
+
178
+ _StickyHeader.displayName = 'MpxStickyHeader'
179
+ 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(props, {
68
- ref: nodeRef,
69
- ...layoutProps
70
- }, [
71
- 'children',
72
- 'enable-offset',
73
- 'style'
74
- ], { layoutRef })
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,33 +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
- disableGesture?: boolean;
59
- 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
60
59
  }
61
60
 
62
61
  /**
@@ -137,8 +136,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
137
136
  'external-var-context': externalVarContext,
138
137
  style = {},
139
138
  autoplay = false,
140
- circular = false,
141
- disableGesture = false
139
+ circular = false
142
140
  } = props
143
141
  const easeingFunc = props['easing-function'] || 'default'
144
142
  const easeDuration = props.duration || 500
@@ -203,23 +201,29 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
203
201
  layoutProps,
204
202
  layoutStyle
205
203
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout: onWrapperLayout })
206
- const innerProps = useInnerProps(props, {
207
- ref: nodeRef
208
- }, [
209
- 'style',
210
- 'indicator-dots',
211
- 'indicator-color',
212
- 'indicator-active-color',
213
- 'previous-margin',
214
- 'vertical',
215
- 'previous-margin',
216
- 'next-margin',
217
- 'easing-function',
218
- 'autoplay',
219
- 'circular',
220
- 'interval',
221
- 'easing-function'
222
- ], { layoutRef: layoutRef })
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 })
223
227
 
224
228
  function onWrapperLayout (e: LayoutChangeEvent) {
225
229
  const { width, height } = e.nativeEvent.layout
@@ -253,8 +257,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
253
257
  dots.push(<View style={[dotCommonStyle, { backgroundColor: unActionColor }]} key={i}></View>)
254
258
  }
255
259
  return (
256
- <View pointerEvents="none" style = {styles['pagination_' + dir]}>
257
- <View style = {[styles['pagerWrapper' + dir]]}>
260
+ <View pointerEvents="none" style={styles['pagination_' + dir]}>
261
+ <View style={[styles['pagerWrapper' + dir]]}>
258
262
  <Animated.View style={[
259
263
  dotCommonStyle,
260
264
  activeDotStyle,
@@ -268,8 +272,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
268
272
  ]}
269
273
  />
270
274
  {dots}
271
- </View>
272
- </View>)
275
+ </View>
276
+ </View>)
273
277
  }
274
278
 
275
279
  function renderItems () {
@@ -394,7 +398,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
394
398
  }
395
399
  }
396
400
 
397
- function getOffset (index:number, stepValue: number) {
401
+ function getOffset (index: number, stepValue: number) {
398
402
  if (!stepValue) return 0
399
403
  let targetOffset = 0
400
404
  if (circular && children.length > 1) {
@@ -406,7 +410,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
406
410
  return targetOffset
407
411
  }
408
412
 
409
- function updateCurrent (index:number, stepValue: number) {
413
+ function updateCurrent (index: number, stepValue: number) {
410
414
  const targetOffset = getOffset(index || 0, stepValue)
411
415
  if (targetOffset !== offset.value) {
412
416
  // 内部基于props.current!==currentIndex.value决定是否使用动画及更新currentIndex.value
@@ -714,25 +718,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
714
718
  function renderSwiper () {
715
719
  const arrPages: Array<ReactNode> | ReactNode = renderItems()
716
720
  return (<View style={[normalStyle, layoutStyle, styles.swiper]} {...layoutProps} {...innerProps}>
717
- <Animated.View style={[{
718
- flexDirection: dir === 'x' ? 'row' : 'column',
719
- width: '100%',
720
- height: '100%'
721
- }, animatedStyles]}>
722
- {wrapChildren({
723
- children: arrPages
724
- }, {
725
- hasVarDec,
726
- varContext: varContextRef.current,
727
- textStyle,
728
- textProps
729
- })}
730
- </Animated.View>
731
- {showsPagination && renderPagination()}
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()}
732
736
  </View>)
733
737
  }
734
738
 
735
- if (children.length === 1 || disableGesture) {
739
+ if (children.length === 1) {
736
740
  return renderSwiper()
737
741
  } else {
738
742
  return (<GestureDetector gesture={gestureHandler}>
@@ -120,20 +120,25 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
120
120
  }
121
121
  }, [])
122
122
 
123
- const innerProps = useInnerProps(props, extendObject({
124
- ref: nodeRef,
125
- style: extendObject({}, normalStyle, layoutStyle)
126
- },
127
- layoutProps,
128
- !disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {})
129
- , [
130
- 'checked',
131
- 'disabled',
132
- 'type',
133
- 'color'
134
- ], {
135
- layoutRef
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(props, {
58
- ref: nodeRef,
59
- style: normalStyle,
60
- selectable: !!selectable || !!userSelect,
61
- allowFontScaling
62
- }, [
63
- 'user-select'
64
- ], {
65
- layoutRef
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,