@mpxjs/webpack-plugin 2.10.15 → 2.10.16-beta.11
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/DynamicEntryDependency.js +1 -1
- package/lib/dependencies/ImportDependency.js +102 -0
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/{retry-runtime-module.js → dependencies/RetryRuntimeModule.js} +1 -1
- package/lib/file-loader.js +13 -3
- package/lib/helpers.js +2 -0
- package/lib/index.js +51 -25
- package/lib/json-compiler/helper.js +72 -2
- package/lib/json-compiler/index.js +16 -56
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +10 -4
- package/lib/native-loader.js +6 -3
- package/lib/platform/json/wx/index.js +30 -29
- package/lib/platform/style/wx/index.js +8 -1
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +21 -5
- 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 +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 +20 -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/index.js +2 -0
- package/lib/react/processJSON.js +39 -71
- package/lib/react/processStyles.js +3 -2
- package/lib/react/processTemplate.js +8 -6
- package/lib/react/script-helper.js +6 -16
- package/lib/react/style-helper.js +10 -2
- package/lib/resolver/AddEnvPlugin.js +13 -0
- package/lib/resolver/AddModePlugin.js +18 -0
- package/lib/runtime/components/react/context.ts +13 -6
- package/lib/runtime/components/react/dist/context.d.ts +76 -0
- package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
- package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +197 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +81 -37
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +40 -12
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +61 -50
- package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -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 +9 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -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 +15 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -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 +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -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 +17 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -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 +30 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-progress.jsx +26 -22
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-slider.jsx +321 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -5
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/parser.d.ts +40 -0
- package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.d.ts +123 -0
- package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.jsx +16 -6
- package/lib/runtime/components/react/mpx-camera.tsx +275 -0
- package/lib/runtime/components/react/mpx-image.tsx +89 -42
- package/lib/runtime/components/react/mpx-input.tsx +50 -18
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +69 -49
- 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-progress.tsx +26 -24
- package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
- package/lib/runtime/components/react/mpx-slider.tsx +444 -0
- package/lib/runtime/components/react/mpx-swiper.tsx +9 -5
- package/lib/runtime/components/react/mpx-text.tsx +38 -5
- package/lib/runtime/components/react/mpx-view.tsx +8 -11
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/utils.tsx +15 -6
- package/lib/runtime/components/web/mpx-input.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +7 -1
- package/lib/runtime/components/web/mpx-video.vue +12 -1
- package/lib/runtime/optionProcessor.js +3 -1
- package/lib/runtime/optionProcessorReact.js +4 -2
- 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.js +178 -15
- package/lib/template-compiler/bind-this.js +2 -2
- package/lib/template-compiler/compiler.js +277 -77
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +12 -10
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/chain-assign.js +47 -0
- package/lib/utils/check-core-version-match.js +75 -15
- package/lib/utils/const.js +2 -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/pre-process-json.js +5 -0
- package/lib/web/index.js +2 -0
- package/lib/web/processJSON.js +44 -16
- 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 +6 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +17 -5
- package/LICENSE +0 -433
- package/lib/dependencies/ImportDependencyTemplate.js +0 -50
|
@@ -35,7 +35,7 @@ import Animated, {
|
|
|
35
35
|
|
|
36
36
|
import useInnerProps from './getInnerListeners'
|
|
37
37
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
38
|
-
import { useLayout, useTransformStyle, extendObject } from './utils'
|
|
38
|
+
import { useLayout, useTransformStyle, extendObject, useRunOnJSCallback } from './utils'
|
|
39
39
|
import Portal from './mpx-portal'
|
|
40
40
|
|
|
41
41
|
export interface ProgressProps {
|
|
@@ -70,7 +70,6 @@ const Progress = forwardRef<
|
|
|
70
70
|
active = false,
|
|
71
71
|
'active-mode': activeMode = 'backwards',
|
|
72
72
|
duration = 30,
|
|
73
|
-
bindactiveend,
|
|
74
73
|
style = {},
|
|
75
74
|
'enable-var': enableVar,
|
|
76
75
|
'external-var-context': externalVarContext,
|
|
@@ -80,7 +79,7 @@ const Progress = forwardRef<
|
|
|
80
79
|
} = props
|
|
81
80
|
|
|
82
81
|
const nodeRef = useRef(null)
|
|
83
|
-
const propsRef = useRef(
|
|
82
|
+
const propsRef = useRef(props)
|
|
84
83
|
propsRef.current = props
|
|
85
84
|
|
|
86
85
|
// 进度值状态
|
|
@@ -113,6 +112,22 @@ const Progress = forwardRef<
|
|
|
113
112
|
style: normalStyle
|
|
114
113
|
})
|
|
115
114
|
|
|
115
|
+
// 使用 useRunOnJSCallback 处理动画回调
|
|
116
|
+
const runOnJSCallbackRef = useRef({
|
|
117
|
+
triggerActiveEnd: (percent: number) => {
|
|
118
|
+
const currentProps = propsRef.current
|
|
119
|
+
if (currentProps.bindactiveend) {
|
|
120
|
+
currentProps.bindactiveend({
|
|
121
|
+
type: 'activeend',
|
|
122
|
+
detail: {
|
|
123
|
+
percent: percent
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
|
|
130
|
+
|
|
116
131
|
// 进度条动画函数
|
|
117
132
|
const startProgressAnimation = (targetPercent: number, startPercent: number, animationDuration: number, onFinished?: () => void) => {
|
|
118
133
|
// 根据 active-mode 设置起始位置
|
|
@@ -125,25 +140,13 @@ const Progress = forwardRef<
|
|
|
125
140
|
},
|
|
126
141
|
(finished) => {
|
|
127
142
|
if (finished && onFinished) {
|
|
128
|
-
//
|
|
129
|
-
|
|
143
|
+
// 在动画回调中,执行传入的worklet函数
|
|
144
|
+
onFinished()
|
|
130
145
|
}
|
|
131
146
|
}
|
|
132
147
|
)
|
|
133
148
|
}
|
|
134
149
|
|
|
135
|
-
// 创建在主线程执行的事件回调函数
|
|
136
|
-
const triggerActiveEnd = (percent: number) => {
|
|
137
|
-
if (bindactiveend) {
|
|
138
|
-
bindactiveend({
|
|
139
|
-
type: 'activeend',
|
|
140
|
-
detail: {
|
|
141
|
-
percent: percent
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
150
|
// 进度变化时的动画效果
|
|
148
151
|
useEffect(() => {
|
|
149
152
|
const targetPercent = Math.max(0, Math.min(100, percent))
|
|
@@ -161,19 +164,18 @@ const Progress = forwardRef<
|
|
|
161
164
|
const percentDiff = Math.abs(targetPercent - startPercent)
|
|
162
165
|
const animationDuration = percentDiff * duration
|
|
163
166
|
|
|
164
|
-
// 创建动画完成回调
|
|
165
|
-
const onAnimationFinished = () => {
|
|
166
|
-
triggerActiveEnd(targetPercent)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
167
|
// 执行动画
|
|
170
|
-
startProgressAnimation(targetPercent, startPercent, animationDuration,
|
|
168
|
+
startProgressAnimation(targetPercent, startPercent, animationDuration, () => {
|
|
169
|
+
'worklet'
|
|
170
|
+
// 在worklet函数内部执行runOnJS调用runOnJSCallback
|
|
171
|
+
runOnJS(runOnJSCallback)('triggerActiveEnd', targetPercent)
|
|
172
|
+
})
|
|
171
173
|
} else {
|
|
172
174
|
progressWidth.value = targetPercent
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
setLastPercent(targetPercent)
|
|
176
|
-
}, [percent, active, activeMode, duration
|
|
178
|
+
}, [percent, active, activeMode, duration])
|
|
177
179
|
|
|
178
180
|
// 初始化时设置进度值
|
|
179
181
|
useEffect(() => {
|
|
@@ -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)
|
|
@@ -268,16 +265,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
268
265
|
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
266
|
}
|
|
270
267
|
useEffect(() => {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return () => {
|
|
279
|
-
initialTimeout.current && clearTimeout(initialTimeout.current)
|
|
280
|
-
}
|
|
268
|
+
initialTimeout.current = setTimeout(() => {
|
|
269
|
+
scrollToOffset(scrollLeft, scrollTop)
|
|
270
|
+
}, 0)
|
|
271
|
+
|
|
272
|
+
return () => {
|
|
273
|
+
initialTimeout.current && clearTimeout(initialTimeout.current)
|
|
281
274
|
}
|
|
282
275
|
}, [scrollTop, scrollLeft])
|
|
283
276
|
|
|
@@ -481,10 +474,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
481
474
|
function scrollToOffset (x = 0, y = 0, animated = scrollWithAnimation) {
|
|
482
475
|
if (scrollViewRef.current) {
|
|
483
476
|
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
477
|
}
|
|
489
478
|
}
|
|
490
479
|
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ min 最小值
|
|
3
|
+
* ✔ max 最大值
|
|
4
|
+
* ✔ step 步长
|
|
5
|
+
* ✔ disabled 是否禁用
|
|
6
|
+
* ✔ value 当前取值
|
|
7
|
+
* ✔ color 背景条的颜色(已废弃,使用 backgroundColor)
|
|
8
|
+
* ✔ selected-color 已选择的颜色(已废弃,使用 activeColor)
|
|
9
|
+
* ✔ activeColor 已选择的颜色
|
|
10
|
+
* ✔ backgroundColor 背景条的颜色
|
|
11
|
+
* ✔ block-size 滑块的大小
|
|
12
|
+
* ✔ block-color 滑块的颜色
|
|
13
|
+
* ✘ show-value 是否显示当前 value
|
|
14
|
+
* ✔ bindchange 完成一次拖动后触发的事件
|
|
15
|
+
* ✔ bindchanging 拖动过程中触发的事件
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
JSX,
|
|
19
|
+
useRef,
|
|
20
|
+
forwardRef,
|
|
21
|
+
useEffect,
|
|
22
|
+
useState,
|
|
23
|
+
createElement,
|
|
24
|
+
ForwardedRef,
|
|
25
|
+
useContext,
|
|
26
|
+
useMemo
|
|
27
|
+
} from 'react'
|
|
28
|
+
import {
|
|
29
|
+
View,
|
|
30
|
+
ViewStyle
|
|
31
|
+
} from 'react-native'
|
|
32
|
+
import { GestureDetector, Gesture, GestureStateChangeEvent, PanGestureHandlerEventPayload } from 'react-native-gesture-handler'
|
|
33
|
+
import Animated, { useSharedValue, useAnimatedStyle, runOnJS } from 'react-native-reanimated'
|
|
34
|
+
import { warn } from '@mpxjs/utils'
|
|
35
|
+
|
|
36
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
37
|
+
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
38
|
+
import { useLayout, useTransformStyle, extendObject, useRunOnJSCallback } from './utils'
|
|
39
|
+
import Portal from './mpx-portal'
|
|
40
|
+
import { FormContext, FormFieldValue } from './context'
|
|
41
|
+
|
|
42
|
+
export interface SliderProps {
|
|
43
|
+
min?: number
|
|
44
|
+
max?: number
|
|
45
|
+
step?: number
|
|
46
|
+
disabled?: boolean
|
|
47
|
+
value?: number
|
|
48
|
+
color?: string
|
|
49
|
+
'selected-color'?: string
|
|
50
|
+
activeColor?: string
|
|
51
|
+
backgroundColor?: string
|
|
52
|
+
'block-size'?: number
|
|
53
|
+
'block-color'?: string
|
|
54
|
+
name?: string
|
|
55
|
+
bindchange?: (event: any) => void
|
|
56
|
+
catchchange?: (event: any) => void
|
|
57
|
+
bindchanging?: (event: any) => void
|
|
58
|
+
catchchanging?: (event: any) => void
|
|
59
|
+
style?: ViewStyle & Record<string, any>
|
|
60
|
+
'enable-offset'?: boolean
|
|
61
|
+
'enable-var'?: boolean
|
|
62
|
+
'external-var-context'?: Record<string, any>
|
|
63
|
+
'parent-font-size'?: number
|
|
64
|
+
'parent-width'?: number
|
|
65
|
+
'parent-height'?: number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const Slider = forwardRef<
|
|
69
|
+
HandlerRef<View, SliderProps>,
|
|
70
|
+
SliderProps
|
|
71
|
+
>((props: SliderProps, ref: ForwardedRef<HandlerRef<View, SliderProps>>): JSX.Element => {
|
|
72
|
+
const {
|
|
73
|
+
min: rawMin = 0,
|
|
74
|
+
max: rawMax = 100,
|
|
75
|
+
step: rawStep = 1,
|
|
76
|
+
disabled = false,
|
|
77
|
+
value: rawValue,
|
|
78
|
+
color,
|
|
79
|
+
'selected-color': selectedColor,
|
|
80
|
+
activeColor = selectedColor || color || '#1aad19',
|
|
81
|
+
backgroundColor = color || '#e9e9e9',
|
|
82
|
+
'block-size': rawBlockSize = 28,
|
|
83
|
+
'block-color': blockColor = '#ffffff',
|
|
84
|
+
name,
|
|
85
|
+
style = {},
|
|
86
|
+
'enable-var': enableVar,
|
|
87
|
+
'external-var-context': externalVarContext,
|
|
88
|
+
'parent-font-size': parentFontSize,
|
|
89
|
+
'parent-width': parentWidth,
|
|
90
|
+
'parent-height': parentHeight
|
|
91
|
+
} = props
|
|
92
|
+
|
|
93
|
+
// 确保数值类型正确
|
|
94
|
+
const min = typeof rawMin === 'string' ? parseFloat(rawMin) : rawMin
|
|
95
|
+
const max = typeof rawMax === 'string' ? parseFloat(rawMax) : rawMax
|
|
96
|
+
const step = typeof rawStep === 'string' ? parseFloat(rawStep) : rawStep
|
|
97
|
+
const value = rawValue !== undefined ? (typeof rawValue === 'string' ? parseFloat(rawValue) : rawValue) : undefined
|
|
98
|
+
const blockSize = typeof rawBlockSize === 'string' ? parseFloat(rawBlockSize) : rawBlockSize
|
|
99
|
+
|
|
100
|
+
// 如果没有提供 value,则使用 min 作为默认值
|
|
101
|
+
const defaultValue = value !== undefined ? value : min
|
|
102
|
+
const nodeRef = useRef(null)
|
|
103
|
+
const trackRef = useRef(null)
|
|
104
|
+
const [currentValue, setCurrentValue] = useState(defaultValue)
|
|
105
|
+
const [trackWidth, setTrackWidth] = useState(0)
|
|
106
|
+
|
|
107
|
+
const thumbPosition = useSharedValue(0)
|
|
108
|
+
const isDragging = useSharedValue(false)
|
|
109
|
+
const startDragPosition = useSharedValue(0) // 记录拖拽开始时的位置
|
|
110
|
+
const startDragValue = useSharedValue(0) // 记录拖拽开始时的值
|
|
111
|
+
|
|
112
|
+
let formValuesMap: Map<string, FormFieldValue> | undefined
|
|
113
|
+
|
|
114
|
+
const propsRef = useRef(props)
|
|
115
|
+
propsRef.current = props
|
|
116
|
+
|
|
117
|
+
const formContext = useContext(FormContext)
|
|
118
|
+
|
|
119
|
+
if (formContext) {
|
|
120
|
+
formValuesMap = formContext.formValuesMap
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const {
|
|
124
|
+
normalStyle,
|
|
125
|
+
hasSelfPercent,
|
|
126
|
+
setWidth,
|
|
127
|
+
setHeight,
|
|
128
|
+
hasPositionFixed
|
|
129
|
+
} = useTransformStyle(style, {
|
|
130
|
+
enableVar,
|
|
131
|
+
externalVarContext,
|
|
132
|
+
parentFontSize,
|
|
133
|
+
parentWidth,
|
|
134
|
+
parentHeight
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({
|
|
138
|
+
props,
|
|
139
|
+
hasSelfPercent,
|
|
140
|
+
setWidth,
|
|
141
|
+
setHeight,
|
|
142
|
+
nodeRef
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
useNodesRef(props, ref, nodeRef, {
|
|
146
|
+
style: normalStyle
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// 使用 useRunOnJSCallback 处理手势回调
|
|
150
|
+
const runOnJSCallbackRef = useRef({
|
|
151
|
+
triggerChangeEvent: (newValue: number) => {
|
|
152
|
+
setCurrentValue(newValue)
|
|
153
|
+
const currentProps = propsRef.current
|
|
154
|
+
const changeHandler = currentProps.bindchange || currentProps.catchchange
|
|
155
|
+
if (changeHandler) {
|
|
156
|
+
changeHandler(getCustomEvent('change', {}, { layoutRef, detail: { value: newValue } }, currentProps))
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
triggerChangingEvent: (newValue: number) => {
|
|
160
|
+
const currentProps = propsRef.current
|
|
161
|
+
const changingHandler = currentProps.bindchanging || currentProps.catchchanging
|
|
162
|
+
if (changingHandler) {
|
|
163
|
+
changingHandler(getCustomEvent('changing', {}, { layoutRef, detail: { value: newValue } }, currentProps))
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
|
|
168
|
+
|
|
169
|
+
// 限制步长,确保 step 大于 0,并且可被 (max - min) 整除
|
|
170
|
+
const validateStep = (step: number, min: number, max: number): number => {
|
|
171
|
+
if (step <= 0) return 1
|
|
172
|
+
if ((max - min) % step !== 0) {
|
|
173
|
+
warn(`Step ${step} is not a divisor of range ${max - min}`)
|
|
174
|
+
}
|
|
175
|
+
return step
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const validStep = validateStep(step, min, max)
|
|
179
|
+
|
|
180
|
+
// 将值约束在 min-max 范围内,并按步长对齐
|
|
181
|
+
const constrainValue = (val: number, minVal: number = min, maxVal: number = max, stepVal: number = validStep): number => {
|
|
182
|
+
const constrained = Math.max(minVal, Math.min(maxVal, val))
|
|
183
|
+
const steps = Math.round((constrained - minVal) / stepVal)
|
|
184
|
+
return minVal + steps * stepVal
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 计算滑块位置
|
|
188
|
+
const getThumbPosition = (val: number, trackW: number = trackWidth, minVal: number = min, maxVal: number = max): number => {
|
|
189
|
+
if (trackW === 0) return 0
|
|
190
|
+
const percentage = (val - minVal) / (maxVal - minVal)
|
|
191
|
+
const position = percentage * trackW
|
|
192
|
+
return position
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// 手势处理
|
|
196
|
+
const panGesture = useMemo(() => {
|
|
197
|
+
const getThumbPositionWorklet = (val: number, trackW: number, minVal: number, maxVal: number): number => {
|
|
198
|
+
'worklet'
|
|
199
|
+
if (trackW === 0) return 0
|
|
200
|
+
const percentage = (val - minVal) / (maxVal - minVal)
|
|
201
|
+
return percentage * trackW
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const constrainValueWorklet = (val: number, minVal: number, maxVal: number, stepVal: number): number => {
|
|
205
|
+
'worklet'
|
|
206
|
+
const constrained = Math.max(minVal, Math.min(maxVal, val))
|
|
207
|
+
const steps = Math.round((constrained - minVal) / stepVal)
|
|
208
|
+
return minVal + steps * stepVal
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return Gesture.Pan()
|
|
212
|
+
.enabled(!disabled) // 通过手势启用状态控制是否可拖拽
|
|
213
|
+
.onBegin(() => {
|
|
214
|
+
'worklet'
|
|
215
|
+
if (trackWidth === 0) return
|
|
216
|
+
isDragging.value = true
|
|
217
|
+
// 记录拖拽开始时的位置 - 使用当前的动画位置
|
|
218
|
+
startDragPosition.value = thumbPosition.value
|
|
219
|
+
// 根据当前位置反推值
|
|
220
|
+
const percentage = thumbPosition.value / trackWidth
|
|
221
|
+
const currentVal = min + percentage * (max - min)
|
|
222
|
+
startDragValue.value = constrainValueWorklet(currentVal, min, max, validStep)
|
|
223
|
+
})
|
|
224
|
+
.onUpdate((event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
225
|
+
'worklet'
|
|
226
|
+
if (trackWidth === 0) return
|
|
227
|
+
|
|
228
|
+
// 基于拖拽开始位置计算新位置
|
|
229
|
+
const newX = startDragPosition.value + event.translationX
|
|
230
|
+
const clampedX = Math.max(0, Math.min(trackWidth, newX))
|
|
231
|
+
|
|
232
|
+
// 计算新值
|
|
233
|
+
const percentage = clampedX / trackWidth
|
|
234
|
+
const rawValue = min + percentage * (max - min)
|
|
235
|
+
const newValue = constrainValueWorklet(rawValue, min, max, validStep)
|
|
236
|
+
|
|
237
|
+
// 更新滑块位置 - 使用约束后的值对应的位置
|
|
238
|
+
const constrainedPosition = getThumbPositionWorklet(newValue, trackWidth, min, max)
|
|
239
|
+
thumbPosition.value = constrainedPosition
|
|
240
|
+
|
|
241
|
+
// 只触发 changing 事件,不更新 currentValue(避免干扰拖拽)
|
|
242
|
+
runOnJS(runOnJSCallback)('triggerChangingEvent', newValue)
|
|
243
|
+
})
|
|
244
|
+
.onEnd((event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
245
|
+
'worklet'
|
|
246
|
+
isDragging.value = false
|
|
247
|
+
|
|
248
|
+
// 基于拖拽开始位置计算最终位置
|
|
249
|
+
const newX = startDragPosition.value + event.translationX
|
|
250
|
+
const clampedX = Math.max(0, Math.min(trackWidth, newX))
|
|
251
|
+
const percentage = clampedX / trackWidth
|
|
252
|
+
const rawValue = min + percentage * (max - min)
|
|
253
|
+
const finalValue = constrainValueWorklet(rawValue, min, max, validStep)
|
|
254
|
+
|
|
255
|
+
// 确保滑块位置与最终值匹配
|
|
256
|
+
const finalPosition = getThumbPositionWorklet(finalValue, trackWidth, min, max)
|
|
257
|
+
thumbPosition.value = finalPosition
|
|
258
|
+
|
|
259
|
+
// 更新 currentValue 并触发 change 事件
|
|
260
|
+
runOnJS(runOnJSCallback)('triggerChangeEvent', finalValue)
|
|
261
|
+
})
|
|
262
|
+
}, [disabled, trackWidth, min, max, validStep, runOnJSCallback])
|
|
263
|
+
|
|
264
|
+
// 当 value 属性变化时更新位置
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
const newValue = constrainValue(defaultValue)
|
|
267
|
+
setCurrentValue(newValue)
|
|
268
|
+
// 同时更新动画位置
|
|
269
|
+
thumbPosition.value = getThumbPosition(newValue)
|
|
270
|
+
}, [defaultValue, min, max, validStep])
|
|
271
|
+
|
|
272
|
+
// 当 trackWidth 变化时更新滑块位置
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
// 只在非拖拽状态下更新位置
|
|
275
|
+
if (!isDragging.value) {
|
|
276
|
+
thumbPosition.value = getThumbPosition(currentValue)
|
|
277
|
+
}
|
|
278
|
+
}, [trackWidth, currentValue])
|
|
279
|
+
|
|
280
|
+
// 动画样式
|
|
281
|
+
const animatedThumbStyle = useAnimatedStyle(() => {
|
|
282
|
+
const blockSizeNum = Math.max(12, Math.min(28, blockSize))
|
|
283
|
+
const trackHeight = 4
|
|
284
|
+
return {
|
|
285
|
+
position: 'absolute',
|
|
286
|
+
top: -((blockSizeNum - trackHeight) / 2),
|
|
287
|
+
left: Math.max(0, Math.min(trackWidth - blockSizeNum, thumbPosition.value - (blockSizeNum / 2))),
|
|
288
|
+
width: blockSizeNum,
|
|
289
|
+
height: blockSizeNum,
|
|
290
|
+
justifyContent: 'center',
|
|
291
|
+
alignItems: 'center'
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
// 轨道布局回调
|
|
296
|
+
const onTrackLayout = (event: any) => {
|
|
297
|
+
const { width } = event.nativeEvent.layout
|
|
298
|
+
setTrackWidth(width)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 表单相关处理
|
|
302
|
+
const resetValue = () => {
|
|
303
|
+
const currentProps = propsRef.current
|
|
304
|
+
const currentValue = currentProps.value !== undefined ? currentProps.value : currentProps.min || 0
|
|
305
|
+
const parsedValue = typeof currentValue === 'string' ? parseFloat(currentValue) : currentValue
|
|
306
|
+
const currentMin = typeof currentProps.min === 'string' ? parseFloat(currentProps.min) : (currentProps.min || 0)
|
|
307
|
+
const currentMax = typeof currentProps.max === 'string' ? parseFloat(currentProps.max) : (currentProps.max || 100)
|
|
308
|
+
const currentStep = typeof currentProps.step === 'string' ? parseFloat(currentProps.step) : (currentProps.step || 1)
|
|
309
|
+
const resetVal = parsedValue !== undefined ? parsedValue : currentMin
|
|
310
|
+
const validatedStep = validateStep(currentStep, currentMin, currentMax)
|
|
311
|
+
const constrainedVal = constrainValue(resetVal, currentMin, currentMax, validatedStep)
|
|
312
|
+
setCurrentValue(constrainedVal)
|
|
313
|
+
thumbPosition.value = getThumbPosition(constrainedVal, trackWidth, currentMin, currentMax)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const getValue = () => {
|
|
317
|
+
return currentValue
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (formValuesMap) {
|
|
321
|
+
if (!name) {
|
|
322
|
+
warn('If a form component is used, the name attribute is required.')
|
|
323
|
+
} else {
|
|
324
|
+
formValuesMap.set(name, { getValue, resetValue })
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
useEffect(() => {
|
|
329
|
+
return () => {
|
|
330
|
+
if (formValuesMap && name) {
|
|
331
|
+
formValuesMap.delete(name)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}, [])
|
|
335
|
+
|
|
336
|
+
// 样式定义
|
|
337
|
+
const blockSizeNum = Math.max(12, Math.min(28, blockSize))
|
|
338
|
+
const trackHeight = 4
|
|
339
|
+
|
|
340
|
+
const containerStyle: ViewStyle = extendObject({} as ViewStyle, {
|
|
341
|
+
flexDirection: 'row' as const,
|
|
342
|
+
alignItems: 'center' as const,
|
|
343
|
+
minHeight: Math.max(blockSizeNum + 8, 40),
|
|
344
|
+
paddingHorizontal: 14 // 固定内边距,不受 block-size 影响
|
|
345
|
+
}, normalStyle, layoutStyle)
|
|
346
|
+
|
|
347
|
+
const trackStyle: ViewStyle = {
|
|
348
|
+
flex: 1,
|
|
349
|
+
height: trackHeight,
|
|
350
|
+
backgroundColor,
|
|
351
|
+
borderRadius: trackHeight / 2,
|
|
352
|
+
position: 'relative'
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 动画进度条样式
|
|
356
|
+
const animatedProgressStyle = useAnimatedStyle(() => {
|
|
357
|
+
return {
|
|
358
|
+
height: '100%',
|
|
359
|
+
backgroundColor: activeColor,
|
|
360
|
+
borderRadius: trackHeight / 2,
|
|
361
|
+
width: Math.max(0, thumbPosition.value)
|
|
362
|
+
}
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
const thumbStyle: ViewStyle = {
|
|
366
|
+
width: blockSizeNum,
|
|
367
|
+
height: blockSizeNum,
|
|
368
|
+
backgroundColor: blockColor,
|
|
369
|
+
borderRadius: blockSizeNum / 2,
|
|
370
|
+
shadowColor: '#000',
|
|
371
|
+
shadowOffset: { width: 0, height: 2 },
|
|
372
|
+
shadowOpacity: 0.2,
|
|
373
|
+
shadowRadius: 4,
|
|
374
|
+
elevation: 4
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const innerProps = useInnerProps(
|
|
378
|
+
extendObject({}, props, layoutProps, {
|
|
379
|
+
ref: nodeRef
|
|
380
|
+
}),
|
|
381
|
+
[
|
|
382
|
+
'min',
|
|
383
|
+
'max',
|
|
384
|
+
'step',
|
|
385
|
+
'disabled',
|
|
386
|
+
'value',
|
|
387
|
+
'color',
|
|
388
|
+
'selected-color',
|
|
389
|
+
'activeColor',
|
|
390
|
+
'backgroundColor',
|
|
391
|
+
'block-size',
|
|
392
|
+
'block-color',
|
|
393
|
+
'bindchange',
|
|
394
|
+
'catchchange',
|
|
395
|
+
'bindchanging',
|
|
396
|
+
'catchchanging'
|
|
397
|
+
],
|
|
398
|
+
{ layoutRef }
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
const sliderContent = createElement(
|
|
402
|
+
View,
|
|
403
|
+
extendObject({}, innerProps, { style: containerStyle }),
|
|
404
|
+
// 轨道容器
|
|
405
|
+
createElement(
|
|
406
|
+
View,
|
|
407
|
+
{
|
|
408
|
+
style: trackStyle,
|
|
409
|
+
onLayout: onTrackLayout,
|
|
410
|
+
ref: trackRef
|
|
411
|
+
},
|
|
412
|
+
// 进度条 - 使用动画样式
|
|
413
|
+
createElement(Animated.View, {
|
|
414
|
+
style: animatedProgressStyle
|
|
415
|
+
}),
|
|
416
|
+
// 滑块容器
|
|
417
|
+
createElement(
|
|
418
|
+
GestureDetector,
|
|
419
|
+
{
|
|
420
|
+
gesture: panGesture
|
|
421
|
+
},
|
|
422
|
+
createElement(
|
|
423
|
+
Animated.View,
|
|
424
|
+
{
|
|
425
|
+
style: [animatedThumbStyle]
|
|
426
|
+
},
|
|
427
|
+
// 滑块
|
|
428
|
+
createElement(View, {
|
|
429
|
+
style: thumbStyle
|
|
430
|
+
})
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
)
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
if (hasPositionFixed) {
|
|
437
|
+
return createElement(Portal, null, sliderContent)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return sliderContent
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
Slider.displayName = 'MpxSlider'
|
|
444
|
+
export default Slider
|
|
@@ -148,7 +148,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
148
148
|
autoplay = false,
|
|
149
149
|
circular = false,
|
|
150
150
|
disableGesture = false,
|
|
151
|
-
current: propCurrent
|
|
151
|
+
current: propCurrent,
|
|
152
152
|
bindchange
|
|
153
153
|
} = props
|
|
154
154
|
const easeingFunc = props['easing-function'] || 'default'
|
|
@@ -199,10 +199,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
199
199
|
// 每个元素的宽度 or 高度,有固定值直接初始化无则0
|
|
200
200
|
const step = useSharedValue(initStep)
|
|
201
201
|
// 记录选中元素的索引值
|
|
202
|
-
const currentIndex = useSharedValue(propCurrent)
|
|
202
|
+
const currentIndex = useSharedValue(propCurrent || 0)
|
|
203
203
|
// const initOffset = getOffset(props.current || 0, initStep)
|
|
204
204
|
// 记录元素的偏移量
|
|
205
|
-
const offset = useSharedValue(getOffset(propCurrent, initStep))
|
|
205
|
+
const offset = useSharedValue(getOffset(propCurrent || 0, initStep))
|
|
206
206
|
const strAbso = 'absolute' + dir.toUpperCase() as StrAbsoType
|
|
207
207
|
const strVelocity = 'velocity' + dir.toUpperCase() as StrVelocityType
|
|
208
208
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
@@ -271,7 +271,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
271
271
|
const iStep = dir === 'x' ? realWidth : realHeight
|
|
272
272
|
if (iStep !== step.value) {
|
|
273
273
|
step.value = iStep
|
|
274
|
-
updateCurrent(propCurrent, iStep)
|
|
274
|
+
updateCurrent(propCurrent || 0, iStep)
|
|
275
275
|
updateAutoplay()
|
|
276
276
|
}
|
|
277
277
|
}
|
|
@@ -520,7 +520,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
520
520
|
// 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
|
|
521
521
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
522
522
|
if (propCurrent !== currentIndex.value) {
|
|
523
|
-
updateCurrent(propCurrent, step.value)
|
|
523
|
+
updateCurrent(propCurrent || 0, step.value)
|
|
524
524
|
}
|
|
525
525
|
}, [propCurrent])
|
|
526
526
|
|
|
@@ -790,6 +790,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
790
790
|
}
|
|
791
791
|
preAbsolutePos.value = e[strAbso]
|
|
792
792
|
})
|
|
793
|
+
.onEnd((e) => {
|
|
794
|
+
// 修复部分安卓机型下onFinalize拿到的absolute值 和 onUpdate不一致的情况,通过onEnd进行修正为最终的位置
|
|
795
|
+
preAbsolutePos.value = e[strAbso]
|
|
796
|
+
})
|
|
793
797
|
.onFinalize((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
794
798
|
'worklet'
|
|
795
799
|
if (touchfinish.value) return
|