keyboard.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { g as getCapacitor } from './capacitor.js';
  5. var ExceptionCode;
  6. (function (ExceptionCode) {
  7. /**
  8. * API is not implemented.
  9. *
  10. * This usually means the API can't be used because it is not implemented for
  11. * the current platform.
  12. */
  13. ExceptionCode["Unimplemented"] = "UNIMPLEMENTED";
  14. /**
  15. * API is not available.
  16. *
  17. * This means the API can't be used right now because:
  18. * - it is currently missing a prerequisite, such as network connectivity
  19. * - it requires a particular platform or browser version
  20. */
  21. ExceptionCode["Unavailable"] = "UNAVAILABLE";
  22. })(ExceptionCode || (ExceptionCode = {}));
  23. var KeyboardResize;
  24. (function (KeyboardResize) {
  25. /**
  26. * Only the `body` HTML element will be resized.
  27. * Relative units are not affected, because the viewport does not change.
  28. *
  29. * @since 1.0.0
  30. */
  31. KeyboardResize["Body"] = "body";
  32. /**
  33. * Only the `ion-app` HTML element will be resized.
  34. * Use it only for Ionic Framework apps.
  35. *
  36. * @since 1.0.0
  37. */
  38. KeyboardResize["Ionic"] = "ionic";
  39. /**
  40. * The whole native Web View will be resized when the keyboard shows/hides.
  41. * This affects the `vh` relative unit.
  42. *
  43. * @since 1.0.0
  44. */
  45. KeyboardResize["Native"] = "native";
  46. /**
  47. * Neither the app nor the Web View are resized.
  48. *
  49. * @since 1.0.0
  50. */
  51. KeyboardResize["None"] = "none";
  52. })(KeyboardResize || (KeyboardResize = {}));
  53. const Keyboard = {
  54. getEngine() {
  55. const capacitor = getCapacitor();
  56. if (capacitor === null || capacitor === void 0 ? void 0 : capacitor.isPluginAvailable('Keyboard')) {
  57. return capacitor.Plugins.Keyboard;
  58. }
  59. return undefined;
  60. },
  61. getResizeMode() {
  62. const engine = this.getEngine();
  63. if (!(engine === null || engine === void 0 ? void 0 : engine.getResizeMode)) {
  64. return Promise.resolve(undefined);
  65. }
  66. return engine.getResizeMode().catch((e) => {
  67. if (e.code === ExceptionCode.Unimplemented) {
  68. // If the native implementation is not available
  69. // we treat it the same as if the plugin is not available.
  70. return undefined;
  71. }
  72. throw e;
  73. });
  74. },
  75. };
  76. export { Keyboard as K, KeyboardResize as a };