Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/rustgis-mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Rust calls Java and never the other way: each frame the app collects what happen
A phone starts in the touch interface: the map, with a Layers button at its top-right corner, a bar
of large buttons under it (Add Data, Capture, the AI Assistant once a provider is set up, More) and
sheets that rise over the map. Until then, **Set Up the Assistant** in the More sheet is the only
trace of the Assistant, and with its extension off there is none; its sheet types into Android's
trace of the Assistant, and with its extension off there is none; its sheet types into the system's
own text field and stands full or half up, with a strip and Stop while it works
([AI Assistant › On a phone](../../docs/user-guide/assistant.md#on-a-phone)). The Layers sheet
switches between the project's maps and layouts when it has more than one, shows and hides layers, zooms to one and
Expand Down Expand Up @@ -420,14 +420,15 @@ cp parcels.gpkg "$(xcrun simctl get_app_container booted org.rustgis.mobile data
| Position | Core Location, best accuracy. Asked the first time (`NSLocationWhenInUseUsageDescription`); positions start once the user allows them. Refused, now or later in Settings, the app says so and stops asking |
| Out of sight | Recording a track turns on background location updates (the app's `location` background mode in `Info.plist`), with iOS's indicator that an app is using the location. Positions found out of sight wait, at most 200,000, as on Android |
| Camera | `UIImagePickerController`: the photo is written as a JPEG to `Library/Application Support/photos`. A device without a camera (the Simulator) says so |
| Typing | The Capture form's fields and the Assistant's are typed into iOS's own text field, in a bar docked above the soft keyboard (`src/ios/entry.rs`): a `UITextField`, or a `UITextView` for several lines, with paste, suggestions, autocorrection, dictation and, for a key, the password manager. A model's name and a provider's address are kept as typed, with neither suggestions nor corrections (on Android too). What it holds is sent as it changes; Done, a tap beside it, Return on a single line, the keyboard's own key that puts it away and the phone being turned close it (the keyboard of winit's window doesn't turn while it is up). Fields the desktop interface draws are typed through winit's own, below |
| Soft keyboard | winit's own (`UIKeyInput`): letters, Backspace and Return reach the form. The room the keyboard takes comes from UIKit's keyboard notices and keeps the field above it. Return reaches the form as the Enter key: winit 0.30 hands it on as the character `"\n"`, which egui takes for no key, so winit's view is given a subclass whose `insertText:` keeps Return for the shell, which gives egui an Enter. Each field then does what it does with Enter: a single-line one ends typing, and a dialog's text box takes Enter as its button (Shift+Enter there starts a new line, which the soft keyboard can't type) |
| Folders | Settings, app data and the cache are in `Library/Application Support` |
| Picked copies | Kept in `picked/`, as on Android: data and projects open from their copies and are edited there. The folder is left out of the device's backups (`NSURLIsExcludedFromBackupKey`), as the documents are the user's elsewhere. Remove Unused Copies removes those the project doesn't name, as on Android |
| Plain HTTP | App Transport Security is off for every host (`NSAllowsArbitraryLoads`): a project's tile layers and services may be any `http://` server, not known when the app is built, so a list of exceptions can't name them. The App Review notes say so |
| Memory limits | What `os_proc_available_memory` says is left stands for the app's limit at start, and is asked again for each job; 1.5 GiB where it says nothing. A memory warning drops the tile and drawing caches, as on Android |
| Plugins | None can be installed, and the registry isn't fetched: App Review doesn't let an app download code that adds to what it does (guideline 2.5.2), and a plugin, from the registry or a file, is such code. Each way of installing one says so (`rustgis_plugins::INSTALLS`). A later build could carry plugins reviewed with the app |

`src/ios.rs` is the one module of the app with `unsafe` code beyond Android's `no_mangle`, an
`src/ios.rs`, with its `ios/entry.rs`, is the one module of the app with `unsafe` code beyond Android's `no_mangle`, an
exception to the workspace's rule allowed by `#![expect(unsafe_code)]` on the module: UIKit's
delegates are Objective-C classes made with `objc2`'s `define_class!`, which needs `unsafe impl`,
a few of UIKit's calls are unsafe in `objc2`, and libSystem's `os_proc_available_memory` is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public void takePhoto() {
* glide typing, dictation, and a password manager for a "secret". What it holds is sent as a
* "text" event each time it changes, and "text-closed" when it closes (Done, Back, or a tap
* beside it, which goes no further). One opened while another is open replaces it. The kind
* is "plain", "lines", "secret" or "number"; done is the label of its button.
* is "plain", "lines", "verbatim", "secret" or "number"; done is the label of its button.
*/
public void enterText(final String id, final String value, final String label, final String kind, final String done) {
// Counted until it closes: the Rust side keeps looking for what is typed meanwhile.
Expand Down Expand Up @@ -584,6 +584,10 @@ private android.app.Dialog textEntry(final String id, String value, String label
| android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
field.setMaxLines(6);
break;
case "verbatim":
field.setInputType(text | android.text.InputType.TYPE_TEXT_VARIATION_URI
| android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
break;
default:
field.setInputType(text | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
}
Expand Down
52 changes: 49 additions & 3 deletions apps/rustgis-mobile/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// each block says why it holds.
#![expect(unsafe_code, reason = "Objective-C classes, the few UIKit calls objc2 marks unsafe and one libSystem function; see each SAFETY")]

mod entry;

use crate::shell;
use eframe::egui;
use objc2::rc::Retained;
Expand All @@ -31,7 +33,7 @@ use objc2_ui_kit::{
UIViewController, UIWindow, UIWindowDidBecomeVisibleNotification, UIWindowScene, UIWindowSceneDelegate,
};
use objc2_uniform_type_identifiers::UTTypeItem;
use rustgis_engine::platform::{Event, Fix, Platform};
use rustgis_engine::platform::{Event, Fix, Platform, TextEntry};
use rustgis_ui_egui::i18n;
use std::cell::{Cell, RefCell};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -712,19 +714,23 @@ define_class!(
let Some(window) = key_window(mtm).map(|window| window.frame()) else { return };
let bottom = window.origin.y + window.size.height;
// Only a keyboard across the window takes room from it: a floating one beside a window
// in Split View or Stage Manager takes none.
// in Split View or Stage Manager takes none, nor one floating over it, clear of its bottom.
let height = frame
.map(|f| {
let across = f.origin.x < window.origin.x + window.size.width && f.origin.x + f.size.width > window.origin.x;
if across { (bottom - f.origin.y).clamp(0.0, window.size.height) } else { 0.0 }
let docked = f.origin.y + f.size.height >= bottom - 1.0;
if across && docked { (bottom - f.origin.y).clamp(0.0, window.size.height) } else { 0.0 }
})
.unwrap_or(0.0);
self.ivars().height.set(height);
// An open text field is put above it by the next frame ([`Ios::place_entry`]).
wake(mtm);
}

#[unsafe(method(keyboardHidden:))]
fn hidden(&self, _notification: &NSNotification) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR text (and apps/rustgis-mobile/README.md and field-work.md) says the keyboard being put away closes an open text field. This handler only clears the height and wakes the window; it doesn't close anything. A field closes when UIKit ends its editing, which covers the on-screen keyboard being dismissed, but a hardware keyboard leaves the bar open with no keyboard by design (place lays it above the safe area). Either the docs should say that, or the field should be closed here. Confidence: high that the wording and the behaviour differ; which one is intended is the author's call.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording is corrected in 1abec0b: it is the keyboard's own key that puts it away that closes the field, as UIKit ends the editing then (textFieldDidEndEditing:, textViewDidEndEditing:). With a hardware keyboard the bar stays, by design.

self.ivars().height.set(0.0);
wake(self.mtm());
}
}
);
Expand Down Expand Up @@ -1012,6 +1018,8 @@ pub struct Ios {
location: Retained<CLLocationManager>,
located: Retained<LocationDelegate>,
keyboard: Retained<KeyboardObserver>,
/// The text field of iOS's own that is open, or was last (UIKit holds its delegate weakly).
entry: RefCell<Option<Retained<entry::Entry>>>,
memory: Retained<MemoryObserver>,
/// A file to save being written, until its export picker shows.
saving: RefCell<Option<Saving>>,
Expand All @@ -1036,6 +1044,7 @@ struct Saving {

impl Drop for Ios {
fn drop(&mut self) {
self.close_entry();
let center = NSNotificationCenter::defaultCenter();
// SAFETY: removes the observers `KeyboardObserver::new` and `MemoryObserver::new` added.
unsafe {
Expand Down Expand Up @@ -1069,6 +1078,7 @@ impl Ios {
location,
located,
keyboard: KeyboardObserver::new(mtm),
entry: RefCell::new(None),
saving: RefCell::new(None),
presenting: RefCell::new(None),
}
Expand Down Expand Up @@ -1160,6 +1170,27 @@ impl Ios {
}
}

/// Keeps the text field of iOS's own that is open above the soft keyboard, which comes, goes
/// and changes height. Closes it as the window turns: what it holds has been told, and a tap
/// opens it again. Lets go of one that closed. Asked each frame (`take_events`).
fn place_entry(&self) {
let Some(entry) = self.entry.borrow().clone() else { return };
match entry.window().filter(|window| entry.is_open() && !entry.turned(window)) {
Some(window) => entry.place(&window, self.keyboard.ivars().height.get()),
// Closed already, this does nothing but let go of it.
None => self.close_entry(),
}
}

/// Closes the text field of iOS's own that is open, if one is.
fn close_entry(&self) {
// Taken first: closing calls back into UIKit, which must not find it borrowed.
let open = self.entry.borrow_mut().take();
if let Some(entry) = open {
entry.close();
}
}

/// The window's view controller on top, to show a picker over.
fn presenter(&self) -> Result<Retained<UIViewController>, String> {
let window = key_window(self.mtm).ok_or_else(|| i18n::fmt("RustGIS has no window to show the picker over yet.", &[]))?;
Expand Down Expand Up @@ -1319,9 +1350,24 @@ impl Platform for Ios {
self.present(&presenter, &picker, true)
}

fn enters_text(&self) -> bool {
true
}

fn enter_text(&self, entry: &TextEntry) -> Result<(), String> {
// One opened while another is open replaces it, which closes first.
self.close_entry();
let window = key_window(self.mtm).ok_or_else(|| i18n::fmt("RustGIS has no window to type in yet.", &[]))?;
let height = || self.keyboard.ivars().height.get();
let opened = entry::Entry::open(self.mtm, self.shared.clone(), &window, entry, &height)?;
self.entry.replace(Some(opened));
Ok(())
}

fn take_events(&self) -> Vec<Event> {
self.check_presented();
self.show_export();
self.place_entry();
self.shared.events.lock().unwrap_or_else(|e| e.into_inner()).take()
}
}
Expand Down
Loading
Loading