1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 05:10:03 -04:00

Force canvas/text input focus on touch for iOS web browsers (#4848)

This commit is contained in:
Salman Abuhaimed
2024-07-23 19:16:51 +03:00
committed by GitHub
parent 56df31ab48
commit 34db001db1
4 changed files with 67 additions and 55 deletions

View File

@@ -5,7 +5,7 @@ use std::cell::Cell;
use wasm_bindgen::prelude::*;
use super::{AppRunner, WebRunner};
use super::{is_mobile, AppRunner, WebRunner};
pub struct TextAgent {
input: web_sys::HtmlInputElement,
@@ -173,16 +173,3 @@ impl Drop for TextAgent {
self.input.remove();
}
}
/// Returns `true` if the app is likely running on a mobile device.
fn is_mobile() -> bool {
fn try_is_mobile() -> Option<bool> {
const MOBILE_DEVICE: [&str; 6] =
["Android", "iPhone", "iPad", "iPod", "webOS", "BlackBerry"];
let user_agent = web_sys::window()?.navigator().user_agent().ok()?;
let is_mobile = MOBILE_DEVICE.iter().any(|&name| user_agent.contains(name));
Some(is_mobile)
}
try_is_mobile().unwrap_or(false)
}