From 1d18a6ca57c0c778f867863e6ea48e97bc391e83 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Wed, 13 Nov 2024 12:43:59 +0100 Subject: [PATCH] android: use show_soft_input to summon the keyboard Route it via the `Window::set_ime_allowed` like on iOS. --- src/changelog/unreleased.md | 1 + src/platform_impl/android/mod.rs | 8 +++++++- src/window.rs | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 6e9802dd1..676bf90c0 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -46,6 +46,7 @@ changelog entry. to fully disable the menu bar and dock in Borderless Fullscreen as commonly done in games. - On X11, the `window` example now understands the `X11_VISUAL_ID` and `X11_SCREEN_ID` env variables to test the respective modifiers of window creation. +- On Android, the soft keyboard can now be shown using `Window::set_ime_allowed`. ### Fixed diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 950e31029..bc0ad680e 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -908,7 +908,13 @@ impl Window { pub fn set_ime_cursor_area(&self, _position: Position, _size: Size) {} - pub fn set_ime_allowed(&self, _allowed: bool) {} + pub fn set_ime_allowed(&self, allowed: bool) { + if allowed { + self.app.show_soft_input(true); + } else { + self.app.hide_soft_input(true); + } + } pub fn set_ime_purpose(&self, _purpose: ImePurpose) {} diff --git a/src/window.rs b/src/window.rs index f19265e3a..9bd002ab4 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1274,7 +1274,8 @@ impl Window { /// /// - **macOS:** IME must be enabled to receive text-input where dead-key sequences are /// combined. - /// - **iOS / Android / Web / Orbital:** Unsupported. + /// - **iOS / Android:** This will show / hide the soft keyboard. + /// - **Web / Orbital:** Unsupported. /// - **X11**: Enabling IME will disable dead keys reporting during compose. /// /// [`Ime`]: crate::event::WindowEvent::Ime