mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
feat(native): the app answers a finger like a native app, not like a web page
After a tap, WebKit and Chrome keep :hover on what was tapped and send a
made-up mouseover, so buttons and rows stayed tinted until the next tap.
While a finger drives the app <html> carries data-touch-input: a PostCSS
step guards every :hover rule with it (no specificity change), and the
made-up mouseover and mouseout stop before any handler. A trackpad or mouse
clears the mark and gets hover back; a browser never sets it.
A control without a press of its own dims the moment a finger lands on it,
after a 60 ms wait so a scroll does not flash rows, and only the innermost
pressed control. A focus: ring no longer stays round a tapped button.
Fields get a fitting return key ("done", "go" in a form, "search" on the
search fields), and addresses, codes and numbers are no longer capitalised
or corrected. Ticking off packing items and tasks, a picker chip, a select
option, a picked date and dragging a plan row now give the haptics a native
list gives.
Confirmations ask through the system where the binary has the new
@capacitor/action-sheet and @capacitor/dialog plugins: a sheet with the
action in red when it destroys something, an alert otherwise, also for
"discard changes" in a sheet. An older app, a browser and a question with a
list under it keep the HTML dialog, as does a system that could not ask.
iOS no longer lifts a page preview on a long press on a link.
This commit is contained in:
@@ -7,9 +7,11 @@ import { closeTopOverlay } from '../mobile/overlayStack';
|
||||
import { isEffectivelyOffline } from '../sync/networkMode';
|
||||
import { checkAppUpdate } from './capabilities';
|
||||
import { installNativeGeolocation } from './geolocation';
|
||||
import { prepareKeyboardFields } from './keyboardFields';
|
||||
import { scrollToTop, startNativeApp } from './nativeApp';
|
||||
import { keepOfflineShellFresh } from './offlineShell';
|
||||
import { isNativeApp, isNativeIos } from './platform';
|
||||
import { trackTouchInput } from './touchInput';
|
||||
|
||||
vi.mock('@capacitor/app', () => ({ App: { addListener: vi.fn(), minimizeApp: vi.fn() } }));
|
||||
vi.mock('@capacitor/keyboard', () => ({
|
||||
@@ -28,6 +30,8 @@ vi.mock('./geolocation', () => ({ installNativeGeolocation: vi.fn() }));
|
||||
vi.mock('./sharedFiles', () => ({ startSharedFiles: vi.fn(async () => {}) }));
|
||||
vi.mock('./push', () => ({ startNativePush: vi.fn(async () => {}), openPushTarget: vi.fn() }));
|
||||
vi.mock('../mobile/overlayStack', () => ({ closeTopOverlay: vi.fn(() => false) }));
|
||||
vi.mock('./touchInput', () => ({ trackTouchInput: vi.fn() }));
|
||||
vi.mock('./keyboardFields', () => ({ prepareKeyboardFields: vi.fn() }));
|
||||
|
||||
function backButtonHandler(): (event: { canGoBack: boolean }) => void {
|
||||
const call = vi.mocked(App.addListener).mock.calls.find(([name]) => name === 'backButton');
|
||||
@@ -57,6 +61,8 @@ describe('startNativeApp', () => {
|
||||
expect(App.addListener).not.toHaveBeenCalled();
|
||||
expect(StatusBar.setStyle).not.toHaveBeenCalled();
|
||||
expect(document.documentElement.hasAttribute('data-native-app')).toBe(false);
|
||||
expect(trackTouchInput).not.toHaveBeenCalled();
|
||||
expect(prepareKeyboardFields).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('marks <html> so a long press selects no text in the app', () => {
|
||||
@@ -64,6 +70,12 @@ describe('startNativeApp', () => {
|
||||
expect(document.documentElement.hasAttribute('data-native-app')).toBe(true);
|
||||
});
|
||||
|
||||
it('follows finger or pointer for hover, press and focus, and fits the keyboard to each field', () => {
|
||||
startNativeApp();
|
||||
expect(trackTouchInput).toHaveBeenCalledTimes(1);
|
||||
expect(prepareKeyboardFields).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("Android's back gesture closes an open sheet before it leaves the page", () => {
|
||||
const back = vi.spyOn(window.history, 'back').mockImplementation(() => {});
|
||||
vi.mocked(closeTopOverlay).mockReturnValueOnce(true);
|
||||
|
||||
Reference in New Issue
Block a user