From 400c622e2230530432a648108b4b1fb365379902 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Mon, 30 Oct 2023 10:42:35 +0100 Subject: [PATCH 1/7] fix: change moment of displaying chat after editing existed message --- src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts index dbfa0c6977b..b85210f640e 100644 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts @@ -20,7 +20,7 @@ const setShouldShowComposeInputKeyboardAware: SetShouldShowComposeInputKeyboardA return; } - keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => { + keyboardDidHideListener = Keyboard.addListener('keyboardWillHide', () => { Composer.setShouldShowComposeInput(true); keyboardDidHideListener?.remove(); }); From bc6fd72827d2d8c55cb66046a8acd34ab192e651 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Tue, 31 Oct 2023 09:21:32 +0100 Subject: [PATCH 2/7] fix: add previous solution for android --- .../setShouldShowComposeInputKeyboardAware/index.native.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts index b85210f640e..918db9e77cc 100644 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts @@ -1,4 +1,4 @@ -import {EmitterSubscription, Keyboard} from 'react-native'; +import {EmitterSubscription, Keyboard, Platform} from 'react-native'; import * as Composer from '@userActions/Composer'; import SetShouldShowComposeInputKeyboardAware from './types'; @@ -20,7 +20,7 @@ const setShouldShowComposeInputKeyboardAware: SetShouldShowComposeInputKeyboardA return; } - keyboardDidHideListener = Keyboard.addListener('keyboardWillHide', () => { + keyboardDidHideListener = Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', () => { Composer.setShouldShowComposeInput(true); keyboardDidHideListener?.remove(); }); From 45b03b08f163b6cb0678d590fcf673d060bc5ac9 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Wed, 1 Nov 2023 18:20:32 +0100 Subject: [PATCH 3/7] refactor: change event handler method --- .../index.native.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts index 918db9e77cc..6ab611e6156 100644 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts @@ -1,12 +1,18 @@ import {EmitterSubscription, Keyboard, Platform} from 'react-native'; +import getOperatingSystem from '@libs/getOperatingSystem'; import * as Composer from '@userActions/Composer'; +import CONST from '@src/CONST'; import SetShouldShowComposeInputKeyboardAware from './types'; -let keyboardDidHideListener: EmitterSubscription | null = null; +let keyboardEventListener: EmitterSubscription | null = null; +// On iOS is visible delay with displaying input after keyboard has been closed with `keyboardDidHide` event +// Because of that - on iOS we can use `keyboardWillHide` that is not available on android +const keyboardEvent = getOperatingSystem() === CONST.OS.IOS ? 'keyboardWillHide' : 'keyboardDidHide'; + const setShouldShowComposeInputKeyboardAware: SetShouldShowComposeInputKeyboardAware = (shouldShow) => { - if (keyboardDidHideListener) { - keyboardDidHideListener.remove(); - keyboardDidHideListener = null; + if (keyboardEventListener) { + keyboardEventListener.remove(); + keyboardEventListener = null; } if (!shouldShow) { @@ -20,9 +26,9 @@ const setShouldShowComposeInputKeyboardAware: SetShouldShowComposeInputKeyboardA return; } - keyboardDidHideListener = Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', () => { + keyboardEventListener = Keyboard.addListener(keyboardEvent, () => { Composer.setShouldShowComposeInput(true); - keyboardDidHideListener?.remove(); + keyboardEventListener?.remove(); }); }; From b18fd59d8d2b57944544a566a50e00d798f55858 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Wed, 1 Nov 2023 18:26:15 +0100 Subject: [PATCH 4/7] fix: removed unused Platform dependency --- src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts index 6ab611e6156..aa9eba198b9 100644 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts @@ -1,4 +1,4 @@ -import {EmitterSubscription, Keyboard, Platform} from 'react-native'; +import {EmitterSubscription, Keyboard} from 'react-native'; import getOperatingSystem from '@libs/getOperatingSystem'; import * as Composer from '@userActions/Composer'; import CONST from '@src/CONST'; From a20986c3f8c3f812aa0f559382653b6650ea9047 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Thu, 2 Nov 2023 18:56:44 +0100 Subject: [PATCH 5/7] fix: changed comment description --- src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts index aa9eba198b9..ba36df6446c 100644 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts @@ -5,7 +5,7 @@ import CONST from '@src/CONST'; import SetShouldShowComposeInputKeyboardAware from './types'; let keyboardEventListener: EmitterSubscription | null = null; -// On iOS is visible delay with displaying input after keyboard has been closed with `keyboardDidHide` event +// On iOS, there is a visible delay in displaying input after the keyboard has been closed with the `keyboardDidHide` event // Because of that - on iOS we can use `keyboardWillHide` that is not available on android const keyboardEvent = getOperatingSystem() === CONST.OS.IOS ? 'keyboardWillHide' : 'keyboardDidHide'; From 1ef898ce3295a851c51c83b052c9f1e63389057a Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Tue, 7 Nov 2023 09:54:26 +0100 Subject: [PATCH 6/7] fix: added files per native platform --- .../index.android.ts | 3 ++ .../index.ios.ts | 5 +++ .../index.native.ts | 35 ------------------ ...uldShowComposeInputKeyboardAwareBuilder.ts | 36 +++++++++++++++++++ 4 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 src/libs/setShouldShowComposeInputKeyboardAware/index.android.ts create mode 100644 src/libs/setShouldShowComposeInputKeyboardAware/index.ios.ts delete mode 100644 src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts create mode 100644 src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.android.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.android.ts new file mode 100644 index 00000000000..68c750b05a5 --- /dev/null +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.android.ts @@ -0,0 +1,3 @@ +import setShouldShowComposeInputKeyboardAwareBuilder from './setShouldShowComposeInputKeyboardAwareBuilder'; + +export default setShouldShowComposeInputKeyboardAwareBuilder('keyboardDidHide'); diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.ios.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.ios.ts new file mode 100644 index 00000000000..cd50938c70b --- /dev/null +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.ios.ts @@ -0,0 +1,5 @@ +import setShouldShowComposeInputKeyboardAwareBuilder from './setShouldShowComposeInputKeyboardAwareBuilder'; + +// On iOS, there is a visible delay in displaying input after the keyboard has been closed with the `keyboardDidHide` event +// Because of that - on iOS we can use `keyboardWillHide` that is not available on android +export default setShouldShowComposeInputKeyboardAwareBuilder('keyboardWillHide'); diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts deleted file mode 100644 index ba36df6446c..00000000000 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.ts +++ /dev/null @@ -1,35 +0,0 @@ -import {EmitterSubscription, Keyboard} from 'react-native'; -import getOperatingSystem from '@libs/getOperatingSystem'; -import * as Composer from '@userActions/Composer'; -import CONST from '@src/CONST'; -import SetShouldShowComposeInputKeyboardAware from './types'; - -let keyboardEventListener: EmitterSubscription | null = null; -// On iOS, there is a visible delay in displaying input after the keyboard has been closed with the `keyboardDidHide` event -// Because of that - on iOS we can use `keyboardWillHide` that is not available on android -const keyboardEvent = getOperatingSystem() === CONST.OS.IOS ? 'keyboardWillHide' : 'keyboardDidHide'; - -const setShouldShowComposeInputKeyboardAware: SetShouldShowComposeInputKeyboardAware = (shouldShow) => { - if (keyboardEventListener) { - keyboardEventListener.remove(); - keyboardEventListener = null; - } - - if (!shouldShow) { - Composer.setShouldShowComposeInput(false); - return; - } - - // If keyboard is already hidden, we should show composer immediately because keyboardDidHide event won't be called - if (!Keyboard.isVisible()) { - Composer.setShouldShowComposeInput(true); - return; - } - - keyboardEventListener = Keyboard.addListener(keyboardEvent, () => { - Composer.setShouldShowComposeInput(true); - keyboardEventListener?.remove(); - }); -}; - -export default setShouldShowComposeInputKeyboardAware; diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts b/src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts new file mode 100644 index 00000000000..9d332c8a29e --- /dev/null +++ b/src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts @@ -0,0 +1,36 @@ +import {EmitterSubscription, Keyboard} from 'react-native'; +import {KeyboardEventName} from 'react-native/Libraries/Components/Keyboard/Keyboard'; +// import getOperatingSystem from '@libs/getOperatingSystem'; +import * as Composer from '@userActions/Composer'; +// import CONST from '@src/CONST'; +import SetShouldShowComposeInputKeyboardAware from './types'; + +let keyboardEventListener: EmitterSubscription | null = null; +// On iOS, there is a visible delay in displaying input after the keyboard has been closed with the `keyboardDidHide` event +// Because of that - on iOS we can use `keyboardWillHide` that is not available on android + +const setShouldShowComposeInputKeyboardAwareBuilder: (keyboardEvent: KeyboardEventName) => SetShouldShowComposeInputKeyboardAware = + (keyboardEvent: KeyboardEventName) => (shouldShow: boolean) => { + if (keyboardEventListener) { + keyboardEventListener.remove(); + keyboardEventListener = null; + } + + if (!shouldShow) { + Composer.setShouldShowComposeInput(false); + return; + } + + // If keyboard is already hidden, we should show composer immediately because keyboardDidHide event won't be called + if (!Keyboard.isVisible()) { + Composer.setShouldShowComposeInput(true); + return; + } + + keyboardEventListener = Keyboard.addListener(keyboardEvent, () => { + Composer.setShouldShowComposeInput(true); + keyboardEventListener?.remove(); + }); + }; + +export default setShouldShowComposeInputKeyboardAwareBuilder; From c47a6fec659368883c52236c39627f03aaa0e6d3 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Tue, 7 Nov 2023 09:55:51 +0100 Subject: [PATCH 7/7] fix: added files per native platform --- .../setShouldShowComposeInputKeyboardAwareBuilder.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts b/src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts index 9d332c8a29e..528b71c45ab 100644 --- a/src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts +++ b/src/libs/setShouldShowComposeInputKeyboardAware/setShouldShowComposeInputKeyboardAwareBuilder.ts @@ -1,8 +1,6 @@ import {EmitterSubscription, Keyboard} from 'react-native'; import {KeyboardEventName} from 'react-native/Libraries/Components/Keyboard/Keyboard'; -// import getOperatingSystem from '@libs/getOperatingSystem'; import * as Composer from '@userActions/Composer'; -// import CONST from '@src/CONST'; import SetShouldShowComposeInputKeyboardAware from './types'; let keyboardEventListener: EmitterSubscription | null = null;