Skip to content

Commit fdbfd73

Browse files
authored
perf: improve keyboard interaction timing (#3541)
## 🎯 Goal <!-- Describe why we are making this change --> ## πŸ›  Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## πŸ§ͺ Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## β˜‘οΈ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android
1 parent d28257f commit fdbfd73

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

β€Žpackage/src/components/Message/hooks/useMessageActionHandlers.tsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
import { useTranslatedMessage } from '../../../hooks/useTranslatedMessage';
2121
import { NativeHandlers } from '../../../native';
2222

23-
const useWithPortalKeyboardSafety = <T extends unknown[]>(callback: (...args: T) => void) => {
23+
export const useWithPortalKeyboardSafety = <T extends unknown[]>(
24+
callback: (...args: T) => void,
25+
) => {
2426
const callbackAfterKeyboardOpen = useAfterKeyboardOpenCallback(callback);
2527

2628
return usePortalSettledCallback(callbackAfterKeyboardOpen);

β€Žpackage/src/hooks/useAfterKeyboardOpenCallback.tsβ€Ž

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { useEffect, useRef } from 'react';
22
import { EventSubscription, Keyboard, Platform } from 'react-native';
33

4-
import { useKeyboardVisibility } from './useKeyboardVisibility';
5-
64
import { useStableCallback } from './useStableCallback';
75

86
import { KeyboardControllerPackage } from '../components/KeyboardCompatibleView/KeyboardControllerAvoidingView';
@@ -18,7 +16,6 @@ import { useMessageInputContext } from '../contexts/messageInputContext/MessageI
1816
export const useAfterKeyboardOpenCallback = <T extends unknown[]>(
1917
callback: (...args: T) => void,
2018
) => {
21-
const isKeyboardVisible = useKeyboardVisibility();
2219
const { inputBoxRef } = useMessageInputContext();
2320
const keyboardSubscriptionRef = useRef<EventSubscription | undefined>(undefined);
2421
// This callback runs from a keyboard event listener, so it must stay fresh across rerenders.
@@ -45,7 +42,7 @@ export const useAfterKeyboardOpenCallback = <T extends unknown[]>(
4542
return;
4643
}
4744

48-
if (isKeyboardVisible) {
45+
if (Keyboard.isVisible()) {
4946
inputBoxRef.current.focus();
5047
runCallback();
5148
return;

0 commit comments

Comments
Β (0)