@mpxjs/webpack-plugin 2.10.16 → 2.10.17
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/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/helpers.js +2 -0
- package/lib/index.js +40 -15
- package/lib/json-compiler/helper.js +72 -2
- package/lib/json-compiler/index.js +14 -54
- 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 +24 -29
- package/lib/platform/style/wx/index.js +8 -1
- package/lib/platform/template/wx/component-config/button.js +12 -3
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- 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/runtime/components/react/context.ts +12 -6
- package/lib/runtime/components/react/dist/context.d.ts +75 -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-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/index.jsx +1 -1
- 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 +107 -57
- 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 +50 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +32 -8
- 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 +58 -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-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-rich-text/index.jsx +1 -1
- 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-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-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 +1 -1
- 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 +10 -2
- 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-canvas/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-image.tsx +130 -77
- package/lib/runtime/components/react/mpx-input.tsx +38 -15
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +66 -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-rich-text/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
- package/lib/runtime/components/react/mpx-text.tsx +38 -5
- package/lib/runtime/components/react/mpx-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +13 -4
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/utils.tsx +15 -6
- 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 +177 -15
- package/lib/template-compiler/compiler.js +268 -70
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +6 -4
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +2 -1
- package/lib/utils/dom-tag-config.js +5 -5
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -0
- package/lib/utils/merge-visitors.js +55 -0
- package/lib/utils/pre-process-json.js +5 -0
- package/lib/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 +9 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +15 -5
- package/lib/utils/chain-assign.js +0 -47
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable space-before-function-paren */
|
|
2
|
+
import React, { ReactNode, useContext, useEffect, useRef } from 'react'
|
|
2
3
|
import { DimensionValue, EmitterSubscription, Keyboard, View, ViewStyle, NativeSyntheticEvent, NativeTouchEvent } from 'react-native'
|
|
3
|
-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
|
|
4
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, cancelAnimation } from 'react-native-reanimated'
|
|
4
5
|
import { KeyboardAvoidContext } from './context'
|
|
5
|
-
import { isIOS } from './utils'
|
|
6
|
+
import { isAndroid, isIOS } from './utils'
|
|
6
7
|
|
|
7
8
|
type KeyboardAvoidViewProps = {
|
|
8
9
|
children?: ReactNode
|
|
@@ -18,15 +19,34 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
18
19
|
const basic = useSharedValue('auto')
|
|
19
20
|
const keyboardAvoid = useContext(KeyboardAvoidContext)
|
|
20
21
|
|
|
22
|
+
// fix: 某些特殊机型下隐藏键盘可能会先触发一次 keyboardWillShow,
|
|
23
|
+
// 比如机型 iPhone 11 Pro,可能会导致显隐动画冲突
|
|
24
|
+
// 因此增加状态标记 + cancelAnimation 来优化
|
|
25
|
+
const isShow = useRef<boolean>(false)
|
|
26
|
+
|
|
21
27
|
const animatedStyle = useAnimatedStyle(() => ({
|
|
22
|
-
|
|
28
|
+
// translate/position top可能会导致底部渲染区域缺失
|
|
29
|
+
marginTop: -offset.value,
|
|
23
30
|
flexBasis: basic.value as DimensionValue
|
|
24
31
|
}))
|
|
25
32
|
|
|
26
33
|
const resetKeyboard = () => {
|
|
34
|
+
if (!isShow.current) {
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
isShow.current = false
|
|
39
|
+
|
|
27
40
|
if (keyboardAvoid?.current) {
|
|
41
|
+
const inputRef = keyboardAvoid.current.ref?.current
|
|
42
|
+
if (inputRef && inputRef.isFocused()) {
|
|
43
|
+
// 修复 Android 点击键盘收起按钮时当前 input 没触发失焦的问题
|
|
44
|
+
inputRef.blur()
|
|
45
|
+
}
|
|
28
46
|
keyboardAvoid.current = null
|
|
29
47
|
}
|
|
48
|
+
|
|
49
|
+
cancelAnimation(offset)
|
|
30
50
|
offset.value = withTiming(0, { duration, easing })
|
|
31
51
|
basic.value = 'auto'
|
|
32
52
|
}
|
|
@@ -40,51 +60,55 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
40
60
|
useEffect(() => {
|
|
41
61
|
let subscriptions: EmitterSubscription[] = []
|
|
42
62
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
function keybaordAvoding(evt: any) {
|
|
64
|
+
if (!keyboardAvoid?.current || isShow.current) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
isShow.current = true
|
|
69
|
+
|
|
70
|
+
const { endCoordinates } = evt
|
|
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
|
+
|
|
51
89
|
const aboveOffset = offset.value + pageY + height - endCoordinates.screenY
|
|
52
90
|
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
|
|
53
91
|
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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) => {
|
|
92
|
+
return aboveOffset > 0 ? belowValue : aboveValue
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
cancelAnimation(offset)
|
|
96
|
+
offset.value = withTiming(calculateOffset(), { duration, easing }, finished => {
|
|
79
97
|
if (finished) {
|
|
80
98
|
// Set flexBasic after animation to trigger re-layout and reset layout information
|
|
81
99
|
basic.value = '99.99%'
|
|
82
100
|
}
|
|
83
101
|
})
|
|
84
102
|
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
103
|
+
}
|
|
104
|
+
;(isIOS ? () => setTimeout(callback) : callback)()
|
|
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)]
|
|
88
112
|
}
|
|
89
113
|
|
|
90
114
|
return () => {
|
|
@@ -93,15 +117,8 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
93
117
|
}, [keyboardAvoid])
|
|
94
118
|
|
|
95
119
|
return (
|
|
96
|
-
<View style={style} onTouchEnd={onTouchEnd}>
|
|
97
|
-
<Animated.View
|
|
98
|
-
style={[
|
|
99
|
-
contentContainerStyle,
|
|
100
|
-
animatedStyle
|
|
101
|
-
]}
|
|
102
|
-
>
|
|
103
|
-
{children}
|
|
104
|
-
</Animated.View>
|
|
120
|
+
<View style={style} onTouchEnd={onTouchEnd} onTouchMove={onTouchEnd}>
|
|
121
|
+
<Animated.View style={[contentContainerStyle, animatedStyle]}>{children}</Animated.View>
|
|
105
122
|
</View>
|
|
106
123
|
)
|
|
107
124
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/* eslint-disable space-before-function-paren */
|
|
2
|
+
import { useState, useMemo, memo } from 'react'
|
|
3
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
4
|
+
import { StatusBar, processColor, TouchableWithoutFeedback, Image, View, StyleSheet, Text } from 'react-native'
|
|
5
|
+
|
|
6
|
+
function convertToHex(color?: string) {
|
|
7
|
+
try {
|
|
8
|
+
const intColor = processColor(color) as number | null | undefined
|
|
9
|
+
if (intColor === null || intColor === undefined) {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
// 将32位整数颜色值转换为RGBA
|
|
13
|
+
const r = (intColor >> 16) & 255
|
|
14
|
+
const g = (intColor >> 8) & 255
|
|
15
|
+
const b = intColor & 255
|
|
16
|
+
// 转换为十六进制
|
|
17
|
+
const hexR = r.toString(16).padStart(2, '0')
|
|
18
|
+
const hexG = g.toString(16).padStart(2, '0')
|
|
19
|
+
const hexB = b.toString(16).padStart(2, '0')
|
|
20
|
+
return `#${hexR}${hexG}${hexB}`
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const titleHeight = 44
|
|
27
|
+
export function useInnerHeaderHeight(pageConfig: PageConfig) {
|
|
28
|
+
const safeArea = useSafeAreaInsets()
|
|
29
|
+
if (pageConfig.navigationStyle === 'custom') {
|
|
30
|
+
return 0
|
|
31
|
+
} else {
|
|
32
|
+
const safeAreaTop = safeArea?.top || 0
|
|
33
|
+
const headerHeight = safeAreaTop + titleHeight
|
|
34
|
+
return headerHeight
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const styles = StyleSheet.create({
|
|
39
|
+
header: {
|
|
40
|
+
elevation: 3
|
|
41
|
+
},
|
|
42
|
+
headerContent: {
|
|
43
|
+
flexDirection: 'row',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
justifyContent: 'center'
|
|
46
|
+
},
|
|
47
|
+
backButton: {
|
|
48
|
+
position: 'absolute',
|
|
49
|
+
height: '100%',
|
|
50
|
+
width: 40,
|
|
51
|
+
left: 0,
|
|
52
|
+
top: 0,
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
justifyContent: 'center'
|
|
55
|
+
},
|
|
56
|
+
backButtonImage: {
|
|
57
|
+
width: 22,
|
|
58
|
+
height: 22
|
|
59
|
+
},
|
|
60
|
+
title: {
|
|
61
|
+
fontSize: 17,
|
|
62
|
+
fontWeight: 600,
|
|
63
|
+
width: '60%',
|
|
64
|
+
textAlign: 'center'
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
const NavColor = {
|
|
68
|
+
White: '#ffffff',
|
|
69
|
+
Black: '#000000'
|
|
70
|
+
}
|
|
71
|
+
// navigationBarTextStyle 只支持黑白 'white'/'black
|
|
72
|
+
const validBarTextStyle = (textStyle?: string) => {
|
|
73
|
+
const textStyleColor = convertToHex(textStyle)
|
|
74
|
+
if (textStyle && textStyleColor && [NavColor.White, NavColor.Black].includes(textStyleColor)) {
|
|
75
|
+
return textStyleColor
|
|
76
|
+
} else {
|
|
77
|
+
return NavColor.White
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface MpxNavProps {
|
|
82
|
+
pageConfig: PageConfig
|
|
83
|
+
navigation: any
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const BACK_ICON =
|
|
87
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg=='
|
|
88
|
+
|
|
89
|
+
const MpxNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
|
|
90
|
+
const [innerPageConfig, setPageConfig] = useState<PageConfig>(pageConfig || {})
|
|
91
|
+
const safeAreaTop = useSafeAreaInsets()?.top || 0
|
|
92
|
+
|
|
93
|
+
navigation.setPageConfig = (config: PageConfig) => {
|
|
94
|
+
setPageConfig(Object.assign({}, innerPageConfig, config))
|
|
95
|
+
}
|
|
96
|
+
const isCustom = innerPageConfig.navigationStyle === 'custom'
|
|
97
|
+
const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
|
|
98
|
+
// 状态栏的颜色
|
|
99
|
+
const statusBarElement = (
|
|
100
|
+
<StatusBar
|
|
101
|
+
translucent
|
|
102
|
+
backgroundColor='transparent'
|
|
103
|
+
barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
if (isCustom) return statusBarElement
|
|
107
|
+
// 假设是栈导航,获取栈的长度
|
|
108
|
+
const stackLength = navigation.getState()?.routes?.length
|
|
109
|
+
const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack
|
|
110
|
+
const isHandleStackTopBack = typeof onStackTopBack === 'function'
|
|
111
|
+
|
|
112
|
+
// 回退按钮与图标
|
|
113
|
+
// prettier-ignore
|
|
114
|
+
const backElement = stackLength > 1 || isHandleStackTopBack
|
|
115
|
+
? (
|
|
116
|
+
<TouchableWithoutFeedback
|
|
117
|
+
onPress={() => {
|
|
118
|
+
if (stackLength <= 1 && isHandleStackTopBack) {
|
|
119
|
+
onStackTopBack()
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
navigation.goBack()
|
|
123
|
+
}}>
|
|
124
|
+
<View style={[styles.backButton]}>
|
|
125
|
+
<Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
|
|
126
|
+
</View>
|
|
127
|
+
</TouchableWithoutFeedback>
|
|
128
|
+
)
|
|
129
|
+
: null
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<View
|
|
133
|
+
style={[
|
|
134
|
+
styles.header,
|
|
135
|
+
{
|
|
136
|
+
paddingTop: safeAreaTop,
|
|
137
|
+
backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
|
|
138
|
+
}
|
|
139
|
+
]}>
|
|
140
|
+
{statusBarElement}
|
|
141
|
+
{/* TODO: 确定 height 的有效性 */}
|
|
142
|
+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
|
|
143
|
+
{/* @ts-expect-error */}
|
|
144
|
+
<View style={styles.headerContent} height={titleHeight}>
|
|
145
|
+
{backElement}
|
|
146
|
+
<Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
|
|
147
|
+
{innerPageConfig.navigationBarTitleText?.trim() || ''}
|
|
148
|
+
</Text>
|
|
149
|
+
</View>
|
|
150
|
+
</View>
|
|
151
|
+
)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
MpxNav.displayName = 'MpxNav'
|
|
155
|
+
export default MpxNav
|
|
@@ -33,6 +33,7 @@ interface PickerViewProps {
|
|
|
33
33
|
style?: {
|
|
34
34
|
[key: string]: any
|
|
35
35
|
}
|
|
36
|
+
'enable-wheel-animation'?: boolean
|
|
36
37
|
'indicator-style'?: Record<string, any>,
|
|
37
38
|
'mask-style'?: Record<string, any>,
|
|
38
39
|
'enable-var'?: boolean
|
|
@@ -69,6 +70,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
69
70
|
value = [],
|
|
70
71
|
bindchange,
|
|
71
72
|
style,
|
|
73
|
+
'enable-wheel-animation': enableWheelAnimation = true,
|
|
72
74
|
'indicator-style': indicatorStyle = {},
|
|
73
75
|
'mask-style': pickerMaskStyle = {},
|
|
74
76
|
'enable-var': enableVar,
|
|
@@ -168,7 +170,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
168
170
|
columnData,
|
|
169
171
|
ref: cloneRef,
|
|
170
172
|
columnIndex: index,
|
|
171
|
-
key: `pick-view-${index}`,
|
|
173
|
+
key: `pick-view-${index}-${columnData.length}`,
|
|
172
174
|
wrapperStyle: {
|
|
173
175
|
height: normalStyle?.height || DefaultPickerItemH,
|
|
174
176
|
itemHeight: indicatorH || DefaultPickerItemH
|
|
@@ -176,7 +178,8 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
176
178
|
onSelectChange: onSelectChange.bind(null, index),
|
|
177
179
|
initialIndex,
|
|
178
180
|
pickerIndicatorStyle,
|
|
179
|
-
pickerMaskStyle
|
|
181
|
+
pickerMaskStyle,
|
|
182
|
+
enableWheelAnimation
|
|
180
183
|
}
|
|
181
184
|
)
|
|
182
185
|
const realElement = React.cloneElement(child, wrappedProps)
|
|
@@ -5,7 +5,8 @@ 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
|
|
8
|
+
import MpxPickerViewColumnItem from './pickerViewColumnItem'
|
|
9
|
+
import MpxPickerViewColumnItemLite from './pickerViewColumnItemLite'
|
|
9
10
|
import { PickerViewColumnAnimationContext } from '../mpx-picker-view/pickerVIewContext'
|
|
10
11
|
import { calcHeightOffsets } from './pickerViewFaces'
|
|
11
12
|
|
|
@@ -25,6 +26,7 @@ interface ColumnProps {
|
|
|
25
26
|
}
|
|
26
27
|
pickerMaskStyle: Record<string, any>
|
|
27
28
|
pickerIndicatorStyle: Record<string, any>
|
|
29
|
+
enableWheelAnimation?: boolean
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
const visibleCount = 5
|
|
@@ -39,6 +41,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
39
41
|
wrapperStyle,
|
|
40
42
|
pickerMaskStyle,
|
|
41
43
|
pickerIndicatorStyle,
|
|
44
|
+
enableWheelAnimation = true,
|
|
42
45
|
'enable-var': enableVar,
|
|
43
46
|
'external-var-context': externalVarContext
|
|
44
47
|
} = props
|
|
@@ -95,6 +98,11 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
95
98
|
return [{ paddingVertical: paddingHeight }]
|
|
96
99
|
}, [paddingHeight])
|
|
97
100
|
|
|
101
|
+
const initialContentOffsetY = useMemo(
|
|
102
|
+
() => initialIndex * itemRawH,
|
|
103
|
+
[initialIndex, itemRawH]
|
|
104
|
+
)
|
|
105
|
+
|
|
98
106
|
const getIndex = useCallback((y: number) => {
|
|
99
107
|
const calc = Math.round(y / itemRawH)
|
|
100
108
|
return Math.max(0, Math.min(calc, maxIndex))
|
|
@@ -152,17 +160,6 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
152
160
|
}, isIOS ? 0 : 200)
|
|
153
161
|
}, [itemRawH, maxIndex, initialIndex])
|
|
154
162
|
|
|
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
|
-
|
|
166
163
|
const onItemLayout = useCallback((e: LayoutChangeEvent) => {
|
|
167
164
|
const { height: rawH } = e.nativeEvent.layout
|
|
168
165
|
const roundedH = Math.round(rawH)
|
|
@@ -287,8 +284,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
287
284
|
|
|
288
285
|
const renderInnerchild = () =>
|
|
289
286
|
columnData.map((item: React.ReactElement, index: number) => {
|
|
290
|
-
return
|
|
291
|
-
<
|
|
287
|
+
return enableWheelAnimation
|
|
288
|
+
? (<MpxPickerViewColumnItem
|
|
292
289
|
key={index}
|
|
293
290
|
item={item}
|
|
294
291
|
index={index}
|
|
@@ -297,8 +294,16 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
297
294
|
textProps={textProps}
|
|
298
295
|
visibleCount={visibleCount}
|
|
299
296
|
onItemLayout={onItemLayout}
|
|
300
|
-
/>
|
|
301
|
-
|
|
297
|
+
/>)
|
|
298
|
+
: (<MpxPickerViewColumnItemLite
|
|
299
|
+
key={index}
|
|
300
|
+
item={item}
|
|
301
|
+
index={index}
|
|
302
|
+
itemHeight={itemHeight}
|
|
303
|
+
textStyle={textStyle}
|
|
304
|
+
textProps={textProps}
|
|
305
|
+
onItemLayout={onItemLayout}
|
|
306
|
+
/>)
|
|
302
307
|
})
|
|
303
308
|
|
|
304
309
|
const renderScollView = () => {
|
|
@@ -320,8 +325,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
320
325
|
onScrollEndDrag,
|
|
321
326
|
onMomentumScrollBegin,
|
|
322
327
|
onMomentumScrollEnd,
|
|
323
|
-
|
|
324
|
-
|
|
328
|
+
contentContainerStyle,
|
|
329
|
+
contentOffset: { x: 0, y: initialContentOffsetY }
|
|
325
330
|
}) as React.ComponentProps<typeof Reanimated.ScrollView>
|
|
326
331
|
|
|
327
332
|
return createElement(
|
|
@@ -351,9 +356,9 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
351
356
|
|
|
352
357
|
return (
|
|
353
358
|
<View style={[styles.wrapper, normalStyle]}>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
359
|
+
{renderScollView()}
|
|
360
|
+
{renderMask()}
|
|
361
|
+
{renderIndicator()}
|
|
357
362
|
</View>
|
|
358
363
|
)
|
|
359
364
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useMemo } from 'react'
|
|
2
2
|
import { LayoutChangeEvent } from 'react-native'
|
|
3
|
-
import Reanimated, { Extrapolation, interpolate, useAnimatedStyle
|
|
3
|
+
import Reanimated, { Extrapolation, interpolate, useAnimatedStyle } from 'react-native-reanimated'
|
|
4
4
|
import { extendObject } from '../utils'
|
|
5
5
|
import { createFaces } from './pickerViewFaces'
|
|
6
6
|
import { usePickerViewColumnAnimationContext, usePickerViewStyleContext } from '../mpx-picker-view/pickerVIewContext'
|
|
@@ -28,20 +28,16 @@ const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
|
|
|
28
28
|
}) => {
|
|
29
29
|
const textStyleFromAncestor = usePickerViewStyleContext()
|
|
30
30
|
const offsetYShared = usePickerViewColumnAnimationContext()
|
|
31
|
-
const facesShared =
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
facesShared.value = createFaces(itemHeight, visibleCount)
|
|
35
|
-
}, [itemHeight])
|
|
31
|
+
const facesShared = useMemo(() => createFaces(itemHeight, visibleCount), [itemHeight, visibleCount])
|
|
36
32
|
|
|
37
33
|
const animatedStyles = useAnimatedStyle(() => {
|
|
38
|
-
const inputRange = facesShared.
|
|
34
|
+
const inputRange = facesShared.map((f) => itemHeight * (index + f.index))
|
|
39
35
|
return {
|
|
40
|
-
opacity: interpolate(offsetYShared.value, inputRange, facesShared.
|
|
36
|
+
opacity: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.opacity), Extrapolation.CLAMP),
|
|
41
37
|
transform: [
|
|
42
|
-
{ translateY: interpolate(offsetYShared.value, inputRange, facesShared.
|
|
43
|
-
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.
|
|
44
|
-
{ scale: interpolate(offsetYShared.value, inputRange, facesShared.
|
|
38
|
+
{ translateY: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.offsetY), Extrapolation.EXTEND) },
|
|
39
|
+
{ rotateX: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
|
|
40
|
+
{ scale: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.scale), Extrapolation.EXTEND) }
|
|
45
41
|
]
|
|
46
42
|
}
|
|
47
43
|
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { LayoutChangeEvent, View } from 'react-native'
|
|
3
|
+
import { extendObject } from '../utils'
|
|
4
|
+
import { usePickerViewStyleContext } from '../mpx-picker-view/pickerVIewContext'
|
|
5
|
+
|
|
6
|
+
interface PickerColumnItemProps {
|
|
7
|
+
item: React.ReactElement
|
|
8
|
+
index: number
|
|
9
|
+
itemHeight: number
|
|
10
|
+
itemWidth?: number | '100%'
|
|
11
|
+
textStyle: Record<string, any>
|
|
12
|
+
textProps?: any
|
|
13
|
+
onItemLayout?: (e: LayoutChangeEvent) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
|
|
17
|
+
item,
|
|
18
|
+
index,
|
|
19
|
+
itemHeight,
|
|
20
|
+
itemWidth = '100%',
|
|
21
|
+
textStyle,
|
|
22
|
+
textProps,
|
|
23
|
+
onItemLayout
|
|
24
|
+
}) => {
|
|
25
|
+
const textStyleFromAncestor = usePickerViewStyleContext()
|
|
26
|
+
const strKey = `picker-column-item-${index}`
|
|
27
|
+
const restProps = index === 0 ? { onLayout: onItemLayout } : {}
|
|
28
|
+
const itemProps = extendObject(
|
|
29
|
+
{
|
|
30
|
+
style: extendObject(
|
|
31
|
+
{ height: itemHeight, width: '100%' },
|
|
32
|
+
textStyleFromAncestor,
|
|
33
|
+
textStyle,
|
|
34
|
+
item.props.style
|
|
35
|
+
)
|
|
36
|
+
},
|
|
37
|
+
textProps,
|
|
38
|
+
restProps
|
|
39
|
+
)
|
|
40
|
+
const realItem = React.cloneElement(item, itemProps)
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<View
|
|
44
|
+
key={strKey}
|
|
45
|
+
style={[
|
|
46
|
+
{ height: itemHeight, width: itemWidth, pointerEvents: 'none' }
|
|
47
|
+
]}
|
|
48
|
+
>
|
|
49
|
+
{realItem}
|
|
50
|
+
</View>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
PickerViewColumnItem.displayName = 'MpxPickerViewColumnItem'
|
|
55
|
+
export default PickerViewColumnItem
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { ReactNode, useContext, useEffect, useRef } from 'react'
|
|
2
|
-
import { PortalContext, RouteContext, VarContext } from '../context'
|
|
2
|
+
import { PortalContext, ProviderContext, RouteContext, VarContext } from '../context'
|
|
3
3
|
import PortalHost, { portal } from './portal-host'
|
|
4
4
|
|
|
5
5
|
export type PortalProps = {
|
|
6
6
|
children?: ReactNode
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const Portal = ({ children }:PortalProps): null => {
|
|
9
|
+
const Portal = ({ children }: PortalProps): null => {
|
|
10
10
|
const manager = useContext(PortalContext)
|
|
11
11
|
const keyRef = useRef<any>(null)
|
|
12
12
|
const { pageId } = useContext(RouteContext) || {}
|
|
13
13
|
const varContext = useContext(VarContext)
|
|
14
|
+
const parentProvides = useContext(ProviderContext)
|
|
15
|
+
|
|
14
16
|
if (varContext) {
|
|
15
17
|
children = (<VarContext.Provider value={varContext} key='varContextWrap'>{children}</VarContext.Provider>)
|
|
16
18
|
}
|
|
19
|
+
if (parentProvides) {
|
|
20
|
+
children = (<ProviderContext.Provider value={parentProvides} key='providerContextWrap'>{children}</ProviderContext.Provider>)
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
useEffect(() => {
|
|
18
24
|
manager.update(keyRef.current, children)
|
|
19
25
|
}, [children])
|
|
@@ -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
|
|