diff --git a/core/src/utils/native/keyboard.ts b/core/src/utils/native/keyboard.ts index 7325b2bee98..6a4e88efbe7 100644 --- a/core/src/utils/native/keyboard.ts +++ b/core/src/utils/native/keyboard.ts @@ -1,5 +1,7 @@ import { win } from '../browser'; +import type { NativePluginError } from './native-interface'; + // Interfaces source: https://capacitorjs.com/docs/apis/keyboard#interfaces export interface KeyboardResizeOptions { mode: KeyboardResize; @@ -18,10 +20,16 @@ export const Keyboard = { }, getResizeMode(): Promise { const engine = this.getEngine(); - if (!engine || !engine.getResizeMode) { + if (!engine?.getResizeMode) { return Promise.resolve(undefined); } - - return engine.getResizeMode(); + return engine.getResizeMode().catch((e: NativePluginError) => { + if (e.code === 'UNIMPLEMENTED') { + // If the native implementation is not available + // we treat it the same as if the plugin is not available. + return undefined; + } + throw e; + }); }, }; diff --git a/core/src/utils/native/native-interface.ts b/core/src/utils/native/native-interface.ts new file mode 100644 index 00000000000..a486f455aa0 --- /dev/null +++ b/core/src/utils/native/native-interface.ts @@ -0,0 +1,13 @@ +/** + * Used to represent a generic error from a native plugin call. + */ +export interface NativePluginError { + /** + * The error code. + */ + code?: string; + /** + * The error message. + */ + message?: string; +}