@mpxjs/webpack-plugin 2.10.16 → 2.10.17-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.
- package/lib/config.js +60 -0
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/file-loader.js +4 -1
- package/lib/global.d.ts +245 -0
- package/lib/helpers.js +2 -0
- package/lib/index.js +80 -19
- package/lib/json-compiler/helper.js +72 -2
- package/lib/json-compiler/index.js +45 -59
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +14 -4
- package/lib/native-loader.js +6 -3
- package/lib/platform/json/wx/index.js +30 -29
- package/lib/platform/style/wx/index.js +51 -36
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +22 -6
- package/lib/platform/template/wx/component-config/camera.js +25 -3
- package/lib/platform/template/wx/component-config/canvas.js +8 -1
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/form.js +27 -2
- package/lib/platform/template/wx/component-config/image.js +5 -0
- package/lib/platform/template/wx/component-config/input.js +11 -1
- package/lib/platform/template/wx/component-config/label.js +10 -2
- package/lib/platform/template/wx/component-config/map.js +11 -0
- package/lib/platform/template/wx/component-config/movable-area.js +4 -1
- package/lib/platform/template/wx/component-config/movable-view.js +17 -2
- package/lib/platform/template/wx/component-config/navigator.js +26 -0
- package/lib/platform/template/wx/component-config/picker-view.js +12 -0
- package/lib/platform/template/wx/component-config/picker.js +3 -1
- package/lib/platform/template/wx/component-config/progress.js +11 -1
- package/lib/platform/template/wx/component-config/rich-text.js +5 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
- package/lib/platform/template/wx/component-config/slider.js +8 -0
- package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
- package/lib/platform/template/wx/component-config/swiper.js +10 -0
- package/lib/platform/template/wx/component-config/text.js +5 -0
- package/lib/platform/template/wx/component-config/textarea.js +20 -3
- package/lib/platform/template/wx/component-config/unsupported.js +10 -1
- package/lib/platform/template/wx/component-config/video.js +10 -0
- package/lib/platform/template/wx/index.js +21 -1
- package/lib/react/LoadAsyncChunkModule.js +1 -1
- package/lib/react/index.js +2 -0
- package/lib/react/processJSON.js +59 -72
- package/lib/react/processScript.js +1 -0
- package/lib/react/processStyles.js +24 -11
- package/lib/react/processTemplate.js +8 -6
- package/lib/react/script-helper.js +6 -17
- package/lib/react/style-helper.js +84 -13
- package/lib/resolver/AddModePlugin.js +23 -8
- package/lib/runtime/components/ali/mpx-recycle-view.mpx +518 -0
- package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
- package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
- package/lib/runtime/components/react/animationHooks/index.ts +75 -0
- package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
- package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
- package/lib/runtime/components/react/context.ts +19 -7
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
- package/lib/runtime/components/react/dist/context.d.ts +79 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +109 -59
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +52 -17
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +62 -49
- package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +65 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-recycle-view.d.ts +45 -0
- package/lib/runtime/components/react/dist/mpx-recycle-view.jsx +307 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +30 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +63 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +77 -44
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -3
- package/lib/runtime/components/react/dist/parser.d.ts +39 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
- package/lib/runtime/components/react/dist/utils.d.ts +124 -0
- package/lib/runtime/components/react/dist/utils.jsx +42 -17
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-image.tsx +132 -79
- package/lib/runtime/components/react/mpx-input.tsx +63 -24
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +70 -48
- package/lib/runtime/components/react/mpx-nav.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
- package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-recycle-view.tsx +437 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -17
- package/lib/runtime/components/react/mpx-sticky-section.tsx +1 -1
- package/lib/runtime/components/react/mpx-swiper.tsx +92 -42
- package/lib/runtime/components/react/mpx-text.tsx +38 -5
- package/lib/runtime/components/react/mpx-view.tsx +28 -13
- package/lib/runtime/components/react/mpx-web-view.tsx +14 -5
- package/lib/runtime/components/react/tsconfig.json +26 -0
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +43 -21
- package/lib/runtime/components/web/mpx-recycle-view.vue +508 -0
- package/lib/runtime/components/wx/mpx-list-header-default.mpx +21 -0
- package/lib/runtime/components/wx/mpx-recycle-item-default.mpx +21 -0
- package/lib/runtime/components/wx/mpx-recycle-view.mpx +193 -0
- package/lib/runtime/components/wx/mpx-section-header-default.mpx +21 -0
- package/lib/runtime/optionProcessor.js +5 -0
- package/lib/runtime/optionProcessorReact.js +7 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/script-setup-compiler/index.js +2 -2
- package/lib/style-compiler/index.js +3 -2
- package/lib/style-compiler/load-postcss-config.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +10 -2
- package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
- package/lib/style-compiler/strip-conditional-loader.js +124 -18
- package/lib/template-compiler/compiler.js +272 -72
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +6 -4
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +19 -1
- package/lib/utils/dom-tag-config.js +6 -6
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -0
- package/lib/utils/merge-visitors.js +55 -0
- package/lib/utils/pre-process-json.js +5 -0
- package/lib/utils/process-extend-components.js +43 -0
- package/lib/utils/string.js +25 -1
- package/lib/web/index.js +2 -0
- package/lib/web/processJSON.js +64 -18
- package/lib/web/processScript.js +1 -1
- package/lib/web/processTemplate.js +6 -4
- package/lib/web/script-helper.js +19 -9
- package/lib/wxs/pre-loader.js +9 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +11 -7
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
- package/lib/utils/chain-assign.js +0 -47
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import React, { forwardRef, useRef, useState, useEffect, useMemo, createElement, useImperativeHandle, useCallback } from 'react'
|
|
2
|
+
import { SectionList, RefreshControl, NativeSyntheticEvent, NativeScrollEvent } from 'react-native'
|
|
3
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
4
|
+
import { extendObject, useLayout, useTransformStyle } from './utils'
|
|
5
|
+
interface ListItem {
|
|
6
|
+
isSectionHeader?: boolean;
|
|
7
|
+
_originalItemIndex?: number;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Section {
|
|
12
|
+
headerData: ListItem | null;
|
|
13
|
+
data: ListItem[];
|
|
14
|
+
hasSectionHeader?: boolean;
|
|
15
|
+
_originalItemIndex?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ItemHeightType {
|
|
19
|
+
value?: number;
|
|
20
|
+
getter?: (item: any, index: number) => number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface RecycleViewProps {
|
|
24
|
+
enhanced?: boolean;
|
|
25
|
+
bounces?: boolean;
|
|
26
|
+
scrollEventThrottle?: number;
|
|
27
|
+
height?: number | string;
|
|
28
|
+
width?: number | string;
|
|
29
|
+
listData?: ListItem[];
|
|
30
|
+
generichash?: string;
|
|
31
|
+
style?: Record<string, any>;
|
|
32
|
+
itemHeight?: ItemHeightType;
|
|
33
|
+
sectionHeaderHeight?: ItemHeightType;
|
|
34
|
+
listHeaderData?: any;
|
|
35
|
+
listHeaderHeight?: ItemHeightType;
|
|
36
|
+
useListHeader?: boolean;
|
|
37
|
+
'genericrecycle-item'?: string;
|
|
38
|
+
'genericsection-header'?: string;
|
|
39
|
+
'genericlist-header'?: string;
|
|
40
|
+
'enable-var'?: boolean;
|
|
41
|
+
'external-var-context'?: any;
|
|
42
|
+
'parent-font-size'?: number;
|
|
43
|
+
'parent-width'?: number;
|
|
44
|
+
'parent-height'?: number;
|
|
45
|
+
'enable-sticky'?: boolean;
|
|
46
|
+
'enable-back-to-top'?: boolean;
|
|
47
|
+
'end-reached-threshold'?: number;
|
|
48
|
+
'refresher-enabled'?: boolean;
|
|
49
|
+
'show-scrollbar'?: boolean;
|
|
50
|
+
'refresher-triggered'?: boolean;
|
|
51
|
+
bindrefresherrefresh?: (event: any) => void;
|
|
52
|
+
bindscrolltolower?: (event: any) => void;
|
|
53
|
+
bindscroll?: (event: any) => void;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface ScrollPositionParams {
|
|
58
|
+
index: number;
|
|
59
|
+
animated?: boolean;
|
|
60
|
+
viewOffset?: number;
|
|
61
|
+
viewPosition?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const getGeneric = (generichash: string, generickey: string) => {
|
|
65
|
+
if (!generichash || !generickey) return null
|
|
66
|
+
const GenericComponent = global.__mpxGenericsMap?.[generichash]?.[generickey]?.()
|
|
67
|
+
if (!GenericComponent) return null
|
|
68
|
+
|
|
69
|
+
return forwardRef((props: any, ref: any) => {
|
|
70
|
+
return createElement(GenericComponent, extendObject({}, {
|
|
71
|
+
ref: ref
|
|
72
|
+
}, props))
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const getListHeaderComponent = (generichash: string, generickey: string, data: any) => {
|
|
77
|
+
if (!generichash || !generickey) return undefined
|
|
78
|
+
const ListHeaderComponent = getGeneric(generichash, generickey)
|
|
79
|
+
return ListHeaderComponent ? createElement(ListHeaderComponent, { listHeaderData: data }) : null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const getSectionHeaderRenderer = (generichash: string, generickey: string) => {
|
|
83
|
+
if (!generichash || !generickey) return undefined
|
|
84
|
+
return (sectionData: { section: Section }) => {
|
|
85
|
+
if (!sectionData.section.hasSectionHeader) return null
|
|
86
|
+
const SectionHeaderComponent = getGeneric(generichash, generickey)
|
|
87
|
+
return SectionHeaderComponent ? createElement(SectionHeaderComponent, { itemData: sectionData.section.headerData }) : null
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const getItemRenderer = (generichash: string, generickey: string) => {
|
|
92
|
+
if (!generichash || !generickey) return undefined
|
|
93
|
+
return ({ item }: { item: any }) => {
|
|
94
|
+
const ItemComponent = getGeneric(generichash, generickey)
|
|
95
|
+
return ItemComponent ? createElement(ItemComponent, { itemData: item }) : null
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const RecycleView = forwardRef<any, RecycleViewProps>((props = {}, ref) => {
|
|
100
|
+
const {
|
|
101
|
+
enhanced = false,
|
|
102
|
+
bounces = true,
|
|
103
|
+
scrollEventThrottle = 0,
|
|
104
|
+
height,
|
|
105
|
+
width,
|
|
106
|
+
listData,
|
|
107
|
+
generichash,
|
|
108
|
+
style = {},
|
|
109
|
+
itemHeight = {},
|
|
110
|
+
sectionHeaderHeight = {},
|
|
111
|
+
listHeaderHeight = {},
|
|
112
|
+
listHeaderData = null,
|
|
113
|
+
useListHeader = false,
|
|
114
|
+
'genericrecycle-item': genericrecycleItem,
|
|
115
|
+
'genericsection-header': genericsectionHeader,
|
|
116
|
+
'genericlist-header': genericListHeader,
|
|
117
|
+
'enable-var': enableVar,
|
|
118
|
+
'external-var-context': externalVarContext,
|
|
119
|
+
'parent-font-size': parentFontSize,
|
|
120
|
+
'parent-width': parentWidth,
|
|
121
|
+
'parent-height': parentHeight,
|
|
122
|
+
'enable-sticky': enableSticky = false,
|
|
123
|
+
'enable-back-to-top': enableBackToTop = false,
|
|
124
|
+
'end-reached-threshold': onEndReachedThreshold = 0.1,
|
|
125
|
+
'refresher-enabled': refresherEnabled,
|
|
126
|
+
'show-scrollbar': showScrollbar = true,
|
|
127
|
+
'refresher-triggered': refresherTriggered
|
|
128
|
+
} = props
|
|
129
|
+
|
|
130
|
+
const [refreshing, setRefreshing] = useState(!!refresherTriggered)
|
|
131
|
+
|
|
132
|
+
const scrollViewRef = useRef<any>(null)
|
|
133
|
+
|
|
134
|
+
const indexMap = useRef<{ [key: string]: string | number }>({})
|
|
135
|
+
|
|
136
|
+
const reverseIndexMap = useRef<{ [key: string]: number }>({})
|
|
137
|
+
|
|
138
|
+
// 缓存 getGeneric 的结果,避免每次都创建新的组件引用
|
|
139
|
+
const genericComponentsCache = useRef<{ [key: string]: any }>({})
|
|
140
|
+
const getCachedGeneric = useCallback((generichash: string, generickey: string) => {
|
|
141
|
+
if (!generichash || !generickey) return null
|
|
142
|
+
|
|
143
|
+
const cacheKey = `${generichash}_${generickey}`
|
|
144
|
+
if (!genericComponentsCache.current[cacheKey]) {
|
|
145
|
+
genericComponentsCache.current[cacheKey] = getGeneric(generichash, generickey)
|
|
146
|
+
}
|
|
147
|
+
return genericComponentsCache.current[cacheKey]
|
|
148
|
+
}, [])
|
|
149
|
+
|
|
150
|
+
// 使用 ref 存储最新的 props,避免渲染函数引用变化导致组件重新挂载
|
|
151
|
+
const propsRef = useRef({ generichash, genericrecycleItem, genericsectionHeader, genericListHeader, listHeaderData, useListHeader })
|
|
152
|
+
|
|
153
|
+
propsRef.current = { generichash, genericrecycleItem, genericsectionHeader, genericListHeader, listHeaderData, useListHeader }
|
|
154
|
+
|
|
155
|
+
// 创建稳定的渲染函数引用,使用 getCachedGeneric 确保组件引用稳定
|
|
156
|
+
const stableItemRenderer = useCallback(({ item }: { item: any }) => {
|
|
157
|
+
const { generichash: hash, genericrecycleItem: key } = propsRef.current
|
|
158
|
+
const ItemComponent = getCachedGeneric(hash, key)
|
|
159
|
+
return ItemComponent ? createElement(ItemComponent, { itemData: item }) : null
|
|
160
|
+
}, [getCachedGeneric])
|
|
161
|
+
|
|
162
|
+
const stableSectionHeaderRenderer = useCallback((sectionData: { section: Section }) => {
|
|
163
|
+
if (!sectionData.section.hasSectionHeader) return null
|
|
164
|
+
const { generichash: hash, genericsectionHeader: key } = propsRef.current
|
|
165
|
+
const SectionHeaderComponent = getCachedGeneric(hash, key)
|
|
166
|
+
return SectionHeaderComponent ? createElement(SectionHeaderComponent, { itemData: sectionData.section.headerData }) : null
|
|
167
|
+
}, [getCachedGeneric])
|
|
168
|
+
|
|
169
|
+
// 创建稳定的 ListHeader 渲染函数,与 section-header 和 item 的处理方式一致
|
|
170
|
+
const getStableListHeader = useCallback(() => {
|
|
171
|
+
const { generichash: hash, genericListHeader: key, listHeaderData: data, useListHeader: use } = propsRef.current
|
|
172
|
+
if (!use || !hash || !key) return null
|
|
173
|
+
const ListHeaderComponent = getCachedGeneric(hash, key)
|
|
174
|
+
return ListHeaderComponent ? createElement(ListHeaderComponent, { listHeaderData: data }) : null
|
|
175
|
+
}, [getCachedGeneric])
|
|
176
|
+
|
|
177
|
+
const {
|
|
178
|
+
hasSelfPercent,
|
|
179
|
+
setWidth,
|
|
180
|
+
setHeight
|
|
181
|
+
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
182
|
+
|
|
183
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef })
|
|
184
|
+
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
if (refreshing !== refresherTriggered) {
|
|
187
|
+
setRefreshing(!!refresherTriggered)
|
|
188
|
+
}
|
|
189
|
+
}, [refresherTriggered])
|
|
190
|
+
|
|
191
|
+
const onRefresh = () => {
|
|
192
|
+
const { bindrefresherrefresh } = props
|
|
193
|
+
bindrefresherrefresh &&
|
|
194
|
+
bindrefresherrefresh(
|
|
195
|
+
getCustomEvent('refresherrefresh', {}, { layoutRef }, props)
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const onEndReached = () => {
|
|
200
|
+
const { bindscrolltolower } = props
|
|
201
|
+
bindscrolltolower &&
|
|
202
|
+
bindscrolltolower(
|
|
203
|
+
getCustomEvent('scrolltolower', {}, { layoutRef }, props)
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
208
|
+
const { bindscroll } = props
|
|
209
|
+
bindscroll &&
|
|
210
|
+
bindscroll(
|
|
211
|
+
getCustomEvent('scroll', event.nativeEvent, { layoutRef }, props)
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 通过sectionIndex和rowIndex获取原始索引
|
|
216
|
+
const getOriginalIndex = (sectionIndex: number, rowIndex: number | 'header'): number => {
|
|
217
|
+
const key = `${sectionIndex}_${rowIndex}`
|
|
218
|
+
return reverseIndexMap.current[key] ?? -1 // 如果找不到,返回-1
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const scrollToIndex = ({ index, animated, viewOffset = 0, viewPosition = 0 }: ScrollPositionParams) => {
|
|
222
|
+
if (scrollViewRef.current) {
|
|
223
|
+
// 通过索引映射表快速定位位置
|
|
224
|
+
const position = indexMap.current[index]
|
|
225
|
+
const [sectionIndex, itemIndex] = (position as string).split('_')
|
|
226
|
+
scrollViewRef.current.scrollToLocation?.({
|
|
227
|
+
itemIndex: itemIndex === 'header' ? 0 : Number(itemIndex) + 1,
|
|
228
|
+
sectionIndex: Number(sectionIndex) || 0,
|
|
229
|
+
animated,
|
|
230
|
+
viewOffset,
|
|
231
|
+
viewPosition
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const getItemHeight = ({ sectionIndex, rowIndex }: { sectionIndex: number, rowIndex: number }) => {
|
|
237
|
+
if (!itemHeight) {
|
|
238
|
+
return 0
|
|
239
|
+
}
|
|
240
|
+
if ((itemHeight as ItemHeightType).getter) {
|
|
241
|
+
const item = convertedListData[sectionIndex].data[rowIndex]
|
|
242
|
+
// 使用getOriginalIndex获取原始索引
|
|
243
|
+
const originalIndex = getOriginalIndex(sectionIndex, rowIndex)
|
|
244
|
+
return (itemHeight as ItemHeightType).getter?.(item, originalIndex) || 0
|
|
245
|
+
} else {
|
|
246
|
+
return (itemHeight as ItemHeightType).value || 0
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const getSectionHeaderHeight = ({ sectionIndex }: { sectionIndex: number }) => {
|
|
251
|
+
const item = convertedListData[sectionIndex]
|
|
252
|
+
const { hasSectionHeader } = item
|
|
253
|
+
// 使用getOriginalIndex获取原始索引
|
|
254
|
+
const originalIndex = getOriginalIndex(sectionIndex, 'header')
|
|
255
|
+
if (!hasSectionHeader) return 0
|
|
256
|
+
if ((sectionHeaderHeight as ItemHeightType).getter) {
|
|
257
|
+
return (sectionHeaderHeight as ItemHeightType).getter?.(item, originalIndex) || 0
|
|
258
|
+
} else {
|
|
259
|
+
return (sectionHeaderHeight as ItemHeightType).value || 0
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const convertedListData = useMemo(() => {
|
|
264
|
+
const sections: Section[] = []
|
|
265
|
+
let currentSection: Section | null = null
|
|
266
|
+
// 清空之前的索引映射
|
|
267
|
+
indexMap.current = {}
|
|
268
|
+
// 清空反向索引映射
|
|
269
|
+
reverseIndexMap.current = {}
|
|
270
|
+
listData.forEach((item: ListItem, index: number) => {
|
|
271
|
+
if (item.isSectionHeader) {
|
|
272
|
+
// 如果已经存在一个 section,先把它添加到 sections 中
|
|
273
|
+
if (currentSection) {
|
|
274
|
+
sections.push(currentSection)
|
|
275
|
+
}
|
|
276
|
+
// 创建新的 section
|
|
277
|
+
currentSection = {
|
|
278
|
+
headerData: item,
|
|
279
|
+
data: [],
|
|
280
|
+
hasSectionHeader: true,
|
|
281
|
+
_originalItemIndex: index
|
|
282
|
+
}
|
|
283
|
+
// 为 section header 添加索引映射
|
|
284
|
+
const sectionIndex = sections.length
|
|
285
|
+
indexMap.current[index] = `${sectionIndex}_header`
|
|
286
|
+
// 添加反向索引映射
|
|
287
|
+
reverseIndexMap.current[`${sectionIndex}_header`] = index
|
|
288
|
+
} else {
|
|
289
|
+
// 如果没有当前 section,创建一个默认的
|
|
290
|
+
if (!currentSection) {
|
|
291
|
+
// 创建默认section (无header的section)
|
|
292
|
+
currentSection = {
|
|
293
|
+
headerData: null,
|
|
294
|
+
data: [],
|
|
295
|
+
hasSectionHeader: false,
|
|
296
|
+
_originalItemIndex: -1
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// 将 item 添加到当前 section 的 data 中
|
|
300
|
+
const itemIndex = currentSection.data.length
|
|
301
|
+
currentSection.data.push(extendObject({}, item, {
|
|
302
|
+
_originalItemIndex: index
|
|
303
|
+
}))
|
|
304
|
+
let sectionIndex
|
|
305
|
+
// 为 item 添加索引映射 - 存储格式为: "sectionIndex_itemIndex"
|
|
306
|
+
if (!currentSection.hasSectionHeader && sections.length === 0) {
|
|
307
|
+
// 在默认section中(第一个且无header)
|
|
308
|
+
sectionIndex = 0
|
|
309
|
+
indexMap.current[index] = `${sectionIndex}_${itemIndex}`
|
|
310
|
+
} else {
|
|
311
|
+
// 在普通section中
|
|
312
|
+
sectionIndex = sections.length
|
|
313
|
+
indexMap.current[index] = `${sectionIndex}_${itemIndex}`
|
|
314
|
+
}
|
|
315
|
+
// 添加反向索引映射
|
|
316
|
+
reverseIndexMap.current[`${sectionIndex}_${itemIndex}`] = index
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
// 添加最后一个 section
|
|
320
|
+
if (currentSection) {
|
|
321
|
+
sections.push(currentSection)
|
|
322
|
+
}
|
|
323
|
+
return sections
|
|
324
|
+
}, [listData])
|
|
325
|
+
|
|
326
|
+
const { getItemLayout } = useMemo(() => {
|
|
327
|
+
const layouts: Array<{ length: number, offset: number, index: number }> = []
|
|
328
|
+
let offset = 0
|
|
329
|
+
|
|
330
|
+
if (useListHeader) {
|
|
331
|
+
// 计算列表头部的高度
|
|
332
|
+
offset += listHeaderHeight.getter?.() || listHeaderHeight.value || 0
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 遍历所有 sections
|
|
336
|
+
convertedListData.forEach((section: Section, sectionIndex: number) => {
|
|
337
|
+
// 添加 section header 的位置信息
|
|
338
|
+
const headerHeight = getSectionHeaderHeight({ sectionIndex })
|
|
339
|
+
layouts.push({
|
|
340
|
+
length: headerHeight,
|
|
341
|
+
offset,
|
|
342
|
+
index: layouts.length
|
|
343
|
+
})
|
|
344
|
+
offset += headerHeight
|
|
345
|
+
|
|
346
|
+
// 添加该 section 中所有 items 的位置信息
|
|
347
|
+
section.data.forEach((item: ListItem, itemIndex: number) => {
|
|
348
|
+
const contenteight = getItemHeight({ sectionIndex, rowIndex: itemIndex })
|
|
349
|
+
layouts.push({
|
|
350
|
+
length: contenteight,
|
|
351
|
+
offset,
|
|
352
|
+
index: layouts.length
|
|
353
|
+
})
|
|
354
|
+
offset += contenteight
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
// 添加该 section 尾部位置信息
|
|
358
|
+
// 因为即使 sectionList 没传 renderSectionFooter,getItemLayout 中的 index 的计算也会包含尾部节点
|
|
359
|
+
layouts.push({
|
|
360
|
+
length: 0,
|
|
361
|
+
offset,
|
|
362
|
+
index: layouts.length
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
return {
|
|
366
|
+
itemLayouts: layouts,
|
|
367
|
+
getItemLayout: (data: any, index: number) => layouts[index]
|
|
368
|
+
}
|
|
369
|
+
}, [convertedListData, useListHeader, itemHeight.value, itemHeight.getter, sectionHeaderHeight.value, sectionHeaderHeight.getter, listHeaderHeight.value, listHeaderHeight.getter])
|
|
370
|
+
|
|
371
|
+
const scrollAdditionalProps = extendObject(
|
|
372
|
+
{
|
|
373
|
+
alwaysBounceVertical: false,
|
|
374
|
+
alwaysBounceHorizontal: false,
|
|
375
|
+
scrollEventThrottle: scrollEventThrottle,
|
|
376
|
+
scrollsToTop: enableBackToTop,
|
|
377
|
+
showsHorizontalScrollIndicator: showScrollbar,
|
|
378
|
+
onEndReachedThreshold,
|
|
379
|
+
ref: scrollViewRef,
|
|
380
|
+
bounces: false,
|
|
381
|
+
stickySectionHeadersEnabled: enableSticky,
|
|
382
|
+
onScroll: onScroll,
|
|
383
|
+
onEndReached: onEndReached
|
|
384
|
+
},
|
|
385
|
+
layoutProps
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
if (enhanced) {
|
|
389
|
+
Object.assign(scrollAdditionalProps, {
|
|
390
|
+
bounces
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
if (refresherEnabled) {
|
|
394
|
+
Object.assign(scrollAdditionalProps, {
|
|
395
|
+
refreshing: refreshing
|
|
396
|
+
})
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
useImperativeHandle(ref, () => {
|
|
400
|
+
return {
|
|
401
|
+
...props,
|
|
402
|
+
scrollToIndex
|
|
403
|
+
}
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
const innerProps = useInnerProps(extendObject({}, props, scrollAdditionalProps), [
|
|
407
|
+
'id',
|
|
408
|
+
'show-scrollbar',
|
|
409
|
+
'lower-threshold',
|
|
410
|
+
'refresher-triggered',
|
|
411
|
+
'refresher-enabled',
|
|
412
|
+
'bindrefresherrefresh'
|
|
413
|
+
], { layoutRef })
|
|
414
|
+
|
|
415
|
+
return createElement(
|
|
416
|
+
SectionList,
|
|
417
|
+
extendObject(
|
|
418
|
+
{
|
|
419
|
+
style: [{ height, width }, style, layoutStyle],
|
|
420
|
+
sections: convertedListData,
|
|
421
|
+
renderItem: stableItemRenderer,
|
|
422
|
+
getItemLayout: getItemLayout,
|
|
423
|
+
ListHeaderComponent: getStableListHeader(),
|
|
424
|
+
renderSectionHeader: stableSectionHeaderRenderer,
|
|
425
|
+
refreshControl: refresherEnabled
|
|
426
|
+
? React.createElement(RefreshControl, {
|
|
427
|
+
onRefresh: onRefresh,
|
|
428
|
+
refreshing: refreshing
|
|
429
|
+
})
|
|
430
|
+
: undefined
|
|
431
|
+
},
|
|
432
|
+
innerProps
|
|
433
|
+
)
|
|
434
|
+
)
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
export default RecycleView
|
|
@@ -159,9 +159,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
159
159
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
|
|
160
160
|
const waitForHandlers = flatGesture(waitFor)
|
|
161
161
|
|
|
162
|
-
const snapScrollTop = useRef(0)
|
|
163
|
-
const snapScrollLeft = useRef(0)
|
|
164
|
-
|
|
165
162
|
const [refreshing, setRefreshing] = useState(false)
|
|
166
163
|
|
|
167
164
|
const [enableScroll, setEnableScroll] = useState(true)
|
|
@@ -262,22 +259,19 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
262
259
|
|
|
263
260
|
// layout 完成前先隐藏,避免安卓闪烁问题
|
|
264
261
|
const refresherLayoutStyle = useMemo(() => { return !hasRefresherLayoutRef.current ? HIDDEN_STYLE : {} }, [hasRefresherLayoutRef.current])
|
|
262
|
+
|
|
265
263
|
const lastOffset = useRef(0)
|
|
266
264
|
|
|
267
265
|
if (scrollX && scrollY) {
|
|
268
266
|
warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion')
|
|
269
267
|
}
|
|
270
268
|
useEffect(() => {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return () => {
|
|
279
|
-
initialTimeout.current && clearTimeout(initialTimeout.current)
|
|
280
|
-
}
|
|
269
|
+
initialTimeout.current = setTimeout(() => {
|
|
270
|
+
scrollToOffset(scrollLeft, scrollTop)
|
|
271
|
+
}, 0)
|
|
272
|
+
|
|
273
|
+
return () => {
|
|
274
|
+
initialTimeout.current && clearTimeout(initialTimeout.current)
|
|
281
275
|
}
|
|
282
276
|
}, [scrollTop, scrollLeft])
|
|
283
277
|
|
|
@@ -481,10 +475,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
481
475
|
function scrollToOffset (x = 0, y = 0, animated = scrollWithAnimation) {
|
|
482
476
|
if (scrollViewRef.current) {
|
|
483
477
|
scrollViewRef.current.scrollTo({ x, y, animated })
|
|
484
|
-
scrollOptions.current.scrollLeft = x
|
|
485
|
-
scrollOptions.current.scrollTop = y
|
|
486
|
-
snapScrollLeft.current = x
|
|
487
|
-
snapScrollTop.current = y
|
|
488
478
|
}
|
|
489
479
|
}
|
|
490
480
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
1
|
import { useRef, forwardRef, createElement, ReactNode, useCallback, useMemo } from 'react'
|
|
3
2
|
import { View, ViewStyle } from 'react-native'
|
|
4
3
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
5
4
|
import { splitProps, splitStyle, useTransformStyle, wrapChildren, useLayout, extendObject } from './utils'
|
|
6
5
|
import { StickyContext } from './context'
|
|
6
|
+
|
|
7
7
|
import useInnerProps from './getInnerListeners'
|
|
8
8
|
|
|
9
9
|
interface StickySectionProps {
|