android: capture current keyboard height
expose a new virtual_keyboard_height function under notedeck::platform::android which gets the current height of the virtual keyboard. We can use this to tranlate the view out of the way Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -6,6 +6,7 @@ description = "The APIs and data structures used by notedeck apps"
|
||||
|
||||
[dependencies]
|
||||
nostrdb = { workspace = true }
|
||||
jni = { workspace = true }
|
||||
url = { workspace = true }
|
||||
strum = { workspace = true }
|
||||
strum_macros = { workspace = true }
|
||||
@@ -35,5 +36,8 @@ tempfile = { workspace = true }
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
security-framework = { workspace = true }
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
jni = { workspace = true }
|
||||
|
||||
[features]
|
||||
profiling = ["puffin", "puffin_egui"]
|
||||
|
||||
@@ -11,6 +11,7 @@ mod muted;
|
||||
pub mod note;
|
||||
mod notecache;
|
||||
mod persist;
|
||||
pub mod platform;
|
||||
pub mod relay_debug;
|
||||
pub mod relayspec;
|
||||
mod result;
|
||||
|
||||
26
crates/notedeck/src/platform/android.rs
Normal file
26
crates/notedeck/src/platform/android.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use std::sync::atomic::{AtomicI32, Ordering};
|
||||
use tracing::debug;
|
||||
|
||||
// Thread-safe static global
|
||||
static KEYBOARD_HEIGHT: AtomicI32 = AtomicI32::new(0);
|
||||
|
||||
/// This function is called by our main notedeck android activity when the
|
||||
/// keyboard height changes. You can use [`virtual_keyboard_height`] to access
|
||||
/// this
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Java_com_damus_notedeck_KeyboardHeightHelper_nativeKeyboardHeightChanged(
|
||||
_env: jni::JNIEnv,
|
||||
_class: jni::objects::JClass,
|
||||
height: jni::sys::jint,
|
||||
) {
|
||||
debug!("updating virtual keyboard height {}", height);
|
||||
|
||||
// Convert and store atomically
|
||||
KEYBOARD_HEIGHT.store(height as i32, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// Gets the current Android virtual keyboard height. Useful for transforming
|
||||
/// the view
|
||||
pub fn virtual_keyboard_height() -> i32 {
|
||||
KEYBOARD_HEIGHT.load(Ordering::SeqCst)
|
||||
}
|
||||
2
crates/notedeck/src/platform/mod.rs
Normal file
2
crates/notedeck/src/platform/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
#[cfg(target_os = "android")]
|
||||
pub mod android;
|
||||
Reference in New Issue
Block a user