Skip to content

Commit 918722c

Browse files
committed
mobile usability improvements
Still quite bad, unfortunately. getting variable height windows to act like mobile apps is not easy, it turns out.
1 parent c3c58ac commit 918722c

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/lib/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ export function mapKeys<T extends Record<string, any>, K extends string>(
8484
): Record<K, T[keyof T]> {
8585
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [f(k as keyof T), v])) as any;
8686
}
87+
88+
export const isMobile = () => {
89+
// detect ios, android, etc
90+
return /Mobi|Android/i.test(navigator.userAgent);
91+
};

src/routes/+layout.svelte

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@
8888
</svelte:head>
8989

9090
<div
91-
class={classNames("min-h-screen overflow-hidden text-white bg-[#1B1B1B] border border-zinc-700", {
91+
class={classNames("overflow-hidden text-white bg-[#1B1B1B] border border-zinc-700", {
9292
"rounded-lg": sys.isTauri,
9393
})}
9494
>
9595
{#if appReady}
9696
<slot />
9797
<SettingsModal />
9898
{:else}
99-
<div class="flex items-center justify-center h-screen">
99+
<!-- adding both heights for fallback. not every browser likes svh -->
100+
<div class="flex items-center justify-center h-screen" style="height: 100svh;">
100101
<div class="animate-spin rounded-full h-32 w-32 border-t-2 border-b-2 border-zinc-700" />
101102
</div>
102103
{/if}

src/routes/+page.svelte

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { tick } from "svelte";
2+
import { onDestroy, onMount, tick } from "svelte";
33
import {
44
currentThread,
55
currentChatThread,
@@ -21,11 +21,39 @@
2121
import { slide } from "svelte/transition";
2222
import IconClose from "$lib/components/IconClose.svelte";
2323
import CloseButton from "$lib/components/CloseButton.svelte";
24+
import { isMobile } from "$lib/utils";
2425
2526
const sys = getSystem();
2627
let message = "";
2728
let textarea: HTMLTextAreaElement | null = null;
2829
30+
let windowHeight = window.innerHeight;
31+
function updateWindowHeight() {
32+
const element = document.querySelector(".your-element");
33+
const innerHeight = window.innerHeight; // Get viewport height in pixels
34+
const targetPct = 100;
35+
windowHeight = innerHeight * (targetPct / 100);
36+
console.log({ windowHeight });
37+
}
38+
39+
onMount(() => {
40+
if (!isMobile()) {
41+
return;
42+
} else {
43+
console.warn("Mobile browser. Manually managing window height.");
44+
}
45+
window.addEventListener("DOMContentLoaded", updateWindowHeight, false);
46+
window.addEventListener("resize", updateWindowHeight, false);
47+
window.addEventListener("orientationchange", updateWindowHeight, false);
48+
});
49+
50+
onDestroy(() => {
51+
if (!isMobile()) return;
52+
window.removeEventListener("DOMContentLoaded", updateWindowHeight, false);
53+
window.removeEventListener("resize", updateWindowHeight, false);
54+
window.removeEventListener("orientationchange", updateWindowHeight, false);
55+
});
56+
2957
const resizeChatInput = () => {
3058
if (!textarea) return;
3159
@@ -82,7 +110,13 @@
82110
)}`;
83111
</script>
84112

85-
<div class:dev-container={dev} class={classNames("app-container", {})}>
113+
<div
114+
class:dev-container={dev}
115+
class={classNames("app-container", {
116+
"rounded-lg": sys.isTauri,
117+
})}
118+
style={isMobile() ? `height: ${windowHeight}px;` : ""}
119+
>
86120
<header data-tauri-drag-region class="app-header p-4 pr-3 border-b border-zinc-700 w-full">
87121
<div class="Left flex items-center space-x-4">
88122
{#if sys.isTauri}
@@ -259,6 +293,7 @@
259293
"bottom";
260294
261295
/* Not sure where the extra height is from, but the specific calc fixes the layout */
296+
/* NOTE This will be overwritten on mobile. See the manual height code above */
262297
height: calc(100vh - 2px);
263298
}
264299
.app-header {

0 commit comments

Comments
 (0)