diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts index 53789a113..693f6a9d1 100644 --- a/packages/core/index.d.ts +++ b/packages/core/index.d.ts @@ -101,7 +101,7 @@ export type { InstrumentationMode, TimerInfo } from './profiling'; export { encoding } from './text'; export * from './trace'; export * from './ui'; -import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, escapeRegexSymbols, convertString } from './utils'; +import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, escapeRegexSymbols, convertString, dismissSoftInput } from './utils'; import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types'; export declare const Utils: { GC: typeof GC; @@ -144,5 +144,6 @@ export declare const Utils: { isUndefined: typeof isUndefined; toUIString: typeof toUIString; verifyCallback: typeof verifyCallback; + dismissSoftInput: typeof dismissSoftInput; }; export { XmlParser, ParserEventType, ParserEvent } from './xml'; diff --git a/packages/core/index.ts b/packages/core/index.ts index d40e172b2..735f7c266 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -122,7 +122,7 @@ export * from './trace'; export * from './ui'; -import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX, escapeRegexSymbols, convertString } from './utils'; +import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX, escapeRegexSymbols, convertString, dismissSoftInput } from './utils'; import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types'; export const Utils = { @@ -170,6 +170,7 @@ export const Utils = { isUndefined, toUIString, verifyCallback, + dismissSoftInput, }; export { XmlParser, ParserEventType, ParserEvent } from './xml'; diff --git a/packages/core/utils/index.android.ts b/packages/core/utils/index.android.ts index 2f0a3f5bc..98f1fdb4f 100644 --- a/packages/core/utils/index.android.ts +++ b/packages/core/utils/index.android.ts @@ -167,3 +167,7 @@ Please ensure you have your manifest correctly configured with the FileProvider. export function isRealDevice(): boolean { return ad.isRealDevice(); } + +export function dismissSoftInput(nativeView?: any): void { + ad.dismissSoftInput(nativeView); +} diff --git a/packages/core/utils/index.d.ts b/packages/core/utils/index.d.ts index 6e947b3c3..ec047b899 100644 --- a/packages/core/utils/index.d.ts +++ b/packages/core/utils/index.d.ts @@ -286,3 +286,8 @@ export function eliminateDuplicates(arr: Array): Array; * Checks whether the application is running on real device and not on simulator/emulator. */ export function isRealDevice(): boolean; + +/** + * Hides the soft input method, usually a soft keyboard. + */ +export function dismissSoftInput(nativeView?: any): void; diff --git a/packages/core/utils/index.ios.ts b/packages/core/utils/index.ios.ts index fba5699e9..eb95362f1 100644 --- a/packages/core/utils/index.ios.ts +++ b/packages/core/utils/index.ios.ts @@ -48,3 +48,10 @@ export function isRealDevice(): boolean { } export const ad = 0; + +export function dismissSoftInput(nativeView?: UIView): void { + if (nativeView instanceof UIView && !nativeView.isFirstResponder) { + return; + } + UIApplication.sharedApplication.sendActionToFromForEvent('resignFirstResponder', null, null, null); +}