mattermost-mobile-upstream/app/utils/keyboard.ts
Carlos Garcia f2857a97d1
Mm 67525 bump min version (#9640)
* bumps minSdkVersion to 30

Older versions are past end-of-life for security patches. voximplant service patch is also updated with minSdkVersion set to 30.

* removes manifest attributes no longer needed when minSdk is 30

* removes guard to for version lower than O

* removes permission check for versions lower than 28

* remove tests related to unsupported android sdk versions

* bumps iOS minSdkVersion to 18

* removes iOS 13/15 guards in hardware-keyboard

* removes iOS 15 guards in NotificationService

* removes iOS 15 guard in Gekidou network delegate

since gekidou is iOS only other platform guards are not needed

* removes version guard no longer needed in voximplant patch

* removes hasWriteStoragePermission dead stub and its call site

* removes unused setSoftKeyboardToAdjustResize from rnutils

The function had no call sites in JS/TS code and the iOS implementation
was a no-op.

* removes version guards and updates config after min version bump

* updates stale iOS 17 simulator references in CI to iOS 18.1

Co-Authored-By: Carlos Garcia <carlos.garcia@mattermost.com>

* fixes malformed patch file headers

- voximplant patch: restore missing diff --git header and index line
  for VIForegroundServiceModule.java, fix stale hunk counter (+11 -> +7)
- notifications patch: fix stale hunk line count (+91 -> +89) after
  KITKAT branch removal

Co-Authored-By: Carlos Garcia <carlos.garcia@mattermost.com>

* remove code below the supported OS versions

* Bump IntuneMAM SDK to 21.8.0 and MSAL to 2.15.0

---------

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2026-09-16 10:53:06 +00:00

45 lines
1.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Platform} from 'react-native';
import {KeyboardController} from 'react-native-keyboard-controller';
const DISMISS_ANIMATION_TIMEOUT = 250;
// Resolve on whichever comes first, and always clear the timer.
const withTimeout = async (promise: Promise<void>, ms: number) => {
let timer: ReturnType<typeof setTimeout> | undefined;
try {
await Promise.race([promise, new Promise<void>((resolve) => {
timer = setTimeout(resolve, ms);
})]);
} finally {
clearTimeout(timer);
}
};
/**
* Dismisses the keyboard via KeyboardController, which both platforms use since
* they always lay out edge-to-edge.
*/
export const dismissKeyboard = async (): Promise<void> => {
const dismissed = KeyboardController.dismiss({animated: false});
// Android only: this promise settles on a `keyboardDidHide` event, and a missed
// one leaves the library's internal state saying "open" so it never settles at
// all. Callers await this before navigating (showPostOptions does), so a missed
// event stops a long press from opening post options. iOS keeps the unbounded
// await — there the event is what tells us the keyboard has left the screen.
if (Platform.OS === 'android') {
await withTimeout(dismissed, DISMISS_ANIMATION_TIMEOUT);
return;
}
await dismissed;
};
/**
* Checks if the keyboard is currently visible.
*/
export const isKeyboardVisible = (): boolean => KeyboardController.isVisible();