@mpxjs/webpack-plugin 2.10.16-beta.7 → 2.10.16-perf.1
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 +0 -60
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/file-loader.js +3 -13
- package/lib/helpers.js +0 -2
- package/lib/index.js +15 -40
- package/lib/json-compiler/helper.js +2 -72
- package/lib/json-compiler/index.js +56 -16
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +4 -10
- package/lib/native-loader.js +3 -6
- package/lib/platform/json/wx/index.js +29 -30
- package/lib/platform/style/wx/index.js +1 -8
- package/lib/platform/template/wx/component-config/ad.js +0 -5
- package/lib/platform/template/wx/component-config/button.js +5 -21
- package/lib/platform/template/wx/component-config/camera.js +3 -25
- package/lib/platform/template/wx/component-config/canvas.js +1 -8
- package/lib/platform/template/wx/component-config/component.js +33 -31
- package/lib/platform/template/wx/component-config/cover-image.js +2 -7
- package/lib/platform/template/wx/component-config/cover-view.js +1 -3
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/form.js +2 -27
- package/lib/platform/template/wx/component-config/image.js +0 -5
- package/lib/platform/template/wx/component-config/input.js +0 -10
- package/lib/platform/template/wx/component-config/label.js +2 -10
- package/lib/platform/template/wx/component-config/map.js +0 -11
- package/lib/platform/template/wx/component-config/movable-area.js +1 -4
- package/lib/platform/template/wx/component-config/movable-view.js +2 -17
- package/lib/platform/template/wx/component-config/navigator.js +0 -26
- package/lib/platform/template/wx/component-config/picker-view.js +0 -12
- package/lib/platform/template/wx/component-config/picker.js +1 -3
- package/lib/platform/template/wx/component-config/progress.js +1 -11
- package/lib/platform/template/wx/component-config/rich-text.js +0 -5
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -12
- package/lib/platform/template/wx/component-config/slider.js +0 -8
- package/lib/platform/template/wx/component-config/swiper-item.js +2 -5
- package/lib/platform/template/wx/component-config/swiper.js +0 -10
- package/lib/platform/template/wx/component-config/text.js +0 -5
- package/lib/platform/template/wx/component-config/textarea.js +2 -19
- package/lib/platform/template/wx/component-config/unsupported.js +1 -10
- package/lib/platform/template/wx/component-config/video.js +0 -10
- package/lib/platform/template/wx/index.js +1 -21
- package/lib/react/index.js +0 -2
- package/lib/react/processJSON.js +71 -39
- package/lib/react/processStyles.js +2 -3
- package/lib/react/processTemplate.js +6 -8
- package/lib/react/script-helper.js +16 -6
- package/lib/react/style-helper.js +2 -10
- package/lib/runtime/components/react/context.ts +6 -12
- package/lib/runtime/components/react/dist/context.js +0 -1
- package/lib/runtime/components/react/dist/mpx-image.jsx +62 -100
- package/lib/runtime/components/react/dist/mpx-input.jsx +9 -35
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +50 -58
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +3 -4
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +18 -12
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +11 -8
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +1 -5
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +14 -6
- package/lib/runtime/components/react/dist/mpx-text.jsx +5 -33
- package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/utils.jsx +6 -16
- package/lib/runtime/components/react/mpx-image.tsx +82 -123
- package/lib/runtime/components/react/mpx-input.tsx +16 -41
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +49 -66
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +2 -5
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +21 -26
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +12 -8
- package/lib/runtime/components/react/mpx-portal/index.tsx +2 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +17 -6
- package/lib/runtime/components/react/mpx-text.tsx +5 -38
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/types/common.d.ts +0 -19
- package/lib/runtime/components/react/utils.tsx +6 -15
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/script-setup-compiler/index.js +2 -2
- package/lib/style-compiler/index.js +2 -3
- package/lib/style-compiler/load-postcss-config.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +2 -10
- package/lib/style-compiler/strip-conditional-loader.js +15 -178
- package/lib/template-compiler/bind-this.js +2 -2
- package/lib/template-compiler/compiler.js +72 -270
- package/lib/template-compiler/gen-node-react.js +6 -18
- package/lib/template-compiler/index.js +10 -12
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +1 -2
- package/lib/utils/dom-tag-config.js +6 -6
- package/lib/utils/env.js +1 -6
- package/lib/utils/pre-process-json.js +0 -5
- package/lib/web/index.js +0 -2
- package/lib/web/processJSON.js +16 -44
- package/lib/web/processScript.js +1 -1
- package/lib/web/processTemplate.js +4 -6
- package/lib/web/script-helper.js +9 -19
- package/lib/wxs/pre-loader.js +1 -1
- package/lib/wxss/loader.js +9 -1
- package/package.json +4 -15
- package/lib/dependencies/RecordModuleIdMapDependency.js +0 -49
- package/lib/runtime/components/react/dist/context.d.ts +0 -75
- package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/event.config.d.ts +0 -8
- package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -8
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -13
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -69
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -28
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.jsx +0 -102
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -24
- 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 +0 -8
- 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 +0 -7
- 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 +0 -21
- 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 +0 -9
- 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 +0 -11
- 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 +0 -3
- 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 +0 -33
- 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 +0 -53
- 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 +0 -21
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -33
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -28
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -19
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -22
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -50
- 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 +0 -13
- 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 +0 -21
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -21
- 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 +0 -66
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -9
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.jsx +0 -132
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -10
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -7
- 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 +0 -8
- 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 +0 -7
- 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 +0 -7
- 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 +0 -7
- 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 +0 -3
- 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 +0 -7
- 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 +0 -7
- 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 +0 -107
- 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 +0 -33
- 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 +0 -9
- 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 +0 -24
- 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 +0 -15
- 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 +0 -14
- 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/pickerViewColumnItemLite.jsx +0 -20
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -17
- 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 +0 -13
- 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 +0 -12
- 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 +0 -23
- 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 +0 -17
- 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 +0 -16
- 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 +0 -30
- 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 +0 -10
- 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 +0 -24
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -21
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -27
- 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 +0 -2
- 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 +0 -25
- 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 +0 -15
- 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 +0 -55
- 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 +0 -8
- 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 +0 -8
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -31
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -18
- 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 +0 -16
- 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 +0 -19
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +0 -53
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -27
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -23
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -8
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -102
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts +0 -35
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -23
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/parser.d.ts +0 -40
- 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/useNodesRef.d.ts +0 -12
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts +0 -123
- package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/mpx-camera.tsx +0 -167
- package/lib/runtime/components/react/mpx-nav.tsx +0 -155
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +0 -55
- package/lib/utils/get-build-tag-component.js +0 -35
|
@@ -62,8 +62,8 @@ export interface ImageProps {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
interface ImageState {
|
|
65
|
-
viewWidth
|
|
66
|
-
viewHeight
|
|
65
|
+
viewWidth?: number
|
|
66
|
+
viewHeight?: number
|
|
67
67
|
imageWidth?: number
|
|
68
68
|
imageHeight?: number
|
|
69
69
|
ratio?: number
|
|
@@ -93,20 +93,9 @@ const ModeMap = new Map<Mode, ImageResizeMode | undefined>([
|
|
|
93
93
|
...cropMode.map<[Mode, ImageResizeMode]>(mode => [mode, 'stretch'])
|
|
94
94
|
])
|
|
95
95
|
|
|
96
|
-
const isNumber = (value: DimensionValue)
|
|
96
|
+
const isNumber = (value: DimensionValue) => typeof value === 'number'
|
|
97
97
|
|
|
98
|
-
const relativeCenteredSize = (viewSize: number, imageSize: number) =>
|
|
99
|
-
return (viewSize - imageSize) / 2
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 获取能完全显示图片的缩放比例:长宽方向的缩放比例最小值即为能完全展示的比例
|
|
103
|
-
function getFitScale (width1: number, height1: number, width2: number, height2: number) {
|
|
104
|
-
return Math.min(width2 / width1, height2 / height1)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function getFillScale (width1: number, height1: number, width2: number, height2: number) {
|
|
108
|
-
return Math.max(width2 / width1, height2 / height1)
|
|
109
|
-
}
|
|
98
|
+
const relativeCenteredSize = (viewSize: number, imageSize: number) => (viewSize - imageSize) / 2
|
|
110
99
|
|
|
111
100
|
function noMeetCalcRule (isSvg: boolean, mode: Mode, viewWidth: number, viewHeight: number, ratio: number) {
|
|
112
101
|
const isMeetSize = viewWidth && viewHeight && ratio
|
|
@@ -115,17 +104,6 @@ function noMeetCalcRule (isSvg: boolean, mode: Mode, viewWidth: number, viewHeig
|
|
|
115
104
|
return false
|
|
116
105
|
}
|
|
117
106
|
|
|
118
|
-
const getFixedWidth = (viewWidth: number, viewHeight: number, ratio: number) => {
|
|
119
|
-
if (!ratio) return viewWidth
|
|
120
|
-
const fixed = viewHeight / ratio
|
|
121
|
-
return !fixed ? viewWidth : fixed
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const getFixedHeight = (viewWidth: number, viewHeight: number, ratio: number) => {
|
|
125
|
-
const fixed = viewWidth * ratio
|
|
126
|
-
return !fixed ? viewHeight : fixed
|
|
127
|
-
}
|
|
128
|
-
|
|
129
107
|
const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, ref): JSX.Element => {
|
|
130
108
|
const {
|
|
131
109
|
src = '',
|
|
@@ -153,6 +131,8 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
153
131
|
{ overflow: 'hidden' }
|
|
154
132
|
)
|
|
155
133
|
|
|
134
|
+
const state = useRef<ImageState>({})
|
|
135
|
+
|
|
156
136
|
const nodeRef = useRef(null)
|
|
157
137
|
useNodesRef(props, ref, nodeRef, {
|
|
158
138
|
defaultStyle
|
|
@@ -168,18 +148,14 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
168
148
|
const onLayout = ({ nativeEvent: { layout: { width, height } } }: LayoutChangeEvent) => {
|
|
169
149
|
state.current.viewWidth = width
|
|
170
150
|
state.current.viewHeight = height
|
|
171
|
-
|
|
172
|
-
if (Math.abs(viewHeight - height) < 0.5 && Math.abs(viewWidth - width) < 0.5) {
|
|
173
|
-
if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
|
|
174
|
-
if (!loaded) setLoaded(true)
|
|
175
|
-
}
|
|
176
|
-
return
|
|
177
|
-
}
|
|
151
|
+
|
|
178
152
|
if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
|
|
153
|
+
setViewWidth(width)
|
|
154
|
+
setViewHeight(height)
|
|
179
155
|
setRatio(state.current.ratio)
|
|
180
156
|
setImageWidth(state.current.imageWidth)
|
|
181
157
|
setImageHeight(state.current.imageHeight)
|
|
182
|
-
|
|
158
|
+
state.current = {}
|
|
183
159
|
setLoaded(true)
|
|
184
160
|
}
|
|
185
161
|
}
|
|
@@ -210,57 +186,43 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
210
186
|
const [ratio, setRatio] = useState(0)
|
|
211
187
|
const [loaded, setLoaded] = useState(!isLayoutMode)
|
|
212
188
|
|
|
213
|
-
const
|
|
214
|
-
viewWidth
|
|
215
|
-
viewHeight
|
|
216
|
-
})
|
|
189
|
+
const fixedHeight = useMemo(() => {
|
|
190
|
+
const fixed = viewWidth * ratio
|
|
191
|
+
return !fixed ? viewHeight : fixed
|
|
192
|
+
}, [ratio, viewWidth, viewHeight])
|
|
217
193
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const fixedHeight = getFixedHeight(viewWidth, viewHeight, ratio)
|
|
224
|
-
setViewHeight(fixedHeight)
|
|
225
|
-
break
|
|
226
|
-
}
|
|
227
|
-
case 'heightFix': {
|
|
228
|
-
setViewHeight(viewHeight)
|
|
229
|
-
const fixedWidth = getFixedWidth(viewWidth, viewHeight, ratio)
|
|
230
|
-
setViewWidth(fixedWidth)
|
|
231
|
-
break
|
|
232
|
-
}
|
|
233
|
-
default:
|
|
234
|
-
setViewHeight(viewHeight)
|
|
235
|
-
setViewWidth(viewWidth)
|
|
236
|
-
break
|
|
237
|
-
}
|
|
238
|
-
}
|
|
194
|
+
const fixedWidth = useMemo(() => {
|
|
195
|
+
if (!ratio) return viewWidth
|
|
196
|
+
const fixed = viewHeight / ratio
|
|
197
|
+
return !fixed ? viewWidth : fixed
|
|
198
|
+
}, [ratio, viewWidth, viewHeight])
|
|
239
199
|
|
|
240
200
|
const modeStyle: ImageStyle = useMemo(() => {
|
|
241
201
|
if (noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio)) return {}
|
|
242
202
|
switch (mode) {
|
|
243
|
-
case 'scaleToFill':
|
|
203
|
+
case 'scaleToFill':
|
|
244
204
|
case 'aspectFit':
|
|
245
205
|
if (isSvg) {
|
|
246
|
-
const scale =
|
|
206
|
+
const scale = ratio <= 1
|
|
207
|
+
? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
|
|
208
|
+
: imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight
|
|
247
209
|
return {
|
|
248
210
|
transform: [
|
|
249
|
-
{
|
|
250
|
-
{ translateX:
|
|
251
|
-
{ scale }
|
|
211
|
+
{ scale },
|
|
212
|
+
ratio <= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
|
|
252
213
|
]
|
|
253
214
|
}
|
|
254
215
|
}
|
|
255
216
|
return {}
|
|
256
217
|
case 'aspectFill':
|
|
257
218
|
if (isSvg) {
|
|
258
|
-
const scale =
|
|
219
|
+
const scale = ratio >= 1
|
|
220
|
+
? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
|
|
221
|
+
: imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight
|
|
259
222
|
return {
|
|
260
223
|
transform: [
|
|
261
|
-
{
|
|
262
|
-
{ translateX:
|
|
263
|
-
{ scale }
|
|
224
|
+
{ scale },
|
|
225
|
+
ratio >= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
|
|
264
226
|
]
|
|
265
227
|
}
|
|
266
228
|
}
|
|
@@ -268,7 +230,9 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
268
230
|
case 'widthFix':
|
|
269
231
|
case 'heightFix':
|
|
270
232
|
if (isSvg) {
|
|
271
|
-
const scale =
|
|
233
|
+
const scale = ratio >= 1
|
|
234
|
+
? imageWidth >= fixedWidth ? fixedWidth / imageWidth : imageWidth / fixedWidth
|
|
235
|
+
: imageHeight >= fixedHeight ? fixedHeight / imageHeight : imageHeight / fixedHeight
|
|
272
236
|
return {
|
|
273
237
|
transform: [{ scale }]
|
|
274
238
|
}
|
|
@@ -331,25 +295,13 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
331
295
|
default:
|
|
332
296
|
return {}
|
|
333
297
|
}
|
|
334
|
-
}, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio])
|
|
298
|
+
}, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio, fixedWidth, fixedHeight])
|
|
335
299
|
|
|
336
300
|
const onSvgLoad = (evt: LayoutChangeEvent) => {
|
|
337
301
|
const { width, height } = evt.nativeEvent.layout
|
|
338
|
-
|
|
302
|
+
setRatio(!width ? 0 : height / width)
|
|
303
|
+
setImageWidth(width)
|
|
339
304
|
setImageHeight(height)
|
|
340
|
-
state.current.ratio = !width ? 0 : height / width
|
|
341
|
-
|
|
342
|
-
if (isWidthFixMode
|
|
343
|
-
? state.current.viewWidth
|
|
344
|
-
: isHeightFixMode
|
|
345
|
-
? state.current.viewHeight
|
|
346
|
-
: state.current.viewWidth && state.current.viewHeight) {
|
|
347
|
-
setRatio(state.current.ratio)
|
|
348
|
-
setImageWidth(width)
|
|
349
|
-
setImageHeight(height)
|
|
350
|
-
setViewSize(state.current.viewWidth!, state.current.viewHeight!, state.current.ratio)
|
|
351
|
-
setLoaded(true)
|
|
352
|
-
}
|
|
353
305
|
|
|
354
306
|
bindload && bindload(
|
|
355
307
|
getCustomEvent(
|
|
@@ -423,11 +375,12 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
423
375
|
: isHeightFixMode
|
|
424
376
|
? state.current.viewHeight
|
|
425
377
|
: state.current.viewWidth && state.current.viewHeight) {
|
|
426
|
-
|
|
378
|
+
state.current.viewWidth && setViewWidth(state.current.viewWidth)
|
|
379
|
+
state.current.viewHeight && setViewHeight(state.current.viewHeight)
|
|
380
|
+
setRatio(!width ? 0 : height / width)
|
|
427
381
|
setImageWidth(width)
|
|
428
382
|
setImageHeight(height)
|
|
429
|
-
|
|
430
|
-
|
|
383
|
+
state.current = {}
|
|
431
384
|
setLoaded(true)
|
|
432
385
|
}
|
|
433
386
|
},
|
|
@@ -449,8 +402,8 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
449
402
|
{},
|
|
450
403
|
normalStyle,
|
|
451
404
|
layoutStyle,
|
|
452
|
-
isHeightFixMode ? { width:
|
|
453
|
-
isWidthFixMode ? { height:
|
|
405
|
+
isHeightFixMode ? { width: fixedWidth } : {},
|
|
406
|
+
isWidthFixMode ? { height: fixedHeight } : {}
|
|
454
407
|
)
|
|
455
408
|
}
|
|
456
409
|
),
|
|
@@ -464,44 +417,50 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
464
417
|
}
|
|
465
418
|
)
|
|
466
419
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
{ transformOrigin: 'left top' },
|
|
476
|
-
modeStyle
|
|
477
|
-
)
|
|
478
|
-
})
|
|
479
|
-
)
|
|
480
|
-
|
|
481
|
-
const BaseImage = renderImage(
|
|
482
|
-
extendObject(
|
|
483
|
-
{
|
|
484
|
-
source: { uri: src },
|
|
485
|
-
resizeMode: resizeMode,
|
|
486
|
-
onLoad: bindload && onImageLoad,
|
|
487
|
-
onError: binderror && onImageError,
|
|
420
|
+
function renderSvgImage () {
|
|
421
|
+
return createElement(
|
|
422
|
+
View,
|
|
423
|
+
innerProps,
|
|
424
|
+
createElement(SvgCssUri, {
|
|
425
|
+
uri: src,
|
|
426
|
+
onLayout: onSvgLoad,
|
|
427
|
+
onError: binderror && onSvgError,
|
|
488
428
|
style: extendObject(
|
|
489
|
-
{
|
|
490
|
-
|
|
491
|
-
width: isCropMode ? imageWidth : '100%',
|
|
492
|
-
height: isCropMode ? imageHeight : '100%'
|
|
493
|
-
},
|
|
494
|
-
isCropMode ? modeStyle : {}
|
|
429
|
+
{ transformOrigin: 'left top' },
|
|
430
|
+
modeStyle
|
|
495
431
|
)
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
)
|
|
432
|
+
})
|
|
433
|
+
)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function renderBaseImage () {
|
|
437
|
+
return renderImage(
|
|
438
|
+
extendObject(
|
|
439
|
+
{
|
|
440
|
+
source: { uri: src },
|
|
441
|
+
resizeMode: resizeMode,
|
|
442
|
+
onLoad: bindload && onImageLoad,
|
|
443
|
+
onError: binderror && onImageError,
|
|
444
|
+
style: extendObject(
|
|
445
|
+
{
|
|
446
|
+
transformOrigin: 'left top',
|
|
447
|
+
width: isCropMode ? imageWidth : '100%',
|
|
448
|
+
height: isCropMode ? imageHeight : '100%'
|
|
449
|
+
},
|
|
450
|
+
isCropMode ? modeStyle : {}
|
|
451
|
+
)
|
|
452
|
+
},
|
|
453
|
+
isLayoutMode ? {} : innerProps
|
|
454
|
+
),
|
|
455
|
+
enableFastImage
|
|
456
|
+
)
|
|
457
|
+
}
|
|
501
458
|
|
|
502
|
-
|
|
459
|
+
function renderLayoutImage () {
|
|
460
|
+
return createElement(View, innerProps, loaded && renderBaseImage())
|
|
461
|
+
}
|
|
503
462
|
|
|
504
|
-
const finalComponent = isSvg ?
|
|
463
|
+
const finalComponent = isSvg ? renderSvgImage() : isLayoutMode ? renderLayoutImage() : renderBaseImage()
|
|
505
464
|
|
|
506
465
|
if (hasPositionFixed) {
|
|
507
466
|
return createElement(Portal, null, finalComponent)
|
|
@@ -280,8 +280,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
const setKeyboardAvoidContext = () => {
|
|
283
|
-
if (keyboardAvoid) {
|
|
284
|
-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef
|
|
283
|
+
if (adjustPosition && keyboardAvoid) {
|
|
284
|
+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef }
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
@@ -295,45 +295,20 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
const onFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
},
|
|
313
|
-
layoutRef
|
|
314
|
-
},
|
|
315
|
-
props
|
|
316
|
-
)
|
|
317
|
-
)
|
|
318
|
-
if (keyboardAvoid?.current?.onKeyboardShow) {
|
|
319
|
-
keyboardAvoid.current.onKeyboardShow = undefined
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
if (keyboardAvoid?.current) {
|
|
323
|
-
// 有 keyboardAvoiding
|
|
324
|
-
if (keyboardAvoid.current.keyboardHeight) {
|
|
325
|
-
// iOS: keyboard 获取高度时机 keyboardWillShow 在 input focus 之前,可以立即执行
|
|
326
|
-
focusAction()
|
|
327
|
-
} else {
|
|
328
|
-
// Android,Harmony: keyboard 获取高度时机 keyboardDidShow 在 input focus 之后,需要延迟回调
|
|
329
|
-
evt.persist()
|
|
330
|
-
keyboardAvoid.current.onKeyboardShow = focusAction
|
|
331
|
-
}
|
|
332
|
-
} else {
|
|
333
|
-
// 无 keyboardAvoiding,直接执行 focus 回调
|
|
334
|
-
focusAction()
|
|
335
|
-
}
|
|
336
|
-
}
|
|
298
|
+
setKeyboardAvoidContext()
|
|
299
|
+
bindfocus && bindfocus(
|
|
300
|
+
getCustomEvent(
|
|
301
|
+
'focus',
|
|
302
|
+
evt,
|
|
303
|
+
{
|
|
304
|
+
detail: {
|
|
305
|
+
value: tmpValue.current || ''
|
|
306
|
+
},
|
|
307
|
+
layoutRef
|
|
308
|
+
},
|
|
309
|
+
props
|
|
310
|
+
)
|
|
311
|
+
)
|
|
337
312
|
}
|
|
338
313
|
|
|
339
314
|
const onBlur = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { ReactNode, useContext, useEffect, useRef } from 'react'
|
|
1
|
+
import React, { ReactNode, useContext, useEffect } from 'react'
|
|
3
2
|
import { DimensionValue, EmitterSubscription, Keyboard, View, ViewStyle, NativeSyntheticEvent, NativeTouchEvent } from 'react-native'
|
|
4
|
-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing
|
|
3
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
|
|
5
4
|
import { KeyboardAvoidContext } from './context'
|
|
6
|
-
import {
|
|
5
|
+
import { isIOS } from './utils'
|
|
7
6
|
|
|
8
7
|
type KeyboardAvoidViewProps = {
|
|
9
8
|
children?: ReactNode
|
|
@@ -19,34 +18,15 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
19
18
|
const basic = useSharedValue('auto')
|
|
20
19
|
const keyboardAvoid = useContext(KeyboardAvoidContext)
|
|
21
20
|
|
|
22
|
-
// fix: 某些特殊机型下隐藏键盘可能会先触发一次 keyboardWillShow,
|
|
23
|
-
// 比如机型 iPhone 11 Pro,可能会导致显隐动画冲突
|
|
24
|
-
// 因此增加状态标记 + cancelAnimation 来优化
|
|
25
|
-
const isShow = useRef<boolean>(false)
|
|
26
|
-
|
|
27
21
|
const animatedStyle = useAnimatedStyle(() => ({
|
|
28
|
-
|
|
29
|
-
marginTop: -offset.value,
|
|
22
|
+
transform: [{ translateY: -offset.value }],
|
|
30
23
|
flexBasis: basic.value as DimensionValue
|
|
31
24
|
}))
|
|
32
25
|
|
|
33
26
|
const resetKeyboard = () => {
|
|
34
|
-
if (!isShow.current) {
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
isShow.current = false
|
|
39
|
-
|
|
40
27
|
if (keyboardAvoid?.current) {
|
|
41
|
-
const inputRef = keyboardAvoid.current.ref?.current
|
|
42
|
-
if (inputRef && inputRef.isFocused()) {
|
|
43
|
-
// 修复 Android 点击键盘收起按钮时当前 input 没触发失焦的问题
|
|
44
|
-
inputRef.blur()
|
|
45
|
-
}
|
|
46
28
|
keyboardAvoid.current = null
|
|
47
29
|
}
|
|
48
|
-
|
|
49
|
-
cancelAnimation(offset)
|
|
50
30
|
offset.value = withTiming(0, { duration, easing })
|
|
51
31
|
basic.value = 'auto'
|
|
52
32
|
}
|
|
@@ -60,55 +40,51 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
60
40
|
useEffect(() => {
|
|
61
41
|
let subscriptions: EmitterSubscription[] = []
|
|
62
42
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow } = keyboardAvoid.current
|
|
72
|
-
keyboardAvoid.current.keyboardHeight = endCoordinates.height
|
|
73
|
-
onKeyboardShow?.()
|
|
74
|
-
if (adjustPosition) {
|
|
75
|
-
// 默认沿用旧版本逻辑,在 android 原生关闭键盘避让的情况下应该将该配置设置为 false,走 mpx 的键盘避让逻辑,否则bundle内的所有input都会无法避让键盘
|
|
76
|
-
const enableNativeKeyboardAvoiding = mpxGlobal?.__mpx?.config?.rnConfig?.enableNativeKeyboardAvoiding ?? true
|
|
77
|
-
const callback = () => {
|
|
78
|
-
ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
|
|
79
|
-
function calculateOffset() {
|
|
80
|
-
// enableNativeKeyboardAvoding 默认开启
|
|
81
|
-
if (enableNativeKeyboardAvoiding && isAndroid) {
|
|
82
|
-
const aboveOffset = pageY + height - endCoordinates.screenY
|
|
83
|
-
const belowOffset = endCoordinates.height - aboveOffset
|
|
84
|
-
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
|
|
85
|
-
const belowValue = Math.min(belowOffset, cursorSpacing)
|
|
86
|
-
return aboveOffset > 0 ? belowValue : aboveValue
|
|
87
|
-
}
|
|
88
|
-
|
|
43
|
+
if (isIOS) {
|
|
44
|
+
subscriptions = [
|
|
45
|
+
Keyboard.addListener('keyboardWillShow', (evt: any) => {
|
|
46
|
+
if (!keyboardAvoid?.current) return
|
|
47
|
+
const { endCoordinates } = evt
|
|
48
|
+
const { ref, cursorSpacing = 0 } = keyboardAvoid.current
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
|
|
89
51
|
const aboveOffset = offset.value + pageY + height - endCoordinates.screenY
|
|
90
52
|
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
|
|
91
53
|
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
54
|
+
const value = aboveOffset > 0 ? belowValue : aboveValue
|
|
55
|
+
offset.value = withTiming(value, { duration, easing }, (finished) => {
|
|
56
|
+
if (finished) {
|
|
57
|
+
// Set flexBasic after animation to trigger re-layout and reset layout information
|
|
58
|
+
basic.value = '99.99%'
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
}),
|
|
64
|
+
Keyboard.addListener('keyboardWillHide', resetKeyboard)
|
|
65
|
+
]
|
|
66
|
+
} else {
|
|
67
|
+
subscriptions = [
|
|
68
|
+
Keyboard.addListener('keyboardDidShow', (evt: any) => {
|
|
69
|
+
if (!keyboardAvoid?.current) return
|
|
70
|
+
const { endCoordinates } = evt
|
|
71
|
+
const { ref, cursorSpacing = 0 } = keyboardAvoid.current
|
|
72
|
+
ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
|
|
73
|
+
const aboveOffset = pageY + height - endCoordinates.screenY
|
|
74
|
+
const belowOffset = endCoordinates.height - aboveOffset
|
|
75
|
+
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
|
|
76
|
+
const belowValue = Math.min(belowOffset, cursorSpacing)
|
|
77
|
+
const value = aboveOffset > 0 ? belowValue : aboveValue
|
|
78
|
+
offset.value = withTiming(value, { duration, easing }, (finished) => {
|
|
97
79
|
if (finished) {
|
|
98
80
|
// Set flexBasic after animation to trigger re-layout and reset layout information
|
|
99
81
|
basic.value = '99.99%'
|
|
100
82
|
}
|
|
101
83
|
})
|
|
102
84
|
})
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (isIOS) {
|
|
109
|
-
subscriptions = [Keyboard.addListener('keyboardWillShow', keybaordAvoding), Keyboard.addListener('keyboardWillHide', resetKeyboard)]
|
|
110
|
-
} else {
|
|
111
|
-
subscriptions = [Keyboard.addListener('keyboardDidShow', keybaordAvoding), Keyboard.addListener('keyboardDidHide', resetKeyboard)]
|
|
85
|
+
}),
|
|
86
|
+
Keyboard.addListener('keyboardDidHide', resetKeyboard)
|
|
87
|
+
]
|
|
112
88
|
}
|
|
113
89
|
|
|
114
90
|
return () => {
|
|
@@ -117,8 +93,15 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
117
93
|
}, [keyboardAvoid])
|
|
118
94
|
|
|
119
95
|
return (
|
|
120
|
-
<View style={style} onTouchEnd={onTouchEnd}
|
|
121
|
-
<Animated.View
|
|
96
|
+
<View style={style} onTouchEnd={onTouchEnd}>
|
|
97
|
+
<Animated.View
|
|
98
|
+
style={[
|
|
99
|
+
contentContainerStyle,
|
|
100
|
+
animatedStyle
|
|
101
|
+
]}
|
|
102
|
+
>
|
|
103
|
+
{children}
|
|
104
|
+
</Animated.View>
|
|
122
105
|
</View>
|
|
123
106
|
)
|
|
124
107
|
}
|
|
@@ -33,7 +33,6 @@ interface PickerViewProps {
|
|
|
33
33
|
style?: {
|
|
34
34
|
[key: string]: any
|
|
35
35
|
}
|
|
36
|
-
'enable-wheel-animation'?: boolean
|
|
37
36
|
'indicator-style'?: Record<string, any>,
|
|
38
37
|
'mask-style'?: Record<string, any>,
|
|
39
38
|
'enable-var'?: boolean
|
|
@@ -70,7 +69,6 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
70
69
|
value = [],
|
|
71
70
|
bindchange,
|
|
72
71
|
style,
|
|
73
|
-
'enable-wheel-animation': enableWheelAnimation = true,
|
|
74
72
|
'indicator-style': indicatorStyle = {},
|
|
75
73
|
'mask-style': pickerMaskStyle = {},
|
|
76
74
|
'enable-var': enableVar,
|
|
@@ -170,7 +168,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
170
168
|
columnData,
|
|
171
169
|
ref: cloneRef,
|
|
172
170
|
columnIndex: index,
|
|
173
|
-
key: `pick-view-${index}
|
|
171
|
+
key: `pick-view-${index}`,
|
|
174
172
|
wrapperStyle: {
|
|
175
173
|
height: normalStyle?.height || DefaultPickerItemH,
|
|
176
174
|
itemHeight: indicatorH || DefaultPickerItemH
|
|
@@ -178,8 +176,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
178
176
|
onSelectChange: onSelectChange.bind(null, index),
|
|
179
177
|
initialIndex,
|
|
180
178
|
pickerIndicatorStyle,
|
|
181
|
-
pickerMaskStyle
|
|
182
|
-
enableWheelAnimation
|
|
179
|
+
pickerMaskStyle
|
|
183
180
|
}
|
|
184
181
|
)
|
|
185
182
|
const realElement = React.cloneElement(child, wrappedProps)
|
|
@@ -5,8 +5,7 @@ import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAn
|
|
|
5
5
|
import useNodesRef, { HandlerRef } from '../useNodesRef'
|
|
6
6
|
import PickerIndicator from './pickerViewIndicator'
|
|
7
7
|
import PickerMask from './pickerViewMask'
|
|
8
|
-
import
|
|
9
|
-
import MpxPickerViewColumnItemLite from './pickerViewColumnItemLite'
|
|
8
|
+
import MpxPickerVIewColumnItem from './pickerViewColumnItem'
|
|
10
9
|
import { PickerViewColumnAnimationContext } from '../mpx-picker-view/pickerVIewContext'
|
|
11
10
|
import { calcHeightOffsets } from './pickerViewFaces'
|
|
12
11
|
|
|
@@ -26,7 +25,6 @@ interface ColumnProps {
|
|
|
26
25
|
}
|
|
27
26
|
pickerMaskStyle: Record<string, any>
|
|
28
27
|
pickerIndicatorStyle: Record<string, any>
|
|
29
|
-
enableWheelAnimation?: boolean
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
const visibleCount = 5
|
|
@@ -41,7 +39,6 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
41
39
|
wrapperStyle,
|
|
42
40
|
pickerMaskStyle,
|
|
43
41
|
pickerIndicatorStyle,
|
|
44
|
-
enableWheelAnimation = true,
|
|
45
42
|
'enable-var': enableVar,
|
|
46
43
|
'external-var-context': externalVarContext
|
|
47
44
|
} = props
|
|
@@ -98,11 +95,6 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
98
95
|
return [{ paddingVertical: paddingHeight }]
|
|
99
96
|
}, [paddingHeight])
|
|
100
97
|
|
|
101
|
-
const initialContentOffsetY = useMemo(
|
|
102
|
-
() => initialIndex * itemRawH,
|
|
103
|
-
[initialIndex, itemRawH]
|
|
104
|
-
)
|
|
105
|
-
|
|
106
98
|
const getIndex = useCallback((y: number) => {
|
|
107
99
|
const calc = Math.round(y / itemRawH)
|
|
108
100
|
return Math.max(0, Math.min(calc, maxIndex))
|
|
@@ -160,6 +152,17 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
160
152
|
}, isIOS ? 0 : 200)
|
|
161
153
|
}, [itemRawH, maxIndex, initialIndex])
|
|
162
154
|
|
|
155
|
+
const onContentSizeChange = useCallback((_w: number, h: number) => {
|
|
156
|
+
const y = initialIndex * itemRawH
|
|
157
|
+
if (y <= h) {
|
|
158
|
+
clearTimerScrollTo()
|
|
159
|
+
timerScrollTo.current = setTimeout(() => {
|
|
160
|
+
scrollViewRef.current?.scrollTo({ x: 0, y, animated: false })
|
|
161
|
+
activeIndex.current = initialIndex
|
|
162
|
+
}, 0)
|
|
163
|
+
}
|
|
164
|
+
}, [itemRawH, initialIndex])
|
|
165
|
+
|
|
163
166
|
const onItemLayout = useCallback((e: LayoutChangeEvent) => {
|
|
164
167
|
const { height: rawH } = e.nativeEvent.layout
|
|
165
168
|
const roundedH = Math.round(rawH)
|
|
@@ -284,8 +287,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
284
287
|
|
|
285
288
|
const renderInnerchild = () =>
|
|
286
289
|
columnData.map((item: React.ReactElement, index: number) => {
|
|
287
|
-
return
|
|
288
|
-
|
|
290
|
+
return (
|
|
291
|
+
<MpxPickerVIewColumnItem
|
|
289
292
|
key={index}
|
|
290
293
|
item={item}
|
|
291
294
|
index={index}
|
|
@@ -294,16 +297,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
294
297
|
textProps={textProps}
|
|
295
298
|
visibleCount={visibleCount}
|
|
296
299
|
onItemLayout={onItemLayout}
|
|
297
|
-
/>
|
|
298
|
-
|
|
299
|
-
key={index}
|
|
300
|
-
item={item}
|
|
301
|
-
index={index}
|
|
302
|
-
itemHeight={itemHeight}
|
|
303
|
-
textStyle={textStyle}
|
|
304
|
-
textProps={textProps}
|
|
305
|
-
onItemLayout={onItemLayout}
|
|
306
|
-
/>)
|
|
300
|
+
/>
|
|
301
|
+
)
|
|
307
302
|
})
|
|
308
303
|
|
|
309
304
|
const renderScollView = () => {
|
|
@@ -325,8 +320,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
325
320
|
onScrollEndDrag,
|
|
326
321
|
onMomentumScrollBegin,
|
|
327
322
|
onMomentumScrollEnd,
|
|
328
|
-
|
|
329
|
-
|
|
323
|
+
onContentSizeChange,
|
|
324
|
+
contentContainerStyle
|
|
330
325
|
}) as React.ComponentProps<typeof Reanimated.ScrollView>
|
|
331
326
|
|
|
332
327
|
return createElement(
|
|
@@ -356,9 +351,9 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
356
351
|
|
|
357
352
|
return (
|
|
358
353
|
<View style={[styles.wrapper, normalStyle]}>
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
354
|
+
{renderScollView()}
|
|
355
|
+
{renderMask()}
|
|
356
|
+
{renderIndicator()}
|
|
362
357
|
</View>
|
|
363
358
|
)
|
|
364
359
|
})
|