@mpxjs/webpack-plugin 2.10.17 → 2.10.18-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.
- package/lib/config.js +60 -0
- package/lib/file-loader.js +4 -1
- package/lib/global.d.ts +231 -0
- package/lib/index.js +70 -73
- package/lib/init.js +3 -0
- package/lib/json-compiler/index.js +13 -4
- package/lib/loader.js +4 -0
- package/lib/platform/json/wx/index.js +6 -0
- package/lib/platform/style/wx/index.js +102 -72
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +10 -3
- 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/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- 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 +10 -0
- 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 +19 -2
- 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/processStyles.js +21 -9
- package/lib/react/script-helper.js +2 -2
- package/lib/react/style-helper.js +76 -13
- package/lib/resolver/AddModePlugin.js +17 -7
- package/lib/resolver/ExtendComponentsPlugin.js +60 -0
- package/lib/runtime/components/ali/mpx-section-list.mpx +566 -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 +197 -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 +12 -3
- 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 +181 -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 +10 -3
- package/lib/runtime/components/react/dist/context.js +1 -2
- package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
- 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 +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
- package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
- package/lib/runtime/components/react/dist/mpx-section-list.d.ts +48 -0
- package/lib/runtime/components/react/dist/mpx-section-list.jsx +292 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +11 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +136 -83
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/parser.d.ts +0 -1
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts +10 -9
- package/lib/runtime/components/react/dist/utils.jsx +47 -24
- package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-image.tsx +2 -2
- package/lib/runtime/components/react/mpx-input.tsx +77 -54
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
- package/lib/runtime/components/react/mpx-section-list.tsx +439 -0
- package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
- package/lib/runtime/components/react/mpx-swiper.tsx +156 -81
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
- package/lib/runtime/components/react/mpx-view.tsx +27 -12
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/tsconfig.json +26 -0
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +51 -27
- package/lib/runtime/components/web/mpx-scroll-view.vue +5 -2
- package/lib/runtime/components/web/mpx-section-list.vue +551 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list.mpx +209 -0
- package/lib/runtime/components/wx/mpx-sticky-header.mpx +40 -0
- package/lib/runtime/components/wx/mpx-sticky-section.mpx +31 -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 +1 -2
- package/lib/style-compiler/strip-conditional.js +244 -0
- package/lib/template-compiler/compiler.js +9 -8
- package/lib/utils/const.js +29 -0
- package/lib/utils/dom-tag-config.js +1 -1
- package/lib/utils/string.js +25 -1
- package/lib/wxss/loader.js +4 -1
- package/lib/wxss/utils.js +7 -2
- package/package.json +7 -14
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
- package/lib/style-compiler/strip-conditional-loader.js +0 -289
|
@@ -42,17 +42,23 @@ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, ext
|
|
|
42
42
|
import { IntersectionObserverContext, ScrollViewContext } from './context';
|
|
43
43
|
import Portal from './mpx-portal';
|
|
44
44
|
const AnimatedScrollView = RNAnimated.createAnimatedComponent(ScrollView);
|
|
45
|
+
const REFRESH_COLOR = {
|
|
46
|
+
black: ['#000'],
|
|
47
|
+
white: ['#fff']
|
|
48
|
+
};
|
|
45
49
|
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
46
50
|
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
47
|
-
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend,
|
|
51
|
+
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchmove, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation = false, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'refresher-threshold': refresherThreshold = 45, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, 'enable-sticky': enableSticky, 'scroll-event-throttle': scrollEventThrottle = 0, 'scroll-into-view-offset': scrollIntoViewOffset = 0, __selectRef } = props;
|
|
48
52
|
const scrollOffset = useRef(new RNAnimated.Value(0)).current;
|
|
49
53
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
50
54
|
const waitForHandlers = flatGesture(waitFor);
|
|
55
|
+
const { refresherContent, otherContent } = getRefresherContent(props.children);
|
|
56
|
+
const hasRefresher = refresherContent && refresherEnabled;
|
|
51
57
|
const [refreshing, setRefreshing] = useState(false);
|
|
52
58
|
const [enableScroll, setEnableScroll] = useState(true);
|
|
53
|
-
const enableScrollValue = useSharedValue(true);
|
|
54
59
|
const [scrollBounces, setScrollBounces] = useState(false);
|
|
55
|
-
const
|
|
60
|
+
const enableScrollValue = useSharedValue(true);
|
|
61
|
+
const bouncesValue = useSharedValue(false);
|
|
56
62
|
const translateY = useSharedValue(0);
|
|
57
63
|
const isAtTop = useSharedValue(true);
|
|
58
64
|
const refresherHeight = useSharedValue(0);
|
|
@@ -68,13 +74,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
68
74
|
const initialTimeout = useRef(null);
|
|
69
75
|
const intersectionObservers = useContext(IntersectionObserverContext);
|
|
70
76
|
const firstScrollIntoViewChange = useRef(true);
|
|
71
|
-
const refreshColor = {
|
|
72
|
-
black: ['#000'],
|
|
73
|
-
white: ['#fff']
|
|
74
|
-
};
|
|
75
77
|
const isContentSizeChange = useRef(false);
|
|
76
|
-
const { refresherContent, otherContent } = getRefresherContent(props.children);
|
|
77
|
-
const hasRefresher = refresherContent && refresherEnabled;
|
|
78
78
|
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, hasPositionFixed, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
79
79
|
const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
|
|
80
80
|
const scrollViewRef = useRef(null);
|
|
@@ -455,67 +455,71 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
455
455
|
runOnJS(runOnJSCallback)('setScrollBounces', newValue);
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
// 处理下拉刷新的手势
|
|
459
|
-
const panGesture =
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
458
|
+
// 处理下拉刷新的手势 - 使用 useMemo 避免每次渲染都创建
|
|
459
|
+
const panGesture = useMemo(() => {
|
|
460
|
+
if (!hasRefresher)
|
|
461
|
+
return Gesture.Pan(); // 返回空手势
|
|
462
|
+
return Gesture.Pan()
|
|
463
|
+
.onUpdate((event) => {
|
|
464
|
+
'worklet';
|
|
465
|
+
if (enhanced && !!bounces) {
|
|
466
|
+
if (event.translationY > 0 && bouncesValue.value) {
|
|
467
|
+
updateBouncesState(false);
|
|
468
|
+
}
|
|
469
|
+
else if ((event.translationY < 0) && !bouncesValue.value) {
|
|
470
|
+
updateBouncesState(true);
|
|
471
|
+
}
|
|
465
472
|
}
|
|
466
|
-
|
|
467
|
-
|
|
473
|
+
if (translateY.value <= 0 && event.translationY < 0) {
|
|
474
|
+
// 滑动到顶再向上开启滚动
|
|
475
|
+
updateScrollState(true);
|
|
468
476
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
477
|
+
else if (event.translationY > 0 && isAtTop.value) {
|
|
478
|
+
// 滚动到顶再向下禁止滚动
|
|
479
|
+
updateScrollState(false);
|
|
480
|
+
}
|
|
481
|
+
// 禁止滚动后切换为滑动
|
|
482
|
+
if (!enableScrollValue.value && isAtTop.value) {
|
|
483
|
+
if (refreshing) {
|
|
484
|
+
// 从完全展开状态(refresherHeight.value)开始计算偏移
|
|
485
|
+
translateY.value = Math.max(0, Math.min(refresherHeight.value, refresherHeight.value + event.translationY));
|
|
486
|
+
}
|
|
487
|
+
else if (event.translationY > 0) {
|
|
488
|
+
// 非刷新状态下的下拉逻辑保持不变
|
|
489
|
+
translateY.value = Math.min(event.translationY * 0.6, refresherHeight.value);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
})
|
|
493
|
+
.onEnd((event) => {
|
|
494
|
+
'worklet';
|
|
495
|
+
if (enableScrollValue.value)
|
|
496
|
+
return;
|
|
480
497
|
if (refreshing) {
|
|
481
|
-
//
|
|
482
|
-
|
|
498
|
+
// 刷新状态下,根据滑动距离决定是否隐藏
|
|
499
|
+
// 如果向下滑动没超过 refresherThreshold,就完全隐藏,如果向上滑动完全隐藏
|
|
500
|
+
if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
|
|
501
|
+
translateY.value = withTiming(0);
|
|
502
|
+
updateScrollState(true);
|
|
503
|
+
runOnJS(runOnJSCallback)('setRefreshing', false);
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
translateY.value = withTiming(refresherHeight.value);
|
|
507
|
+
}
|
|
483
508
|
}
|
|
484
|
-
else if (event.translationY
|
|
485
|
-
//
|
|
486
|
-
translateY.value =
|
|
509
|
+
else if (event.translationY >= refresherHeight.value) {
|
|
510
|
+
// 触发刷新
|
|
511
|
+
translateY.value = withTiming(refresherHeight.value);
|
|
512
|
+
runOnJS(runOnJSCallback)('onRefresh');
|
|
487
513
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
.onEnd((event) => {
|
|
491
|
-
'worklet';
|
|
492
|
-
if (enableScrollValue.value)
|
|
493
|
-
return;
|
|
494
|
-
if (refreshing) {
|
|
495
|
-
// 刷新状态下,根据滑动距离决定是否隐藏
|
|
496
|
-
// 如果向下滑动没超过 refresherThreshold,就完全隐藏,如果向上滑动完全隐藏
|
|
497
|
-
if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
|
|
514
|
+
else {
|
|
515
|
+
// 回弹
|
|
498
516
|
translateY.value = withTiming(0);
|
|
499
517
|
updateScrollState(true);
|
|
500
518
|
runOnJS(runOnJSCallback)('setRefreshing', false);
|
|
501
519
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
else if (event.translationY >= refresherHeight.value) {
|
|
507
|
-
// 触发刷新
|
|
508
|
-
translateY.value = withTiming(refresherHeight.value);
|
|
509
|
-
runOnJS(runOnJSCallback)('onRefresh');
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
// 回弹
|
|
513
|
-
translateY.value = withTiming(0);
|
|
514
|
-
updateScrollState(true);
|
|
515
|
-
runOnJS(runOnJSCallback)('setRefreshing', false);
|
|
516
|
-
}
|
|
517
|
-
})
|
|
518
|
-
.simultaneousWithExternalGesture(scrollViewRef);
|
|
520
|
+
})
|
|
521
|
+
.simultaneousWithExternalGesture(scrollViewRef);
|
|
522
|
+
}, [hasRefresher, enhanced, bounces, refreshing, refresherThreshold]);
|
|
519
523
|
const scrollAdditionalProps = extendObject({
|
|
520
524
|
style: extendObject(hasOwn(innerStyle, 'flex') || hasOwn(innerStyle, 'flexGrow')
|
|
521
525
|
? {}
|
|
@@ -575,29 +579,31 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
575
579
|
'bindrefresherrefresh'
|
|
576
580
|
], { layoutRef });
|
|
577
581
|
const ScrollViewComponent = enableSticky ? AnimatedScrollView : ScrollView;
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
582
|
+
const createScrollViewContent = () => {
|
|
583
|
+
const wrappedChildren = wrapChildren(hasRefresher ? extendObject({}, props, { children: otherContent }) : props, {
|
|
584
|
+
hasVarDec,
|
|
585
|
+
varContext: varContextRef.current,
|
|
586
|
+
textStyle,
|
|
587
|
+
textProps
|
|
588
|
+
});
|
|
589
|
+
return createElement(ScrollViewContext.Provider, { value: contextValue }, wrappedChildren);
|
|
590
|
+
};
|
|
591
|
+
const withRefresherScrollView = () => {
|
|
592
|
+
return createElement(GestureDetector, { gesture: panGesture }, createElement(ScrollViewComponent, innerProps, createElement(Animated.View, { style: [refresherAnimatedStyle, refresherLayoutStyle], onLayout: onRefresherLayout }, refresherContent), createElement(Animated.View, { style: contentAnimatedStyle }, createScrollViewContent())));
|
|
593
|
+
};
|
|
594
|
+
const commonScrollView = () => {
|
|
595
|
+
const refreshControl = refresherEnabled
|
|
586
596
|
? createElement(RefreshControl, extendObject({
|
|
587
597
|
progressBackgroundColor: refresherBackground,
|
|
588
598
|
refreshing: refreshing,
|
|
589
599
|
onRefresh: onRefresh
|
|
590
600
|
}, refresherDefaultStyle && refresherDefaultStyle !== 'none'
|
|
591
|
-
? { colors:
|
|
601
|
+
? { colors: REFRESH_COLOR[refresherDefaultStyle] }
|
|
592
602
|
: {}))
|
|
593
|
-
: undefined
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
textStyle,
|
|
598
|
-
textProps
|
|
599
|
-
})));
|
|
600
|
-
let scrollViewComponent = hasRefresher ? withRefresherScrollView : commonScrollView;
|
|
603
|
+
: undefined;
|
|
604
|
+
return createElement(ScrollViewComponent, extendObject({}, innerProps, { refreshControl }), createScrollViewContent());
|
|
605
|
+
};
|
|
606
|
+
let scrollViewComponent = hasRefresher ? withRefresherScrollView() : commonScrollView();
|
|
601
607
|
if (hasPositionFixed) {
|
|
602
608
|
scrollViewComponent = createElement(Portal, null, scrollViewComponent);
|
|
603
609
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface ListItem {
|
|
3
|
+
isSectionHeader?: boolean;
|
|
4
|
+
_originalItemIndex?: number;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
interface ItemHeightType {
|
|
8
|
+
value?: number;
|
|
9
|
+
getter?: (item: any, index: number) => number;
|
|
10
|
+
}
|
|
11
|
+
interface SectionListProps {
|
|
12
|
+
enhanced?: boolean;
|
|
13
|
+
bounces?: boolean;
|
|
14
|
+
scrollEventThrottle?: number;
|
|
15
|
+
height?: number | string;
|
|
16
|
+
width?: number | string;
|
|
17
|
+
listData?: ListItem[];
|
|
18
|
+
generichash?: string;
|
|
19
|
+
style?: Record<string, any>;
|
|
20
|
+
itemHeight?: ItemHeightType;
|
|
21
|
+
sectionHeaderHeight?: ItemHeightType;
|
|
22
|
+
listHeaderData?: any;
|
|
23
|
+
listHeaderHeight?: ItemHeightType;
|
|
24
|
+
useListHeader?: boolean;
|
|
25
|
+
listFooterData?: any;
|
|
26
|
+
useListFooter?: boolean;
|
|
27
|
+
'genericrecycle-item'?: string;
|
|
28
|
+
'genericsection-header'?: string;
|
|
29
|
+
'genericlist-header'?: string;
|
|
30
|
+
'genericlist-footer'?: string;
|
|
31
|
+
'enable-var'?: boolean;
|
|
32
|
+
'external-var-context'?: any;
|
|
33
|
+
'parent-font-size'?: number;
|
|
34
|
+
'parent-width'?: number;
|
|
35
|
+
'parent-height'?: number;
|
|
36
|
+
'enable-sticky'?: boolean;
|
|
37
|
+
'enable-back-to-top'?: boolean;
|
|
38
|
+
'end-reached-threshold'?: number;
|
|
39
|
+
'refresher-enabled'?: boolean;
|
|
40
|
+
'show-scrollbar'?: boolean;
|
|
41
|
+
'refresher-triggered'?: boolean;
|
|
42
|
+
bindrefresherrefresh?: (event: any) => void;
|
|
43
|
+
bindscrolltolower?: (event: any) => void;
|
|
44
|
+
bindscroll?: (event: any) => void;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
declare const _SectionList: React.ForwardRefExoticComponent<Omit<SectionListProps, "ref"> & React.RefAttributes<any>>;
|
|
48
|
+
export default _SectionList;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import React, { forwardRef, useRef, useState, useEffect, useMemo, createElement, useImperativeHandle, memo } from 'react';
|
|
2
|
+
import { SectionList, RefreshControl } from 'react-native';
|
|
3
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
4
|
+
import { extendObject, useLayout, useTransformStyle } from './utils';
|
|
5
|
+
const getGeneric = (generichash, generickey) => {
|
|
6
|
+
if (!generichash || !generickey)
|
|
7
|
+
return null;
|
|
8
|
+
const GenericComponent = global.__mpxGenericsMap?.[generichash]?.[generickey]?.();
|
|
9
|
+
if (!GenericComponent)
|
|
10
|
+
return null;
|
|
11
|
+
return memo(forwardRef((props, ref) => {
|
|
12
|
+
return createElement(GenericComponent, extendObject({}, {
|
|
13
|
+
ref: ref
|
|
14
|
+
}, props));
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
17
|
+
const _SectionList = forwardRef((props = {}, ref) => {
|
|
18
|
+
const { enhanced = false, bounces = true, scrollEventThrottle = 0, height, width, listData, generichash, style = {}, itemHeight = {}, sectionHeaderHeight = {}, listHeaderHeight = {}, listHeaderData = null, useListHeader = false, listFooterData = null, useListFooter = false, 'genericrecycle-item': genericrecycleItem, 'genericsection-header': genericsectionHeader, 'genericlist-header': genericListHeader, 'genericlist-footer': genericListFooter, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'enable-sticky': enableSticky = false, 'enable-back-to-top': enableBackToTop = false, 'end-reached-threshold': onEndReachedThreshold = 0.1, 'refresher-enabled': refresherEnabled, 'show-scrollbar': showScrollbar = true, 'refresher-triggered': refresherTriggered } = props;
|
|
19
|
+
const [refreshing, setRefreshing] = useState(!!refresherTriggered);
|
|
20
|
+
const scrollViewRef = useRef(null);
|
|
21
|
+
const indexMap = useRef({});
|
|
22
|
+
const reverseIndexMap = useRef({});
|
|
23
|
+
const { hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
24
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef });
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (refreshing !== refresherTriggered) {
|
|
27
|
+
setRefreshing(!!refresherTriggered);
|
|
28
|
+
}
|
|
29
|
+
}, [refresherTriggered]);
|
|
30
|
+
const onRefresh = () => {
|
|
31
|
+
const { bindrefresherrefresh } = props;
|
|
32
|
+
bindrefresherrefresh &&
|
|
33
|
+
bindrefresherrefresh(getCustomEvent('refresherrefresh', {}, { layoutRef }, props));
|
|
34
|
+
};
|
|
35
|
+
const onEndReached = () => {
|
|
36
|
+
const { bindscrolltolower } = props;
|
|
37
|
+
bindscrolltolower &&
|
|
38
|
+
bindscrolltolower(getCustomEvent('scrolltolower', {}, { layoutRef }, props));
|
|
39
|
+
};
|
|
40
|
+
const onScroll = (event) => {
|
|
41
|
+
const { bindscroll } = props;
|
|
42
|
+
bindscroll &&
|
|
43
|
+
bindscroll(getCustomEvent('scroll', event.nativeEvent, { layoutRef }, props));
|
|
44
|
+
};
|
|
45
|
+
// 通过sectionIndex和rowIndex获取原始索引
|
|
46
|
+
const getOriginalIndex = (sectionIndex, rowIndex) => {
|
|
47
|
+
const key = `${sectionIndex}_${rowIndex}`;
|
|
48
|
+
return reverseIndexMap.current[key] ?? -1; // 如果找不到,返回-1
|
|
49
|
+
};
|
|
50
|
+
const scrollToIndex = ({ index, animated, viewOffset = 0, viewPosition = 0 }) => {
|
|
51
|
+
if (scrollViewRef.current) {
|
|
52
|
+
// 通过索引映射表快速定位位置
|
|
53
|
+
const position = indexMap.current[index];
|
|
54
|
+
const [sectionIndex, itemIndex] = position.split('_');
|
|
55
|
+
scrollViewRef.current.scrollToLocation?.({
|
|
56
|
+
itemIndex: itemIndex === 'header' ? 0 : Number(itemIndex) + 1,
|
|
57
|
+
sectionIndex: Number(sectionIndex) || 0,
|
|
58
|
+
animated,
|
|
59
|
+
viewOffset,
|
|
60
|
+
viewPosition
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const getItemHeight = ({ sectionIndex, rowIndex }) => {
|
|
65
|
+
if (!itemHeight) {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
if (itemHeight.getter) {
|
|
69
|
+
const item = convertedListData[sectionIndex].data[rowIndex];
|
|
70
|
+
// 使用getOriginalIndex获取原始索引
|
|
71
|
+
const originalIndex = getOriginalIndex(sectionIndex, rowIndex);
|
|
72
|
+
return itemHeight.getter?.(item, originalIndex) || 0;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return itemHeight.value || 0;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const getSectionHeaderHeight = ({ sectionIndex }) => {
|
|
79
|
+
const item = convertedListData[sectionIndex];
|
|
80
|
+
const { hasSectionHeader } = item;
|
|
81
|
+
// 使用getOriginalIndex获取原始索引
|
|
82
|
+
const originalIndex = getOriginalIndex(sectionIndex, 'header');
|
|
83
|
+
if (!hasSectionHeader)
|
|
84
|
+
return 0;
|
|
85
|
+
if (sectionHeaderHeight.getter) {
|
|
86
|
+
return sectionHeaderHeight.getter?.(item, originalIndex) || 0;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return sectionHeaderHeight.value || 0;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const convertedListData = useMemo(() => {
|
|
93
|
+
const sections = [];
|
|
94
|
+
let currentSection = null;
|
|
95
|
+
// 清空之前的索引映射
|
|
96
|
+
indexMap.current = {};
|
|
97
|
+
// 清空反向索引映射
|
|
98
|
+
reverseIndexMap.current = {};
|
|
99
|
+
// 处理 listData 为空的情况
|
|
100
|
+
if (!listData || !listData.length) {
|
|
101
|
+
return sections;
|
|
102
|
+
}
|
|
103
|
+
listData.forEach((item, index) => {
|
|
104
|
+
if (item.isSectionHeader) {
|
|
105
|
+
// 如果已经存在一个 section,先把它添加到 sections 中
|
|
106
|
+
if (currentSection) {
|
|
107
|
+
sections.push(currentSection);
|
|
108
|
+
}
|
|
109
|
+
// 创建新的 section
|
|
110
|
+
currentSection = {
|
|
111
|
+
headerData: item,
|
|
112
|
+
data: [],
|
|
113
|
+
hasSectionHeader: true,
|
|
114
|
+
_originalItemIndex: index
|
|
115
|
+
};
|
|
116
|
+
// 为 section header 添加索引映射
|
|
117
|
+
const sectionIndex = sections.length;
|
|
118
|
+
indexMap.current[index] = `${sectionIndex}_header`;
|
|
119
|
+
// 添加反向索引映射
|
|
120
|
+
reverseIndexMap.current[`${sectionIndex}_header`] = index;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// 如果没有当前 section,创建一个默认的
|
|
124
|
+
if (!currentSection) {
|
|
125
|
+
// 创建默认section (无header的section)
|
|
126
|
+
currentSection = {
|
|
127
|
+
headerData: null,
|
|
128
|
+
data: [],
|
|
129
|
+
hasSectionHeader: false,
|
|
130
|
+
_originalItemIndex: -1
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// 将 item 添加到当前 section 的 data 中
|
|
134
|
+
const itemIndex = currentSection.data.length;
|
|
135
|
+
currentSection.data.push(extendObject({}, item, {
|
|
136
|
+
_originalItemIndex: index
|
|
137
|
+
}));
|
|
138
|
+
let sectionIndex;
|
|
139
|
+
// 为 item 添加索引映射 - 存储格式为: "sectionIndex_itemIndex"
|
|
140
|
+
if (!currentSection.hasSectionHeader && sections.length === 0) {
|
|
141
|
+
// 在默认section中(第一个且无header)
|
|
142
|
+
sectionIndex = 0;
|
|
143
|
+
indexMap.current[index] = `${sectionIndex}_${itemIndex}`;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// 在普通section中
|
|
147
|
+
sectionIndex = sections.length;
|
|
148
|
+
indexMap.current[index] = `${sectionIndex}_${itemIndex}`;
|
|
149
|
+
}
|
|
150
|
+
// 添加反向索引映射
|
|
151
|
+
reverseIndexMap.current[`${sectionIndex}_${itemIndex}`] = index;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
// 添加最后一个 section
|
|
155
|
+
if (currentSection) {
|
|
156
|
+
sections.push(currentSection);
|
|
157
|
+
}
|
|
158
|
+
return sections;
|
|
159
|
+
}, [listData]);
|
|
160
|
+
const { getItemLayout } = useMemo(() => {
|
|
161
|
+
const layouts = [];
|
|
162
|
+
let offset = 0;
|
|
163
|
+
if (useListHeader) {
|
|
164
|
+
// 计算列表头部的高度
|
|
165
|
+
offset += listHeaderHeight.getter?.() || listHeaderHeight.value || 0;
|
|
166
|
+
}
|
|
167
|
+
// 遍历所有 sections
|
|
168
|
+
convertedListData.forEach((section, sectionIndex) => {
|
|
169
|
+
// 添加 section header 的位置信息
|
|
170
|
+
const headerHeight = getSectionHeaderHeight({ sectionIndex });
|
|
171
|
+
layouts.push({
|
|
172
|
+
length: headerHeight,
|
|
173
|
+
offset,
|
|
174
|
+
index: layouts.length
|
|
175
|
+
});
|
|
176
|
+
offset += headerHeight;
|
|
177
|
+
// 添加该 section 中所有 items 的位置信息
|
|
178
|
+
section.data.forEach((item, itemIndex) => {
|
|
179
|
+
const contenteight = getItemHeight({ sectionIndex, rowIndex: itemIndex });
|
|
180
|
+
layouts.push({
|
|
181
|
+
length: contenteight,
|
|
182
|
+
offset,
|
|
183
|
+
index: layouts.length
|
|
184
|
+
});
|
|
185
|
+
offset += contenteight;
|
|
186
|
+
});
|
|
187
|
+
// 添加该 section 尾部位置信息
|
|
188
|
+
// 因为即使 sectionList 没传 renderSectionFooter,getItemLayout 中的 index 的计算也会包含尾部节点
|
|
189
|
+
layouts.push({
|
|
190
|
+
length: 0,
|
|
191
|
+
offset,
|
|
192
|
+
index: layouts.length
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
itemLayouts: layouts,
|
|
197
|
+
getItemLayout: (data, index) => layouts[index]
|
|
198
|
+
};
|
|
199
|
+
}, [convertedListData, useListHeader, itemHeight.value, itemHeight.getter, sectionHeaderHeight.value, sectionHeaderHeight.getter, listHeaderHeight.value, listHeaderHeight.getter]);
|
|
200
|
+
const scrollAdditionalProps = extendObject({
|
|
201
|
+
alwaysBounceVertical: false,
|
|
202
|
+
alwaysBounceHorizontal: false,
|
|
203
|
+
scrollEventThrottle: scrollEventThrottle,
|
|
204
|
+
scrollsToTop: enableBackToTop,
|
|
205
|
+
showsHorizontalScrollIndicator: showScrollbar,
|
|
206
|
+
onEndReachedThreshold,
|
|
207
|
+
ref: scrollViewRef,
|
|
208
|
+
bounces: false,
|
|
209
|
+
stickySectionHeadersEnabled: enableSticky,
|
|
210
|
+
onScroll: onScroll,
|
|
211
|
+
onEndReached: onEndReached
|
|
212
|
+
}, layoutProps);
|
|
213
|
+
if (enhanced) {
|
|
214
|
+
Object.assign(scrollAdditionalProps, {
|
|
215
|
+
bounces
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (refresherEnabled) {
|
|
219
|
+
Object.assign(scrollAdditionalProps, {
|
|
220
|
+
refreshing: refreshing
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
useImperativeHandle(ref, () => {
|
|
224
|
+
return {
|
|
225
|
+
...props,
|
|
226
|
+
scrollToIndex
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
const innerProps = useInnerProps(extendObject({}, props, scrollAdditionalProps), [
|
|
230
|
+
'id',
|
|
231
|
+
'show-scrollbar',
|
|
232
|
+
'lower-threshold',
|
|
233
|
+
'refresher-triggered',
|
|
234
|
+
'refresher-enabled',
|
|
235
|
+
'bindrefresherrefresh'
|
|
236
|
+
], { layoutRef });
|
|
237
|
+
// 使用 ref 保存最新的数据,避免数据变化时组件销毁重建
|
|
238
|
+
const listHeaderDataRef = useRef(listHeaderData);
|
|
239
|
+
listHeaderDataRef.current = listHeaderData;
|
|
240
|
+
const listFooterDataRef = useRef(listFooterData);
|
|
241
|
+
listFooterDataRef.current = listFooterData;
|
|
242
|
+
// 使用 useMemo 获取 GenericComponent 并创建渲染函数,避免每次组件更新都重新创建函数引用导致不必要的重新渲染
|
|
243
|
+
const renderItem = useMemo(() => {
|
|
244
|
+
const ItemComponent = getGeneric(generichash, genericrecycleItem);
|
|
245
|
+
if (!ItemComponent)
|
|
246
|
+
return undefined;
|
|
247
|
+
return ({ item }) => createElement(ItemComponent, { itemData: item });
|
|
248
|
+
}, [generichash, genericrecycleItem]);
|
|
249
|
+
const renderSectionHeader = useMemo(() => {
|
|
250
|
+
const SectionHeaderComponent = getGeneric(generichash, genericsectionHeader);
|
|
251
|
+
if (!SectionHeaderComponent)
|
|
252
|
+
return undefined;
|
|
253
|
+
return (sectionData) => {
|
|
254
|
+
if (!sectionData.section.hasSectionHeader)
|
|
255
|
+
return null;
|
|
256
|
+
return createElement(SectionHeaderComponent, { itemData: sectionData.section.headerData });
|
|
257
|
+
};
|
|
258
|
+
}, [generichash, genericsectionHeader]);
|
|
259
|
+
const ListHeaderComponent = useMemo(() => {
|
|
260
|
+
if (!useListHeader)
|
|
261
|
+
return null;
|
|
262
|
+
const ListHeaderGenericComponent = getGeneric(generichash, genericListHeader);
|
|
263
|
+
if (!ListHeaderGenericComponent)
|
|
264
|
+
return null;
|
|
265
|
+
return () => createElement(ListHeaderGenericComponent, { listHeaderData: listHeaderDataRef.current });
|
|
266
|
+
}, [useListHeader, generichash, genericListHeader]);
|
|
267
|
+
const ListFooterComponent = useMemo(() => {
|
|
268
|
+
if (!useListFooter)
|
|
269
|
+
return null;
|
|
270
|
+
const ListFooterGenericComponent = getGeneric(generichash, genericListFooter);
|
|
271
|
+
if (!ListFooterGenericComponent)
|
|
272
|
+
return null;
|
|
273
|
+
return () => createElement(ListFooterGenericComponent, { listFooterData: listFooterDataRef.current });
|
|
274
|
+
}, [useListFooter, generichash, genericListFooter]);
|
|
275
|
+
return createElement(SectionList, extendObject({
|
|
276
|
+
style: [{ height, width }, style, layoutStyle],
|
|
277
|
+
sections: convertedListData,
|
|
278
|
+
renderItem: renderItem,
|
|
279
|
+
getItemLayout: getItemLayout,
|
|
280
|
+
ListHeaderComponent: useListHeader ? ListHeaderComponent : null,
|
|
281
|
+
ListFooterComponent: useListFooter ? ListFooterComponent : null,
|
|
282
|
+
renderSectionHeader: renderSectionHeader,
|
|
283
|
+
refreshControl: refresherEnabled
|
|
284
|
+
? React.createElement(RefreshControl, {
|
|
285
|
+
onRefresh: onRefresh,
|
|
286
|
+
refreshing: refreshing
|
|
287
|
+
})
|
|
288
|
+
: undefined
|
|
289
|
+
}, innerProps));
|
|
290
|
+
});
|
|
291
|
+
_SectionList.displayName = 'MpxSectionList';
|
|
292
|
+
export default _SectionList;
|
|
@@ -15,4 +15,3 @@ interface StickyHeaderProps {
|
|
|
15
15
|
}
|
|
16
16
|
declare const _StickyHeader: import("react").ForwardRefExoticComponent<StickyHeaderProps & import("react").RefAttributes<HandlerRef<View, StickyHeaderProps>>>;
|
|
17
17
|
export default _StickyHeader;
|
|
18
|
-
//# sourceMappingURL=mpx-sticky-header.d.ts.map
|
|
@@ -8,9 +8,8 @@ import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
|
8
8
|
const _StickyHeader = forwardRef((stickyHeaderProps = {}, ref) => {
|
|
9
9
|
const { textProps, innerProps: props = {} } = splitProps(stickyHeaderProps);
|
|
10
10
|
const { style, bindstickontopchange, padding = [0, 0, 0, 0], 'offset-top': offsetTop = 0, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
11
|
-
const
|
|
11
|
+
const { scrollOffset, gestureRef: scrollViewRef } = useContext(ScrollViewContext);
|
|
12
12
|
const stickyContext = useContext(StickyContext);
|
|
13
|
-
const { scrollOffset } = scrollViewContext;
|
|
14
13
|
const { registerStickyHeader, unregisterStickyHeader } = stickyContext;
|
|
15
14
|
const headerRef = useRef(null);
|
|
16
15
|
const isStickOnTopRef = useRef(false);
|
|
@@ -29,7 +28,6 @@ const _StickyHeader = forwardRef((stickyHeaderProps = {}, ref) => {
|
|
|
29
28
|
}, []);
|
|
30
29
|
function updatePosition() {
|
|
31
30
|
if (headerRef.current) {
|
|
32
|
-
const scrollViewRef = scrollViewContext.gestureRef;
|
|
33
31
|
if (scrollViewRef && scrollViewRef.current) {
|
|
34
32
|
headerRef.current.measureLayout(scrollViewRef.current, (left, top) => {
|
|
35
33
|
Animated.timing(headerTopAnimated, {
|
|
@@ -52,7 +50,7 @@ const _StickyHeader = forwardRef((stickyHeaderProps = {}, ref) => {
|
|
|
52
50
|
style: normalStyle
|
|
53
51
|
});
|
|
54
52
|
useEffect(() => {
|
|
55
|
-
if (!bindstickontopchange)
|
|
53
|
+
if (!bindstickontopchange || !scrollOffset)
|
|
56
54
|
return;
|
|
57
55
|
const listener = scrollOffset.addListener((state) => {
|
|
58
56
|
const currentScrollValue = state.value;
|
|
@@ -70,24 +68,26 @@ const _StickyHeader = forwardRef((stickyHeaderProps = {}, ref) => {
|
|
|
70
68
|
return () => {
|
|
71
69
|
scrollOffset.removeListener(listener);
|
|
72
70
|
};
|
|
73
|
-
}, []);
|
|
71
|
+
}, [bindstickontopchange, scrollOffset]);
|
|
74
72
|
const animatedStyle = useMemo(() => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
outputRange: [0, 1],
|
|
78
|
-
extrapolateLeft: 'clamp',
|
|
79
|
-
extrapolateRight: 'extend'
|
|
80
|
-
});
|
|
81
|
-
const finalTranslateY = offsetTop === 0
|
|
82
|
-
? translateY
|
|
83
|
-
: Animated.add(translateY, Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
|
|
73
|
+
if (scrollOffset) {
|
|
74
|
+
const translateY = Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
|
|
84
75
|
inputRange: [0, 1],
|
|
85
|
-
outputRange: [0,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
outputRange: [0, 1],
|
|
77
|
+
extrapolateLeft: 'clamp',
|
|
78
|
+
extrapolateRight: 'extend'
|
|
79
|
+
});
|
|
80
|
+
const finalTranslateY = offsetTop === 0
|
|
81
|
+
? translateY
|
|
82
|
+
: Animated.add(translateY, Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
|
|
83
|
+
inputRange: [0, 1],
|
|
84
|
+
outputRange: [0, offsetTop],
|
|
85
|
+
extrapolate: 'clamp'
|
|
86
|
+
}));
|
|
87
|
+
return {
|
|
88
|
+
transform: [{ translateY: finalTranslateY }]
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
91
|
}, [scrollOffset, headerTopAnimated, offsetTop]);
|
|
92
92
|
const innerProps = useInnerProps(extendObject({}, props, {
|
|
93
93
|
ref: headerRef,
|
|
@@ -13,4 +13,3 @@ interface StickySectionProps {
|
|
|
13
13
|
}
|
|
14
14
|
declare const _StickySection: import("react").ForwardRefExoticComponent<StickySectionProps & import("react").RefAttributes<HandlerRef<View, StickySectionProps>>>;
|
|
15
15
|
export default _StickySection;
|
|
16
|
-
//# sourceMappingURL=mpx-sticky-section.d.ts.map
|