Skip to content

Commit 6f29392

Browse files
Fix Android keyboard gap using navigation events (#8565) (#8566)
(cherry picked from commit f2383f8) Co-authored-by: Elias Nahum <[email protected]>
1 parent 84badb4 commit 6f29392

File tree

6 files changed

+28
-143
lines changed

6 files changed

+28
-143
lines changed

app/constants/screens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ export const SCREENS_AS_BOTTOM_SHEET = new Set<string>([
199199
CALL_HOST_CONTROLS,
200200
]);
201201

202+
export const SCREENS_WITH_EXTRA_KEYBOARD = new Set<string>([CHANNEL, THREAD]);
203+
202204
export const NOT_READY = [
203205
CREATE_TEAM,
204206
];

app/hooks/android_adjust_soft_keyboard/index.test.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

app/hooks/android_adjust_soft_keyboard/index.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

app/screens/channel/channel.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import FloatingCallContainer from '@calls/components/floating_call_container';
1010
import FreezeScreen from '@components/freeze_screen';
1111
import PostDraft from '@components/post_draft';
1212
import {ExtraKeyboardProvider} from '@context/extra_keyboard';
13-
import {useAndroidAdjustSoftKeyboard} from '@hooks/android_adjust_soft_keyboard';
1413
import useAndroidHardwareBackHandler from '@hooks/android_back_handler';
1514
import {useChannelSwitch} from '@hooks/channel_switch';
1615
import {useIsTablet} from '@hooks/device';
@@ -79,7 +78,6 @@ const Channel = ({
7978
}, [componentId]);
8079

8180
useAndroidHardwareBackHandler(componentId, handleBack);
82-
useAndroidAdjustSoftKeyboard(componentId);
8381

8482
const marginTop = defaultHeight + (isTablet ? 0 : -insets.top);
8583
useEffect(() => {

app/screens/navigation.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
/* eslint-disable max-lines */
55

6+
import RNUtils from '@mattermost/rnutils';
67
import merge from 'deepmerge';
78
import {Appearance, DeviceEventEmitter, StatusBar, Platform, Alert, type EmitterSubscription} from 'react-native';
8-
import {type ComponentWillAppearEvent, type ImageResource, type LayoutOrientation, Navigation, type Options, OptionsModalPresentationStyle, type OptionsTopBarButton, type ScreenPoppedEvent, type EventSubscription} from 'react-native-navigation';
9+
import {type ComponentWillAppearEvent, type ImageResource, type LayoutOrientation, Navigation, type Options, OptionsModalPresentationStyle, type OptionsTopBarButton, type ScreenPoppedEvent, type EventSubscription, type ComponentDidAppearEvent} from 'react-native-navigation';
910
import tinyColor from 'tinycolor2';
1011

1112
import CompassIcon from '@components/compass_icon';
1213
import {Events, Screens, Launch} from '@constants';
13-
import {NOT_READY} from '@constants/screens';
14+
import {NOT_READY, SCREENS_WITH_EXTRA_KEYBOARD} from '@constants/screens';
1415
import {getDefaultThemeByAppearance} from '@context/theme';
1516
import EphemeralStore from '@store/ephemeral_store';
1617
import NavigationStore from '@store/navigation_store';
@@ -39,6 +40,8 @@ export function registerNavigationListeners() {
3940
Navigation.events().registerScreenPoppedListener(onPoppedListener),
4041
Navigation.events().registerCommandListener(onCommandListener),
4142
Navigation.events().registerComponentWillAppearListener(onScreenWillAppear),
43+
Navigation.events().registerComponentDidAppearListener(onScreenDidAppear),
44+
Navigation.events().registerComponentDidDisappearListener(onScreenDidDisappear),
4245
];
4346
}
4447

@@ -76,12 +79,33 @@ function onPoppedListener({componentId}: ScreenPoppedEvent) {
7679
NavigationStore.removeScreenFromStack(componentId as AvailableScreens);
7780
}
7881

82+
function setAndroidSoftKeyboard(screen: AvailableScreens) {
83+
if (Platform.OS !== 'android') {
84+
return;
85+
}
86+
87+
if (SCREENS_WITH_EXTRA_KEYBOARD.has(screen) || (isTablet() && screen === Screens.HOME)) {
88+
RNUtils.setSoftKeyboardToAdjustNothing();
89+
} else {
90+
RNUtils.setSoftKeyboardToAdjustResize();
91+
}
92+
}
93+
7994
function onScreenWillAppear(event: ComponentWillAppearEvent) {
8095
if (event.componentId === Screens.HOME) {
8196
DeviceEventEmitter.emit(Events.TAB_BAR_VISIBLE, true);
8297
}
8398
}
8499

100+
function onScreenDidAppear(event: ComponentDidAppearEvent) {
101+
setAndroidSoftKeyboard(event.componentId as AvailableScreens);
102+
}
103+
104+
function onScreenDidDisappear() {
105+
const screen = NavigationStore.getVisibleScreen();
106+
setAndroidSoftKeyboard(screen);
107+
}
108+
85109
export const loginAnimationOptions = () => {
86110
const theme = getThemeFromState();
87111
return {

app/screens/thread/thread.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import PostDraft from '@components/post_draft';
1313
import RoundedHeaderContext from '@components/rounded_header_context';
1414
import {Screens} from '@constants';
1515
import {ExtraKeyboardProvider} from '@context/extra_keyboard';
16-
import {useAndroidAdjustSoftKeyboard} from '@hooks/android_adjust_soft_keyboard';
1716
import useAndroidHardwareBackHandler from '@hooks/android_back_handler';
1817
import useDidUpdate from '@hooks/did_update';
1918
import {popTopScreen, setButtons} from '@screens/navigation';
@@ -57,7 +56,6 @@ const Thread = ({
5756
}, [componentId]);
5857

5958
useAndroidHardwareBackHandler(componentId, close);
60-
useAndroidAdjustSoftKeyboard(componentId);
6159

6260
useEffect(() => {
6361
if (isCRTEnabled && rootId) {

0 commit comments

Comments
 (0)