Skip to content

Commit beb8e38

Browse files
authored
Merge pull request #42622 from dominictb/fix/41137
fix: keep the Android keyboard visible when pasting
2 parents 779d29d + 6f58097 commit beb8e38

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,7 @@ PODS:
18521852
- RNGoogleSignin (10.0.1):
18531853
- GoogleSignIn (~> 7.0)
18541854
- React-Core
1855-
- RNLiveMarkdown (0.1.83):
1855+
- RNLiveMarkdown (0.1.84):
18561856
- glog
18571857
- hermes-engine
18581858
- RCT-Folly (= 2022.05.16.00)
@@ -1870,9 +1870,9 @@ PODS:
18701870
- React-utils
18711871
- ReactCommon/turbomodule/bridging
18721872
- ReactCommon/turbomodule/core
1873-
- RNLiveMarkdown/common (= 0.1.83)
1873+
- RNLiveMarkdown/common (= 0.1.84)
18741874
- Yoga
1875-
- RNLiveMarkdown/common (0.1.83):
1875+
- RNLiveMarkdown/common (0.1.84):
18761876
- glog
18771877
- hermes-engine
18781878
- RCT-Folly (= 2022.05.16.00)
@@ -2589,7 +2589,7 @@ SPEC CHECKSUMS:
25892589
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
25902590
RNGestureHandler: 74b7b3d06d667ba0bbf41da7718f2607ae0dfe8f
25912591
RNGoogleSignin: ccaa4a81582cf713eea562c5dd9dc1961a715fd0
2592-
RNLiveMarkdown: 88030b7d9a31f5f6e67743df48ad952d64513b4a
2592+
RNLiveMarkdown: bf516c02a4549a059829a3fbb8f51c2e0a3110e7
25932593
RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81
25942594
rnmapbox-maps: df8fe93dbd251f25022f4023d31bc04160d4d65c
25952595
RNPermissions: 0b61d30d21acbeafe25baaa47d9bae40a0c65216
@@ -2606,7 +2606,7 @@ SPEC CHECKSUMS:
26062606
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
26072607
Turf: 13d1a92d969ca0311bbc26e8356cca178ce95da2
26082608
VisionCamera: 1394a316c7add37e619c48d7aa40b38b954bf055
2609-
Yoga: 64cd2a583ead952b0315d5135bf39e053ae9be70
2609+
Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312
26102610

26112611
PODFILE CHECKSUM: 66a5c97ae1059e4da1993a4ad95abe5d819f555b
26122612

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@babel/plugin-proposal-private-methods": "^7.18.6",
6666
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
6767
"@dotlottie/react-player": "^1.6.3",
68-
"@expensify/react-native-live-markdown": "0.1.83",
68+
"@expensify/react-native-live-markdown": "0.1.84",
6969
"@expo/metro-runtime": "~3.1.1",
7070
"@formatjs/intl-datetimeformat": "^6.10.0",
7171
"@formatjs/intl-listformat": "^7.2.2",

src/hooks/useHtmlPaste/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ const insertAtCaret = (target: HTMLElement, text: string) => {
1818
// Move caret to the end of the newly inserted text node.
1919
range.setStart(node, node.length);
2020
range.setEnd(node, node.length);
21-
selection.removeAllRanges();
22-
selection.addRange(range);
21+
selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
2322

2423
// Dispatch paste event to simulate real browser behavior
2524
target.dispatchEvent(new Event('paste', {bubbles: true}));
@@ -46,9 +45,19 @@ const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeLi
4645
insertByCommand(text);
4746
}
4847

48+
if (!textInputRef.current?.isFocused()) {
49+
textInputRef.current?.focus();
50+
return;
51+
}
52+
4953
// Pointer will go out of sight when a large paragraph is pasted on the web. Refocusing the input keeps the cursor in view.
50-
textInputRef.current?.blur();
51-
textInputRef.current?.focus();
54+
// To avoid the keyboard toggle issue in mWeb if using blur() and focus() functions, we just need to dispatch the event to trigger the onFocus handler
55+
// We need to trigger the bubbled "focusin" event to make sure the onFocus handler is triggered
56+
textInputHTMLElement.dispatchEvent(
57+
new FocusEvent('focusin', {
58+
bubbles: true,
59+
}),
60+
);
5261
// eslint-disable-next-line no-empty
5362
} catch (e) {}
5463
// We only need to set the callback once.

0 commit comments

Comments
 (0)