@mpxjs/webpack-plugin 2.9.69-beta.4 → 2.9.69-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.
Files changed (30) hide show
  1. package/lib/runtime/components/react/context.ts +1 -1
  2. package/lib/runtime/components/react/dist/mpx-button.jsx +11 -11
  3. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +1 -1
  4. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +16 -2
  5. package/lib/runtime/components/react/dist/mpx-portal/portal-consumer.jsx +1 -1
  6. package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +10 -41
  7. package/lib/runtime/components/react/dist/mpx-portal.jsx +1 -0
  8. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +13 -7
  9. package/lib/runtime/components/react/dist/mpx-swiper.jsx +382 -325
  10. package/lib/runtime/components/react/dist/mpx-view.jsx +15 -13
  11. package/lib/runtime/components/react/dist/mpx-web-view.jsx +19 -32
  12. package/lib/runtime/components/react/dist/pickerFaces.js +1 -6
  13. package/lib/runtime/components/react/dist/useAnimationHooks.js +15 -10
  14. package/lib/runtime/components/react/dist/utils.jsx +57 -0
  15. package/lib/runtime/components/react/mpx-button.tsx +12 -13
  16. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +1 -1
  17. package/lib/runtime/components/react/mpx-picker-view-column.tsx +18 -2
  18. package/lib/runtime/components/react/mpx-portal/portal-consumer.tsx +1 -1
  19. package/lib/runtime/components/react/mpx-portal/portal-host.tsx +14 -45
  20. package/lib/runtime/components/react/mpx-portal.tsx +1 -0
  21. package/lib/runtime/components/react/mpx-swiper-item.tsx +13 -7
  22. package/lib/runtime/components/react/mpx-swiper.tsx +377 -330
  23. package/lib/runtime/components/react/mpx-view.tsx +17 -14
  24. package/lib/runtime/components/react/mpx-web-view.tsx +19 -32
  25. package/lib/runtime/components/react/pickerFaces.ts +1 -6
  26. package/lib/runtime/components/react/types/global.d.ts +4 -0
  27. package/lib/runtime/components/react/useAnimationHooks.ts +14 -10
  28. package/lib/runtime/components/react/utils.tsx +64 -0
  29. package/lib/wxss/loader.js +15 -2
  30. package/package.json +1 -1
@@ -42,7 +42,7 @@ export interface PortalManagerContextValue {
42
42
  export interface PortalContextValue {
43
43
  mount: (children: React.ReactNode, key?: number, pageId?: number|null) => number| undefined
44
44
  update: (key: number, children: React.ReactNode, pageId?: number|null) => void
45
- unmount: (key: number, pageId?: number|null) => void
45
+ unmount: (key: number) => void
46
46
  manager?: PortalManagerContextValue
47
47
  }
48
48
 
@@ -38,7 +38,7 @@ import { createElement, useEffect, useRef, forwardRef, useContext } from 'react'
38
38
  import { View, StyleSheet, Animated, Easing } from 'react-native';
39
39
  import { warn } from '@mpxjs/utils';
40
40
  import { GestureDetector } from 'react-native-gesture-handler';
41
- import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHoverStyle } from './utils';
41
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils';
42
42
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
43
43
  import useNodesRef from './useNodesRef';
44
44
  import { RouteContext, FormContext } from './context';
@@ -132,7 +132,8 @@ const Button = forwardRef((buttonProps, ref) => {
132
132
  const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap } = props;
133
133
  const pageId = useContext(RouteContext);
134
134
  const formContext = useContext(FormContext);
135
- const { isHover, enableHoverStyle, gesture } = useHoverStyle({ hoverStyle, hoverStartTime, hoverStayTime, disabled });
135
+ const enableHover = hoverClass !== 'none';
136
+ const { isHover, gesture } = useHover({ enableHover, hoverStartTime, hoverStayTime, disabled });
136
137
  let submitFn;
137
138
  let resetFn;
138
139
  if (formContext) {
@@ -140,23 +141,22 @@ const Button = forwardRef((buttonProps, ref) => {
140
141
  resetFn = formContext.reset;
141
142
  }
142
143
  const isMiniSize = size === 'mini';
143
- const applyHoverEffect = isHover && hoverClass !== 'none';
144
144
  const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type];
145
- const normalBackgroundColor = disabled ? disabledColor : applyHoverEffect || loading ? hoverColor : color;
145
+ const normalBackgroundColor = disabled ? disabledColor : isHover || loading ? hoverColor : color;
146
146
  const plainBorderColor = disabled
147
147
  ? 'rgba(0, 0, 0, .2)'
148
- : applyHoverEffect
148
+ : isHover
149
149
  ? `rgba(${plainColor},.6)`
150
150
  : `rgb(${plainColor})`;
151
151
  const normalBorderColor = type === 'default' ? 'rgba(0, 0, 0, .2)' : normalBackgroundColor;
152
152
  const plainTextColor = disabled
153
153
  ? 'rgba(0, 0, 0, .2)'
154
- : applyHoverEffect
154
+ : isHover
155
155
  ? `rgba(${plainColor}, .6)`
156
156
  : `rgb(${plainColor})`;
157
157
  const normalTextColor = type === 'default'
158
- ? `rgba(0, 0, 0, ${disabled ? 0.3 : applyHoverEffect || loading ? 0.6 : 1})`
159
- : `rgba(255 ,255 ,255 , ${disabled || applyHoverEffect || loading ? 0.6 : 1})`;
158
+ ? `rgba(0, 0, 0, ${disabled ? 0.3 : isHover || loading ? 0.6 : 1})`
159
+ : `rgba(255 ,255 ,255 , ${disabled || isHover || loading ? 0.6 : 1})`;
160
160
  const viewStyle = {
161
161
  borderWidth: 1,
162
162
  borderStyle: 'solid',
@@ -166,7 +166,7 @@ const Button = forwardRef((buttonProps, ref) => {
166
166
  const defaultViewStyle = extendObject({}, styles.button, isMiniSize ? styles.buttonMini : null, viewStyle);
167
167
  const defaultTextStyle = extendObject({}, styles.text, isMiniSize ? styles.textMini : {}, { color: plain ? plainTextColor : normalTextColor });
168
168
  const defaultStyle = extendObject({}, defaultViewStyle, defaultTextStyle);
169
- const styleObj = extendObject({}, defaultStyle, style, applyHoverEffect ? hoverStyle : {});
169
+ const styleObj = extendObject({}, defaultStyle, style, isHover ? hoverStyle : {});
170
170
  const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
171
171
  const nodeRef = useRef(null);
172
172
  useNodesRef(props, ref, nodeRef, { style: normalStyle });
@@ -263,8 +263,8 @@ const Button = forwardRef((buttonProps, ref) => {
263
263
  textStyle,
264
264
  textProps
265
265
  }));
266
- return enableHoverStyle
267
- ? createElement(GestureDetector, { gesture }, baseButton)
266
+ return enableHover
267
+ ? createElement(GestureDetector, { gesture: gesture }, baseButton)
268
268
  : baseButton;
269
269
  });
270
270
  Button.displayName = 'MpxButton';
@@ -14,8 +14,8 @@ const _PickerViewColumnItem = ({ item, index, itemHeight, itemWidth = '100%', te
14
14
  return {
15
15
  opacity: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.opacity), Extrapolation.CLAMP),
16
16
  transform: [
17
- { rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
18
17
  { translateY: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.offsetY), Extrapolation.EXTEND) },
18
+ { rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
19
19
  { scale: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.scale), Extrapolation.EXTEND) }
20
20
  ]
21
21
  };
@@ -25,6 +25,7 @@ const _PickerViewColumn = forwardRef((props, ref) => {
25
25
  const prevScrollingInfo = useRef({ index: initialIndex, y: 0 });
26
26
  const touching = useRef(false);
27
27
  const scrolling = useRef(false);
28
+ const timerScrollTo = useRef(null);
28
29
  const activeIndex = useRef(initialIndex);
29
30
  const prevIndex = usePrevious(initialIndex);
30
31
  const prevMaxIndex = usePrevious(maxIndex);
@@ -65,6 +66,17 @@ const _PickerViewColumn = forwardRef((props, ref) => {
65
66
  }
66
67
  });
67
68
  const debounceResetScrollPosition = useDebounceCallback(stableResetScrollPosition, 10);
69
+ const clearTimerScrollTo = () => {
70
+ if (timerScrollTo.current) {
71
+ clearTimeout(timerScrollTo.current);
72
+ timerScrollTo.current = null;
73
+ }
74
+ };
75
+ useEffect(() => {
76
+ return () => {
77
+ clearTimerScrollTo();
78
+ };
79
+ }, []);
68
80
  useEffect(() => {
69
81
  if (!scrollViewRef.current ||
70
82
  !itemRawH ||
@@ -76,7 +88,8 @@ const _PickerViewColumn = forwardRef((props, ref) => {
76
88
  maxIndex !== prevMaxIndex) {
77
89
  return;
78
90
  }
79
- setTimeout(() => {
91
+ clearTimerScrollTo();
92
+ timerScrollTo.current = setTimeout(() => {
80
93
  scrollViewRef.current?.scrollTo({
81
94
  x: 0,
82
95
  y: getYofIndex(initialIndex),
@@ -88,7 +101,8 @@ const _PickerViewColumn = forwardRef((props, ref) => {
88
101
  const onContentSizeChange = (_w, h) => {
89
102
  const y = getYofIndex(initialIndex);
90
103
  if (y <= h) {
91
- setTimeout(() => {
104
+ clearTimerScrollTo();
105
+ timerScrollTo.current = setTimeout(() => {
92
106
  scrollViewRef.current?.scrollTo({ x: 0, y, animated: false });
93
107
  }, 0);
94
108
  }
@@ -15,7 +15,7 @@ const PortalConsumer = ({ manager, children }) => {
15
15
  const curPageId = navigation?.pageId;
16
16
  keyRef.current = manager.mount(children, undefined, curPageId);
17
17
  return () => {
18
- manager.unmount(keyRef.current, curPageId);
18
+ manager.unmount(keyRef.current);
19
19
  };
20
20
  }, []);
21
21
  return null;
@@ -6,6 +6,7 @@ import { PortalContext } from '../context';
6
6
  // events
7
7
  const addType = 'MPX_RN_ADD_PORTAL';
8
8
  const removeType = 'MPX_RN_REMOVE_PORTAL';
9
+ const updateType = 'MPX_RN_UPDATE_PORTAL';
9
10
  // fix react native web does not support DeviceEventEmitter
10
11
  const TopViewEventEmitter = DeviceEventEmitter || new NativeEventEmitter();
11
12
  const styles = StyleSheet.create({
@@ -23,6 +24,9 @@ class PortalGuard {
23
24
  remove = (key) => {
24
25
  TopViewEventEmitter.emit(removeType, key);
25
26
  };
27
+ update = (key, e) => {
28
+ TopViewEventEmitter.emit(updateType, key, e);
29
+ };
26
30
  }
27
31
  /**
28
32
  * portal
@@ -33,6 +37,7 @@ const PortalHost = ({ children }) => {
33
37
  const _queue = useRef([]);
34
38
  const _addType = useRef(null);
35
39
  const _removeType = useRef(null);
40
+ const _updateType = useRef(null);
36
41
  const manager = useRef(null);
37
42
  let currentPageId;
38
43
  const _mount = (children, _key, curPageId) => {
@@ -45,23 +50,12 @@ const PortalHost = ({ children }) => {
45
50
  if (manager.current) {
46
51
  manager.current.mount(key, children);
47
52
  }
48
- else {
49
- _queue.current.push({ type: 'mount', key, children });
50
- }
51
53
  return key;
52
54
  };
53
- const _unmount = (key, curPageId) => {
54
- const navigation = getFocusedNavigation();
55
- const pageId = navigation?.pageId;
56
- if (pageId !== (curPageId ?? currentPageId)) {
57
- return;
58
- }
55
+ const _unmount = (key) => {
59
56
  if (manager.current) {
60
57
  manager.current.unmount(key);
61
58
  }
62
- else {
63
- _queue.current.push({ type: 'unmount', key });
64
- }
65
59
  };
66
60
  const _update = (key, children, curPageId) => {
67
61
  const navigation = getFocusedNavigation();
@@ -72,41 +66,17 @@ const PortalHost = ({ children }) => {
72
66
  if (manager.current) {
73
67
  manager.current.update(key, children);
74
68
  }
75
- else {
76
- const op = { type: 'mount', key, children };
77
- const index = _queue.current.findIndex((o) => o.type === 'mount' || (o.type === 'update' && o.key === key));
78
- if (index > -1) {
79
- _queue.current[index] = op;
80
- }
81
- else {
82
- _queue.current.push(op);
83
- }
84
- }
85
69
  };
86
70
  useEffect(() => {
87
71
  const navigation = getFocusedNavigation();
88
72
  currentPageId = navigation?.pageId;
89
73
  _addType.current = TopViewEventEmitter.addListener(addType, _mount);
90
74
  _removeType.current = TopViewEventEmitter.addListener(removeType, _unmount);
75
+ _updateType.current = TopViewEventEmitter.addListener(updateType, _update);
91
76
  return () => {
92
- while (_queue.current.length && manager.current) {
93
- const action = _queue.current.pop();
94
- if (!action) {
95
- continue;
96
- }
97
- // tslint:disable-next-line:switch-default
98
- switch (action.type) {
99
- case 'mount':
100
- manager.current?.mount(action.key, action.children);
101
- break;
102
- case 'update':
103
- manager.current?.update(action.key, action.children);
104
- break;
105
- case 'unmount':
106
- manager.current?.unmount(action.key);
107
- break;
108
- }
109
- }
77
+ _addType.current?.remove();
78
+ _removeType.current?.remove();
79
+ _updateType.current?.remove();
110
80
  };
111
81
  }, []);
112
82
  return (<PortalContext.Provider value={{
@@ -114,7 +84,6 @@ const PortalHost = ({ children }) => {
114
84
  update: _update,
115
85
  unmount: _unmount
116
86
  }}>
117
- {/* Need collapsable=false here to clip the elevations, otherwise they appear above Portal components */}
118
87
  <View style={styles.container} collapsable={false}>
119
88
  {children}
120
89
  </View>
@@ -9,4 +9,5 @@ const Portal = ({ children }) => {
9
9
  Portal.Host = PortalHost;
10
10
  Portal.add = portal.add;
11
11
  Portal.remove = portal.remove;
12
+ Portal.update = portal.update;
12
13
  export default Portal;
@@ -10,6 +10,7 @@ const _SwiperItem = forwardRef((props, ref) => {
10
10
  const offset = contextValue.offset || 0;
11
11
  const step = contextValue.step || 0;
12
12
  const scale = contextValue.scale || false;
13
+ const dir = contextValue.dir || 'x';
13
14
  const { textProps } = splitProps(props);
14
15
  const nodeRef = useRef(null);
15
16
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext });
@@ -33,14 +34,19 @@ const _SwiperItem = forwardRef((props, ref) => {
33
34
  return {};
34
35
  const inputRange = [step.value, 0];
35
36
  const outputRange = [0.7, 1];
36
- return {
37
- transform: [{
38
- scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
39
- }]
40
- };
37
+ // 实现元素的宽度跟随step从0到真实宽度,且不能触发重新渲染整个组件,通过AnimatedStyle的方式实现
38
+ const outerLayoutStyle = dir === 'x' ? { width: step.value, height: '100%' } : { width: '100%', height: step.value };
39
+ const transformStyle = [];
40
+ if (scale) {
41
+ transformStyle.push({
42
+ scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
43
+ });
44
+ }
45
+ return Object.assign(outerLayoutStyle, {
46
+ transform: transformStyle
47
+ });
41
48
  });
42
- const mergeStyle = [innerStyle, layoutStyle, { width: '100%', height: '100%' }, scale ? itemAnimatedStyle : {}].concat(customStyle);
43
- return (<Animated.View {...innerProps} style={mergeStyle} data-itemId={props['item-id']}>
49
+ return (<Animated.View {...innerProps} style={[innerStyle, layoutStyle, itemAnimatedStyle, customStyle]} data-itemId={props['item-id']}>
44
50
  {wrapChildren(props, {
45
51
  hasVarDec,
46
52
  varContext: varContextRef.current,