@mpxjs/webpack-plugin 2.9.69-beta.0 → 2.9.69-beta.2

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 (50) hide show
  1. package/lib/index.js +17 -1
  2. package/lib/platform/style/wx/index.js +18 -18
  3. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  4. package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
  5. package/lib/resolver/AddEnvPlugin.js +1 -0
  6. package/lib/resolver/AddModePlugin.js +1 -0
  7. package/lib/runtime/components/react/context.ts +8 -0
  8. package/lib/runtime/components/react/dist/context.js +2 -0
  9. package/lib/runtime/components/react/dist/getInnerListeners.js +3 -4
  10. package/lib/runtime/components/react/dist/mpx-input.jsx +1 -1
  11. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
  12. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +1 -1
  13. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +54 -52
  14. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +1 -1
  15. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
  16. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +21 -6
  17. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +25 -8
  18. package/lib/runtime/components/react/dist/mpx-swiper.jsx +150 -148
  19. package/lib/runtime/components/react/dist/mpx-view.jsx +9 -40
  20. package/lib/runtime/components/react/dist/mpx-web-view.jsx +50 -12
  21. package/lib/runtime/components/react/dist/pickerFaces.js +1 -1
  22. package/lib/runtime/components/react/dist/useAnimationHooks.js +1 -1
  23. package/lib/runtime/components/react/dist/utils.jsx +63 -4
  24. package/lib/runtime/components/react/getInnerListeners.ts +3 -5
  25. package/lib/runtime/components/react/mpx-input.tsx +1 -1
  26. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  27. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
  28. package/lib/runtime/components/react/mpx-picker-view-column.tsx +177 -159
  29. package/lib/runtime/components/react/mpx-picker-view.tsx +35 -37
  30. package/lib/runtime/components/react/mpx-rich-text/index.tsx +12 -18
  31. package/lib/runtime/components/react/mpx-scroll-view.tsx +30 -13
  32. package/lib/runtime/components/react/mpx-swiper-item.tsx +38 -10
  33. package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
  34. package/lib/runtime/components/react/mpx-view.tsx +11 -51
  35. package/lib/runtime/components/react/mpx-web-view.tsx +57 -13
  36. package/lib/runtime/components/react/pickerFaces.ts +15 -7
  37. package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
  38. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  39. package/lib/runtime/components/react/{pickerOverlay.tsx → pickerViewOverlay.tsx} +5 -3
  40. package/lib/runtime/components/react/types/global.d.ts +3 -1
  41. package/lib/runtime/components/react/useAnimationHooks.ts +1 -1
  42. package/lib/runtime/components/react/utils.tsx +75 -5
  43. package/lib/style-compiler/index.js +3 -4
  44. package/lib/style-compiler/strip-conditional-loader.js +118 -0
  45. package/lib/template-compiler/compiler.js +9 -14
  46. package/lib/utils/pre-process-json.js +5 -9
  47. package/package.json +1 -1
  48. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
  49. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  50. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
@@ -32,15 +32,14 @@
32
32
  * ✔ bindscroll
33
33
  */
34
34
  import { ScrollView } from 'react-native-gesture-handler'
35
- import { View, RefreshControl, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle } from 'react-native'
36
- import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, createElement } from 'react'
35
+ import { View, RefreshControl, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent, ViewStyle, Platform } from 'react-native'
36
+ import { JSX, ReactNode, RefObject, useRef, useState, useEffect, forwardRef, useContext, createElement, useMemo } from 'react'
37
37
  import { useAnimatedRef } from 'react-native-reanimated'
38
38
  import { warn } from '@mpxjs/utils'
39
39
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
40
40
  import useNodesRef, { HandlerRef } from './useNodesRef'
41
41
  import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler } from './utils'
42
- import { IntersectionObserverContext } from './context'
43
-
42
+ import { IntersectionObserverContext, ScrollViewContext } from './context'
44
43
  interface ScrollViewProps {
45
44
  children?: ReactNode;
46
45
  enhanced?: boolean;
@@ -194,6 +193,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
194
193
  gestureRef: scrollViewRef
195
194
  })
196
195
 
196
+ const contextValue = useMemo(() => {
197
+ return {
198
+ gestureRef: scrollViewRef
199
+ }
200
+ }, [])
201
+
197
202
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
198
203
 
199
204
  if (scrollX && scrollY) {
@@ -313,6 +318,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
313
318
  })
314
319
  }
315
320
 
321
+ const observerTimers: {[key: string]: any} = {}
316
322
  function onScroll (e: NativeSyntheticEvent<NativeScrollEvent>) {
317
323
  const { bindscroll } = props
318
324
  const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
@@ -334,7 +340,15 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
334
340
  updateScrollOptions(e, { scrollLeft, scrollTop })
335
341
  if (enableTriggerIntersectionObserver && intersectionObservers) {
336
342
  for (const key in intersectionObservers) {
337
- intersectionObservers[key].throttleMeasure()
343
+ if (Platform.OS === 'android') {
344
+ intersectionObservers[key].throttleMeasure();
345
+ } else {
346
+ // TODO: 由于iOS在onScroll滚动的过程中view的计算measureInWindow计算的值不发生变化,所以暂时在ios上加一个延时计算
347
+ observerTimers[key] && clearTimeout(observerTimers[key])
348
+ observerTimers[key] = setTimeout(() => {
349
+ intersectionObservers[key].throttleMeasure();
350
+ }, 300)
351
+ }
338
352
  }
339
353
  }
340
354
  }
@@ -507,14 +521,17 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
507
521
  }, (refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : null)))
508
522
  : undefined
509
523
  }),
510
- wrapChildren(
511
- props,
512
- {
513
- hasVarDec,
514
- varContext: varContextRef.current,
515
- textStyle,
516
- textProps
517
- }
524
+ createElement(ScrollViewContext.Provider,
525
+ { value: contextValue },
526
+ wrapChildren(
527
+ props,
528
+ {
529
+ hasVarDec,
530
+ varContext: varContextRef.current,
531
+ textStyle,
532
+ textProps
533
+ }
534
+ )
518
535
  )
519
536
  )
520
537
  })
@@ -1,8 +1,10 @@
1
- import { View, LayoutChangeEvent } from 'react-native'
2
- import { ReactNode, forwardRef, useRef } from 'react'
1
+ import { View } from 'react-native'
2
+ import Animated, { useAnimatedStyle, interpolate, SharedValue } from 'react-native-reanimated'
3
+ import { ReactNode, forwardRef, useRef, useContext } from 'react'
3
4
  import useInnerProps from './getInnerListeners'
4
5
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
5
6
  import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
7
+ import { SwiperContext } from './context'
6
8
 
7
9
  interface SwiperItemProps {
8
10
  'item-id'?: string;
@@ -14,15 +16,29 @@ interface SwiperItemProps {
14
16
  'parent-height'?: number;
15
17
  children?: ReactNode;
16
18
  style?: Object;
19
+ customStyle: [];
20
+ itemIndex: number;
21
+ }
22
+
23
+ interface ContextType {
24
+ offset: SharedValue<number>;
25
+ step: SharedValue<number>;
26
+ scale: boolean;
17
27
  }
18
28
 
19
29
  const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
20
30
  const {
21
31
  'enable-var': enableVar,
22
32
  'external-var-context': externalVarContext,
23
- style
33
+ style,
34
+ customStyle,
35
+ itemIndex
24
36
  } = props
25
37
 
38
+ const contextValue = useContext(SwiperContext) as ContextType
39
+ const offset = contextValue.offset || 0
40
+ const step = contextValue.step || 0
41
+ const scale = contextValue.scale || false
26
42
  const { textProps } = splitProps(props)
27
43
  const nodeRef = useRef(null)
28
44
 
@@ -47,19 +63,31 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
47
63
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
48
64
 
49
65
  const innerProps = useInnerProps(props, {
50
- style: { ...innerStyle, ...layoutStyle },
51
66
  ref: nodeRef,
52
67
  ...layoutProps
53
68
  }, [
54
69
  'children',
55
- 'enable-offset'
70
+ 'enable-offset',
71
+ 'style'
56
72
  ], { layoutRef })
57
73
 
74
+ const itemAnimatedStyle = useAnimatedStyle(() => {
75
+ if (!step.value) return {}
76
+ const inputRange = [step.value, 0]
77
+ const outputRange = [0.7, 1]
78
+ return {
79
+ transform: [{
80
+ scale: interpolate(Math.abs(Math.abs(offset.value) - itemIndex * step.value), inputRange, outputRange)
81
+ }]
82
+ }
83
+ })
84
+ const mergeStyle = [innerStyle, layoutStyle, { width: '100%', height: '100%' }, scale ? itemAnimatedStyle : {}].concat(customStyle)
58
85
  return (
59
- <View
60
- data-itemId={props['item-id']}
61
- {...innerProps}>
62
- {
86
+ <Animated.View
87
+ {...innerProps}
88
+ style={mergeStyle}
89
+ data-itemId={props['item-id']}>
90
+ {
63
91
  wrapChildren(
64
92
  props,
65
93
  {
@@ -70,7 +98,7 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
70
98
  }
71
99
  )
72
100
  }
73
- </View>
101
+ </Animated.View>
74
102
  )
75
103
  })
76
104