Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: fullscreen app shift on ios

Ilian Sapundshiev9beb73ca59fe
diff --git a/src/renderer/components/FileView.tsx b/src/renderer/components/FileView.tsx
index ed7882c5a..ddbf2204f 100644
--- a/src/renderer/components/FileView.tsx
+++ b/src/renderer/components/FileView.tsx
@@ -219,6 +219,60 @@ function FileView(props: Props) {
isSearchMode,
]);
+ // iOS uses CSS fullscreen (the native Fullscreen API leaves WKWebView with a
+ // stale inset after exit). When fullscreen there, turn the container into a
+ // fixed, full-viewport overlay above the app chrome instead of relying on the
+ // :fullscreen pseudo-class. Other platforms use the real Fullscreen API.
+ const cssFullscreen =
+ isFullscreen && (AppConfig.isCapacitoriOS || AppConfig.isCordovaiOS);
+
+ // `position: fixed` is contained — not viewport-relative — by any ancestor
+ // with `contain`/`transform`/`filter`/`perspective`/`will-change` (the
+ // Splitter panes set `contain: layout paint`). That trapped the overlay
+ // inside the file-view pane. While CSS-fullscreen is active, neutralize those
+ // properties up the ancestor chain so the overlay fills the real viewport,
+ // and restore them on exit. (Portaling to <body> would escape it too, but
+ // moving the iframe in the DOM reloads it and loses editor state.)
+ useEffect(() => {
+ if (!cssFullscreen) return undefined;
+ const start = fileViewerContainer.current?.parentElement;
+ const saved: Array<{ node: HTMLElement; props: Record<string, string> }> =
+ [];
+ const RESET: Record<string, string> = {
+ contain: 'none',
+ transform: 'none',
+ filter: 'none',
+ perspective: 'none',
+ willChange: 'auto',
+ };
+ let node: HTMLElement | null = start || null;
+ while (node && node !== document.body) {
+ const cs = getComputedStyle(node);
+ const traps =
+ (cs.contain && cs.contain !== 'none') ||
+ (cs.transform && cs.transform !== 'none') ||
+ (cs.filter && cs.filter !== 'none') ||
+ (cs.perspective && cs.perspective !== 'none') ||
+ (cs.willChange && cs.willChange !== 'auto');
+ if (traps) {
+ const props: Record<string, string> = {};
+ Object.keys(RESET).forEach((k) => {
+ props[k] = node!.style[k as any];
+ node!.style[k as any] = RESET[k];
+ });
+ saved.push({ node, props });
+ }
+ node = node.parentElement;
+ }
+ return () => {
+ saved.forEach(({ node: n, props }) => {
+ Object.keys(props).forEach((k) => {
+ n.style[k as any] = props[k];
+ });
+ });
+ };
+ }, [cssFullscreen]);
+
return (
<Box
ref={fileViewerContainer}
@@ -228,6 +282,16 @@ function FileView(props: Props) {
display: 'flex',
flex: '1 1 100%',
backgroundColor: theme.palette.background.default,
+ ...(cssFullscreen && {
+ position: 'fixed',
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ width: '100%',
+ height: '100%',
+ zIndex: 5000,
+ }),
}}
>
{isFullscreen && (
diff --git a/src/renderer/hooks/FullScreenContextProvider.tsx b/src/renderer/hooks/FullScreenContextProvider.tsx
index eed66a8c3..cd1334c70 100644
--- a/src/renderer/hooks/FullScreenContextProvider.tsx
+++ b/src/renderer/hooks/FullScreenContextProvider.tsx
@@ -2,8 +2,15 @@
Copyright (c) 2024-present The TagSpaces GmbH. All rights reserved.
*/
-import React, { createContext, useCallback, useMemo, useState } from 'react';
+import React, {
+ createContext,
+ useCallback,
+ useEffect,
+ useMemo,
+ useState,
+} from 'react';
+import AppConfig from '-/AppConfig';
import fscreen from 'fscreen';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
@@ -29,19 +36,41 @@ export const FullScreenContextProvider = ({
const { openedEntry } = useOpenedEntryContext();
const [isFullscreen, setFullscreen] = useState<boolean>(false);
+ // On iOS the native (element) Fullscreen API leaves WKWebView with a stale
+ // status-bar inset after exit — the whole app ends up shifted/short and it
+ // can't be corrected reliably from JS. So on iOS we don't use the native API
+ // at all: we just flip `isFullscreen` and FileView styles its container as a
+ // fixed, full-viewport overlay (CSS fullscreen). No native frame change → no
+ // inset bug. Everywhere else keeps the real Fullscreen API via fscreen.
+ const useCssFullscreen = AppConfig.isCapacitoriOS || AppConfig.isCordovaiOS;
+
const toggleFullScreen = useCallback(
(element: HTMLDivElement) => {
- if (openedEntry.isFile) {
- if (isFullscreen) {
- fscreen.exitFullscreen();
- } else {
- fscreen.requestFullscreen(element); //fileViewerContainer.current);
- }
+ if (!openedEntry.isFile) {
+ return;
+ }
+ if (useCssFullscreen) {
+ setFullscreen((prev) => !prev);
+ return;
+ }
+ if (isFullscreen) {
+ fscreen.exitFullscreen();
+ } else {
+ fscreen.requestFullscreen(element); //fileViewerContainer.current);
}
},
- [isFullscreen],
+ [isFullscreen, openedEntry.isFile, useCssFullscreen],
);
+ // Safety: drop CSS fullscreen when no file is open (entry closed), so it can't
+ // get stuck on. File navigation (prev/next) keeps a file open, so fullscreen
+ // persists across it — matching the native behaviour.
+ useEffect(() => {
+ if (useCssFullscreen && !openedEntry?.isFile) {
+ setFullscreen(false);
+ }
+ }, [openedEntry?.isFile, useCssFullscreen]);
+
const context = useMemo(() => {
return {
isFullscreen,
diff --git a/src/renderer/services/io-capacitor.ts b/src/renderer/services/io-capacitor.ts
index 0521cad6f..3b08c0644 100644
--- a/src/renderer/services/io-capacitor.ts
+++ b/src/renderer/services/io-capacitor.ts
@@ -135,10 +135,11 @@ function normalizePath(path) {
// --- Lifecycle ---
-async function onDeviceReady() {
- console.log('Capacitor Device Ready: ' + Capacitor.getPlatform());
-
- // Configure status bar — ensure WebView does not render behind it
+// Configure the status bar so the WebView does not render behind it. Re-asserting
+// setOverlaysWebView({overlay:false}) also forces the native side to re-inset and
+// resize the WebView to full height — used to recover from iOS leaving the
+// WebView ~status-bar-height short after exiting element fullscreen.
+async function setupStatusBar() {
try {
const { StatusBar, Style } = require('@capacitor/status-bar');
await StatusBar.setOverlaysWebView({ overlay: false });
@@ -146,6 +147,13 @@ async function onDeviceReady() {
} catch (e) {
console.warn('StatusBar setup failed:', e);
}
+}
+
+async function onDeviceReady() {
+ console.log('Capacitor Device Ready: ' + Capacitor.getPlatform());
+
+ // Configure status bar — ensure WebView does not render behind it
+ await setupStatusBar();
// Enable background mode
if (BackgroundMode) {
@@ -1190,6 +1198,7 @@ if (Capacitor.isNativePlatform()) {
export {
onDeviceReady,
+ setupStatusBar,
onDeviceBackButton,
handleOpenURL,
normalizePath,