@mpxjs/webpack-plugin 2.10.3-beta.4 → 2.10.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/text.js +18 -3
- package/lib/platform/template/wx/component-config/view.js +0 -2
- package/lib/platform/template/wx/index.js +41 -93
- package/lib/react/processScript.js +1 -18
- package/lib/runtime/components/react/dist/event.config.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +18 -7
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
- package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +178 -96
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
- package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +3 -3
- package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +64 -16
- package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
- package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +192 -25
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +8 -7
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-video.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +4 -4
- package/lib/runtime/components/react/dist/utils.jsx +1 -1
- package/lib/runtime/components/react/event.config.ts +2 -0
- package/lib/runtime/components/react/getInnerListeners.ts +28 -25
- package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
- package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-input.tsx +11 -13
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
- package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +239 -118
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
- package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
- package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
- package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
- package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
- package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +7 -7
- package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +70 -19
- package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
- package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
- package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
- package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +249 -43
- package/lib/runtime/components/react/mpx-simple-text.tsx +10 -8
- package/lib/runtime/components/react/mpx-simple-view.tsx +11 -16
- package/lib/runtime/components/react/mpx-swiper.tsx +2 -4
- package/lib/runtime/components/react/mpx-video.tsx +2 -2
- package/lib/runtime/components/react/mpx-web-view.tsx +4 -4
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +5 -1
- package/lib/runtime/components/react/utils.tsx +1 -1
- package/lib/runtime/components/web/mpx-input.vue +1 -1
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/template-compiler/compiler.js +7 -7
- package/package.json +3 -4
- /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
- /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
- /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
- /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
- /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
- /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
package/lib/index.js
CHANGED
|
@@ -131,7 +131,7 @@ class MpxWebpackPlugin {
|
|
|
131
131
|
errors.push('MpxWebpackPlugin supports mode to be "web" only when srcMode is set to "wx"!')
|
|
132
132
|
}
|
|
133
133
|
if (isReact(options.mode) && options.srcMode !== 'wx') {
|
|
134
|
-
errors.push('MpxWebpackPlugin supports mode to be "ios"
|
|
134
|
+
errors.push('MpxWebpackPlugin supports mode to be "ios" | "android" | "harmony" only when srcMode is set to "wx"!')
|
|
135
135
|
}
|
|
136
136
|
if (options.dynamicComponentRules && !options.dynamicRuntime) {
|
|
137
137
|
errors.push('Please make sure you have set dynamicRuntime true in mpx webpack plugin config because you have use the dynamic runtime feature.')
|
|
@@ -25,15 +25,15 @@ module.exports = function ({ print }) {
|
|
|
25
25
|
},
|
|
26
26
|
ios (tag, { el }) {
|
|
27
27
|
el.isBuiltIn = true
|
|
28
|
-
return 'mpx-text'
|
|
28
|
+
return el.isSimple ? 'mpx-simple-text' : 'mpx-text'
|
|
29
29
|
},
|
|
30
30
|
android (tag, { el }) {
|
|
31
31
|
el.isBuiltIn = true
|
|
32
|
-
return 'mpx-text'
|
|
32
|
+
return el.isSimple ? 'mpx-simple-text' : 'mpx-text'
|
|
33
33
|
},
|
|
34
34
|
harmony (tag, { el }) {
|
|
35
35
|
el.isBuiltIn = true
|
|
36
|
-
return 'mpx-text'
|
|
36
|
+
return el.isSimple ? 'mpx-simple-text' : 'mpx-text'
|
|
37
37
|
},
|
|
38
38
|
props: [
|
|
39
39
|
{
|
|
@@ -59,6 +59,21 @@ module.exports = function ({ print }) {
|
|
|
59
59
|
el.isBuiltIn = true
|
|
60
60
|
},
|
|
61
61
|
qa: qaPropLog
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
test: /^(is-simple)$/,
|
|
65
|
+
android (prop, { el }) {
|
|
66
|
+
el.isSimple = true
|
|
67
|
+
return false
|
|
68
|
+
},
|
|
69
|
+
harmony (prop, { el }) {
|
|
70
|
+
el.isSimple = true
|
|
71
|
+
return false
|
|
72
|
+
},
|
|
73
|
+
ios (prop, { el }) {
|
|
74
|
+
el.isSimple = true
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
62
77
|
}
|
|
63
78
|
]
|
|
64
79
|
}
|
|
@@ -31,12 +31,10 @@ module.exports = function ({ print }) {
|
|
|
31
31
|
android (tag, { el }) {
|
|
32
32
|
el.isBuiltIn = true
|
|
33
33
|
return el.isSimple ? 'mpx-simple-view' : 'mpx-view'
|
|
34
|
-
return 'mpx-view'
|
|
35
34
|
},
|
|
36
35
|
harmony (tag, { el }) {
|
|
37
36
|
el.isBuiltIn = true
|
|
38
37
|
return el.isSimple ? 'mpx-simple-view' : 'mpx-view'
|
|
39
|
-
return 'mpx-view'
|
|
40
38
|
},
|
|
41
39
|
qa (tag) {
|
|
42
40
|
return 'div'
|
|
@@ -8,6 +8,41 @@ const normalize = require('../../../utils/normalize')
|
|
|
8
8
|
const { dash2hump } = require('../../../utils/hump-dash')
|
|
9
9
|
|
|
10
10
|
module.exports = function getSpec ({ warn, error }) {
|
|
11
|
+
function getRnDirectiveEventHandle (mode) {
|
|
12
|
+
return function ({ name, value }, { eventRules, el }) {
|
|
13
|
+
const match = this.test.exec(name)
|
|
14
|
+
const prefix = match[1]
|
|
15
|
+
const eventName = match[2]
|
|
16
|
+
const modifierStr = match[3] || ''
|
|
17
|
+
const meta = {
|
|
18
|
+
modifierStr
|
|
19
|
+
}
|
|
20
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode })
|
|
21
|
+
const rEventName = runRules(eventRules, eventName, { mode, data: { el } })
|
|
22
|
+
return {
|
|
23
|
+
name: rPrefix + rEventName + meta.modifierStr,
|
|
24
|
+
value
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function rnEventRulesHandle (eventName) {
|
|
30
|
+
const eventMap = {
|
|
31
|
+
tap: 'tap',
|
|
32
|
+
longtap: 'longpress',
|
|
33
|
+
longpress: 'longpress',
|
|
34
|
+
touchstart: 'touchstart',
|
|
35
|
+
touchmove: 'touchmove',
|
|
36
|
+
touchend: 'touchend',
|
|
37
|
+
touchcancel: 'touchcancel'
|
|
38
|
+
}
|
|
39
|
+
if (eventMap[eventName]) {
|
|
40
|
+
return eventMap[eventName]
|
|
41
|
+
} else {
|
|
42
|
+
error(`React native environment does not support [${eventName}] event!`)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
11
46
|
const spec = {
|
|
12
47
|
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ios', 'android', 'harmony'],
|
|
13
48
|
// props预处理
|
|
@@ -389,51 +424,9 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
389
424
|
value
|
|
390
425
|
}
|
|
391
426
|
},
|
|
392
|
-
ios (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const eventName = match[2]
|
|
396
|
-
const modifierStr = match[3] || ''
|
|
397
|
-
const meta = {
|
|
398
|
-
modifierStr
|
|
399
|
-
}
|
|
400
|
-
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'ios' })
|
|
401
|
-
const rEventName = runRules(eventRules, eventName, { mode: 'ios', data: { el } })
|
|
402
|
-
return {
|
|
403
|
-
name: rPrefix + rEventName + meta.modifierStr,
|
|
404
|
-
value
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
android ({ name, value }, { eventRules, el }) {
|
|
408
|
-
const match = this.test.exec(name)
|
|
409
|
-
const prefix = match[1]
|
|
410
|
-
const eventName = match[2]
|
|
411
|
-
const modifierStr = match[3] || ''
|
|
412
|
-
const meta = {
|
|
413
|
-
modifierStr
|
|
414
|
-
}
|
|
415
|
-
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'android' })
|
|
416
|
-
const rEventName = runRules(eventRules, eventName, { mode: 'android', data: { el } })
|
|
417
|
-
return {
|
|
418
|
-
name: rPrefix + rEventName + meta.modifierStr,
|
|
419
|
-
value
|
|
420
|
-
}
|
|
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
|
-
}
|
|
427
|
+
ios: getRnDirectiveEventHandle('ios'),
|
|
428
|
+
android: getRnDirectiveEventHandle('android'),
|
|
429
|
+
harmony: getRnDirectiveEventHandle('harmony')
|
|
437
430
|
},
|
|
438
431
|
// 无障碍
|
|
439
432
|
{
|
|
@@ -537,54 +530,9 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
537
530
|
error(`Web environment does not support [${eventName}] event!`)
|
|
538
531
|
}
|
|
539
532
|
},
|
|
540
|
-
ios
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
longtap: 'longpress',
|
|
544
|
-
longpress: 'longpress',
|
|
545
|
-
touchstart: 'touchstart',
|
|
546
|
-
touchmove: 'touchmove',
|
|
547
|
-
touchend: 'touchend',
|
|
548
|
-
touchcancel: 'touchcancel'
|
|
549
|
-
}
|
|
550
|
-
if (eventMap[eventName]) {
|
|
551
|
-
return eventMap[eventName]
|
|
552
|
-
} else {
|
|
553
|
-
error(`React native environment does not support [${eventName}] event!`)
|
|
554
|
-
}
|
|
555
|
-
},
|
|
556
|
-
android (eventName) {
|
|
557
|
-
const eventMap = {
|
|
558
|
-
tap: 'tap',
|
|
559
|
-
longtap: 'longpress',
|
|
560
|
-
longpress: 'longpress',
|
|
561
|
-
touchstart: 'touchstart',
|
|
562
|
-
touchmove: 'touchmove',
|
|
563
|
-
touchend: 'touchend',
|
|
564
|
-
touchcancel: 'touchcancel'
|
|
565
|
-
}
|
|
566
|
-
if (eventMap[eventName]) {
|
|
567
|
-
return eventMap[eventName]
|
|
568
|
-
} else {
|
|
569
|
-
error(`React native environment does not support [${eventName}] event!`)
|
|
570
|
-
}
|
|
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
|
-
}
|
|
533
|
+
ios: rnEventRulesHandle,
|
|
534
|
+
android: rnEventRulesHandle,
|
|
535
|
+
harmony: rnEventRulesHandle
|
|
588
536
|
},
|
|
589
537
|
// web event escape
|
|
590
538
|
{
|
|
@@ -17,7 +17,6 @@ module.exports = function (script, {
|
|
|
17
17
|
genericsInfo
|
|
18
18
|
}, callback) {
|
|
19
19
|
let scriptSrcMode = srcMode
|
|
20
|
-
const mode = loaderContext.getMpx().mode
|
|
21
20
|
if (script) {
|
|
22
21
|
scriptSrcMode = script.mode || scriptSrcMode
|
|
23
22
|
} else {
|
|
@@ -28,23 +27,7 @@ module.exports = function (script, {
|
|
|
28
27
|
if (ctorType === 'app') {
|
|
29
28
|
output += `
|
|
30
29
|
import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
31
|
-
|
|
32
|
-
${mode === 'ios' || mode === 'harmony' ? "import { createNativeStackNavigator as createStackNavigator } from '@react-navigation/native-stack'" : "import { createStackNavigator } from '@react-navigation/stack'"}
|
|
33
|
-
import PortalHost from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-portal/portal-host'
|
|
34
|
-
import { useHeaderHeight } from '@react-navigation/elements';
|
|
35
|
-
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
36
|
-
import { GestureHandlerRootView } from 'react-native-gesture-handler'
|
|
37
|
-
|
|
38
|
-
global.__navigationHelper = {
|
|
39
|
-
NavigationContainer: NavigationContainer,
|
|
40
|
-
createStackNavigator: createStackNavigator,
|
|
41
|
-
useHeaderHeight: useHeaderHeight,
|
|
42
|
-
StackActions: StackActions,
|
|
43
|
-
GestureHandlerRootView: GestureHandlerRootView,
|
|
44
|
-
PortalHost: PortalHost,
|
|
45
|
-
SafeAreaProvider: SafeAreaProvider,
|
|
46
|
-
useSafeAreaInsets: useSafeAreaInsets
|
|
47
|
-
}\n`
|
|
30
|
+
\n`
|
|
48
31
|
const { pagesMap, firstPage } = buildPagesMap({
|
|
49
32
|
localPagesMap,
|
|
50
33
|
loaderContext,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const TAP_EVENTS = ['bindtap', 'catchtap', 'capture-bindtap', 'capture-catchtap'];
|
|
2
|
+
export const LONGPRESS_EVENTS = ['bindlongpress', 'catchlongpress', 'capture-bindlongpress', 'capture-catchlongpress'];
|
|
2
3
|
const eventConfigMap = {
|
|
3
4
|
bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
|
|
4
5
|
bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef, useMemo } from 'react';
|
|
2
2
|
import { hasOwn, collectDataset } from '@mpxjs/utils';
|
|
3
3
|
import { omit, extendObject, useNavigation } from './utils';
|
|
4
|
-
import eventConfigMap, { TAP_EVENTS } from './event.config';
|
|
4
|
+
import eventConfigMap, { TAP_EVENTS, LONGPRESS_EVENTS } from './event.config';
|
|
5
5
|
const globalEventState = {
|
|
6
6
|
needPress: true
|
|
7
7
|
};
|
|
@@ -74,8 +74,23 @@ function handleEmitEvent(events, type, oe, propsRef, config, navigation) {
|
|
|
74
74
|
events.forEach((event) => {
|
|
75
75
|
if (propsRef.current[event]) {
|
|
76
76
|
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
|
|
77
|
+
// 检查是否已经被上层的 catch 阻止
|
|
78
|
+
if ((type === 'tap' || type === 'longpress') && oe._stoppedEventTypes?.has(type)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
77
81
|
if (match) {
|
|
78
|
-
|
|
82
|
+
const eventBase = match[2] || '';
|
|
83
|
+
if (eventBase === 'tap' || eventBase === 'longpress') {
|
|
84
|
+
// 为 tap、longpress 添加标记,影响后续的冒泡
|
|
85
|
+
if (!oe._stoppedEventTypes) {
|
|
86
|
+
oe._stoppedEventTypes = new Set();
|
|
87
|
+
}
|
|
88
|
+
oe._stoppedEventTypes.add(eventBase);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// 原生 touch 事件使用 stopPropagation
|
|
92
|
+
oe.stopPropagation();
|
|
93
|
+
}
|
|
79
94
|
}
|
|
80
95
|
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config, navigation));
|
|
81
96
|
}
|
|
@@ -116,11 +131,7 @@ function handleTouchstart(e, type, ref, propsRef, config, navigation) {
|
|
|
116
131
|
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
117
132
|
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
|
|
118
133
|
handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config, navigation);
|
|
119
|
-
|
|
120
|
-
if (catchlongpress ||
|
|
121
|
-
bindlongpress ||
|
|
122
|
-
captureCatchlongpress ||
|
|
123
|
-
captureBindlongpress) {
|
|
134
|
+
if (LONGPRESS_EVENTS.some(eventName => propsRef.current[eventName])) {
|
|
124
135
|
ref.current.startTimer[type] = setTimeout(() => {
|
|
125
136
|
// 只要触发过longpress, 全局就不再触发tap
|
|
126
137
|
globalEventState.needPress = false;
|
|
@@ -193,7 +193,7 @@ const _Canvas = forwardRef((props = {}, ref) => {
|
|
|
193
193
|
node: canvasRef.current,
|
|
194
194
|
context: context2D
|
|
195
195
|
});
|
|
196
|
-
if (
|
|
196
|
+
if (__mpx_mode__ !== 'ios') {
|
|
197
197
|
const isAndroid9 = Platform.Version >= 28;
|
|
198
198
|
return createElement(View, innerProps, createElement(WebView, {
|
|
199
199
|
ref: (element) => {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Text } from 'react-native';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { extendObject } from './utils';
|
|
4
|
+
const InlineText = (props) => {
|
|
5
|
+
const { allowFontScaling = false } = props;
|
|
6
|
+
return createElement(Text, extendObject({}, props, {
|
|
7
|
+
allowFontScaling
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
InlineText.displayName = 'MpxInlineText';
|
|
11
|
+
export default InlineText;
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
* ✘ bind:onkeyboardheightchange
|
|
39
39
|
*/
|
|
40
40
|
import { forwardRef, useRef, useState, useContext, useEffect, createElement } from 'react';
|
|
41
|
-
import {
|
|
41
|
+
import { TextInput } from 'react-native';
|
|
42
42
|
import { warn } from '@mpxjs/utils';
|
|
43
|
-
import { useUpdateEffect, useTransformStyle, useLayout, extendObject } from './utils';
|
|
43
|
+
import { useUpdateEffect, useTransformStyle, useLayout, extendObject, isIOS } from './utils';
|
|
44
44
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
45
45
|
import useNodesRef from './useNodesRef';
|
|
46
46
|
import { FormContext, KeyboardAvoidContext } from './context';
|
|
@@ -48,10 +48,7 @@ const keyboardTypeMap = {
|
|
|
48
48
|
text: 'default',
|
|
49
49
|
number: 'numeric',
|
|
50
50
|
idcard: 'default',
|
|
51
|
-
digit:
|
|
52
|
-
ios: 'decimal-pad',
|
|
53
|
-
android: 'numeric'
|
|
54
|
-
}) || ''
|
|
51
|
+
digit: isIOS ? 'decimal-pad' : 'numeric'
|
|
55
52
|
};
|
|
56
53
|
const Input = forwardRef((props, ref) => {
|
|
57
54
|
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,
|
|
@@ -82,7 +79,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
82
79
|
const lineCount = useRef(0);
|
|
83
80
|
const [inputValue, setInputValue] = useState(defaultValue);
|
|
84
81
|
const [contentHeight, setContentHeight] = useState(0);
|
|
85
|
-
const [selection, setSelection] = useState({ start: -1, end:
|
|
82
|
+
const [selection, setSelection] = useState({ start: -1, end: tmpValue.current.length });
|
|
86
83
|
const styleObj = extendObject({ padding: 0, backgroundColor: '#fff' }, style, multiline && autoHeight
|
|
87
84
|
? { height: 'auto', minHeight: Math.max(style?.minHeight || 35, contentHeight) }
|
|
88
85
|
: {});
|
|
@@ -94,15 +91,17 @@ const Input = forwardRef((props, ref) => {
|
|
|
94
91
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
95
92
|
useEffect(() => {
|
|
96
93
|
if (inputValue !== value) {
|
|
97
|
-
|
|
94
|
+
const parsed = parseValue(value);
|
|
95
|
+
tmpValue.current = parsed;
|
|
96
|
+
setInputValue(parsed);
|
|
98
97
|
}
|
|
99
98
|
}, [value]);
|
|
100
99
|
useEffect(() => {
|
|
101
|
-
if (
|
|
102
|
-
setSelection({ start:
|
|
100
|
+
if (selectionStart > -1) {
|
|
101
|
+
setSelection({ start: selectionStart, end: selectionEnd === -1 ? tmpValue.current.length : selectionEnd });
|
|
103
102
|
}
|
|
104
|
-
else if (
|
|
105
|
-
setSelection({ start:
|
|
103
|
+
else if (typeof cursor === 'number') {
|
|
104
|
+
setSelection({ start: cursor, end: cursor });
|
|
106
105
|
}
|
|
107
106
|
}, [cursor, selectionStart, selectionEnd]);
|
|
108
107
|
// have not selection on the Android platformg
|
|
@@ -211,6 +210,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
211
210
|
}
|
|
212
211
|
};
|
|
213
212
|
const resetValue = () => {
|
|
213
|
+
tmpValue.current = '';
|
|
214
214
|
setInputValue('');
|
|
215
215
|
};
|
|
216
216
|
const getValue = () => {
|
|
@@ -255,7 +255,7 @@ const Input = forwardRef((props, ref) => {
|
|
|
255
255
|
maxLength: maxlength === -1 ? undefined : maxlength,
|
|
256
256
|
editable: !disabled,
|
|
257
257
|
autoFocus: !!autoFocus || !!focus,
|
|
258
|
-
selection: selection,
|
|
258
|
+
selection: selectionStart > -1 || typeof cursor === 'number' ? selection : undefined,
|
|
259
259
|
selectionColor: cursorColor,
|
|
260
260
|
blurOnSubmit: !multiline && !confirmHold,
|
|
261
261
|
underlineColorAndroid: 'rgba(0,0,0,0)',
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useMemo } from 'react';
|
|
2
|
-
import { Keyboard,
|
|
2
|
+
import { Keyboard, View } from 'react-native';
|
|
3
3
|
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated';
|
|
4
4
|
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
|
|
5
5
|
import { KeyboardAvoidContext } from './context';
|
|
6
|
+
import { isIOS } from './utils';
|
|
6
7
|
const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
|
|
7
|
-
const isIOS = Platform.OS === 'ios';
|
|
8
8
|
const duration = isIOS ? 250 : 300;
|
|
9
9
|
const easing = isIOS ? Easing.inOut(Easing.ease) : Easing.out(Easing.quad);
|
|
10
10
|
const offset = useSharedValue(0);
|