@mpxjs/webpack-plugin 2.10.1-beta.7 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +433 -0
- package/lib/config.js +1 -2
- package/lib/index.js +12 -2
- package/lib/platform/json/wx/index.js +3 -6
- package/lib/platform/style/wx/index.js +12 -23
- package/lib/platform/template/wx/component-config/button.js +2 -19
- package/lib/platform/template/wx/component-config/canvas.js +0 -4
- package/lib/platform/template/wx/component-config/checkbox-group.js +0 -4
- package/lib/platform/template/wx/component-config/checkbox.js +0 -4
- package/lib/platform/template/wx/component-config/cover-image.js +1 -7
- package/lib/platform/template/wx/component-config/cover-view.js +0 -4
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -3
- package/lib/platform/template/wx/component-config/form.js +1 -7
- package/lib/platform/template/wx/component-config/icon.js +0 -4
- package/lib/platform/template/wx/component-config/image.js +1 -7
- package/lib/platform/template/wx/component-config/input.js +3 -18
- package/lib/platform/template/wx/component-config/label.js +0 -4
- package/lib/platform/template/wx/component-config/movable-area.js +1 -7
- package/lib/platform/template/wx/component-config/movable-view.js +3 -12
- package/lib/platform/template/wx/component-config/navigator.js +0 -4
- package/lib/platform/template/wx/component-config/picker-view-column.js +0 -4
- package/lib/platform/template/wx/component-config/picker-view.js +1 -7
- package/lib/platform/template/wx/component-config/picker.js +1 -7
- package/lib/platform/template/wx/component-config/radio-group.js +0 -4
- package/lib/platform/template/wx/component-config/radio.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +0 -4
- package/lib/platform/template/wx/component-config/root-portal.js +0 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +2 -10
- package/lib/platform/template/wx/component-config/swiper-item.js +1 -7
- package/lib/platform/template/wx/component-config/swiper.js +3 -12
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +1 -7
- package/lib/platform/template/wx/component-config/textarea.js +3 -18
- package/lib/platform/template/wx/component-config/unsupported.js +0 -7
- package/lib/platform/template/wx/component-config/video.js +2 -10
- package/lib/platform/template/wx/component-config/view.js +1 -7
- package/lib/platform/template/wx/component-config/web-view.js +0 -4
- package/lib/platform/template/wx/index.js +13 -32
- package/lib/react/processScript.js +2 -2
- package/lib/runtime/components/react/KeyboardAvoidingView.tsx +30 -18
- package/lib/runtime/components/react/context.ts +3 -4
- package/lib/runtime/components/react/dist/KeyboardAvoidingView.jsx +23 -13
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -44
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +7 -4
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +6 -6
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +4 -4
- package/lib/runtime/components/react/dist/utils.jsx +0 -15
- package/lib/runtime/components/react/mpx-image.tsx +2 -2
- package/lib/runtime/components/react/mpx-input.tsx +66 -54
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +2 -2
- package/lib/runtime/components/react/mpx-scroll-view.tsx +8 -4
- package/lib/runtime/components/react/mpx-textarea.tsx +10 -6
- package/lib/runtime/components/react/mpx-web-view.tsx +4 -4
- package/lib/runtime/components/react/types/global.d.ts +1 -1
- package/lib/runtime/components/react/utils.tsx +1 -16
- package/lib/runtime/components/web/mini-video-controls.min.js +1 -1
- package/lib/template-compiler/compiler.js +3 -3
- package/lib/utils/env.js +1 -1
- package/package.json +4 -4
|
@@ -15,8 +15,6 @@ module.exports = function ({ print }) {
|
|
|
15
15
|
const iosEventLogError = print({ platform: 'ios', tag: TAG_NAME, isError: false, type: 'event' })
|
|
16
16
|
const androidPropLog = print({ platform: 'android', tag: TAG_NAME, isError: false })
|
|
17
17
|
const androidEventLogError = print({ platform: 'android', tag: TAG_NAME, isError: false, type: 'event' })
|
|
18
|
-
const harmonyPropLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false })
|
|
19
|
-
const harmonyEventLogError = print({ platform: 'harmony', tag: TAG_NAME, isError: false, type: 'event' })
|
|
20
18
|
return {
|
|
21
19
|
test: TAG_NAME,
|
|
22
20
|
web (tag, { el }) {
|
|
@@ -27,10 +25,6 @@ module.exports = function ({ print }) {
|
|
|
27
25
|
el.isBuiltIn = true
|
|
28
26
|
return 'mpx-video'
|
|
29
27
|
},
|
|
30
|
-
harmony (tag, { el }) {
|
|
31
|
-
el.isBuiltIn = true
|
|
32
|
-
return 'mpx-video'
|
|
33
|
-
},
|
|
34
28
|
ios (tag, { el }) {
|
|
35
29
|
el.isBuiltIn = true
|
|
36
30
|
return 'mpx-video'
|
|
@@ -72,8 +66,7 @@ module.exports = function ({ print }) {
|
|
|
72
66
|
},
|
|
73
67
|
{
|
|
74
68
|
test: /^(duration|enable-danmu|danmu-btn|page-gesture|direction|show-progress|show-fullscreen-btn|show-center-play-btn|enable-progress-gesture|show-mute-btn|title|play-btn-position|enable-play-gesture|auto-pause-if-navigate|auto-pause-if-open-native|vslide-gesture|vslide-gesture-in-fullscreen|show-bottom-progress|ad-unit-id|poster-for-crawler|show-casting-button|picture-in-picture-mode|picture-in-picture-show-progress| picture-in-picture-init-position|enable-auto-rotation|show-snapshot-button|show-screen-lock-button|show-background-playback-button|background-poster|referrer-policy|is-live)$/,
|
|
75
|
-
android: androidPropLog
|
|
76
|
-
harmony: harmonyPropLog
|
|
69
|
+
android: androidPropLog
|
|
77
70
|
}
|
|
78
71
|
],
|
|
79
72
|
event: [
|
|
@@ -115,8 +108,7 @@ module.exports = function ({ print }) {
|
|
|
115
108
|
},
|
|
116
109
|
{
|
|
117
110
|
test: /^(progress|enterpictureinpicture|leavepictureinpicture|castinguserselect|castingstatechange|castinginterrupt)$/,
|
|
118
|
-
android: androidEventLogError
|
|
119
|
-
harmony: harmonyEventLogError
|
|
111
|
+
android: androidEventLogError
|
|
120
112
|
}
|
|
121
113
|
]
|
|
122
114
|
}
|
|
@@ -5,7 +5,6 @@ module.exports = function ({ print }) {
|
|
|
5
5
|
const qaEventLogError = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' })
|
|
6
6
|
const iosPropLog = print({ platform: 'ios', tag: TAG_NAME, isError: false })
|
|
7
7
|
const androidPropLog = print({ platform: 'android', tag: TAG_NAME, isError: false })
|
|
8
|
-
const harmonyPropLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false })
|
|
9
8
|
|
|
10
9
|
return {
|
|
11
10
|
// 匹配标签名,可传递正则
|
|
@@ -32,10 +31,6 @@ module.exports = function ({ print }) {
|
|
|
32
31
|
el.isBuiltIn = true
|
|
33
32
|
return 'mpx-view'
|
|
34
33
|
},
|
|
35
|
-
harmony (tag, { el }) {
|
|
36
|
-
el.isBuiltIn = true
|
|
37
|
-
return 'mpx-view'
|
|
38
|
-
},
|
|
39
34
|
qa (tag) {
|
|
40
35
|
return 'div'
|
|
41
36
|
},
|
|
@@ -51,8 +46,7 @@ module.exports = function ({ print }) {
|
|
|
51
46
|
}, {
|
|
52
47
|
test: /^(hover-stop-propagation)$/,
|
|
53
48
|
android: androidPropLog,
|
|
54
|
-
ios: iosPropLog
|
|
55
|
-
harmony: harmonyPropLog
|
|
49
|
+
ios: iosPropLog
|
|
56
50
|
}
|
|
57
51
|
],
|
|
58
52
|
// 组件事件中的差异部分
|
|
@@ -9,7 +9,7 @@ const { dash2hump } = require('../../../utils/hump-dash')
|
|
|
9
9
|
|
|
10
10
|
module.exports = function getSpec ({ warn, error }) {
|
|
11
11
|
const spec = {
|
|
12
|
-
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ios', 'android'
|
|
12
|
+
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ios', 'android'],
|
|
13
13
|
// props预处理
|
|
14
14
|
preProps: [],
|
|
15
15
|
// props后处理
|
|
@@ -347,6 +347,18 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
347
347
|
value
|
|
348
348
|
}
|
|
349
349
|
},
|
|
350
|
+
// tt ({ name, value }, { eventRules }) {
|
|
351
|
+
// const match = this.test.exec(name)
|
|
352
|
+
// const prefix = match[1]
|
|
353
|
+
// const eventName = match[2]
|
|
354
|
+
// const modifierStr = match[3] || ''
|
|
355
|
+
// const rEventName = runRules(eventRules, eventName, { mode: 'tt' })
|
|
356
|
+
// return {
|
|
357
|
+
// // 字节将所有事件转为小写
|
|
358
|
+
// name: prefix + rEventName.toLowerCase() + modifierStr,
|
|
359
|
+
// value
|
|
360
|
+
// }
|
|
361
|
+
// },
|
|
350
362
|
tt ({ name, value }, { eventRules }) {
|
|
351
363
|
const match = this.test.exec(name)
|
|
352
364
|
const prefix = match[1]
|
|
@@ -418,21 +430,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
418
430
|
name: rPrefix + rEventName + meta.modifierStr,
|
|
419
431
|
value
|
|
420
432
|
}
|
|
421
|
-
},
|
|
422
|
-
harmony ({ name, value }, { eventRules, el }) {
|
|
423
|
-
const match = this.test.exec(name)
|
|
424
|
-
const prefix = match[1]
|
|
425
|
-
const eventName = match[2]
|
|
426
|
-
const modifierStr = match[3] || ''
|
|
427
|
-
const meta = {
|
|
428
|
-
modifierStr
|
|
429
|
-
}
|
|
430
|
-
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'harmony' })
|
|
431
|
-
const rEventName = runRules(eventRules, eventName, { mode: 'harmony', data: { el } })
|
|
432
|
-
return {
|
|
433
|
-
name: rPrefix + rEventName + meta.modifierStr,
|
|
434
|
-
value
|
|
435
|
-
}
|
|
436
433
|
}
|
|
437
434
|
},
|
|
438
435
|
// 无障碍
|
|
@@ -568,22 +565,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
568
565
|
} else {
|
|
569
566
|
error(`React native environment does not support [${eventName}] event!`)
|
|
570
567
|
}
|
|
571
|
-
},
|
|
572
|
-
harmony (eventName) {
|
|
573
|
-
const eventMap = {
|
|
574
|
-
tap: 'tap',
|
|
575
|
-
longtap: 'longpress',
|
|
576
|
-
longpress: 'longpress',
|
|
577
|
-
touchstart: 'touchstart',
|
|
578
|
-
touchmove: 'touchmove',
|
|
579
|
-
touchend: 'touchend',
|
|
580
|
-
touchcancel: 'touchcancel'
|
|
581
|
-
}
|
|
582
|
-
if (eventMap[eventName]) {
|
|
583
|
-
return eventMap[eventName]
|
|
584
|
-
} else {
|
|
585
|
-
error(`React native environment does not support [${eventName}] event!`)
|
|
586
|
-
}
|
|
587
568
|
}
|
|
588
569
|
},
|
|
589
570
|
// web event escape
|
|
@@ -27,7 +27,7 @@ module.exports = function (script, {
|
|
|
27
27
|
output += `
|
|
28
28
|
import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
29
29
|
import { NavigationContainer, StackActions } from '@react-navigation/native'
|
|
30
|
-
${mode === 'ios'
|
|
30
|
+
${mode === 'ios' ? "import { createNativeStackNavigator as createStackNavigator } from '@react-navigation/native-stack'" : "import { createStackNavigator } from '@react-navigation/stack'"}
|
|
31
31
|
import PortalHost from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-portal/portal-host'
|
|
32
32
|
import { useHeaderHeight } from '@react-navigation/elements';
|
|
33
33
|
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
@@ -35,7 +35,7 @@ import { GestureHandlerRootView } from 'react-native-gesture-handler'
|
|
|
35
35
|
|
|
36
36
|
global.__navigationHelper = {
|
|
37
37
|
NavigationContainer: NavigationContainer,
|
|
38
|
-
createStackNavigator:
|
|
38
|
+
createStackNavigator: createStackNavigator,
|
|
39
39
|
useHeaderHeight: useHeaderHeight,
|
|
40
40
|
StackActions: StackActions,
|
|
41
41
|
GestureHandlerRootView: GestureHandlerRootView,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { ReactNode, useContext, useEffect } from 'react'
|
|
1
|
+
import React, { ReactNode, useContext, useEffect, useMemo } from 'react'
|
|
2
2
|
import { DimensionValue, EmitterSubscription, Keyboard, Platform, View, ViewStyle } from 'react-native'
|
|
3
|
-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
|
|
3
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, runOnJS } from 'react-native-reanimated'
|
|
4
|
+
import { GestureDetector, Gesture } from 'react-native-gesture-handler'
|
|
4
5
|
import { KeyboardAvoidContext } from './context'
|
|
5
|
-
import { extendObject } from './utils'
|
|
6
6
|
|
|
7
7
|
type KeyboardAvoidViewProps = {
|
|
8
8
|
children?: ReactNode
|
|
@@ -19,6 +19,17 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
19
19
|
const basic = useSharedValue('auto')
|
|
20
20
|
const keyboardAvoid = useContext(KeyboardAvoidContext)
|
|
21
21
|
|
|
22
|
+
const dismiss = () => {
|
|
23
|
+
Keyboard.isVisible() && Keyboard.dismiss()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const gesture = useMemo(() => {
|
|
27
|
+
return Gesture.Tap()
|
|
28
|
+
.onEnd(() => {
|
|
29
|
+
runOnJS(dismiss)()
|
|
30
|
+
})
|
|
31
|
+
}, [])
|
|
32
|
+
|
|
22
33
|
const animatedStyle = useAnimatedStyle(() => {
|
|
23
34
|
return Object.assign(
|
|
24
35
|
{
|
|
@@ -29,10 +40,9 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
29
40
|
})
|
|
30
41
|
|
|
31
42
|
const resetKeyboard = () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
43
|
+
if (keyboardAvoid?.current) {
|
|
44
|
+
keyboardAvoid.current = null
|
|
45
|
+
}
|
|
36
46
|
offset.value = withTiming(0, { duration, easing })
|
|
37
47
|
basic.value = 'auto'
|
|
38
48
|
}
|
|
@@ -48,7 +58,7 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
48
58
|
const { ref, cursorSpacing = 0 } = keyboardAvoid.current
|
|
49
59
|
setTimeout(() => {
|
|
50
60
|
ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
|
|
51
|
-
const aboveOffset =
|
|
61
|
+
const aboveOffset = pageY + height - endCoordinates.screenY
|
|
52
62
|
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
|
|
53
63
|
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
|
|
54
64
|
const value = aboveOffset > 0 ? belowValue : aboveValue
|
|
@@ -92,16 +102,18 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
|
|
|
92
102
|
}, [keyboardAvoid])
|
|
93
103
|
|
|
94
104
|
return (
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
<GestureDetector gesture={gesture}>
|
|
106
|
+
<View style={style}>
|
|
107
|
+
<Animated.View
|
|
108
|
+
style={[
|
|
109
|
+
contentContainerStyle,
|
|
110
|
+
animatedStyle
|
|
111
|
+
]}
|
|
112
|
+
>
|
|
113
|
+
{children}
|
|
114
|
+
</Animated.View>
|
|
115
|
+
</View>
|
|
116
|
+
</GestureDetector>
|
|
105
117
|
)
|
|
106
118
|
}
|
|
107
119
|
|
|
@@ -5,10 +5,9 @@ export type LabelContextValue = MutableRefObject<{
|
|
|
5
5
|
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
|
|
6
6
|
}>
|
|
7
7
|
|
|
8
|
-
export type KeyboardAvoidContextValue = MutableRefObject<
|
|
9
|
-
cursorSpacing: number
|
|
10
|
-
|
|
11
|
-
}>
|
|
8
|
+
export type KeyboardAvoidContextValue = MutableRefObject<
|
|
9
|
+
{ cursorSpacing: number, ref: MutableRefObject<any> } | null
|
|
10
|
+
>
|
|
12
11
|
|
|
13
12
|
export interface GroupValue {
|
|
14
13
|
[key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useContext, useEffect } from 'react';
|
|
1
|
+
import React, { useContext, useEffect, useMemo } from 'react';
|
|
2
2
|
import { Keyboard, Platform, View } from 'react-native';
|
|
3
|
-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated';
|
|
3
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, runOnJS } from 'react-native-reanimated';
|
|
4
|
+
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
|
|
4
5
|
import { KeyboardAvoidContext } from './context';
|
|
5
|
-
import { extendObject } from './utils';
|
|
6
6
|
const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
7
7
|
const isIOS = Platform.OS === 'ios';
|
|
8
8
|
const duration = isIOS ? 250 : 300;
|
|
@@ -10,16 +10,24 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
|
10
10
|
const offset = useSharedValue(0);
|
|
11
11
|
const basic = useSharedValue('auto');
|
|
12
12
|
const keyboardAvoid = useContext(KeyboardAvoidContext);
|
|
13
|
+
const dismiss = () => {
|
|
14
|
+
Keyboard.isVisible() && Keyboard.dismiss();
|
|
15
|
+
};
|
|
16
|
+
const gesture = useMemo(() => {
|
|
17
|
+
return Gesture.Tap()
|
|
18
|
+
.onEnd(() => {
|
|
19
|
+
runOnJS(dismiss)();
|
|
20
|
+
});
|
|
21
|
+
}, []);
|
|
13
22
|
const animatedStyle = useAnimatedStyle(() => {
|
|
14
23
|
return Object.assign({
|
|
15
24
|
transform: [{ translateY: -offset.value }]
|
|
16
25
|
}, isIOS ? {} : { flexBasis: basic.value });
|
|
17
26
|
});
|
|
18
27
|
const resetKeyboard = () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
28
|
+
if (keyboardAvoid?.current) {
|
|
29
|
+
keyboardAvoid.current = null;
|
|
30
|
+
}
|
|
23
31
|
offset.value = withTiming(0, { duration, easing });
|
|
24
32
|
basic.value = 'auto';
|
|
25
33
|
};
|
|
@@ -34,7 +42,7 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
|
34
42
|
const { ref, cursorSpacing = 0 } = keyboardAvoid.current;
|
|
35
43
|
setTimeout(() => {
|
|
36
44
|
ref?.current?.measure((x, y, width, height, pageX, pageY) => {
|
|
37
|
-
const aboveOffset =
|
|
45
|
+
const aboveOffset = pageY + height - endCoordinates.screenY;
|
|
38
46
|
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
|
|
39
47
|
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing);
|
|
40
48
|
const value = aboveOffset > 0 ? belowValue : aboveValue;
|
|
@@ -77,13 +85,15 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
|
77
85
|
subscriptions.forEach(subscription => subscription.remove());
|
|
78
86
|
};
|
|
79
87
|
}, [keyboardAvoid]);
|
|
80
|
-
return (<
|
|
81
|
-
<
|
|
88
|
+
return (<GestureDetector gesture={gesture}>
|
|
89
|
+
<View style={style}>
|
|
90
|
+
<Animated.View style={[
|
|
82
91
|
contentContainerStyle,
|
|
83
92
|
animatedStyle
|
|
84
93
|
]}>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
{children}
|
|
95
|
+
</Animated.View>
|
|
96
|
+
</View>
|
|
97
|
+
</GestureDetector>);
|
|
88
98
|
};
|
|
89
99
|
export default KeyboardAvoidingView;
|
|
@@ -272,7 +272,7 @@ const Image = forwardRef((props, ref) => {
|
|
|
272
272
|
uri: src,
|
|
273
273
|
onLayout: onSvgLoad,
|
|
274
274
|
onError: binderror && onSvgError,
|
|
275
|
-
style: extendObject({ transformOrigin: 'top
|
|
275
|
+
style: extendObject({ transformOrigin: 'left top' }, modeStyle)
|
|
276
276
|
}));
|
|
277
277
|
const BaseImage = renderImage(extendObject({
|
|
278
278
|
source: { uri: src },
|
|
@@ -280,7 +280,7 @@ const Image = forwardRef((props, ref) => {
|
|
|
280
280
|
onLoad: bindload && onImageLoad,
|
|
281
281
|
onError: binderror && onImageError,
|
|
282
282
|
style: extendObject({
|
|
283
|
-
transformOrigin: 'top
|
|
283
|
+
transformOrigin: 'left top',
|
|
284
284
|
width: isCropMode ? imageWidth : '100%',
|
|
285
285
|
height: isCropMode ? imageHeight : '100%'
|
|
286
286
|
}, isCropMode ? modeStyle : {})
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ✔ password
|
|
5
5
|
* ✔ placeholder
|
|
6
6
|
* - placeholder-style: Only support color.
|
|
7
|
-
*
|
|
7
|
+
* - placeholder-class: Only support color.
|
|
8
8
|
* ✔ disabled
|
|
9
9
|
* ✔ maxlength
|
|
10
10
|
* ✔ cursor-spacing
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
import { forwardRef, useRef, useState, useContext, useEffect, createElement } from 'react';
|
|
41
41
|
import { Platform, TextInput } from 'react-native';
|
|
42
42
|
import { warn } from '@mpxjs/utils';
|
|
43
|
-
import {
|
|
43
|
+
import { useUpdateEffect, useTransformStyle, useLayout, extendObject } from './utils';
|
|
44
44
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
45
45
|
import useNodesRef from './useNodesRef';
|
|
46
46
|
import { FormContext, KeyboardAvoidContext } from './context';
|
|
@@ -54,7 +54,7 @@ const keyboardTypeMap = {
|
|
|
54
54
|
}) || ''
|
|
55
55
|
};
|
|
56
56
|
const Input = forwardRef((props, ref) => {
|
|
57
|
-
const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
57
|
+
const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
58
58
|
// private
|
|
59
59
|
multiline, 'auto-height': autoHeight, bindlinechange } = props;
|
|
60
60
|
const formContext = useContext(FormContext);
|
|
@@ -76,7 +76,6 @@ const Input = forwardRef((props, ref) => {
|
|
|
76
76
|
};
|
|
77
77
|
const keyboardType = keyboardTypeMap[type];
|
|
78
78
|
const defaultValue = parseValue(value);
|
|
79
|
-
const placeholderTextColor = parseInlineStyle(placeholderStyle)?.color;
|
|
80
79
|
const textAlignVertical = multiline ? 'top' : 'auto';
|
|
81
80
|
const tmpValue = useRef(defaultValue);
|
|
82
81
|
const cursorIndex = useRef(0);
|
|
@@ -85,7 +84,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
85
84
|
const [contentHeight, setContentHeight] = useState(0);
|
|
86
85
|
const [selection, setSelection] = useState({ start: -1, end: -1 });
|
|
87
86
|
const styleObj = extendObject({ padding: 0, backgroundColor: '#fff' }, style, multiline && autoHeight
|
|
88
|
-
? { minHeight: Math.max(style?.minHeight || 35, contentHeight) }
|
|
87
|
+
? { height: 'auto', minHeight: Math.max(style?.minHeight || 35, contentHeight) }
|
|
89
88
|
: {});
|
|
90
89
|
const { hasSelfPercent, normalStyle, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
91
90
|
const nodeRef = useRef(null);
|
|
@@ -106,44 +105,54 @@ const Input = forwardRef((props, ref) => {
|
|
|
106
105
|
setSelection({ start: selectionStart, end: selectionEnd });
|
|
107
106
|
}
|
|
108
107
|
}, [cursor, selectionStart, selectionEnd]);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
// have not selection on the Android platformg
|
|
109
|
+
const getCursorIndex = (changedSelection, prevValue, curValue) => {
|
|
110
|
+
if (changedSelection)
|
|
111
|
+
return changedSelection.end;
|
|
112
|
+
if (!prevValue || !curValue || prevValue.length === curValue.length)
|
|
113
|
+
return curValue.length;
|
|
114
|
+
const prevStr = prevValue.substring(cursorIndex.current);
|
|
115
|
+
const curStr = curValue.substring(cursorIndex.current);
|
|
116
|
+
return cursorIndex.current + curStr.length - prevStr.length;
|
|
114
117
|
};
|
|
115
118
|
const onChange = (evt) => {
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
const { text, selection } = evt.nativeEvent;
|
|
120
|
+
// will trigger twice on the Android platformg, prevent the second trigger
|
|
121
|
+
if (tmpValue.current === text)
|
|
118
122
|
return;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
const index = getCursorIndex(selection, tmpValue.current, text);
|
|
124
|
+
tmpValue.current = text;
|
|
125
|
+
cursorIndex.current = index;
|
|
126
|
+
if (bindinput) {
|
|
127
|
+
const result = bindinput(getCustomEvent('input', evt, {
|
|
128
|
+
detail: {
|
|
129
|
+
value: tmpValue.current,
|
|
130
|
+
cursor: cursorIndex.current
|
|
131
|
+
},
|
|
132
|
+
layoutRef
|
|
133
|
+
}, props));
|
|
134
|
+
if (typeof result === 'string') {
|
|
135
|
+
tmpValue.current = result;
|
|
136
|
+
setInputValue(result);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
setInputValue(tmpValue.current);
|
|
140
|
+
}
|
|
129
141
|
}
|
|
130
142
|
else {
|
|
131
143
|
setInputValue(tmpValue.current);
|
|
132
144
|
}
|
|
133
145
|
};
|
|
134
146
|
const setKeyboardAvoidContext = () => {
|
|
135
|
-
if (adjustPosition && keyboardAvoid
|
|
136
|
-
|
|
137
|
-
cursorSpacing,
|
|
138
|
-
ref: nodeRef
|
|
139
|
-
});
|
|
147
|
+
if (adjustPosition && keyboardAvoid) {
|
|
148
|
+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef };
|
|
140
149
|
}
|
|
141
150
|
};
|
|
142
|
-
const
|
|
151
|
+
const onTouchStart = () => {
|
|
143
152
|
// sometimes the focus event occurs later than the keyboardWillShow event
|
|
144
153
|
setKeyboardAvoidContext();
|
|
145
154
|
};
|
|
146
|
-
const
|
|
155
|
+
const onFocus = (evt) => {
|
|
147
156
|
setKeyboardAvoidContext();
|
|
148
157
|
bindfocus && bindfocus(getCustomEvent('focus', evt, {
|
|
149
158
|
detail: {
|
|
@@ -152,7 +161,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
152
161
|
layoutRef
|
|
153
162
|
}, props));
|
|
154
163
|
};
|
|
155
|
-
const
|
|
164
|
+
const onBlur = (evt) => {
|
|
156
165
|
bindblur && bindblur(getCustomEvent('blur', evt, {
|
|
157
166
|
detail: {
|
|
158
167
|
value: tmpValue.current || '',
|
|
@@ -179,11 +188,14 @@ const Input = forwardRef((props, ref) => {
|
|
|
179
188
|
}, props));
|
|
180
189
|
};
|
|
181
190
|
const onSelectionChange = (evt) => {
|
|
182
|
-
|
|
191
|
+
const { selection } = evt.nativeEvent;
|
|
192
|
+
const { start, end } = selection;
|
|
193
|
+
cursorIndex.current = start;
|
|
194
|
+
setSelection(selection);
|
|
183
195
|
bindselectionchange && bindselectionchange(getCustomEvent('selectionchange', evt, {
|
|
184
196
|
detail: {
|
|
185
|
-
selectionStart:
|
|
186
|
-
selectionEnd:
|
|
197
|
+
selectionStart: start,
|
|
198
|
+
selectionEnd: end
|
|
187
199
|
},
|
|
188
200
|
layoutRef
|
|
189
201
|
}, props));
|
|
@@ -252,24 +264,22 @@ const Input = forwardRef((props, ref) => {
|
|
|
252
264
|
maxLength: maxlength === -1 ? undefined : maxlength,
|
|
253
265
|
editable: !disabled,
|
|
254
266
|
autoFocus: !!autoFocus || !!focus,
|
|
255
|
-
returnKeyType: confirmType,
|
|
256
267
|
selection: selection,
|
|
257
268
|
selectionColor: cursorColor,
|
|
258
269
|
blurOnSubmit: !multiline && !confirmHold,
|
|
259
270
|
underlineColorAndroid: 'rgba(0,0,0,0)',
|
|
260
271
|
textAlignVertical: textAlignVertical,
|
|
261
|
-
placeholderTextColor:
|
|
272
|
+
placeholderTextColor: placeholderStyle?.color,
|
|
262
273
|
multiline: !!multiline
|
|
263
|
-
}, layoutProps, {
|
|
264
|
-
onTouchStart
|
|
265
|
-
onFocus
|
|
266
|
-
onBlur
|
|
274
|
+
}, !!multiline && confirmType === 'return' ? {} : { enterKeyHint: confirmType }, layoutProps, {
|
|
275
|
+
onTouchStart,
|
|
276
|
+
onFocus,
|
|
277
|
+
onBlur,
|
|
278
|
+
onChange,
|
|
279
|
+
onSelectionChange,
|
|
280
|
+
onContentSizeChange,
|
|
267
281
|
onKeyPress: bindconfirm && onKeyPress,
|
|
268
|
-
onSubmitEditing: bindconfirm && multiline && onSubmitEditing
|
|
269
|
-
onSelectionChange: onSelectionChange,
|
|
270
|
-
onTextInput: onTextInput,
|
|
271
|
-
onChange: onChange,
|
|
272
|
-
onContentSizeChange: onContentSizeChange
|
|
282
|
+
onSubmitEditing: bindconfirm && multiline && onSubmitEditing
|
|
273
283
|
}), [
|
|
274
284
|
'type',
|
|
275
285
|
'password',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef, useRef, useState, useMemo, useEffect, useCallback } from 'react';
|
|
2
2
|
import { StyleSheet, View } from 'react-native';
|
|
3
3
|
import Reanimated, { useAnimatedRef, useScrollViewOffset } from 'react-native-reanimated';
|
|
4
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAndroid, isIOS
|
|
4
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAndroid, isIOS } from './utils';
|
|
5
5
|
import useNodesRef from './useNodesRef';
|
|
6
6
|
import PickerIndicator from './pickerViewIndicator';
|
|
7
7
|
import PickerMask from './pickerViewMask';
|
|
@@ -81,7 +81,7 @@ const _PickerViewColumn = forwardRef((props, ref) => {
|
|
|
81
81
|
y: initialIndex * itemRawH,
|
|
82
82
|
animated: false
|
|
83
83
|
});
|
|
84
|
-
}, isAndroid
|
|
84
|
+
}, isAndroid ? 200 : 0);
|
|
85
85
|
activeIndex.current = initialIndex;
|
|
86
86
|
}, [itemRawH, maxIndex, initialIndex]);
|
|
87
87
|
const onContentSizeChange = useCallback((_w, h) => {
|
|
@@ -41,7 +41,7 @@ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, ext
|
|
|
41
41
|
import { IntersectionObserverContext, ScrollViewContext } from './context';
|
|
42
42
|
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
43
43
|
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
44
|
-
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchstart, bindtouchmove, bindtouchend, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, __selectRef } = props;
|
|
44
|
+
const { enhanced = false, bounces = true, style = {}, binddragstart, binddragging, binddragend, bindtouchstart, bindtouchmove, bindtouchend, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'enable-trigger-intersection-observer': enableTriggerIntersectionObserver = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation = false, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'scroll-into-view': scrollIntoView = '', 'scroll-top': scrollTop = 0, 'scroll-left': scrollLeft = 0, 'refresher-triggered': refresherTriggered, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'simultaneous-handlers': originSimultaneousHandlers, 'wait-for': waitFor, __selectRef } = props;
|
|
45
45
|
const simultaneousHandlers = flatGesture(originSimultaneousHandlers);
|
|
46
46
|
const waitForHandlers = flatGesture(waitFor);
|
|
47
47
|
const [refreshing, setRefreshing] = useState(true);
|
|
@@ -73,7 +73,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
73
73
|
pagingEnabled,
|
|
74
74
|
fastDeceleration: false,
|
|
75
75
|
decelerationDisabled: false,
|
|
76
|
-
scrollTo
|
|
76
|
+
scrollTo
|
|
77
77
|
},
|
|
78
78
|
gestureRef: scrollViewRef
|
|
79
79
|
});
|
|
@@ -112,6 +112,9 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
112
112
|
}
|
|
113
113
|
firstScrollIntoViewChange.current = true;
|
|
114
114
|
}, [scrollIntoView]);
|
|
115
|
+
function scrollTo({ top = 0, left = 0, animated = false }) {
|
|
116
|
+
scrollToOffset(left, top, animated);
|
|
117
|
+
}
|
|
115
118
|
function handleScrollIntoView() {
|
|
116
119
|
const refs = __selectRef(`#${scrollIntoView}`, 'node');
|
|
117
120
|
if (!refs)
|
|
@@ -230,9 +233,9 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
230
233
|
}
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
|
-
function scrollToOffset(x = 0, y = 0) {
|
|
236
|
+
function scrollToOffset(x = 0, y = 0, animated = scrollWithAnimation) {
|
|
234
237
|
if (scrollViewRef.current) {
|
|
235
|
-
scrollViewRef.current.scrollTo({ x, y, animated
|
|
238
|
+
scrollViewRef.current.scrollTo({ x, y, animated });
|
|
236
239
|
scrollOptions.current.scrollLeft = x;
|
|
237
240
|
scrollOptions.current.scrollTop = y;
|
|
238
241
|
snapScrollLeft.current = x;
|
|
@@ -3,33 +3,33 @@
|
|
|
3
3
|
* Subtraction:
|
|
4
4
|
* type, password, confirm-hold
|
|
5
5
|
* Addition:
|
|
6
|
-
*
|
|
6
|
+
* ✔ confirm-type
|
|
7
7
|
* ✔ auto-height
|
|
8
8
|
* ✘ fixed
|
|
9
9
|
* ✘ show-confirm-bar
|
|
10
10
|
* ✔ bindlinechange: No `heightRpx` info.
|
|
11
11
|
*/
|
|
12
12
|
import { forwardRef, createElement } from 'react';
|
|
13
|
-
import { Keyboard } from 'react-native';
|
|
14
13
|
import Input from './mpx-input';
|
|
15
14
|
import { omit, extendObject } from './utils';
|
|
16
15
|
const DEFAULT_TEXTAREA_WIDTH = 300;
|
|
17
16
|
const DEFAULT_TEXTAREA_HEIGHT = 150;
|
|
18
17
|
const Textarea = forwardRef((props, ref) => {
|
|
19
|
-
const { style = {} } = props;
|
|
18
|
+
const { style = {}, 'confirm-type': confirmType = 'return' } = props;
|
|
20
19
|
const restProps = omit(props, [
|
|
21
20
|
'ref',
|
|
22
21
|
'type',
|
|
23
22
|
'style',
|
|
24
23
|
'password',
|
|
25
24
|
'multiline',
|
|
25
|
+
'confirm-type',
|
|
26
26
|
'confirm-hold'
|
|
27
27
|
]);
|
|
28
28
|
return createElement(Input, extendObject(restProps, {
|
|
29
|
-
ref
|
|
29
|
+
ref,
|
|
30
|
+
confirmType,
|
|
30
31
|
multiline: true,
|
|
31
|
-
|
|
32
|
-
bindblur: () => Keyboard.dismiss(),
|
|
32
|
+
'confirm-type': confirmType,
|
|
33
33
|
style: extendObject({
|
|
34
34
|
width: DEFAULT_TEXTAREA_WIDTH,
|
|
35
35
|
height: DEFAULT_TEXTAREA_HEIGHT
|