@mpxjs/webpack-plugin 2.10.4-beta.12 → 2.10.4-beta.13

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.
@@ -4,7 +4,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS
4
4
  import React, { forwardRef, useRef, useEffect, useMemo } from 'react';
5
5
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
6
6
  import useNodesRef from './useNodesRef'; // 引入辅助函数
7
- import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject } from './utils';
7
+ import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
8
8
  import { SwiperContext } from './context';
9
9
  /**
10
10
  * 默认的Style类型
@@ -70,11 +70,13 @@ const easeMap = {
70
70
  easeInOutCubic: Easing.inOut(Easing.cubic)
71
71
  };
72
72
  const SwiperWrapper = forwardRef((props, ref) => {
73
- const { 'indicator-dots': showsPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, style = {}, autoplay = false, circular = false } = props;
73
+ const { 'indicator-dots': showsPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false } = props;
74
74
  const easeingFunc = props['easing-function'] || 'default';
75
75
  const easeDuration = props.duration || 500;
76
76
  const horizontal = props.vertical !== undefined ? !props.vertical : true;
77
77
  const nodeRef = useRef(null);
78
+ // 手势协同gesture 1.0
79
+ const swiperGestureRef = useRef();
78
80
  useNodesRef(props, ref, nodeRef, {});
79
81
  // 计算transfrom之类的
80
82
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, {
@@ -121,6 +123,23 @@ const SwiperWrapper = forwardRef((props, ref) => {
121
123
  const moveTime = useSharedValue(0);
122
124
  const timerId = useRef(0);
123
125
  const intervalTimer = props.interval || 500;
126
+ const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
127
+ const waitForHandlers = flatGesture(waitFor);
128
+ // 判断gesture手势是否需要协同处理、等待手势失败响应
129
+ const gestureSwitch = useRef(false);
130
+ // 初始化上一次的手势
131
+ const prevSimultaneousHandlersRef = useRef(originSimultaneousHandlers || []);
132
+ const prevWaitForHandlersRef = useRef(waitFor || []);
133
+ const hasSimultaneousHandlersChanged = prevSimultaneousHandlersRef.current.length !== (originSimultaneousHandlers?.length || 0) ||
134
+ (originSimultaneousHandlers || []).some((handler, index) => handler !== prevSimultaneousHandlersRef.current[index]);
135
+ const hasWaitForHandlersChanged = prevWaitForHandlersRef.current.length !== (waitFor?.length || 0) ||
136
+ (waitFor || []).some((handler, index) => handler !== prevWaitForHandlersRef.current[index]);
137
+ if (hasSimultaneousHandlersChanged || hasWaitForHandlersChanged) {
138
+ gestureSwitch.current = !gestureSwitch.current;
139
+ }
140
+ // 存储上一次的手势
141
+ prevSimultaneousHandlersRef.current = originSimultaneousHandlers || [];
142
+ prevWaitForHandlersRef.current = waitFor || [];
124
143
  const {
125
144
  // 存储layout布局信息
126
145
  layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout: onWrapperLayout });
@@ -625,11 +644,25 @@ const SwiperWrapper = forwardRef((props, ref) => {
625
644
  else {
626
645
  handleEnd(eventData);
627
646
  }
628
- });
647
+ }).withRef(swiperGestureRef);
648
+ // swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
649
+ if (dir === 'x') {
650
+ gesturePan.activeOffsetX([-1, 1]).failOffsetY([-5, 5]);
651
+ }
652
+ else {
653
+ gesturePan.activeOffsetY([-1, 1]).failOffsetX([-5, 5]);
654
+ }
655
+ // 手势协同2.0
656
+ if (simultaneousHandlers && simultaneousHandlers.length) {
657
+ gesturePan.simultaneousWithExternalGesture(...simultaneousHandlers);
658
+ }
659
+ if (waitForHandlers && waitForHandlers.length) {
660
+ gesturePan.requireExternalGestureToFail(...waitForHandlers);
661
+ }
629
662
  return {
630
663
  gestureHandler: gesturePan
631
664
  };
632
- }, []);
665
+ }, [gestureSwitch.current]);
633
666
  const animatedStyles = useAnimatedStyle(() => {
634
667
  if (dir === 'x') {
635
668
  return { transform: [{ translateX: offset.value }], opacity: step.value > 0 ? 1 : 0 };
@@ -1,11 +1,11 @@
1
1
  import { View, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
2
- import { GestureDetector, Gesture } from 'react-native-gesture-handler'
2
+ import { GestureDetector, Gesture, PanGesture } from 'react-native-gesture-handler'
3
3
  import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS, useAnimatedReaction, cancelAnimation } from 'react-native-reanimated'
4
4
 
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, extendObject } from './utils'
8
+ import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, GestureHandler, flatGesture } from './utils'
9
9
  import { SwiperContext } from './context'
10
10
  /**
11
11
  * ✔ indicator-dots
@@ -55,6 +55,8 @@ interface SwiperProps {
55
55
  'parent-width'?: number
56
56
  'parent-height'?: number
57
57
  'external-var-context'?: Record<string, any>
58
+ 'wait-for'?: Array<GestureHandler>
59
+ 'simultaneous-handlers'?: Array<GestureHandler>
58
60
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
59
61
  }
60
62
 
@@ -134,6 +136,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
134
136
  'parent-width': parentWidth,
135
137
  'parent-height': parentHeight,
136
138
  'external-var-context': externalVarContext,
139
+ 'simultaneous-handlers': originSimultaneousHandlers = [],
140
+ 'wait-for': waitFor = [],
137
141
  style = {},
138
142
  autoplay = false,
139
143
  circular = false
@@ -142,6 +146,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
142
146
  const easeDuration = props.duration || 500
143
147
  const horizontal = props.vertical !== undefined ? !props.vertical : true
144
148
  const nodeRef = useRef<View>(null)
149
+ // 手势协同gesture 1.0
150
+ const swiperGestureRef = useRef<PanGesture>()
145
151
  useNodesRef<View, SwiperProps>(props, ref, nodeRef, {})
146
152
  // 计算transfrom之类的
147
153
  const {
@@ -195,6 +201,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
195
201
  const moveTime = useSharedValue(0)
196
202
  const timerId = useRef(0 as number | ReturnType<typeof setTimeout>)
197
203
  const intervalTimer = props.interval || 500
204
+ const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
205
+ const waitForHandlers = flatGesture(waitFor)
206
+ // 判断gesture手势是否需要协同处理、等待手势失败响应
207
+ const gestureSwitch = useRef(false)
208
+ // 初始化上一次的手势
209
+ const prevSimultaneousHandlersRef = useRef<Array<GestureHandler>>(originSimultaneousHandlers || [])
210
+ const prevWaitForHandlersRef = useRef<Array<GestureHandler>>(waitFor || [])
211
+ const hasSimultaneousHandlersChanged = prevSimultaneousHandlersRef.current.length !== (originSimultaneousHandlers?.length || 0) ||
212
+ (originSimultaneousHandlers || []).some((handler, index) => handler !== prevSimultaneousHandlersRef.current[index])
213
+
214
+ const hasWaitForHandlersChanged = prevWaitForHandlersRef.current.length !== (waitFor?.length || 0) ||
215
+ (waitFor || []).some((handler, index) => handler !== prevWaitForHandlersRef.current[index])
216
+
217
+ if (hasSimultaneousHandlersChanged || hasWaitForHandlersChanged) {
218
+ gestureSwitch.current = !gestureSwitch.current
219
+ }
220
+ // 存储上一次的手势
221
+ prevSimultaneousHandlersRef.current = originSimultaneousHandlers || []
222
+ prevWaitForHandlersRef.current = waitFor || []
198
223
  const {
199
224
  // 存储layout布局信息
200
225
  layoutRef,
@@ -701,11 +726,25 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
701
726
  } else {
702
727
  handleEnd(eventData)
703
728
  }
704
- })
729
+ }).withRef(swiperGestureRef)
730
+ // swiper横向,当y轴滑动5像素手势失效;swiper纵向只响应swiper的滑动事件
731
+ if (dir === 'x') {
732
+ gesturePan.activeOffsetX([-1, 1]).failOffsetY([-5, 5])
733
+ } else {
734
+ gesturePan.activeOffsetY([-1, 1]).failOffsetX([-5, 5])
735
+ }
736
+ // 手势协同2.0
737
+ if (simultaneousHandlers && simultaneousHandlers.length) {
738
+ gesturePan.simultaneousWithExternalGesture(...simultaneousHandlers)
739
+ }
740
+
741
+ if (waitForHandlers && waitForHandlers.length) {
742
+ gesturePan.requireExternalGestureToFail(...waitForHandlers)
743
+ }
705
744
  return {
706
745
  gestureHandler: gesturePan
707
746
  }
708
- }, [])
747
+ }, [gestureSwitch.current])
709
748
 
710
749
  const animatedStyles = useAnimatedStyle(() => {
711
750
  if (dir === 'x') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.4-beta.12",
3
+ "version": "2.10.4-beta.13",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"