@mpxjs/webpack-plugin 2.9.70-alpha.0 → 2.9.70

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 (99) hide show
  1. package/LICENSE +433 -0
  2. package/README.md +1 -1
  3. package/lib/config.js +0 -14
  4. package/lib/dependencies/ResolveDependency.js +0 -5
  5. package/lib/index.js +7 -38
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +0 -53
  8. package/lib/parser.js +1 -1
  9. package/lib/platform/json/wx/index.js +21 -8
  10. package/lib/platform/style/wx/index.js +51 -54
  11. package/lib/platform/template/wx/component-config/button.js +2 -14
  12. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  13. package/lib/platform/template/wx/component-config/image.js +0 -4
  14. package/lib/platform/template/wx/component-config/index.js +1 -1
  15. package/lib/platform/template/wx/component-config/input.js +0 -4
  16. package/lib/platform/template/wx/component-config/rich-text.js +6 -2
  17. package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
  18. package/lib/platform/template/wx/component-config/switch.js +0 -4
  19. package/lib/platform/template/wx/component-config/text.js +0 -4
  20. package/lib/platform/template/wx/component-config/textarea.js +0 -5
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  22. package/lib/platform/template/wx/component-config/view.js +0 -4
  23. package/lib/platform/template/wx/index.js +1 -127
  24. package/lib/resolve-loader.js +1 -4
  25. package/lib/runtime/components/react/dist/getInnerListeners.js +5 -6
  26. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
  28. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +96 -107
  29. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +26 -27
  30. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +480 -0
  31. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +68 -0
  32. package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
  33. package/lib/runtime/components/react/dist/mpx-view.jsx +6 -3
  34. package/lib/runtime/components/react/dist/pickerFaces.js +6 -12
  35. package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerOverlay.jsx} +3 -5
  36. package/lib/runtime/components/react/dist/useAnimationHooks.js +7 -8
  37. package/lib/runtime/components/react/dist/utils.jsx +89 -60
  38. package/lib/runtime/components/react/event.config.ts +25 -26
  39. package/lib/runtime/components/react/getInnerListeners.ts +212 -169
  40. package/lib/runtime/components/react/mpx-button.tsx +9 -14
  41. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  42. package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
  43. package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
  44. package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
  45. package/lib/runtime/components/react/mpx-form.tsx +15 -20
  46. package/lib/runtime/components/react/mpx-icon.tsx +2 -2
  47. package/lib/runtime/components/react/mpx-image.tsx +87 -47
  48. package/lib/runtime/components/react/mpx-input.tsx +24 -32
  49. package/lib/runtime/components/react/mpx-label.tsx +12 -14
  50. package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
  51. package/lib/runtime/components/react/mpx-movable-view.tsx +20 -24
  52. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  53. package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
  54. package/lib/runtime/components/react/mpx-radio.tsx +19 -25
  55. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  56. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  57. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  58. package/lib/runtime/components/react/mpx-scroll-view.tsx +40 -41
  59. package/lib/runtime/components/react/mpx-switch.tsx +19 -15
  60. package/lib/runtime/components/react/mpx-text.tsx +8 -16
  61. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  62. package/lib/runtime/components/react/mpx-view.tsx +18 -20
  63. package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
  64. package/lib/runtime/components/react/types/global.d.ts +2 -1
  65. package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
  66. package/lib/runtime/components/react/utils.tsx +91 -60
  67. package/lib/runtime/components/web/mpx-web-view.vue +34 -20
  68. package/lib/runtime/optionProcessor.js +0 -22
  69. package/lib/style-compiler/index.js +1 -1
  70. package/lib/style-compiler/plugins/scope-id.js +30 -2
  71. package/lib/template-compiler/compiler.js +30 -26
  72. package/lib/utils/env.js +1 -6
  73. package/lib/utils/pre-process-json.js +9 -5
  74. package/package.json +4 -7
  75. package/lib/dependencies/AddEntryDependency.js +0 -24
  76. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +0 -39
  77. package/lib/runtime/components/react/dist/mpx-swiper.jsx +0 -606
  78. package/lib/runtime/components/react/dist/pickerVIewContext.js +0 -9
  79. package/lib/runtime/components/react/dist/pickerViewMask.jsx +0 -18
  80. package/lib/runtime/components/tenon/getInnerListeners.js +0 -334
  81. package/lib/runtime/components/tenon/tenon-button.vue +0 -309
  82. package/lib/runtime/components/tenon/tenon-image.vue +0 -66
  83. package/lib/runtime/components/tenon/tenon-input.vue +0 -171
  84. package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -26
  85. package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -127
  86. package/lib/runtime/components/tenon/tenon-switch.vue +0 -96
  87. package/lib/runtime/components/tenon/tenon-text.vue +0 -70
  88. package/lib/runtime/components/tenon/tenon-textarea.vue +0 -86
  89. package/lib/runtime/components/tenon/tenon-view.vue +0 -93
  90. package/lib/runtime/components/web/event.js +0 -105
  91. package/lib/runtime/optionProcessor.tenon.js +0 -84
  92. package/lib/style-compiler/plugins/hm.js +0 -20
  93. package/lib/tenon/index.js +0 -117
  94. package/lib/tenon/processJSON.js +0 -352
  95. package/lib/tenon/processScript.js +0 -203
  96. package/lib/tenon/processStyles.js +0 -21
  97. package/lib/tenon/processTemplate.js +0 -126
  98. package/lib/tenon/script-helper.js +0 -223
  99. package/lib/utils/get-relative-path.js +0 -25
@@ -316,8 +316,7 @@ var handleError = function (err, message) {
316
316
  document.removeEventListener('message', handleIncomingMessage);
317
317
  };
318
318
 
319
- function handleIncomingMessage(e) {
320
- var data = JSON.parse(e.data);
319
+ function handleIncomingMessage(data) {
321
320
  if (Array.isArray(data)) {
322
321
  for (var i = 0; i < data.length; i++) {
323
322
  try {
@@ -335,8 +334,7 @@ function handleIncomingMessage(e) {
335
334
  }
336
335
  }
337
336
 
338
- window.addEventListener('message', handleIncomingMessage);
339
- document.addEventListener('message', handleIncomingMessage);
337
+ window.mpxWebviewMessageCallback = handleIncomingMessage
340
338
  </script>
341
339
 
342
340
 
@@ -69,7 +69,11 @@ const _Canvas = forwardRef((props = {}, ref) => {
69
69
  useEffect(() => {
70
70
  const webviewPostMessage = (message) => {
71
71
  if (canvasRef.current.webview) {
72
- canvasRef.current.webview.postMessage(JSON.stringify(message));
72
+ const jsCode = `
73
+ window.mpxWebviewMessageCallback(${JSON.stringify(message)});
74
+ true;
75
+ `;
76
+ canvasRef.current.webview.injectJavaScript(jsCode);
73
77
  }
74
78
  };
75
79
  // 设置bus
@@ -1,58 +1,42 @@
1
- import React, { forwardRef, useRef, useState, useMemo, useEffect, useCallback } from 'react';
2
- import { Platform, SafeAreaView, StyleSheet } from 'react-native';
3
- import Reanimated, { useAnimatedRef, useScrollViewOffset } from 'react-native-reanimated';
4
- import { vibrateShort } from '@mpxjs/api-proxy';
5
- import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious } from './utils';
1
+ import { Animated, SafeAreaView } from 'react-native';
2
+ import React, { forwardRef, useRef, useState, useMemo, useCallback, useEffect } from 'react';
3
+ import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout, usePrevious } from './utils';
6
4
  import useNodesRef from './useNodesRef';
7
- import PickerOverlay from './pickerViewOverlay';
8
- import PickerMask from './pickerViewMask';
9
- import MpxPickerVIewColumnItem from './mpx-picker-view-column-item';
10
- import { PickerViewColumnAnimationContext } from './pickerVIewContext';
5
+ import { createFaces } from './pickerFaces';
6
+ import PickerOverlay from './pickerOverlay';
7
+ // 默认的单个选项高度
8
+ const DefaultPickerItemH = 36;
9
+ // 默认一屏可见选项个数
11
10
  const visibleCount = 5;
12
11
  const _PickerViewColumn = forwardRef((props, ref) => {
13
- const { columnData, columnIndex, columnStyle, initialIndex, onSelectChange, style, wrapperStyle, pickerMaskStyle, pickerOverlayStyle, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
12
+ const { columnData, columnIndex, initialIndex, onSelectChange, onColumnItemRawHChange, getInnerLayout, style, wrapperStyle, pickerOverlayStyle, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
14
13
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
15
- const { textStyle: textStyleFromParent = {} } = splitStyle(columnStyle);
16
- const { textStyle = {} } = splitStyle(normalStyle);
14
+ const { textStyle } = splitStyle(normalStyle);
17
15
  const { textProps } = splitProps(props);
18
- const scrollViewRef = useAnimatedRef();
19
- const offsetYShared = useScrollViewOffset(scrollViewRef);
16
+ const scrollViewRef = useRef(null);
20
17
  useNodesRef(props, ref, scrollViewRef, {
21
18
  style: normalStyle
22
19
  });
23
- const { height: pickerH, itemHeight } = wrapperStyle;
24
- const [scrollViewWidth, setScrollViewWidth] = useState('100%');
25
- const [itemRawW, setItemRawW] = useState('100%');
26
- const [itemRawH, setItemRawH] = useState(itemHeight);
20
+ const { height: pickerH, itemHeight = DefaultPickerItemH } = wrapperStyle;
21
+ const [itemRawH, setItemRawH] = useState(0); // 单个选项真实渲染高度
27
22
  const maxIndex = useMemo(() => columnData.length - 1, [columnData]);
28
- const maxScrollViewWidth = useRef(-1);
29
- const prevScrollingInfo = useRef({ index: initialIndex, y: 0 });
30
23
  const touching = useRef(false);
31
24
  const scrolling = useRef(false);
32
25
  const activeIndex = useRef(initialIndex);
33
26
  const prevIndex = usePrevious(initialIndex);
34
27
  const prevMaxIndex = usePrevious(maxIndex);
35
- const { layoutProps } = useLayout({
36
- props,
37
- hasSelfPercent,
38
- setWidth,
39
- setHeight,
40
- nodeRef: scrollViewRef
41
- });
42
- // console.log('[mpx-picker-view-column], render ---> columnIndex=', columnIndex, 'initialIndex=', initialIndex, 'columnData=', columnData.length)
43
- // const initialOffset = useMemo(() => ({
44
- // x: 0,
45
- // y: itemRawH * initialIndex
46
- // }), [itemRawH])
28
+ const initialOffset = useMemo(() => ({
29
+ x: 0,
30
+ y: itemRawH * initialIndex
31
+ }), [itemRawH]);
47
32
  const snapToOffsets = useMemo(() => columnData.map((_, i) => i * itemRawH), [columnData, itemRawH]);
48
- const paddingHeight = useMemo(() => Math.round((pickerH - itemRawH) / 2), [pickerH, itemRawH]);
49
33
  const contentContainerStyle = useMemo(() => {
50
- return [{ paddingVertical: paddingHeight }];
51
- }, [paddingHeight]);
52
- const getIndex = useCallback((y) => {
53
- const calc = Math.round(y / itemRawH);
54
- return Math.max(0, Math.min(calc, maxIndex));
55
- }, [itemRawH, maxIndex]);
34
+ return [
35
+ {
36
+ paddingVertical: Math.round(pickerH - itemRawH) / 2
37
+ }
38
+ ];
39
+ }, [pickerH, itemRawH]);
56
40
  useEffect(() => {
57
41
  if (!scrollViewRef.current ||
58
42
  !itemRawH ||
@@ -64,55 +48,40 @@ const _PickerViewColumn = forwardRef((props, ref) => {
64
48
  maxIndex !== prevMaxIndex) {
65
49
  return;
66
50
  }
67
- // console.log('[mpx-picker-view-column], useEffect ---> columnIndex=', columnIndex, 'initialIndex=', initialIndex, 'y=', itemRawH * initialIndex, `${scrollViewRef.current?.scrollTo}`)
68
- setTimeout(() => {
69
- scrollViewRef.current?.scrollTo({
70
- x: 0,
71
- y: itemRawH * initialIndex,
72
- animated: false
73
- });
74
- }, 0);
75
51
  activeIndex.current = initialIndex;
52
+ scrollViewRef.current.scrollTo({
53
+ x: 0,
54
+ y: itemRawH * initialIndex,
55
+ animated: false
56
+ });
76
57
  }, [itemRawH, initialIndex]);
77
- const onContentSizeChange = (_w, h) => {
78
- const y = itemRawH * initialIndex;
79
- // console.log('[mpx-picker-view-column], onContentSizeChange --->', 'columnIndex=', columnIndex, '_w=', _w, 'h=', h, 'y=', y)
80
- if (y <= h) {
81
- setTimeout(() => {
82
- scrollViewRef.current?.scrollTo({ x: 0, y, animated: false });
83
- }, 0);
84
- }
58
+ const onScrollViewLayout = () => {
59
+ getInnerLayout && getInnerLayout(layoutRef);
85
60
  };
86
- const onScrollViewLayout = (e) => {
87
- const { width } = e.nativeEvent.layout;
88
- const widthInt = Math.ceil(width);
89
- // console.log('[mpx-picker-view-column], onScrollViewLayout --->', 'columnIndex=', columnIndex, 'widthInt=', widthInt, 'scrollViewWidth=', scrollViewWidth)
90
- if (widthInt !== scrollViewWidth) {
91
- const maxW = maxScrollViewWidth.current;
92
- if (maxW !== -1 && widthInt > maxW) {
93
- return;
94
- }
95
- if (maxW === -1) {
96
- maxScrollViewWidth.current = Math.ceil(widthInt * 1.5);
97
- }
98
- setScrollViewWidth(widthInt);
99
- }
100
- if (itemRawW === '100%') {
101
- setItemRawW(widthInt);
102
- }
61
+ const { layoutRef, layoutProps } = useLayout({
62
+ props,
63
+ hasSelfPercent,
64
+ setWidth,
65
+ setHeight,
66
+ nodeRef: scrollViewRef,
67
+ onLayout: onScrollViewLayout
68
+ });
69
+ const onContentSizeChange = (w, h) => {
70
+ scrollViewRef.current?.scrollTo({
71
+ x: 0,
72
+ y: itemRawH * initialIndex,
73
+ animated: false
74
+ });
103
75
  };
104
76
  const onItemLayout = (e) => {
105
77
  const { height: rawH } = e.nativeEvent.layout;
106
78
  if (rawH && itemRawH !== rawH) {
107
79
  setItemRawH(rawH);
80
+ onColumnItemRawHChange(rawH);
108
81
  }
109
82
  };
110
83
  const onTouchStart = () => {
111
84
  touching.current = true;
112
- prevScrollingInfo.current = {
113
- index: activeIndex.current,
114
- y: activeIndex.current * itemRawH
115
- };
116
85
  };
117
86
  const onTouchEnd = () => {
118
87
  touching.current = false;
@@ -136,45 +105,65 @@ const _PickerViewColumn = forwardRef((props, ref) => {
136
105
  onSelectChange(calcIndex);
137
106
  }
138
107
  };
139
- const onScroll = (e) => {
140
- if (Platform.OS === 'android') {
141
- return;
142
- }
143
- const { y } = e.nativeEvent.contentOffset;
144
- const { index: prevIndex, y: _y } = prevScrollingInfo.current;
145
- if (touching.current || scrolling.current) {
146
- if (Math.abs(y - _y) >= itemRawH) {
147
- const currentId = getIndex(y);
148
- if (currentId !== prevIndex) {
149
- prevScrollingInfo.current = {
150
- index: currentId,
151
- y: currentId * itemRawH
152
- };
153
- vibrateShort({ type: 'selection' });
154
- }
155
- }
156
- }
157
- };
108
+ const offsetY = useRef(new Animated.Value(0)).current;
109
+ const onScroll = useMemo(() => Animated.event([{ nativeEvent: { contentOffset: { y: offsetY } } }], {
110
+ useNativeDriver: true
111
+ }), [offsetY]);
112
+ const faces = useMemo(() => createFaces(itemRawH, visibleCount), [itemRawH]);
113
+ const getTransform = useCallback((index) => {
114
+ const inputRange = faces.map((f) => itemRawH * (index + f.index));
115
+ return {
116
+ opacity: offsetY.interpolate({
117
+ inputRange: inputRange,
118
+ outputRange: faces.map((x) => x.opacity),
119
+ extrapolate: 'clamp'
120
+ }),
121
+ rotateX: offsetY.interpolate({
122
+ inputRange: inputRange,
123
+ outputRange: faces.map((x) => `${x.deg}deg`),
124
+ extrapolate: 'extend'
125
+ }),
126
+ translateY: offsetY.interpolate({
127
+ inputRange: inputRange,
128
+ outputRange: faces.map((x) => x.offsetY),
129
+ extrapolate: 'extend'
130
+ })
131
+ };
132
+ }, [offsetY, faces, itemRawH]);
158
133
  const renderInnerchild = () => columnData.map((item, index) => {
159
- return (<MpxPickerVIewColumnItem key={index} item={item} index={index} itemHeight={itemHeight} itemWidth={itemRawW} textStyleFromParent={textStyleFromParent} textStyle={textStyle} hasVarDec={hasVarDec} varContext={varContextRef.current} textProps={textProps} visibleCount={visibleCount} onItemLayout={onItemLayout}/>);
134
+ const InnerProps = index === 0 ? { onLayout: onItemLayout } : {};
135
+ const strKey = `picker-column-${columnIndex}-${index}`;
136
+ const { opacity, rotateX, translateY } = getTransform(index);
137
+ return (<Animated.View key={strKey} {...InnerProps} style={[
138
+ {
139
+ height: itemHeight || DefaultPickerItemH,
140
+ width: '100%',
141
+ opacity,
142
+ transform: [
143
+ { translateY },
144
+ { rotateX },
145
+ { perspective: 1000 } // 适配 Android
146
+ ]
147
+ }
148
+ ]}>
149
+ {wrapChildren({ children: item }, {
150
+ hasVarDec,
151
+ varContext: varContextRef.current,
152
+ textStyle,
153
+ textProps
154
+ })}
155
+ </Animated.View>);
160
156
  });
161
157
  const renderScollView = () => {
162
- return (<PickerViewColumnAnimationContext.Provider value={offsetYShared}>
163
- <Reanimated.ScrollView ref={scrollViewRef} bounces={true} horizontal={false} nestedScrollEnabled={true} removeClippedSubviews={false} showsVerticalScrollIndicator={false} showsHorizontalScrollIndicator={false} scrollEventThrottle={16} {...layoutProps} style={[{ width: scrollViewWidth }]} decelerationRate="fast" snapToOffsets={snapToOffsets} onScroll={onScroll} onLayout={onScrollViewLayout} onTouchStart={onTouchStart} onTouchEnd={onTouchEnd} onTouchCancel={onTouchCancel} onMomentumScrollBegin={onMomentumScrollBegin} onMomentumScrollEnd={onMomentumScrollEnd} onContentSizeChange={onContentSizeChange} contentContainerStyle={contentContainerStyle}>
164
- {renderInnerchild()}
165
- </Reanimated.ScrollView>
166
- </PickerViewColumnAnimationContext.Provider>);
158
+ return (<Animated.ScrollView ref={scrollViewRef} bounces={true} horizontal={false} pagingEnabled={false} nestedScrollEnabled={true} removeClippedSubviews={true} showsVerticalScrollIndicator={false} showsHorizontalScrollIndicator={false} {...layoutProps} scrollEventThrottle={16} contentContainerStyle={contentContainerStyle} contentOffset={initialOffset} snapToOffsets={snapToOffsets} onContentSizeChange={onContentSizeChange} onScroll={onScroll} onTouchStart={onTouchStart} onTouchEnd={onTouchEnd} onTouchCancel={onTouchCancel} onMomentumScrollBegin={onMomentumScrollBegin} onMomentumScrollEnd={onMomentumScrollEnd}>
159
+ {renderInnerchild()}
160
+ </Animated.ScrollView>);
167
161
  };
168
162
  const renderOverlay = () => (<PickerOverlay itemHeight={itemHeight} overlayItemStyle={pickerOverlayStyle}/>);
169
- const renderMask = () => (<PickerMask itemHeight={itemHeight} maskContainerStyle={pickerMaskStyle}/>);
170
- return (<SafeAreaView style={[styles.wrapper, normalStyle]}>
163
+ return (<SafeAreaView style={[{ display: 'flex', flex: 1 }]}>
171
164
  {renderScollView()}
172
- {renderMask()}
173
165
  {renderOverlay()}
174
166
  </SafeAreaView>);
175
167
  });
176
- const styles = StyleSheet.create({
177
- wrapper: { display: 'flex', flex: 1 }
178
- });
179
168
  _PickerViewColumn.displayName = 'MpxPickerViewColumn';
180
169
  export default _PickerViewColumn;
@@ -1,8 +1,8 @@
1
1
  import { View } from 'react-native';
2
- import React, { forwardRef, useRef } from 'react';
2
+ import React, { forwardRef, useState, useRef } from 'react';
3
3
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
4
4
  import useNodesRef from './useNodesRef';
5
- import { useLayout, splitProps, splitStyle, wrapChildren, parseInlineStyle, useTransformStyle, extendObject } from './utils';
5
+ import { useLayout, splitProps, splitStyle, wrapChildren, parseInlineStyle, useTransformStyle, useDebounceCallback, useStableCallback, extendObject } from './utils';
6
6
  const styles = {
7
7
  wrapper: {
8
8
  display: 'flex',
@@ -13,43 +13,42 @@ const styles = {
13
13
  alignItems: 'center'
14
14
  }
15
15
  };
16
- const DefaultPickerItemH = 36;
17
16
  const _PickerView = forwardRef((props, ref) => {
18
17
  const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props;
18
+ // indicatorStyle 需要转换为rn的style
19
+ // 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
19
20
  const indicatorStyle = parseInlineStyle(props['indicator-style']);
20
- const pickerMaskStyle = parseInlineStyle(props['mask-style']);
21
21
  const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle;
22
+ const [pickMaxH, setPickMaxH] = useState(0);
22
23
  const nodeRef = useRef(null);
23
24
  const cloneRef = useRef(null);
24
25
  const activeValueRef = useRef(value);
25
26
  activeValueRef.current = value.slice();
26
- const snapActiveValueRef = useRef(null);
27
- console.log('[mpx-picker-view] value=', value, Date.now());
28
27
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
29
28
  useNodesRef(props, ref, nodeRef, {
30
29
  style: normalStyle
31
30
  });
32
- const { layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
31
+ const {
32
+ // 存储layout布局信息
33
+ layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef });
33
34
  const { textProps } = splitProps(props);
34
35
  const { textStyle } = splitStyle(normalStyle);
36
+ const onColumnItemRawHChange = (height) => {
37
+ if (height > pickMaxH) {
38
+ setPickMaxH(height);
39
+ }
40
+ };
41
+ const bindchangeDebounce = useDebounceCallback(useStableCallback(bindchange), 300);
35
42
  const onSelectChange = (columnIndex, selectedIndex) => {
43
+ bindchangeDebounce.clear();
36
44
  const activeValue = activeValueRef.current;
37
45
  activeValue[columnIndex] = selectedIndex;
38
- console.log('[mpx-picker-view], onSelectChange ---> columnIndex=', columnIndex, 'selectedIndex=', selectedIndex, 'activeValue=', activeValue);
39
46
  const eventData = getCustomEvent('change', {}, { detail: { value: activeValue, source: 'change' }, layoutRef });
40
- bindchange?.(eventData);
41
- snapActiveValueRef.current = activeValueRef.current;
47
+ bindchangeDebounce(eventData);
42
48
  };
43
- const hasDiff = (a = [], b) => {
44
- return a.some((v, i) => v !== b[i]);
45
- };
46
- const onInitialChange = (isInvalid, value) => {
47
- if (isInvalid || !snapActiveValueRef.current || hasDiff(snapActiveValueRef.current, value)) {
48
- console.log('[mpx-picker-view], onInitialChange-1 ===> value=', value);
49
- const eventData = getCustomEvent('change', {}, { detail: { value, source: 'change' }, layoutRef });
50
- bindchange?.(eventData);
51
- snapActiveValueRef.current = value.slice();
52
- }
49
+ const onInitialChange = (value) => {
50
+ const eventData = getCustomEvent('change', {}, { detail: { value, source: 'change' }, layoutRef });
51
+ bindchange?.(eventData); // immediate
53
52
  };
54
53
  const innerProps = useInnerProps(props, extendObject({
55
54
  ref: nodeRef,
@@ -60,6 +59,7 @@ const _PickerView = forwardRef((props, ref) => {
60
59
  layoutProps
61
60
  }), ['enable-offset'], { layoutRef });
62
61
  const renderColumn = (child, index, columnData, initialIndex) => {
62
+ const extraProps = {};
63
63
  const childProps = child?.props || {};
64
64
  const wrappedProps = extendObject({}, childProps, {
65
65
  columnData,
@@ -67,15 +67,14 @@ const _PickerView = forwardRef((props, ref) => {
67
67
  columnIndex: index,
68
68
  key: `pick-view-${index}`,
69
69
  wrapperStyle: {
70
- height: normalStyle?.height || DefaultPickerItemH,
71
- itemHeight: indicatorH || DefaultPickerItemH
70
+ height: normalStyle?.height || 0,
71
+ itemHeight: indicatorH || 0
72
72
  },
73
- columnStyle: normalStyle,
73
+ onColumnItemRawHChange,
74
74
  onSelectChange: onSelectChange.bind(null, index),
75
75
  initialIndex,
76
- pickerOverlayStyle,
77
- pickerMaskStyle
78
- });
76
+ pickerOverlayStyle
77
+ }, extraProps);
79
78
  const realElement = React.cloneElement(child, wrappedProps);
80
79
  return wrapChildren({
81
80
  children: realElement
@@ -111,7 +110,7 @@ const _PickerView = forwardRef((props, ref) => {
111
110
  validValue.push(validIndex);
112
111
  renderColumns.push(renderColumn(item, index, columnData, validIndex));
113
112
  });
114
- onInitialChange(isInvalid, validValue);
113
+ isInvalid && onInitialChange(validValue);
115
114
  return renderColumns;
116
115
  };
117
116
  return (<View {...innerProps}>