@mpxjs/webpack-plugin 2.10.3-beta.4 → 2.10.3-beta.6

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.
@@ -82,7 +82,7 @@ const Input = forwardRef((props, ref) => {
82
82
  const lineCount = useRef(0);
83
83
  const [inputValue, setInputValue] = useState(defaultValue);
84
84
  const [contentHeight, setContentHeight] = useState(0);
85
- const [selection, setSelection] = useState({ start: -1, end: -1 });
85
+ const [selection, setSelection] = useState({ start: -1, end: tmpValue.current.length });
86
86
  const styleObj = extendObject({ padding: 0, backgroundColor: '#fff' }, style, multiline && autoHeight
87
87
  ? { height: 'auto', minHeight: Math.max(style?.minHeight || 35, contentHeight) }
88
88
  : {});
@@ -94,15 +94,17 @@ const Input = forwardRef((props, ref) => {
94
94
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
95
95
  useEffect(() => {
96
96
  if (inputValue !== value) {
97
- setInputValue(parseValue(value));
97
+ const parsed = parseValue(value);
98
+ tmpValue.current = parsed;
99
+ setInputValue(parsed);
98
100
  }
99
101
  }, [value]);
100
102
  useEffect(() => {
101
- if (typeof cursor === 'number') {
102
- setSelection({ start: cursor, end: cursor });
103
+ if (selectionStart > -1) {
104
+ setSelection({ start: selectionStart, end: selectionEnd === -1 ? tmpValue.current.length : selectionEnd });
103
105
  }
104
- else if (selectionStart >= 0 && selectionEnd >= 0 && selectionStart !== selectionEnd) {
105
- setSelection({ start: selectionStart, end: selectionEnd });
106
+ else if (typeof cursor === 'number') {
107
+ setSelection({ start: cursor, end: cursor });
106
108
  }
107
109
  }, [cursor, selectionStart, selectionEnd]);
108
110
  // have not selection on the Android platformg
@@ -152,6 +154,9 @@ const Input = forwardRef((props, ref) => {
152
154
  // sometimes the focus event occurs later than the keyboardWillShow event
153
155
  setKeyboardAvoidContext();
154
156
  };
157
+ const onTouchEnd = (evt) => {
158
+ evt.nativeEvent.origin = 'input';
159
+ };
155
160
  const onFocus = (evt) => {
156
161
  setKeyboardAvoidContext();
157
162
  bindfocus && bindfocus(getCustomEvent('focus', evt, {
@@ -211,6 +216,7 @@ const Input = forwardRef((props, ref) => {
211
216
  }
212
217
  };
213
218
  const resetValue = () => {
219
+ tmpValue.current = '';
214
220
  setInputValue('');
215
221
  };
216
222
  const getValue = () => {
@@ -255,7 +261,7 @@ const Input = forwardRef((props, ref) => {
255
261
  maxLength: maxlength === -1 ? undefined : maxlength,
256
262
  editable: !disabled,
257
263
  autoFocus: !!autoFocus || !!focus,
258
- selection: selection,
264
+ selection: selectionStart > -1 || typeof cursor === 'number' ? selection : undefined,
259
265
  selectionColor: cursorColor,
260
266
  blurOnSubmit: !multiline && !confirmHold,
261
267
  underlineColorAndroid: 'rgba(0,0,0,0)',
@@ -264,6 +270,7 @@ const Input = forwardRef((props, ref) => {
264
270
  multiline: !!multiline
265
271
  }, !!multiline && confirmType === 'return' ? {} : { enterKeyHint: confirmType }, layoutProps, {
266
272
  onTouchStart,
273
+ onTouchEnd,
267
274
  onFocus,
268
275
  onBlur,
269
276
  onChange,
@@ -1,7 +1,6 @@
1
- import React, { useContext, useEffect, useMemo } from 'react';
2
- import { Keyboard, Platform, View } from 'react-native';
1
+ import React, { useContext, useEffect } from 'react';
2
+ import { Keyboard, View, Platform } from 'react-native';
3
3
  import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated';
4
- import { GestureDetector, Gesture } from 'react-native-gesture-handler';
5
4
  import { KeyboardAvoidContext } from './context';
6
5
  const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
7
6
  const isIOS = Platform.OS === 'ios';
@@ -10,20 +9,10 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
10
9
  const offset = useSharedValue(0);
11
10
  const basic = useSharedValue('auto');
12
11
  const keyboardAvoid = useContext(KeyboardAvoidContext);
13
- const dismiss = () => {
14
- Keyboard.isVisible() && Keyboard.dismiss();
15
- };
16
- const gesture = useMemo(() => {
17
- return Gesture.Tap()
18
- .onEnd(() => {
19
- dismiss();
20
- }).runOnJS(true);
21
- }, []);
22
- const animatedStyle = useAnimatedStyle(() => {
23
- return Object.assign({
24
- transform: [{ translateY: -offset.value }]
25
- }, isIOS ? {} : { flexBasis: basic.value });
26
- });
12
+ const animatedStyle = useAnimatedStyle(() => ({
13
+ transform: [{ translateY: -offset.value }],
14
+ flexBasis: basic.value
15
+ }));
27
16
  const resetKeyboard = () => {
28
17
  if (keyboardAvoid?.current) {
29
18
  keyboardAvoid.current = null;
@@ -31,6 +20,11 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
31
20
  offset.value = withTiming(0, { duration, easing });
32
21
  basic.value = 'auto';
33
22
  };
23
+ const onTouchEnd = ({ nativeEvent }) => {
24
+ if (nativeEvent.origin !== 'input') {
25
+ Keyboard.isVisible() && Keyboard.dismiss();
26
+ }
27
+ };
34
28
  useEffect(() => {
35
29
  let subscriptions = [];
36
30
  if (isIOS) {
@@ -46,7 +40,12 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
46
40
  const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
47
41
  const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing);
48
42
  const value = aboveOffset > 0 ? belowValue : aboveValue;
49
- offset.value = withTiming(value, { duration, easing });
43
+ offset.value = withTiming(value, { duration, easing }, (finished) => {
44
+ if (finished) {
45
+ // Set flexBasic after animation to trigger re-layout and reset layout information
46
+ basic.value = '99.99%';
47
+ }
48
+ });
50
49
  });
51
50
  });
52
51
  }),
@@ -68,11 +67,7 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
68
67
  const value = aboveOffset > 0 ? belowValue : aboveValue;
69
68
  offset.value = withTiming(value, { duration, easing }, (finished) => {
70
69
  if (finished) {
71
- /**
72
- * In the Android environment, the layout information is not synchronized after the animation,
73
- * which results in the inability to correctly trigger element events.
74
- * Here, we utilize flexBasic to proactively trigger a re-layout
75
- */
70
+ // Set flexBasic after animation to trigger re-layout and reset layout information
76
71
  basic.value = '99.99%';
77
72
  }
78
73
  });
@@ -85,16 +80,14 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
85
80
  subscriptions.forEach(subscription => subscription.remove());
86
81
  };
87
82
  }, [keyboardAvoid]);
88
- return (<GestureDetector gesture={gesture}>
89
- <View style={style}>
90
- <Animated.View style={[
83
+ return (<View style={style} onTouchEnd={onTouchEnd}>
84
+ <Animated.View style={[
91
85
  contentContainerStyle,
92
86
  animatedStyle
93
87
  ]}>
94
- {children}
95
- </Animated.View>
96
- </View>
97
- </GestureDetector>);
88
+ {children}
89
+ </Animated.View>
90
+ </View>);
98
91
  };
99
92
  KeyboardAvoidingView.displayName = 'MpxKeyboardAvoidingView';
100
93
  export default KeyboardAvoidingView;
@@ -51,7 +51,8 @@ import {
51
51
  TextInputSelectionChangeEventData,
52
52
  TextInputFocusEventData,
53
53
  TextInputChangeEventData,
54
- TextInputSubmitEditingEventData
54
+ TextInputSubmitEditingEventData,
55
+ NativeTouchEvent
55
56
  } from 'react-native'
56
57
  import { warn } from '@mpxjs/utils'
57
58
  import { useUpdateEffect, useTransformStyle, useLayout, extendObject } from './utils'
@@ -195,7 +196,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
195
196
 
196
197
  const [inputValue, setInputValue] = useState(defaultValue)
197
198
  const [contentHeight, setContentHeight] = useState(0)
198
- const [selection, setSelection] = useState({ start: -1, end: -1 })
199
+ const [selection, setSelection] = useState({ start: -1, end: tmpValue.current.length })
199
200
 
200
201
  const styleObj = extendObject(
201
202
  { padding: 0, backgroundColor: '#fff' },
@@ -221,15 +222,17 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
221
222
 
222
223
  useEffect(() => {
223
224
  if (inputValue !== value) {
224
- setInputValue(parseValue(value))
225
+ const parsed = parseValue(value)
226
+ tmpValue.current = parsed
227
+ setInputValue(parsed)
225
228
  }
226
229
  }, [value])
227
230
 
228
231
  useEffect(() => {
229
- if (typeof cursor === 'number') {
232
+ if (selectionStart > -1) {
233
+ setSelection({ start: selectionStart, end: selectionEnd === -1 ? tmpValue.current.length : selectionEnd })
234
+ } else if (typeof cursor === 'number') {
230
235
  setSelection({ start: cursor, end: cursor })
231
- } else if (selectionStart >= 0 && selectionEnd >= 0 && selectionStart !== selectionEnd) {
232
- setSelection({ start: selectionStart, end: selectionEnd })
233
236
  }
234
237
  }, [cursor, selectionStart, selectionEnd])
235
238
 
@@ -290,6 +293,10 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
290
293
  setKeyboardAvoidContext()
291
294
  }
292
295
 
296
+ const onTouchEnd = (evt: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
297
+ evt.nativeEvent.origin = 'input'
298
+ }
299
+
293
300
  const onFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
294
301
  setKeyboardAvoidContext()
295
302
  bindfocus && bindfocus(
@@ -388,6 +395,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
388
395
  }
389
396
 
390
397
  const resetValue = () => {
398
+ tmpValue.current = ''
391
399
  setInputValue('')
392
400
  }
393
401
 
@@ -440,7 +448,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
440
448
  maxLength: maxlength === -1 ? undefined : maxlength,
441
449
  editable: !disabled,
442
450
  autoFocus: !!autoFocus || !!focus,
443
- selection: selection,
451
+ selection: selectionStart > -1 || typeof cursor === 'number' ? selection : undefined,
444
452
  selectionColor: cursorColor,
445
453
  blurOnSubmit: !multiline && !confirmHold,
446
454
  underlineColorAndroid: 'rgba(0,0,0,0)',
@@ -452,6 +460,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
452
460
  layoutProps,
453
461
  {
454
462
  onTouchStart,
463
+ onTouchEnd,
455
464
  onFocus,
456
465
  onBlur,
457
466
  onChange,
@@ -1,7 +1,6 @@
1
- import React, { ReactNode, useContext, useEffect, useMemo } from 'react'
2
- import { DimensionValue, EmitterSubscription, Keyboard, Platform, View, ViewStyle } from 'react-native'
3
- import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, runOnJS } from 'react-native-reanimated'
4
- import { GestureDetector, Gesture } from 'react-native-gesture-handler'
1
+ import React, { ReactNode, useContext, useEffect } from 'react'
2
+ import { DimensionValue, EmitterSubscription, Keyboard, View, ViewStyle, Platform, NativeSyntheticEvent, NativeTouchEvent } from 'react-native'
3
+ import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
5
4
  import { KeyboardAvoidContext } from './context'
6
5
 
7
6
  type KeyboardAvoidViewProps = {
@@ -19,25 +18,10 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
19
18
  const basic = useSharedValue('auto')
20
19
  const keyboardAvoid = useContext(KeyboardAvoidContext)
21
20
 
22
- const dismiss = () => {
23
- Keyboard.isVisible() && Keyboard.dismiss()
24
- }
25
-
26
- const gesture = useMemo(() => {
27
- return Gesture.Tap()
28
- .onEnd(() => {
29
- dismiss()
30
- }).runOnJS(true)
31
- }, [])
32
-
33
- const animatedStyle = useAnimatedStyle(() => {
34
- return Object.assign(
35
- {
36
- transform: [{ translateY: -offset.value }]
37
- },
38
- isIOS ? {} : { flexBasis: basic.value as DimensionValue }
39
- )
40
- })
21
+ const animatedStyle = useAnimatedStyle(() => ({
22
+ transform: [{ translateY: -offset.value }],
23
+ flexBasis: basic.value as DimensionValue
24
+ }))
41
25
 
42
26
  const resetKeyboard = () => {
43
27
  if (keyboardAvoid?.current) {
@@ -47,6 +31,12 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
47
31
  basic.value = 'auto'
48
32
  }
49
33
 
34
+ const onTouchEnd = ({ nativeEvent }: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
35
+ if (nativeEvent.origin !== 'input') {
36
+ Keyboard.isVisible() && Keyboard.dismiss()
37
+ }
38
+ }
39
+
50
40
  useEffect(() => {
51
41
  let subscriptions: EmitterSubscription[] = []
52
42
 
@@ -62,7 +52,12 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
62
52
  const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
63
53
  const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
64
54
  const value = aboveOffset > 0 ? belowValue : aboveValue
65
- offset.value = withTiming(value, { duration, easing })
55
+ offset.value = withTiming(value, { duration, easing }, (finished) => {
56
+ if (finished) {
57
+ // Set flexBasic after animation to trigger re-layout and reset layout information
58
+ basic.value = '99.99%'
59
+ }
60
+ })
66
61
  })
67
62
  })
68
63
  }),
@@ -82,11 +77,7 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
82
77
  const value = aboveOffset > 0 ? belowValue : aboveValue
83
78
  offset.value = withTiming(value, { duration, easing }, (finished) => {
84
79
  if (finished) {
85
- /**
86
- * In the Android environment, the layout information is not synchronized after the animation,
87
- * which results in the inability to correctly trigger element events.
88
- * Here, we utilize flexBasic to proactively trigger a re-layout
89
- */
80
+ // Set flexBasic after animation to trigger re-layout and reset layout information
90
81
  basic.value = '99.99%'
91
82
  }
92
83
  })
@@ -102,18 +93,16 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
102
93
  }, [keyboardAvoid])
103
94
 
104
95
  return (
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>
96
+ <View style={style} onTouchEnd={onTouchEnd}>
97
+ <Animated.View
98
+ style={[
99
+ contentContainerStyle,
100
+ animatedStyle
101
+ ]}
102
+ >
103
+ {children}
104
+ </Animated.View>
105
+ </View>
117
106
  )
118
107
  }
119
108
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.3-beta.4",
3
+ "version": "2.10.3-beta.6",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"