From 501650577d7f4e287359b6c713aa9eafb9def046 Mon Sep 17 00:00:00 2001 From: Tyler Slaton Date: Mon, 30 Nov 2026 11:59:35 -0800 Subject: [PATCH 1/7] OpenBot Mobile: Account and the delete sheets in the look of the other tabs, and More as a menu on iOS Account was drawn as a page of settings, cards of bordered rows with icon tiles, on an app whose other tabs are lists to the screen's edges. It read as another app's screen. - Account is a list with no cards (`ListRow`): each organization with its letter on a rounded square and a tick on the one worked in, Notifications as the phone's own switch, which now turns them off too, and Sign out and Delete account as the two buttons at the foot. The avatar's letters grow with it. - Delete account and Delete organization follow: the organizations that stop a deletion are the same rows, what is deleted and kept has an icon each in place of bullet characters, the sheet waits to be told which of its two forms it is, and a field no longer carries a required mark. - On iOS the tab bar's last button opens a small menu over the tab the person is on (Routines, Approval inbox, Memory, Skills, Connections), in iOS's own glass with SF Symbols, and what is picked opens in the app's stack. The press is caught over the button, so the bar's highlight no longer slides to it and back. Android keeps More as a tab. Both draw the one list in src/more-items.ts. - The gallery has the new rows, and docs/app-guidelines.md says when a list runs to the edges and when it is a card. Checked on the iOS simulator in light and dark: Account, the menu, picking Routines from it, and both sheets. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 6 + docs/app-guidelines.md | 12 +- mobile/app/(tabs)/(account)/account.tsx | 256 +++++++++++++----------- mobile/app/(tabs)/(more)/more.tsx | 83 ++++---- mobile/app/(tabs)/_layout.tsx | 175 ++++++++++------ mobile/app/delete-account.tsx | 213 +++++++++++--------- mobile/app/delete-organization.tsx | 67 ++++--- mobile/app/gallery.tsx | 27 +++ mobile/package-lock.json | 1 + mobile/package.json | 1 + mobile/src/components/index.ts | 1 + mobile/src/components/list-row.tsx | 131 ++++++++++++ mobile/src/components/person-avatar.tsx | 6 +- mobile/src/icons.ts | 1 + mobile/src/more-items.ts | 68 +++++++ mobile/src/more-menu.tsx | 226 +++++++++++++++++++++ mobile/tests/more-items.test.ts | 64 ++++++ 17 files changed, 999 insertions(+), 339 deletions(-) create mode 100644 mobile/src/components/list-row.tsx create mode 100644 mobile/src/more-items.ts create mode 100644 mobile/src/more-menu.tsx create mode 100644 mobile/tests/more-items.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e885bf842a..e3a4a9d934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. ## Unreleased +- **OpenBot Mobile: Account in the look of the other tabs, and More as a menu on iOS.** Account is + a list to the screen's edges: each organization with its letter and a tick on the one you work + in, Notifications as the phone's own switch, which now turns them off too, Sign out as a button, + and Delete account under it. The Delete account and Delete organization sheets follow. On iOS the + tab bar's last button opens a small menu (Routines, Approval inbox, Memory, Skills, Connections) + over the tab you are on. Android keeps More as a tab. - **Delete your account from OpenBot Mobile.** Account, then Delete account: type your email address and "delete my account". The account goes in 14 days, or at once with Delete now, as in the web app. A sign-in older than ten minutes is asked for again first. Somebody who signs in again before diff --git a/docs/app-guidelines.md b/docs/app-guidelines.md index a718bbcbcb..9f656d7033 100644 --- a/docs/app-guidelines.md +++ b/docs/app-guidelines.md @@ -233,8 +233,16 @@ Native's, and builds its own only when neither fits. The development build shows counts what waits), and More (Routines, the approval inbox with a count of what waits there, Memory, Skills and Connections). Each tab is a stack of its own with the native header, its title at the start of the bar. A conversation, a Bot and everything else opened from a tab open in the app's - stack over the tabs, so the tab bar steps aside and the message box has the bottom to itself; - what opens from More stays in More. + stack over the tabs, so the tab bar steps aside and the message box has the bottom to itself. +- **More is a menu on iOS.** The bar's last button opens a small menu over the tab the person is + on, drawn as iOS draws one (its glass, SF Symbols), and what is picked opens in the app's stack + (`mobile/src/more-menu.tsx`). A tab that only held a list of five links cost a screen and a second + tap. Android keeps More as a tab with the same list. Both read `mobile/src/more-items.ts`. +- **A tab's own list runs to the screen's edges, with no card** (`ListRow`): Chats, Bots, and your + Account, where an organization is a row with its letter and the one worked in has the tick. A + card of rows with hairlines and icon tiles (`Rows`) is for a page of settings opened from one. + What a row is about shows in its shape: a person is a circle, a Bot its orb, an organization a + rounded square with its letter. - **Chats** is the word for conversations, everywhere a person reads it. - **A chat** is headed as iMessage heads one: the orbs of the Bots in it and their names, and tapping it opens the Bot's page, or a group's Bots. It reads from the top down, and opens at its diff --git a/mobile/app/(tabs)/(account)/account.tsx b/mobile/app/(tabs)/(account)/account.tsx index ed9dc872a0..8ffaa06983 100644 --- a/mobile/app/(tabs)/(account)/account.tsx +++ b/mobile/app/(tabs)/(account)/account.tsx @@ -1,26 +1,23 @@ import { router } from "expo-router"; +import { Button } from "heroui-native/button"; import { useCallback, useEffect, useState } from "react"; -import { View } from "react-native"; +import { ActivityIndicator, View } from "react-native"; +import { useCSSVariable } from "uniwind"; import { chooseOrganization, organizationChoices } from "../../../src/api"; import { getAccountDeletion } from "../../../src/api/generated/people/people"; import { authClient, serverUrl } from "../../../src/auth"; import { Icon, + ListRow, + Monogram, Notice, PersonAvatar, - Row, - Rows, + RowGlyph, ScrollScreen, - Section, Text, + Toggle, } from "../../../src/components"; -import { - IconBell, - IconBuilding, - IconCheck, - IconLogout, - IconTrash, -} from "../../../src/icons"; +import { IconBell, IconCheck } from "../../../src/icons"; import { pushTurnedOn, registerPush, @@ -28,20 +25,38 @@ import { } from "../../../src/notifications"; import { useLoad } from "../../../src/use-load"; +/** The name over a group of rows, on the line the rows' words start on. */ +function GroupLabel({ children }: { children: string }) { + return ( + + {children} + + ); +} + /** - * Your account, a tab of its own: who is signed in, the organization they work in - * (and the others they can switch to), notifications on this phone, and signing out. It opens as a - * Bot's page does: the person, centered, then a card of rows for each part. + * Your account, a tab of its own: who is signed in, the organization they work in (and the others they can + * switch to), notifications on this phone, and the two ways out. + * + * Drawn as the other tabs are, a list to the screen's edges with no cards: an organization is a row with its + * letter, and the one worked in has the tick. Notifications is the phone's own switch. Sign out and Delete account are + * the two buttons at the foot, the second in the quieter red of what can't be taken back. */ export default function Account() { const { data: session } = authClient.useSession(); + const muted = useCSSVariable("--color-muted") as string | undefined; const [busy, setBusy] = useState(""); const [error, setError] = useState(""); - const [pushRegistered, setPushRegistered] = useState(false); + const [pushOn, setPushOn] = useState(false); // Said as it is on this phone, not as it was before the app last started. useEffect(() => { void pushTurnedOn() - .then(setPushRegistered) + .then(setPushOn) .catch(() => {}); }, []); const loadOrganizations = useCallback(() => organizationChoices(), []); @@ -68,119 +83,136 @@ export default function Account() { setBusy(""); } } + /** The switch moves at once, and goes back if the phone or OpenBot refuses. */ + function setNotifications(on: boolean) { + setPushOn(on); + void act("push", async () => { + try { + if (on) await registerPush(); + else await unregisterPush(); + } catch (failure) { + setPushOn(!on); + throw failure; + } + }); + } const person = session?.user.name || session?.user.email || ""; const listed = organizations.data?.organizations ?? []; // The OpenBot this phone is signed in to, as its address reads without the scheme. const server = serverUrl.replace(/^https?:\/\//, "").replace(/\/$/, ""); return ( - - - - - + + + + + {person} {session?.user.name && session.user.email ? ( - + {session.user.email} ) : null} - + {error || organizations.error ? ( + + + + ) : null} {listed.length > 0 ? ( -
1 ? "Organizations" : "Organization"}> - - {listed.map((organization) => { - const current = organization.id === organizations.data?.currentId; - return ( - : undefined - } - chevron={false} - onPress={ - current || busy - ? undefined - : () => - void act(organization.id, async () => { - await chooseOrganization(organization.id); - await organizations.refresh(); - // Anything open over the tabs is the other organization's. Nothing is - // open when Account is a tab, and there is then nothing to dismiss. - if (router.canDismiss()) router.dismissAll(); - router.replace("/"); - }) - } - /> - ); - })} - -
+ <> + + {listed.length > 1 ? "Organizations" : "Organization"} + + {listed.map((organization) => { + const current = organization.id === organizations.data?.currentId; + const name = organization.name ?? organization.id; + return ( + } + title={name} + description={current ? "You're working here" : undefined} + accessibilityLabel={ + current ? `${name}, you're working here` : `Work in ${name}` + } + accessibilityState={{ + selected: current, + busy: busy === organization.id, + }} + trailing={ + busy === organization.id ? ( + + ) : current ? ( + + ) : undefined + } + disabled={Boolean(busy)} + onPress={ + current + ? undefined + : () => + void act(organization.id, async () => { + await chooseOrganization(organization.id); + await organizations.refresh(); + // Anything open over the tabs is the other organization's. Nothing is + // open when Account is a tab, and there is then nothing to dismiss. + if (router.canDismiss()) router.dismissAll(); + router.replace("/"); + }) + } + /> + ); + })} + ) : null} -
- - - ) : ( - - Turn on - - ) - } - chevron={false} - onPress={ - pushRegistered || busy - ? undefined - : () => - void act("push", async () => { - await registerPush(); - setPushRegistered(true); - }) - } + This phone + } + title="Notifications" + description={ + pushOn + ? "Bots tell you when they finish or need you." + : "Get told when a Bot finishes or needs you." + } + trailing={ + - -
- - - void act("sign-out", async () => { - await unregisterPush(); - await authClient.signOut(); - }) + } + /> + + + + {`Signed in to ${server}`} + + + {deletion.data ? ( + + + + ) : null}
); } diff --git a/mobile/app/(tabs)/(more)/more.tsx b/mobile/app/(tabs)/(more)/more.tsx index 919124fcc5..e82811c778 100644 --- a/mobile/app/(tabs)/(more)/more.tsx +++ b/mobile/app/(tabs)/(more)/more.tsx @@ -18,12 +18,24 @@ import { IconChevronRight, IconClock, IconPlug, + type TablerIcon, } from "../../../src/icons"; +import { MORE_ITEMS, type MoreItem } from "../../../src/more-items"; import { useLoad } from "../../../src/use-load"; +/** Each part's glyph in the app's own set, which what is inside a screen is drawn with. */ +const ICONS: Record = { + routines: IconClock, + approvals: IconChecks, + memory: IconBrain, + skills: IconBook, + connections: IconPlug, +}; + /** - * More: the parts of the app that don't have a tab. The routines Bots run, what every Bot - * remembers, knows and connects to, and the approval inbox. + * More: the parts of the app that don't have a tab (src/more-items.ts). The routines Bots run, what every Bot + * remembers, knows and connects to, and the approval inbox. Android's tab. On iOS the same list is a menu that + * rises from the tab bar (src/more-menu.tsx), and this screen is not opened. */ export default function More() { const { data: session } = authClient.useSession(); @@ -39,51 +51,34 @@ export default function More() { const waiting = (inbox.data?.requests.filter((request) => request.status === "pending") .length ?? 0) + (inbox.data?.questions.length ?? 0); + const row = (item: MoreItem) => ( + + ) : undefined + } + onPress={() => router.push(item.route)} + /> + ); return ( - - router.push("/routines")} - /> - : undefined} - onPress={() => router.push("/approvals")} - /> - + {MORE_ITEMS.filter((item) => !item.yourBots).map(row)}
- - router.push("/memory")} - /> - router.push("/skills")} - /> - router.push("/connections")} - /> - + {MORE_ITEMS.filter((item) => item.yourBots).map(row)}
); diff --git a/mobile/app/(tabs)/_layout.tsx b/mobile/app/(tabs)/_layout.tsx index eb4e81e2a8..4c5cfffeef 100644 --- a/mobile/app/(tabs)/_layout.tsx +++ b/mobile/app/(tabs)/_layout.tsx @@ -1,8 +1,28 @@ import { usePathname } from "expo-router"; import { NativeTabs } from "expo-router/native-tabs"; +import { useState } from "react"; +import { Platform, Pressable, useWindowDimensions, View } from "react-native"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useCSSVariable } from "uniwind"; +import { MoreMenu } from "../../src/more-menu"; import { useNeedsYouCount } from "../../src/needs-you-count"; +/** + * More is a menu on iOS: the bar's last button opens it over the tab the person is on, and what they pick opens + * in the app's stack (src/more-menu.tsx). The tab is told not to open, and still says it was pressed. Android + * keeps More as a tab with its list, where a menu rising from the navigation bar is not the platform's way. + */ +const MORE_IS_A_MENU = Platform.OS === "ios"; + +/** + * Where iOS draws the bar's buttons, measured on the phone: the five share the bar's width less this much, the + * bar is this tall, and it sits this far into the room the home indicator keeps. For the press that is caught + * over More, below. + */ +const BAR_SIDES = 57; +const BAR_HEIGHT = 62; +const BAR_INTO_HOME_ROOM = 12; + /** * The Bots tab is OpenBot's orb as a flat glyph, at SF Symbols' line weight: an outline with the orb's * sheen, filled when the tab is open, tinted as the other tabs' icons are. @@ -20,6 +40,9 @@ const ORB_FILLED = require("../../assets/tab-orb-filled.png"); export default function TabsLayout() { // Read again on each move between tabs, so starting or hiding something in Needs you shows here. const waiting = useNeedsYouCount(true, usePathname()); + const [menuOpen, setMenuOpen] = useState(false); + const insets = useSafeAreaInsets(); + const { width } = useWindowDimensions(); const [foreground, muted, background, highlight, danger] = useCSSVariable([ "--color-foreground", "--color-muted", @@ -28,65 +51,99 @@ export default function TabsLayout() { "--color-danger", ]) as (string | undefined)[]; return ( - - - - - - - - - - - - - - 0 ? `Needs you, ${waiting} waiting` : "Needs you" - } + + { + // The route's key starts with its name: only More's press opens the menu. + if (MORE_IS_A_MENU && event.target?.startsWith("(more)")) + setMenuOpen(true); + }, + }} + // The open tab in the text color, the rest in the quieter one: the scheme has no brand blue. + tintColor={foreground} + iconColor={{ default: muted, selected: foreground }} + // Android's bar on the screen's ground, with the sidebar's soft highlight behind the open tab. + backgroundColor={background} + indicatorColor={highlight} + badgeBackgroundColor={danger} + labelVisibilityMode="unlabeled" > - - - {waiting > 0 ? ( - - {waiting > 99 ? "99+" : String(waiting)} - - ) : null} - - - - - - + + + + + + + + + + + + + 0 ? `Needs you, ${waiting} waiting` : "Needs you" + } + > + + + {waiting > 0 ? ( + + {waiting > 99 ? "99+" : String(waiting)} + + ) : null} + + + + + + + {MORE_IS_A_MENU ? ( + <> + {/* + * The press on More is caught here, over the button, before the bar has it. A tab that is told not to + * open still slid the bar's highlight to itself and back on every press. The tab stays told not to + * open, for a screen reader, which presses the tab itself, and for a bar laid out another way. + */} + setMenuOpen(true)} + style={{ + position: "absolute", + right: BAR_SIDES / 2, + width: (width - BAR_SIDES) / 5, + height: BAR_HEIGHT, + bottom: Math.max(insets.bottom - BAR_INTO_HOME_ROOM, 8), + }} + /> + setMenuOpen(false)} /> + + ) : null} +
); } diff --git a/mobile/app/delete-account.tsx b/mobile/app/delete-account.tsx index 3157e0800f..220ee90667 100644 --- a/mobile/app/delete-account.tsx +++ b/mobile/app/delete-account.tsx @@ -4,7 +4,8 @@ import { Input } from "heroui-native/input"; import { Label } from "heroui-native/label"; import { TextField } from "heroui-native/text-field"; import { useCallback, useState } from "react"; -import { Alert, View } from "react-native"; +import { ActivityIndicator, Alert, View } from "react-native"; +import { useCSSVariable } from "uniwind"; import { blockerWayOn, blockerWords, @@ -22,26 +23,43 @@ import { } from "../src/api/generated/people/people"; import { authClient, signIn } from "../src/auth"; import { + ListRow, + Monogram, Notice, - Row, - Rows, + RowGlyph, Screen, ScrollScreen, - Section, SheetTitle, Text, } from "../src/components"; -import { IconBuilding } from "../src/icons"; +import { IconArchive, IconTrash, type TablerIcon } from "../src/icons"; import { useLoad } from "../src/use-load"; const TITLE = "Delete account"; -/** One line of what is deleted or kept. */ -function Line({ children }: { children: string }) { +/** What happens to one kind of thing: its glyph, the word for it, and each thing it covers on a line of its own. */ +function Outcome({ + icon, + tone, + title, + lines, +}: { + icon: TablerIcon; + tone?: "danger"; + title: string; + lines: string[]; +}) { return ( - - • - {children} + + + + {title} + {lines.map((line) => ( + + {line} + + ))} + ); } @@ -69,6 +87,7 @@ export default function DeleteAccount() { ); const [error, setError] = useState(""); const [signInAgain, setSignInAgain] = useState(false); + const muted = useCSSVariable("--color-muted") as string | undefined; // Back from deleting an organization that stopped it: the list is read again, and has one less. const { refresh: readStanding } = standing; @@ -175,98 +194,108 @@ export default function DeleteAccount() { } } + const said = error || standing.error; return ( - - void again()} - > - {busy === "sign-in" ? "Opening sign-in…" : "Sign in again"} - - ) : undefined - } - /> - {blockers.length > 0 ? ( - // A sentence, not a section's label: a label is one line, and this one doesn't fit one. - - + + {said ? ( + + void again()} + > + {busy === "sign-in" ? "Opening sign-in…" : "Sign in again"} + + ) : undefined + } + /> + + ) : null} + {!standing.data ? ( + // Whether an organization stops the deletion decides what this sheet is, so it waits to be told. + standing.error ? null : ( + + + + ) + ) : blockers.length > 0 ? ( + <> + Before you can delete your account, sort out these organizations. - - {blockers.map((blocker) => { - const onPress = wayOn(blocker); - return ( - - ); - })} - - + {blockers.map((blocker) => { + const onPress = wayOn(blocker); + return ( + } + title={blocker.organizationName} + description={blockerWords(blocker)} + chevron={Boolean(onPress)} + disabled={Boolean(busy)} + onPress={onPress} + /> + ); + })} + ) : ( - <> + {`Your account is deleted in ${DELETION_WAIT_DAYS} days. Sign in before then to cancel. Delete now deletes it straight away, and you can't undo it.`} -
- - - Your conversations, memory, Bots, skills and routines that are - only yours. - - Your saved logins, connections and computer. - -
-
- - - Messages you sent in organizations you share with others. They - show as from Deleted user. - - - Security log entries, for 180 days, without your name or - email. - - -
- - - + - - - - - - + + + + + + + + + + + + - +
)}
diff --git a/mobile/app/delete-organization.tsx b/mobile/app/delete-organization.tsx index fc2c130325..4f9e8cc331 100644 --- a/mobile/app/delete-organization.tsx +++ b/mobile/app/delete-organization.tsx @@ -4,9 +4,11 @@ import { Input } from "heroui-native/input"; import { Label } from "heroui-native/label"; import { TextField } from "heroui-native/text-field"; import { useState } from "react"; +import { View } from "react-native"; import { typedOrganizationName } from "../src/account-deletion"; import { deleteOrganization } from "../src/api/generated/organizations/organizations"; import { + Monogram, Notice, Screen, ScrollScreen, @@ -54,36 +56,43 @@ export default function DeleteOrganization() { - + - {`Delete ${name ?? "this organization"}?`} - - Its Bots, conversations and computers are deleted for everyone. - Members keep their accounts and their other organizations. You can't - undo it. - - - To keep the organization, make someone else an owner first. You do - that in OpenBot in a browser, in the organization's settings. - - - - - - + + + + {`Delete ${name ?? "this organization"}?`} + + Its Bots, conversations and computers are deleted for everyone. + Members keep their accounts and their other organizations. You + can't undo it. + + + To keep the organization, make someone else an owner first. You do + that in OpenBot in a browser, in the organization's settings. + + + + + + + + + + ); diff --git a/mobile/app/gallery.tsx b/mobile/app/gallery.tsx index a30a8f9325..d6e923a74d 100644 --- a/mobile/app/gallery.tsx +++ b/mobile/app/gallery.tsx @@ -11,14 +11,18 @@ import { Composer, ConversationRow, EmptyState, + Icon, IconButton, + ListRow, Message, MessageDay, MessageEvent, MessageWorking, + Monogram, Notice, PersonAvatar, Row, + RowGlyph, Rows, ScrollScreen, SearchBar, @@ -41,6 +45,7 @@ import { IconBell, IconBook, IconBrain, + IconCheck, IconMessages, IconPlayerPause, IconPlug, @@ -318,6 +323,28 @@ export default function Gallery() { {}} />
+ + + } + title="Acme" + description="You're working here" + trailing={} + /> + } + title="Hill Climbing" + onPress={() => {}} + /> + } + title="Notifications" + description="Get told when a Bot finishes or needs you." + onPress={() => {}} + chevron + /> + + diff --git a/mobile/package-lock.json b/mobile/package-lock.json index 9b6f7250c8..7b19412fa7 100644 --- a/mobile/package-lock.json +++ b/mobile/package-lock.json @@ -27,6 +27,7 @@ "expo-document-picker": "~58.0.5", "expo-file-system": "~58.0.14", "expo-font": "~58.0.12", + "expo-glass-effect": "~58.0.5", "expo-image-picker": "~58.0.10", "expo-linking": "~58.0.17", "expo-network": "~58.0.5", diff --git a/mobile/package.json b/mobile/package.json index 0b5897e539..ca19cae44c 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -34,6 +34,7 @@ "expo-document-picker": "~58.0.5", "expo-file-system": "~58.0.14", "expo-font": "~58.0.12", + "expo-glass-effect": "~58.0.5", "expo-image-picker": "~58.0.10", "expo-linking": "~58.0.17", "expo-network": "~58.0.5", diff --git a/mobile/src/components/index.ts b/mobile/src/components/index.ts index 604409d9a4..95f51ce7cd 100644 --- a/mobile/src/components/index.ts +++ b/mobile/src/components/index.ts @@ -21,6 +21,7 @@ export { EmptyState } from "./empty-state"; export { Icon } from "./icon"; export { IconButton } from "./icon-button"; export { KeyboardBar } from "./keyboard-bar"; +export { ListRow, Monogram, RowGlyph } from "./list-row"; export { Message, MessageDay, diff --git a/mobile/src/components/list-row.tsx b/mobile/src/components/list-row.tsx new file mode 100644 index 0000000000..78da2dfe8e --- /dev/null +++ b/mobile/src/components/list-row.tsx @@ -0,0 +1,131 @@ +import type { ReactNode } from "react"; +import { Pressable, View } from "react-native"; +import type { TablerIcon } from "../icons"; +import { IconChevronRight } from "../icons"; +import { cn } from "./cn"; +import { Icon } from "./icon"; +import { Text } from "./text"; + +/** How wide what leads a row is, so every row's words start on the same line down the screen. */ +const LEAD = 40; + +/** + * A row of a phone's own list, edge to edge with no card around it, as Chats and Bots are drawn: what leads it, + * its name, a line under it, and what trails it. For a top-level screen's list. A page of settings, with its + * card and hairlines, is `Rows`. + * + * It presses to the screen's edges. A row that opens something shows a chevron. One that acts where it is (a + * pick, a switch) brings its own `trailing` or none. + */ +export function ListRow({ + leading, + title, + description, + trailing, + onPress, + chevron = false, + disabled, + accessibilityLabel, + accessibilityState, +}: { + leading?: ReactNode; + title: string; + description?: string; + trailing?: ReactNode; + onPress?: () => void; + /** True for a row that opens a page. */ + chevron?: boolean; + disabled?: boolean; + accessibilityLabel?: string; + accessibilityState?: { selected?: boolean; busy?: boolean }; +}) { + const content = ( + + {leading} + + + {title} + + {description ? ( + + {description} + + ) : null} + + {trailing ?? + (chevron ? ( + + ) : null)} + + ); + if (!onPress) return content; + return ( + + {content} + + ); +} + +/** + * What leads a row for an organization: its first letter on a quiet rounded square. A person is a circle + * (`PersonAvatar`) and a Bot is its orb, so the shape alone says which of the three a row is. + */ +export function Monogram({ + name, + size = LEAD, +}: { + name: string; + size?: number; +}) { + const letter = name.trim()[0]?.toUpperCase() ?? "?"; + return ( + + + {letter} + + + ); +} + +/** What leads a row that is about a thing, not somebody: its icon on the same quiet ground, round. */ +export function RowGlyph({ + icon, + tone = "default", + size = LEAD, +}: { + icon: TablerIcon; + tone?: "default" | "danger"; + size?: number; +}) { + return ( + + + + ); +} diff --git a/mobile/src/components/person-avatar.tsx b/mobile/src/components/person-avatar.tsx index 40cdfb3a26..a7375d4e5a 100644 --- a/mobile/src/components/person-avatar.tsx +++ b/mobile/src/components/person-avatar.tsx @@ -23,7 +23,11 @@ export function PersonAvatar({ className="items-center justify-center rounded-full border border-border bg-fill" style={{ width: size, height: size }} > - + {/* The letters grow with the circle: at a list's size they are a caption, on a profile a heading. */} + {initials || "?"} diff --git a/mobile/src/icons.ts b/mobile/src/icons.ts index 708b9aa2d2..43572372a1 100644 --- a/mobile/src/icons.ts +++ b/mobile/src/icons.ts @@ -6,6 +6,7 @@ export type { Icon as TablerIcon } from "@tabler/icons-react-native"; export { default as IconAlertCircle } from "@tabler/icons-react-native/IconAlertCircle"; export { default as IconAlertTriangle } from "@tabler/icons-react-native/IconAlertTriangle"; +export { default as IconArchive } from "@tabler/icons-react-native/IconArchive"; export { default as IconArrowsExchange } from "@tabler/icons-react-native/IconArrowsExchange"; export { default as IconArrowUp } from "@tabler/icons-react-native/IconArrowUp"; export { default as IconBell } from "@tabler/icons-react-native/IconBell"; diff --git a/mobile/src/more-items.ts b/mobile/src/more-items.ts new file mode 100644 index 0000000000..7842975296 --- /dev/null +++ b/mobile/src/more-items.ts @@ -0,0 +1,68 @@ +/** + * The parts of the app that have no tab of their own, in the order they are listed: what the More menu offers + * on iOS (./more-menu.tsx) and what the More screen lists on Android (app/(tabs)/(more)/more.tsx). One list, so + * the two never say different things. + * + * It imports nothing, so it can be tested without a phone. + */ +export type MoreItem = { + key: "routines" | "approvals" | "memory" | "skills" | "connections"; + title: string; + /** What the screen's row says under the title. The menu has no room for it. */ + description: string; + /** The screen it opens, in the app's stack over the tabs. */ + route: "/routines" | "/approvals" | "/memory" | "/skills" | "/connections"; + /** Its glyph in iOS's own set, which the platform's chrome is drawn with. */ + sf: string; + /** The screen's second group, under "Your Bots". The menu draws a line before the first of them. */ + yourBots: boolean; +}; + +export const MORE_ITEMS: readonly MoreItem[] = [ + { + key: "routines", + title: "Routines", + description: "What your Bots do for you on a schedule", + route: "/routines", + sf: "clock", + yourBots: false, + }, + { + key: "approvals", + title: "Approval inbox", + description: "What your Bots asked you to approve", + route: "/approvals", + sf: "checkmark.circle", + yourBots: false, + }, + { + key: "memory", + title: "Memory", + description: "What your Bots remember about you", + route: "/memory", + sf: "brain", + yourBots: true, + }, + { + key: "skills", + title: "Skills", + description: "What your Bots know how to do", + route: "/skills", + sf: "book", + yourBots: true, + }, + { + key: "connections", + title: "Connections", + description: "The apps your Bots use as you", + route: "/connections", + sf: "powerplug", + yourBots: true, + }, +]; + +/** How many wait in the approval inbox, as a row says it: nothing for none, and no more than two digits. */ +export function waitingLabel(count: number): string | undefined { + if (count <= 0) return undefined; + return count > 99 ? "99+" : String(count); +} diff --git a/mobile/src/more-menu.tsx b/mobile/src/more-menu.tsx new file mode 100644 index 0000000000..a14e30e3ec --- /dev/null +++ b/mobile/src/more-menu.tsx @@ -0,0 +1,226 @@ +/** + * The More menu: what has no tab of its own (./more-items.ts), in a small menu that rises from the tab bar's + * last button and opens the screen that is picked. On iOS, where a tab that only held a list of five links + * cost a screen and a second tap. + * + * It is the platform's chrome, so it is drawn as iOS draws a menu: its own glass where the phone has it (iOS 26) + * and its blur material before that, SF Symbols, and a row to a line. A tap outside puts it away. It grows from + * the corner it was called from, and only fades where the person asked for less motion. + */ +import { BlurView } from "expo-blur"; +import { GlassView, isLiquidGlassAvailable } from "expo-glass-effect"; +import { router } from "expo-router"; +import { SymbolView } from "expo-symbols"; +import { type ReactNode, useCallback, useEffect, useState } from "react"; +import { Pressable, StyleSheet, View } from "react-native"; +import Animated, { + Easing, + runOnJS, + useAnimatedStyle, + useReducedMotion, + useSharedValue, + withTiming, +} from "react-native-reanimated"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; +import { useCSSVariable } from "uniwind"; +import { loadApprovalInbox } from "./api"; +import { Text } from "./components"; +import { MORE_ITEMS, type MoreItem, waitingLabel } from "./more-items"; +import { useLoad } from "./use-load"; + +/** How far the tab bar's top edge is above the home indicator's room, and the gap the menu leaves over it. */ +const TAB_BAR = 54; +const GAP = 10; +const WIDTH = 248; +const RADIUS = 26; +const OPEN_MS = 260; +const CLOSE_MS = 150; + +/** + * The menu's ground: the phone's own glass, and its blur where there is none. Either stands off the screen by a + * soft shadow under it, on a view of its own: one that clips to its corners would clip its shadow too. On a + * light page glass alone has no edge to see. + */ +function Ground({ children }: { children: ReactNode }) { + // A hairline in the scheme's border: on a light page, glass over white has no edge of its own to see. + const edge = useCSSVariable("--color-border") as string | undefined; + return ( + + {isLiquidGlassAvailable() ? ( + + {children} + + ) : ( + + + {children} + + )} + + ); +} + +export function MoreMenu({ + open, + onClose, +}: { + open: boolean; + onClose: () => void; +}) { + const insets = useSafeAreaInsets(); + const reduceMotion = useReducedMotion(); + const [foreground, border] = useCSSVariable([ + "--color-foreground", + "--color-border", + ]) as (string | undefined)[]; + // Drawn until it has finished leaving, so closing is seen. + const [drawn, setDrawn] = useState(open); + const shown = useSharedValue(0); + useEffect(() => { + if (open) { + setDrawn(true); + shown.value = withTiming(1, { + duration: OPEN_MS, + easing: Easing.out(Easing.exp), + }); + return; + } + shown.value = withTiming( + 0, + { duration: CLOSE_MS, easing: Easing.in(Easing.quad) }, + (finished) => { + if (finished) runOnJS(setDrawn)(false); + }, + ); + }, [open, shown]); + const rising = useAnimatedStyle(() => ({ + opacity: Math.min(1, shown.value * 1.6), + transform: reduceMotion + ? [] + : [ + { scale: 0.82 + 0.18 * shown.value }, + { translateY: 10 * (1 - shown.value) }, + ], + })); + + // How many approvals and questions wait, read while the menu is open. + const loadInbox = useCallback(() => loadApprovalInbox(), []); + const inbox = useLoad(loadInbox, open); + const waiting = waitingLabel( + (inbox.data?.requests.filter((request) => request.status === "pending") + .length ?? 0) + (inbox.data?.questions.length ?? 0), + ); + + const pick = useCallback( + (item: MoreItem) => { + onClose(); + router.push(item.route); + }, + [onClose], + ); + + if (!drawn) return null; + return ( + + + + + {MORE_ITEMS.map((item, index) => ( + + {item.yourBots && !MORE_ITEMS[index - 1]?.yourBots ? ( + + ) : null} + pick(item)} + className="active:bg-foreground/10" + style={styles.row} + > + + + {item.title} + + {item.key === "approvals" && waiting ? ( + + + {waiting} + + + ) : null} + + + ))} + + + + ); +} + +const styles = StyleSheet.create({ + menu: { + position: "absolute", + right: 21, + width: WIDTH, + transformOrigin: "bottom right", + }, + ground: { + borderRadius: RADIUS, + borderCurve: "continuous", + overflow: "hidden", + paddingVertical: 8, + }, + // Drawn by React Native, so it shows under glass, which has no layer of its own to cast one. + lifted: { + borderRadius: RADIUS, + borderCurve: "continuous", + boxShadow: "0 14 34 rgba(0, 0, 0, 0.2), 0 2 6 rgba(0, 0, 0, 0.08)", + }, + edged: { borderWidth: StyleSheet.hairlineWidth }, + row: { + minHeight: 48, + flexDirection: "row", + alignItems: "center", + gap: 14, + paddingHorizontal: 18, + }, + symbol: { width: 24, height: 24 }, + rule: { + height: StyleSheet.hairlineWidth, + marginVertical: 6, + marginHorizontal: 18, + }, +}); diff --git a/mobile/tests/more-items.test.ts b/mobile/tests/more-items.test.ts new file mode 100644 index 0000000000..14ea24d196 --- /dev/null +++ b/mobile/tests/more-items.test.ts @@ -0,0 +1,64 @@ +/** + * What has no tab of its own (src/more-items.ts): the one list the More menu on iOS and the More screen on Android + * both draw, and the tab that opens the menu. + */ + +import { expect, test } from "bun:test"; +import { existsSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import { MORE_ITEMS, waitingLabel } from "../src/more-items"; + +const app = (...parts: string[]) => + join(import.meta.dir, "..", "app", ...parts); + +test("every part opens a screen the app has", () => { + for (const item of MORE_ITEMS) + expect(existsSync(app(`${item.route.slice(1)}.tsx`))).toBe(true); +}); + +test("no part is listed twice, and each has its words and its glyph", () => { + expect(new Set(MORE_ITEMS.map((item) => item.key)).size).toBe( + MORE_ITEMS.length, + ); + expect(new Set(MORE_ITEMS.map((item) => item.route)).size).toBe( + MORE_ITEMS.length, + ); + for (const item of MORE_ITEMS) { + expect(item.title.length).toBeGreaterThan(0); + expect(item.description.length).toBeGreaterThan(0); + expect(item.sf).toMatch(/^[a-z0-9.]+$/); + } +}); + +test("the parts that are about every Bot come last, together", () => { + // The menu draws one line before the first of them, and the screen puts them under one heading. + const groups = MORE_ITEMS.map((item) => item.yourBots); + expect(groups).toEqual([...groups].sort((a, b) => Number(a) - Number(b))); + expect(groups.includes(true)).toBe(true); + expect(groups.includes(false)).toBe(true); +}); + +test("how many wait is said only when some do, and in no more than two digits", () => { + expect(waitingLabel(0)).toBeUndefined(); + expect(waitingLabel(-1)).toBeUndefined(); + expect(waitingLabel(1)).toBe("1"); + expect(waitingLabel(99)).toBe("99"); + expect(waitingLabel(100)).toBe("99+"); +}); + +test("on iOS the More tab opens the menu and never its own screen", () => { + // The tab bar needs a phone, so its source is read: the tab is told not to open, and its press opens the menu. + const tabs = readFileSync(app("(tabs)", "_layout.tsx"), "utf8"); + expect(tabs).toContain('const MORE_IS_A_MENU = Platform.OS === "ios";'); + expect(tabs).toContain("disabled={MORE_IS_A_MENU}"); + expect(tabs).toContain('event.target?.startsWith("(more)")'); +}); + +test("both the menu and the screen draw the one list", () => { + const read = (...parts: string[]) => + readFileSync(join(import.meta.dir, "..", ...parts), "utf8"); + expect(read("src", "more-menu.tsx")).toContain("MORE_ITEMS.map("); + expect(read("app", "(tabs)", "(more)", "more.tsx")).toContain( + "MORE_ITEMS.filter(", + ); +}); From 85314b7e2d58c4c90ae48be7a1083626ef37e06b Mon Sep 17 00:00:00 2001 From: Tyler Slaton Date: Mon, 30 Nov 2026 12:23:07 -0800 Subject: [PATCH 2/7] OpenBot Mobile: empty lists say so in the middle of the screen, an organization swipes for its way out, and a shorter Delete organization sheet An empty state had a boxed icon and sat at the top of the page. It is now a glyph, its name, a line or two and one button, in the middle of what the person sees. A page (ScrollScreen) and a tab's list (ScreenList) are as tall as what the bars leave, read from a safe area provider of the screen's own, so the empty page centers and doesn't scroll. An organization's row on Account swipes left for one action (SwipeRow): Delete for its owner, which opens the Delete organization sheet, and Leave for anybody else, asked about first. A person's own organization has none. After either, the person's organizations are read again, and if it was the one they worked in they work in another of theirs. The Delete organization sheet says one thing: what goes, the name to type, the button. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 4 +- docs/app-guidelines.md | 7 + mobile/app/(tabs)/(account)/account.tsx | 142 ++++++++++++++------ mobile/app/(tabs)/(bots)/bots.tsx | 5 +- mobile/app/(tabs)/(conversations)/index.tsx | 7 +- mobile/app/delete-account.tsx | 3 + mobile/app/delete-organization.tsx | 79 +++++------ mobile/app/gallery.tsx | 24 +++- mobile/app/memory.tsx | 4 +- mobile/app/routines.tsx | 2 +- mobile/src/api/index.ts | 3 +- mobile/src/api/request.ts | 12 ++ mobile/src/components/empty-state.tsx | 24 ++-- mobile/src/components/index.ts | 3 +- mobile/src/components/screen.tsx | 74 +++++++++- mobile/src/components/swipe-row.tsx | 141 +++++++++++++++++++ mobile/src/organization.ts | 25 ++++ mobile/tests/organization-way-out.test.ts | 111 +++++++++++++++ 18 files changed, 561 insertions(+), 109 deletions(-) create mode 100644 mobile/src/components/swipe-row.tsx create mode 100644 mobile/tests/organization-way-out.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e3a4a9d934..0d70446b9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,9 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. in, Notifications as the phone's own switch, which now turns them off too, Sign out as a button, and Delete account under it. The Delete account and Delete organization sheets follow. On iOS the tab bar's last button opens a small menu (Routines, Approval inbox, Memory, Skills, Connections) - over the tab you are on. Android keeps More as a tab. + over the tab you are on. Android keeps More as a tab. Swipe an organization on Account to delete + it, if you own it, or to leave it. A list with nothing in it yet says so in the middle of the + screen. - **Delete your account from OpenBot Mobile.** Account, then Delete account: type your email address and "delete my account". The account goes in 14 days, or at once with Delete now, as in the web app. A sign-in older than ten minutes is asked for again first. Somebody who signs in again before diff --git a/docs/app-guidelines.md b/docs/app-guidelines.md index 9f656d7033..bc1ed03544 100644 --- a/docs/app-guidelines.md +++ b/docs/app-guidelines.md @@ -243,6 +243,13 @@ Native's, and builds its own only when neither fits. The development build shows card of rows with hairlines and icon tiles (`Rows`) is for a page of settings opened from one. What a row is about shows in its shape: a person is a circle, a Bot its orb, an organization a rounded square with its letter. +- **A row's own action is a swipe** (`SwipeRow`): the row slides left and one button is in the room + it leaves, as in the phone's own lists. A swipe alone never does it, and what deletes still asks + first. An organization on Account swipes for Delete (its owner) or Leave (anybody else). +- **An empty list says so in the middle of the screen** (`EmptyState`): a glyph, its name, a line or + two, and one button when the way on is right there. No box around it. A page (`ScrollScreen`) and a + tab's list (`ScreenList`) are as tall as what the bars leave, so it centers in what the person + sees and the empty page doesn't scroll. - **Chats** is the word for conversations, everywhere a person reads it. - **A chat** is headed as iMessage heads one: the orbs of the Bots in it and their names, and tapping it opens the Bot's page, or a group's Bots. It reads from the top down, and opens at its diff --git a/mobile/app/(tabs)/(account)/account.tsx b/mobile/app/(tabs)/(account)/account.tsx index 8ffaa06983..d3f5ae872a 100644 --- a/mobile/app/(tabs)/(account)/account.tsx +++ b/mobile/app/(tabs)/(account)/account.tsx @@ -1,9 +1,15 @@ -import { router } from "expo-router"; +import { router, useFocusEffect } from "expo-router"; import { Button } from "heroui-native/button"; import { useCallback, useEffect, useState } from "react"; -import { ActivityIndicator, View } from "react-native"; +import { ActivityIndicator, Alert, View } from "react-native"; import { useCSSVariable } from "uniwind"; -import { chooseOrganization, organizationChoices } from "../../../src/api"; +import { + chooseOrganization, + ME, + organizationChoices, + rereadOrganizations, +} from "../../../src/api"; +import { removeOrganizationMember } from "../../../src/api/generated/organizations/organizations"; import { getAccountDeletion } from "../../../src/api/generated/people/people"; import { authClient, serverUrl } from "../../../src/auth"; import { @@ -14,15 +20,18 @@ import { PersonAvatar, RowGlyph, ScrollScreen, + type SwipeAction, + SwipeRow, Text, Toggle, } from "../../../src/components"; -import { IconBell, IconCheck } from "../../../src/icons"; +import { IconBell, IconCheck, IconLogout, IconTrash } from "../../../src/icons"; import { pushTurnedOn, registerPush, unregisterPush, } from "../../../src/notifications"; +import { type ListedOrganization, wayOut } from "../../../src/organization"; import { useLoad } from "../../../src/use-load"; /** The name over a group of rows, on the line the rows' words start on. */ @@ -44,8 +53,10 @@ function GroupLabel({ children }: { children: string }) { * switch to), notifications on this phone, and the two ways out. * * Drawn as the other tabs are, a list to the screen's edges with no cards: an organization is a row with its - * letter, and the one worked in has the tick. Notifications is the phone's own switch. Sign out and Delete account are - * the two buttons at the foot, the second in the quieter red of what can't be taken back. + * letter, and the one worked in has the tick. A row swipes to the left for the way out of that organization + * (src/organization.ts): its owner deletes it, anybody else leaves it, and the person's own has none. + * Notifications is the phone's own switch. Sign out and Delete account are the two buttons at the foot, the + * second in the quieter red of what can't be taken back. */ export default function Account() { const { data: session } = authClient.useSession(); @@ -68,6 +79,13 @@ export default function Account() { // The person's own too, so the line stays while it is read again. const loadDeletion = useCallback(() => getAccountDeletion(), []); const deletion = useLoad(loadDeletion, Boolean(session), { keep: true }); + // Read again each time the tab comes back: an organization deleted in the sheet over it is gone from the list. + const rereadList = organizations.refresh; + useFocusEffect( + useCallback(() => { + void rereadList(); + }, [rereadList]), + ); async function act(name: string, work: () => Promise) { setBusy(name); setError(""); @@ -96,6 +114,49 @@ export default function Account() { } }); } + /** What a row offers when it is swiped: the way out of that organization, asked about before it is done. */ + function swipe(organization: ListedOrganization): SwipeAction | undefined { + const name = organization.name ?? organization.id; + const way = wayOut(organization); + if (way === "delete") + return { + label: "Delete", + accessibilityLabel: `Delete ${name}`, + icon: IconTrash, + tone: "danger", + // The sheet says what goes with it, and waits for its name to be typed. + onPress: () => + router.push({ + pathname: "/delete-organization", + params: { id: organization.id, name }, + }), + }; + if (way === "leave") + return { + label: "Leave", + accessibilityLabel: `Leave ${name}`, + icon: IconLogout, + onPress: () => + Alert.alert( + `Leave ${name}?`, + "You stop being a member. What you made there stays there.", + [ + { text: "Cancel", style: "cancel" }, + { + text: "Leave", + style: "destructive", + onPress: () => + void act(organization.id, async () => { + await removeOrganizationMember(organization.id, ME); + await rereadOrganizations(); + await organizations.refresh(); + }), + }, + ], + ), + }; + return undefined; + } const person = session?.user.name || session?.user.email || ""; const listed = organizations.data?.organizations ?? []; // The OpenBot this phone is signed in to, as its address reads without the scheme. @@ -129,40 +190,45 @@ export default function Account() { const current = organization.id === organizations.data?.currentId; const name = organization.name ?? organization.id; return ( - } - title={name} - description={current ? "You're working here" : undefined} - accessibilityLabel={ - current ? `${name}, you're working here` : `Work in ${name}` - } - accessibilityState={{ - selected: current, - busy: busy === organization.id, - }} - trailing={ - busy === organization.id ? ( - - ) : current ? ( - - ) : undefined - } + action={swipe(organization)} disabled={Boolean(busy)} - onPress={ - current - ? undefined - : () => - void act(organization.id, async () => { - await chooseOrganization(organization.id); - await organizations.refresh(); - // Anything open over the tabs is the other organization's. Nothing is - // open when Account is a tab, and there is then nothing to dismiss. - if (router.canDismiss()) router.dismissAll(); - router.replace("/"); - }) - } - /> + > + } + title={name} + description={current ? "You're working here" : undefined} + accessibilityLabel={ + current ? `${name}, you're working here` : `Work in ${name}` + } + accessibilityState={{ + selected: current, + busy: busy === organization.id, + }} + trailing={ + busy === organization.id ? ( + + ) : current ? ( + + ) : undefined + } + disabled={Boolean(busy)} + onPress={ + current + ? undefined + : () => + void act(organization.id, async () => { + await chooseOrganization(organization.id); + await organizations.refresh(); + // Anything open over the tabs is the other organization's. Nothing is + // open when Account is a tab, and there is then nothing to dismiss. + if (router.canDismiss()) router.dismissAll(); + router.replace("/"); + }) + } + /> + ); })} diff --git a/mobile/app/(tabs)/(bots)/bots.tsx b/mobile/app/(tabs)/(bots)/bots.tsx index 33230e40b2..18e1a9ad11 100644 --- a/mobile/app/(tabs)/(bots)/bots.tsx +++ b/mobile/app/(tabs)/(bots)/bots.tsx @@ -1,6 +1,6 @@ import { router, Stack } from "expo-router"; import { useCallback } from "react"; -import { FlatList, View } from "react-native"; +import { View } from "react-native"; import { everyBot } from "../../../src/api"; import { authClient } from "../../../src/auth"; import { @@ -9,6 +9,7 @@ import { Notice, Refresh, Screen, + ScreenList, } from "../../../src/components"; import { tabRoot } from "../../../src/header"; import { IconPlus, IconRobot } from "../../../src/icons"; @@ -34,7 +35,7 @@ export default function Bots() { }, ])} /> - bot.id} diff --git a/mobile/app/(tabs)/(conversations)/index.tsx b/mobile/app/(tabs)/(conversations)/index.tsx index 3768c55170..839d7f3e5d 100644 --- a/mobile/app/(tabs)/(conversations)/index.tsx +++ b/mobile/app/(tabs)/(conversations)/index.tsx @@ -1,7 +1,7 @@ import { router, Stack } from "expo-router"; import { Button } from "heroui-native/button"; import { useCallback, useEffect, useMemo, useState } from "react"; -import { FlatList, View } from "react-native"; +import { View } from "react-native"; import { useCSSVariable } from "uniwind"; import { type ConversationSummary, @@ -24,6 +24,7 @@ import { Notice, Refresh, Screen, + ScreenList, } from "../../../src/components"; import { tabRoot } from "../../../src/header"; import { homeView } from "../../../src/home-view"; @@ -248,7 +249,7 @@ export default function Conversations() { ]), }} /> - item.id} @@ -328,7 +329,7 @@ export default function Conversations() { description={ query ? "No chat has those words in it." - : "Start one with a Bot with the + button." + : "Start one with the + button." } /> ) : undefined diff --git a/mobile/app/delete-account.tsx b/mobile/app/delete-account.tsx index 220ee90667..473377cf02 100644 --- a/mobile/app/delete-account.tsx +++ b/mobile/app/delete-account.tsx @@ -15,6 +15,7 @@ import { scheduledSentence, typedRight, } from "../src/account-deletion"; +import { rereadOrganizations } from "../src/api"; import type { AccountDeletionBlocker } from "../src/api/generated/model"; import { removeOrganizationMember } from "../src/api/generated/organizations/organizations"; import { @@ -163,6 +164,8 @@ export default function DeleteAccount() { setError(""); try { await removeOrganizationMember(blocker.organizationId, "me"); + // Gone from the person's own list too, and from what the app works in if it was that one. + await rereadOrganizations().catch(() => {}); await standing.refresh(); } catch (failure) { setError( diff --git a/mobile/app/delete-organization.tsx b/mobile/app/delete-organization.tsx index 4f9e8cc331..f77fcd67ae 100644 --- a/mobile/app/delete-organization.tsx +++ b/mobile/app/delete-organization.tsx @@ -4,11 +4,10 @@ import { Input } from "heroui-native/input"; import { Label } from "heroui-native/label"; import { TextField } from "heroui-native/text-field"; import { useState } from "react"; -import { View } from "react-native"; import { typedOrganizationName } from "../src/account-deletion"; +import { rereadOrganizations } from "../src/api"; import { deleteOrganization } from "../src/api/generated/organizations/organizations"; import { - Monogram, Notice, Screen, ScrollScreen, @@ -19,12 +18,13 @@ import { const TITLE = "Delete organization"; /** - * Deleting an organization the person is the only owner of, opened from the list of what stops their account - * being deleted (./delete-account.tsx). Without it that list had no way on from the phone. + * Deleting an organization the person owns, opened from its row on Account (a swipe) and from the list of what + * stops their account being deleted (./delete-account.tsx). * - * The web app's step (Organization settings, Delete), in its words: everything in the organization goes for - * everybody, so the person types its name first. OpenBot decides whether it can go, and its refusal is shown as - * it says it: a person's own organization, and the one that comes with OpenBot, stay. + * One thing is asked here, so one thing is on the sheet: what goes, the organization's name to type, and the + * button. It is the web app's step (Organization settings, Delete): everything in the organization goes for + * everybody, so the person types its name first. OpenBot decides whether it can go, and its refusal is shown as it + * says it: a person's own organization, and the one that comes with OpenBot, stay. */ export default function DeleteOrganization() { const { id, name } = useLocalSearchParams<{ id: string; name: string }>(); @@ -39,7 +39,9 @@ export default function DeleteOrganization() { setError(""); try { await deleteOrganization(id); - // Back to the list of what stops the account being deleted, which reads again and has one less. + // Gone from the person's list, and from what the app works in if it was that one. It is deleted either + // way, so a list that can't be read now is read again by the screen under this sheet. + await rereadOrganizations().catch(() => {}); router.back(); } catch (failure) { setError( @@ -56,43 +58,32 @@ export default function DeleteOrganization() { - + - - - - {`Delete ${name ?? "this organization"}?`} - - Its Bots, conversations and computers are deleted for everyone. - Members keep their accounts and their other organizations. You - can't undo it. - - - To keep the organization, make someone else an owner first. You do - that in OpenBot in a browser, in the organization's settings. - - - - - - - - - - + + {name || "This organization"} + { + " and its Bots, conversations and computers are deleted for everyone. You can't undo it." + } + + + + + + ); diff --git a/mobile/app/gallery.tsx b/mobile/app/gallery.tsx index d6e923a74d..0a58f7347d 100644 --- a/mobile/app/gallery.tsx +++ b/mobile/app/gallery.tsx @@ -30,6 +30,7 @@ import { Section, Segmented, SheetTitle, + SwipeRow, Text, Toggle, } from "../src/components"; @@ -51,6 +52,7 @@ import { IconPlug, IconSettings, IconTool, + IconTrash, } from "../src/icons"; const BOTS = [ @@ -331,11 +333,21 @@ export default function Gallery() { description="You're working here" trailing={} /> - } - title="Hill Climbing" - onPress={() => {}} - /> + {}, + }} + > + } + title="Hill Climbing" + description="Swipe it to the left" + onPress={() => {}} + /> + } title="Notifications" @@ -474,7 +486,7 @@ export default function Gallery() { New chat} /> diff --git a/mobile/app/memory.tsx b/mobile/app/memory.tsx index a35f484038..16b0ba1538 100644 --- a/mobile/app/memory.tsx +++ b/mobile/app/memory.tsx @@ -145,8 +145,8 @@ export default function MemoryScreen() { {list?.length === 0 && !adding ? ( Add a memory diff --git a/mobile/app/routines.tsx b/mobile/app/routines.tsx index 0d67796855..b1a8a13e8b 100644 --- a/mobile/app/routines.tsx +++ b/mobile/app/routines.tsx @@ -124,7 +124,7 @@ export default function Routines() { ) : null}
diff --git a/mobile/src/api/index.ts b/mobile/src/api/index.ts index 68af8f103a..4705479954 100644 --- a/mobile/src/api/index.ts +++ b/mobile/src/api/index.ts @@ -40,12 +40,13 @@ export { ApiError, chooseOrganization, DEPLOYMENT_ORGANIZATION_ID, - readDeployment, ME, ORGANIZATION_ID, organizationAddress, organizationChoices, organizationsHeld, + readDeployment, + rereadOrganizations, setSignedInPerson, } from "./request"; diff --git a/mobile/src/api/request.ts b/mobile/src/api/request.ts index fc49d29b16..67c382e2cc 100644 --- a/mobile/src/api/request.ts +++ b/mobile/src/api/request.ts @@ -238,6 +238,18 @@ export async function chooseOrganization( return chosen; } +/** + * The person deleted one of their organizations from this phone, or left it: read which ones they have now. When it + * was the one they worked in, they work in another of theirs from here on, and every screen is told, as for a pick. + */ +export async function rereadOrganizations(): Promise { + const token = (await authClient.getAccessToken()) ?? ""; + const before = await organizations.current(token).catch(() => undefined); + const now = await organizations.reread(token); + if (now.currentId !== before) reportOrganizationChosen(); + return now; +} + /** The person asking, as the API addresses them in its `people/{personId}` operations. */ export const ME = "me"; diff --git a/mobile/src/components/empty-state.tsx b/mobile/src/components/empty-state.tsx index 609c54191a..bcf6fbf3d1 100644 --- a/mobile/src/components/empty-state.tsx +++ b/mobile/src/components/empty-state.tsx @@ -6,7 +6,13 @@ import { Text } from "./text"; /** * What a list shows while it has nothing in it: what will appear, and how to make it appear - * ("No conversations yet. Start one with a Bot."). + * ("No chats yet. Start one with the + button."). + * + * It stands in the middle of what the person sees, as the phone's own empty lists do: it takes the room its + * screen has left (`Screen` and `ScrollScreen` are as tall as what no bar covers) and centers in it, a little + * above the middle, where the eye puts the center. Under a page's own top (a Bot's name and tabs) it centers + * in what is left below. Nothing is drawn around it: its glyph, its name, one or two lines, and one button + * when the way on is here. */ export function EmptyState({ icon, @@ -20,23 +26,25 @@ export function EmptyState({ action?: ReactNode; }) { return ( - + {icon ? ( - - + + ) : null} - - + + {title} {description ? ( - + {description} ) : null} - {action} + {action ? ( + {action} + ) : null} ); } diff --git a/mobile/src/components/index.ts b/mobile/src/components/index.ts index 95f51ce7cd..8f6729deab 100644 --- a/mobile/src/components/index.ts +++ b/mobile/src/components/index.ts @@ -31,12 +31,13 @@ export { export { Notice } from "./notice"; export { PersonAvatar } from "./person-avatar"; export { Row, Rows } from "./rows"; -export { Refresh, Screen, ScrollScreen } from "./screen"; +export { Refresh, Screen, ScreenList, ScrollScreen } from "./screen"; export { SearchBar } from "./search-bar"; export { SearchField } from "./search-field"; export { Section } from "./section"; export { Segmented } from "./segmented"; export { SheetTitle } from "./sheet-title"; +export { type SwipeAction, SwipeRow } from "./swipe-row"; export { Text, type TextVariant } from "./text"; export { Toggle } from "./toggle"; export { DecisionCard, StepsLine } from "./transcript"; diff --git a/mobile/src/components/screen.tsx b/mobile/src/components/screen.tsx index aa8be71063..442b04ea6a 100644 --- a/mobile/src/components/screen.tsx +++ b/mobile/src/components/screen.tsx @@ -2,14 +2,27 @@ import { useFocusEffect } from "expo-router"; import { HeaderHeightContext } from "expo-router/react-navigation"; import { type ComponentRef, + createContext, type ReactNode, useCallback, useContext, + useEffect, useRef, useState, } from "react"; -import { RefreshControl, type RefreshControlProps, View } from "react-native"; +import { + FlatList, + type FlatListProps, + RefreshControl, + type RefreshControlProps, + View, +} from "react-native"; import { KeyboardAwareScrollView } from "react-native-keyboard-controller"; +import { + SafeAreaProvider, + useSafeAreaFrame, + useSafeAreaInsets, +} from "react-native-safe-area-context"; import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg"; import { useCSSVariable, withUniwind } from "uniwind"; import { cn } from "./cn"; @@ -84,6 +97,43 @@ export function TopFade() { ); } +/** + * How tall the part of a screen is that no bar covers: under the header, over the tab bar and the home + * indicator. A list as tall as this at least has room to put what it says while it is empty in the middle of + * what the person sees (`EmptyState`), and is never made taller than the screen by it. + */ +const SeenHeight = createContext(undefined); + +/** {@link SeenHeight} for the screen this is drawn in: undefined until the phone has said. */ +function useSeenHeight(): number | undefined { + return useContext(SeenHeight); +} + +/** Says the height once the phone knows it, and again each time a bar grows or goes. */ +function Seen({ onChange }: { onChange: (height: number) => void }) { + const frame = useSafeAreaFrame(); + const insets = useSafeAreaInsets(); + const height = Math.max(0, frame.height - insets.top - insets.bottom); + useEffect(() => onChange(height), [height, onChange]); + return null; +} + +/** + * Measures {@link SeenHeight} for the screen it lies over. The phone knows how far its bars reach into a view, and + * a safe area provider of the screen's own reads that for this screen: the app's one provider, at the root, knows + * only the status bar and the home indicator. It draws nothing and takes no touch, and nothing is drawn inside + * it, so what the screen's own parts read as the safe area stays the app's. + */ +function SeenProbe({ onChange }: { onChange: (height: number) => void }) { + return ( + + + + + + ); +} + /** A screen's ground: the scheme's `background`, under the native header the route draws. */ export function Screen({ children, @@ -95,9 +145,11 @@ export function Screen({ /** False in a sheet, which has no header for its content to fade under. */ fade?: boolean; }) { + const [seen, setSeen] = useState(); return ( - {children} + {children} + {fade ? : null} ); @@ -124,12 +176,15 @@ export function ScrollScreen({ /** False in a sheet, which has no header for its content to fade under. */ fade?: boolean; }) { + const [seen, setSeen] = useState(); // Inside a View: as the screen's own first child, the scroll view leaves an iOS 26 large title blank. return ( {children} + {fade ? : null} ); } +/** + * A `Screen`'s long list: a `FlatList` as tall as what the person sees at least ({@link SeenHeight}), so what + * it says while it is empty stands in the middle of the screen. It takes what a `FlatList` takes. + */ +export function ScreenList(props: FlatListProps) { + const seen = useSeenHeight(); + return ( + + ); +} + /** Pull to refresh, its spinner in the scheme's quieter text color. */ export function Refresh({ refreshing, diff --git a/mobile/src/components/swipe-row.tsx b/mobile/src/components/swipe-row.tsx new file mode 100644 index 0000000000..c6f02fbf77 --- /dev/null +++ b/mobile/src/components/swipe-row.tsx @@ -0,0 +1,141 @@ +import { type ReactNode, useEffect, useRef } from "react"; +import { Pressable, View } from "react-native"; +import Swipeable, { + type SwipeableMethods, +} from "react-native-gesture-handler/ReanimatedSwipeable"; +import Animated, { + type SharedValue, + useAnimatedStyle, +} from "react-native-reanimated"; +import { useCSSVariable } from "uniwind"; +import type { TablerIcon } from "../icons"; +import { cn } from "./cn"; +import { Icon } from "./icon"; +import { Text } from "./text"; + +/** What a row offers when it is swiped: `danger` for what deletes. */ +export type SwipeAction = { + label: string; + /** What a screen reader calls it: the label names no row ("Delete HillClimbing"). */ + accessibilityLabel?: string; + icon: TablerIcon; + tone?: "default" | "danger"; + onPress: () => void; +}; + +/** How wide the action's button is, and the room on each side of it. */ +const WIDTH = 76; + +/** The one row whose action shows, so swiping a second row puts the first away, as the phone's lists do. */ +let shown: { close: () => void } | null = null; + +/** The action's button: it fades and grows into the room the row leaves as it is swiped. */ +function Action({ + action, + progress, + onPress, +}: { + action: SwipeAction; + progress: SharedValue; + onPress: () => void; +}) { + const arriving = useAnimatedStyle(() => { + const along = Math.min(1, Math.max(0, progress.value)); + return { opacity: along, transform: [{ scale: 0.85 + 0.15 * along }] }; + }); + const danger = action.tone === "danger"; + return ( + + + + + + {action.label} + + + + + ); +} + +/** + * A row that can be swiped to the left for one action, as the phone's own lists are: the row slides, the action's + * button is in the room it leaves, and a tap on the button does it. A swipe alone never does: what these do can't + * be taken back. Without an `action` it is the row and nothing else. + * + * The same action is the row's own for somebody who can't swipe: a screen reader offers it on the row. + */ +export function SwipeRow({ + action, + disabled, + children, +}: { + action?: SwipeAction; + disabled?: boolean; + children: ReactNode; +}) { + const swipeable = useRef(null); + const self = useRef({ close: () => swipeable.current?.close() }).current; + // The row slides over its action, so it has the page's ground: a row with none would show the action through it. + const ground = useCSSVariable("--color-background") as string | undefined; + useEffect( + () => () => { + if (shown === self) shown = null; + }, + [self], + ); + if (!action) return children; + const act = () => { + self.close(); + action.onPress(); + }; + return ( + { + if (shown !== self) shown?.close(); + shown = self; + }} + onSwipeableClose={() => { + if (shown === self) shown = null; + }} + renderRightActions={(progress) => ( + + )} + > + + {children} + + + ); +} diff --git a/mobile/src/organization.ts b/mobile/src/organization.ts index cbba077b8c..fcece5f721 100644 --- a/mobile/src/organization.ts +++ b/mobile/src/organization.ts @@ -13,8 +13,24 @@ export type ListedOrganization = { id: string; name?: string; active?: boolean; + /** The person's role in it, as the server answers it: "owner", "admin", "member", or one this app doesn't know. */ + role?: string; + /** Whether it is the person's own: the one OpenBot made for them when they first signed in. */ + personal?: boolean; }; +/** + * How somebody is rid of one of their organizations from the phone: its owner deletes it, anybody else leaves it, + * and their own stays with their account. Where the server didn't say which it is to them, nothing is offered. + * OpenBot decides in the end, and its refusal is shown as it says it: the last owner can't leave. + */ +export type WayOut = "delete" | "leave" | "none"; + +export function wayOut(organization: ListedOrganization): WayOut { + if (organization.personal !== false || !organization.role) return "none"; + return organization.role === "owner" ? "delete" : "leave"; +} + /** What somebody in no organization is told. */ export const IN_NO_ORGANIZATION = "You aren't a member of an organization here. Ask an admin to add you."; @@ -128,6 +144,15 @@ export function createOrganizationChoice( return chosen; }, + /** + * The person's organizations changed from this phone (they deleted one, or left it): what is known is forgotten, + * and they are read again. A pick that is gone is not used, so the person works in another of theirs. + */ + async reread(signedInAs: string): Promise { + known = undefined; + return choices(signedInAs); + }, + /** * The organization `organizationId` answered that it isn't there for this person: they were removed from it, or it * was deleted. When it is the one they work in, what is known is forgotten, so the next request reads their diff --git a/mobile/tests/organization-way-out.test.ts b/mobile/tests/organization-way-out.test.ts new file mode 100644 index 0000000000..39de070b5e --- /dev/null +++ b/mobile/tests/organization-way-out.test.ts @@ -0,0 +1,111 @@ +/** + * The way out of an organization from the phone (src/organization.ts): which one a row on Account offers when it is + * swiped, and that the person's organizations are read again once one of them is gone. + */ + +import { expect, test } from "bun:test"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; +import { + createOrganizationChoice, + type ListedOrganization, + wayOut, +} from "../src/organization"; + +const source = (...parts: string[]) => + readFileSync(join(import.meta.dir, "..", ...parts), "utf8"); + +const organization = ( + change: Partial, +): ListedOrganization => ({ + id: "org_work", + name: "Work", + role: "member", + personal: false, + ...change, +}); + +test("an owner deletes an organization, and anybody else leaves it", () => { + expect(wayOut(organization({ role: "owner" }))).toBe("delete"); + expect(wayOut(organization({ role: "admin" }))).toBe("leave"); + expect(wayOut(organization({ role: "member" }))).toBe("leave"); + // A role this app doesn't know is a member's. + expect(wayOut(organization({ role: "auditor" }))).toBe("leave"); +}); + +test("a person's own organization has no way out, whatever their role in it", () => { + expect(wayOut(organization({ personal: true, role: "owner" }))).toBe("none"); + expect(wayOut(organization({ personal: true, role: "member" }))).toBe("none"); +}); + +test("nothing is offered where the server didn't say what the organization is to the person", () => { + // An OpenBot that keeps one organization has no list of them: the phone knows only its id. + expect(wayOut({ id: "default", active: true })).toBe("none"); + expect(wayOut(organization({ role: undefined }))).toBe("none"); + expect(wayOut(organization({ personal: undefined }))).toBe("none"); +}); + +test("after one is deleted or left, the list is read again and a pick that is gone is not used", async () => { + let listed: ListedOrganization[] = [ + { id: "org_own", active: true }, + { id: "org_work" }, + ]; + let reads = 0; + const kept = new Map([["person_1", "org_work"]]); + const choice = createOrganizationChoice( + async () => { + reads += 1; + return listed; + }, + { + read: async (person) => kept.get(person) ?? null, + write: async (person, id) => { + kept.set(person, id); + }, + }, + () => "person_1", + ); + expect(await choice.current("token")).toBe("org_work"); + // Asked again, it is what is known: one read for the sign-in. + expect(await choice.current("token")).toBe("org_work"); + expect(reads).toBe(1); + + listed = [{ id: "org_own", active: true }]; + const now = await choice.reread("token"); + expect(reads).toBe(2); + expect(now.organizations.map((one) => one.id)).toEqual(["org_own"]); + expect(now.currentId).toBe("org_own"); + expect(await choice.current("token")).toBe("org_own"); +}); + +test("Account's rows swipe for the way out, and both ways read the person's organizations again", () => { + // The screens need a phone, so their source is read. + const account = source("app", "(tabs)", "(account)", "account.tsx"); + expect(account).toContain("action={swipe(organization)}"); + expect(account).toContain("wayOut(organization)"); + expect(account).toContain("await rereadOrganizations();"); + expect(source("app", "delete-organization.tsx")).toContain( + "await rereadOrganizations()", + ); + // A swipe alone does nothing: what it offers can't be taken back, so only a tap on the button does it. + const row = source("src", "components", "swipe-row.tsx"); + expect(row).toContain("overshootRight={false}"); + expect(row).not.toContain("onSwipeableOpen="); +}); + +test("an empty list says so in the middle of the screen", () => { + // The page and the list are as tall as what the person sees, and the empty state takes the room left in them. + const screen = source("src", "components", "screen.tsx"); + expect(screen).toContain("contentContainerStyle={{ minHeight: seen }}"); + expect(screen).toContain( + "contentContainerStyle={[{ minHeight: seen }, props.contentContainerStyle]}", + ); + expect(source("src", "components", "empty-state.tsx")).toContain( + 'className="grow items-center justify-center', + ); + for (const list of [ + ["app", "(tabs)", "(bots)", "bots.tsx"], + ["app", "(tabs)", "(conversations)", "index.tsx"], + ]) + expect(source(...list)).toContain(" Date: Mon, 30 Nov 2026 12:38:11 -0800 Subject: [PATCH 3/7] OpenBot Mobile: More is the system's menu, Notifications is one place, and a tidier Account More on iOS opens iOS's own menu (@expo/ui's Menu) from a clear button over the tab bar's last one, in place of the menu the app drew. expo-glass-effect, which only that menu used, is gone again, so the branch adds no native package. Notifications is the approval inbox under a new name, with the phone's switch for notifications as its first row. The switch is no longer on Account. Account starts everything on one line: who is signed in as a row, the organizations with a tick on the one worked in, then Sign out, Delete account, and which OpenBot it is. A swiped row's action is its glyph alone. The fade under the header shows only once a page is scrolled, so it no longer lies over a page's own first lines. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 17 +- docs/app-guidelines.md | 19 +- mobile/app/(tabs)/(account)/account.tsx | 124 +++------ mobile/app/(tabs)/(more)/_layout.tsx | 2 +- mobile/app/(tabs)/(more)/more.tsx | 14 +- mobile/app/(tabs)/_layout.tsx | 58 ++-- mobile/app/_layout.tsx | 2 +- mobile/app/approvals.tsx | 65 ++++- mobile/app/gallery.tsx | 2 +- mobile/package-lock.json | 1 - mobile/package.json | 1 - mobile/src/components/screen.tsx | 125 ++++++--- mobile/src/components/swipe-row.tsx | 31 +-- mobile/src/more-items.ts | 23 +- mobile/src/more-menu.android.tsx | 6 + mobile/src/more-menu.tsx | 305 +++++++--------------- mobile/tests/more-items.test.ts | 41 ++- mobile/tests/organization-way-out.test.ts | 12 +- 18 files changed, 406 insertions(+), 442 deletions(-) create mode 100644 mobile/src/more-menu.android.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d70446b9d..d88207af68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,14 +8,15 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. ## Unreleased -- **OpenBot Mobile: Account in the look of the other tabs, and More as a menu on iOS.** Account is - a list to the screen's edges: each organization with its letter and a tick on the one you work - in, Notifications as the phone's own switch, which now turns them off too, Sign out as a button, - and Delete account under it. The Delete account and Delete organization sheets follow. On iOS the - tab bar's last button opens a small menu (Routines, Approval inbox, Memory, Skills, Connections) - over the tab you are on. Android keeps More as a tab. Swipe an organization on Account to delete - it, if you own it, or to leave it. A list with nothing in it yet says so in the middle of the - screen. +- **OpenBot Mobile: Account in the look of the other tabs, More as a menu on iOS, and one place + for notifications.** Account is a list to the screen's edges: who is signed in, each organization + with its letter and a tick on the one you work in, then Sign out and Delete account. Swipe an + organization to delete it, if you own it, or to leave it. The Delete account and Delete + organization sheets follow. On iOS the tab bar's last button opens the system's menu (Routines, + Notifications, Memory, Skills, Connections) over the tab you are on. Android keeps More as a tab. + Notifications is the approval inbox under a new name, with the phone's switch for notifications + at its top, which now turns them off too. A list with nothing in it yet says so in the middle of + the screen. - **Delete your account from OpenBot Mobile.** Account, then Delete account: type your email address and "delete my account". The account goes in 14 days, or at once with Delete now, as in the web app. A sign-in older than ten minutes is asked for again first. Somebody who signs in again before diff --git a/docs/app-guidelines.md b/docs/app-guidelines.md index bc1ed03544..9b5118fcb9 100644 --- a/docs/app-guidelines.md +++ b/docs/app-guidelines.md @@ -230,26 +230,31 @@ Native's, and builds its own only when neither fits. The development build shows own while the app opens. - **The tabs** are the signed-in app's five, in the platform's tab bar, as icons with no words: Chats, Bots (OpenBot's orb as a flat glyph), your Account in the middle, Needs you (its badge - counts what waits), and More (Routines, the approval inbox with a count of what waits there, Memory, + counts what waits), and More (Routines, Notifications with a count of what waits there, Memory, Skills and Connections). Each tab is a stack of its own with the native header, its title at the start of the bar. A conversation, a Bot and everything else opened from a tab open in the app's stack over the tabs, so the tab bar steps aside and the message box has the bottom to itself. -- **More is a menu on iOS.** The bar's last button opens a small menu over the tab the person is - on, drawn as iOS draws one (its glass, SF Symbols), and what is picked opens in the app's stack - (`mobile/src/more-menu.tsx`). A tab that only held a list of five links cost a screen and a second - tap. Android keeps More as a tab with the same list. Both read `mobile/src/more-items.ts`. +- **More is a menu on iOS, and the menu is the system's.** The bar's last button opens iOS's own + menu (`@expo/ui`'s `Menu`) over the tab the person is on, and what is picked opens in the app's + stack (`mobile/src/more-menu.tsx`). Nothing of the menu is drawn by the app. A tab that only held + a list of five links cost a screen and a second tap. Android keeps More as a tab with the same + list. Both read `mobile/src/more-items.ts`. +- **Notifications is one place**, in More: the phone's switch for them, and under it what the + person's Bots wait on them for (approvals and questions). - **A tab's own list runs to the screen's edges, with no card** (`ListRow`): Chats, Bots, and your Account, where an organization is a row with its letter and the one worked in has the tick. A card of rows with hairlines and icon tiles (`Rows`) is for a page of settings opened from one. What a row is about shows in its shape: a person is a circle, a Bot its orb, an organization a rounded square with its letter. -- **A row's own action is a swipe** (`SwipeRow`): the row slides left and one button is in the room - it leaves, as in the phone's own lists. A swipe alone never does it, and what deletes still asks +- **A row's own action is a swipe** (`SwipeRow`): the row slides left and one button, its glyph + alone, is in the room it leaves, as in the phone's own lists. A swipe alone never does it, and what deletes still asks first. An organization on Account swipes for Delete (its owner) or Leave (anybody else). - **An empty list says so in the middle of the screen** (`EmptyState`): a glyph, its name, a line or two, and one button when the way on is right there. No box around it. A page (`ScrollScreen`) and a tab's list (`ScreenList`) are as tall as what the bars leave, so it centers in what the person sees and the empty page doesn't scroll. +- **The fade under the header is for what has scrolled under it.** A page at rest has none over its + own first lines. - **Chats** is the word for conversations, everywhere a person reads it. - **A chat** is headed as iMessage heads one: the orbs of the Bots in it and their names, and tapping it opens the Bot's page, or a group's Bots. It reads from the top down, and opens at its diff --git a/mobile/app/(tabs)/(account)/account.tsx b/mobile/app/(tabs)/(account)/account.tsx index d3f5ae872a..a2ea0b452b 100644 --- a/mobile/app/(tabs)/(account)/account.tsx +++ b/mobile/app/(tabs)/(account)/account.tsx @@ -1,6 +1,6 @@ import { router, useFocusEffect } from "expo-router"; import { Button } from "heroui-native/button"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useState } from "react"; import { ActivityIndicator, Alert, View } from "react-native"; import { useCSSVariable } from "uniwind"; import { @@ -18,65 +18,38 @@ import { Monogram, Notice, PersonAvatar, - RowGlyph, ScrollScreen, type SwipeAction, SwipeRow, Text, - Toggle, } from "../../../src/components"; -import { IconBell, IconCheck, IconLogout, IconTrash } from "../../../src/icons"; -import { - pushTurnedOn, - registerPush, - unregisterPush, -} from "../../../src/notifications"; +import { IconCheck, IconLogout, IconTrash } from "../../../src/icons"; +import { unregisterPush } from "../../../src/notifications"; import { type ListedOrganization, wayOut } from "../../../src/organization"; import { useLoad } from "../../../src/use-load"; -/** The name over a group of rows, on the line the rows' words start on. */ -function GroupLabel({ children }: { children: string }) { - return ( - - {children} - - ); -} - /** - * Your account, a tab of its own: who is signed in, the organization they work in (and the others they can - * switch to), notifications on this phone, and the two ways out. + * Your account, a tab of its own: who is signed in, the organizations they can work in, and the two ways out. * - * Drawn as the other tabs are, a list to the screen's edges with no cards: an organization is a row with its - * letter, and the one worked in has the tick. A row swipes to the left for the way out of that organization - * (src/organization.ts): its owner deletes it, anybody else leaves it, and the person's own has none. - * Notifications is the phone's own switch. Sign out and Delete account are the two buttons at the foot, the - * second in the quieter red of what can't be taken back. + * Everything starts on one line down the screen, as the other tabs' lists do, with no cards. Who is signed in + * is the first row. An organization is a row with its letter, and the one worked in has the tick: a tap works + * in another, and a swipe to the left is the way out of one (src/organization.ts), where its owner deletes it, + * anybody else leaves it, and the person's own has none. Sign out and Delete account are the two buttons at + * the foot, the second in the quieter red of what can't be taken back, and which OpenBot this is under them. + * Notifications are in More (app/approvals.tsx). */ export default function Account() { const { data: session } = authClient.useSession(); const muted = useCSSVariable("--color-muted") as string | undefined; const [busy, setBusy] = useState(""); const [error, setError] = useState(""); - const [pushOn, setPushOn] = useState(false); - // Said as it is on this phone, not as it was before the app last started. - useEffect(() => { - void pushTurnedOn() - .then(setPushOn) - .catch(() => {}); - }, []); const loadOrganizations = useCallback(() => organizationChoices(), []); // The person's own list, whichever organization they work in: it stays on screen while it is read again. const organizations = useLoad(loadOrganizations, Boolean(session), { keep: true, }); // Deleting the account is offered where this OpenBot has it: one that answers where the deletion stands. - // The person's own too, so the line stays while it is read again. + // The person's own too, so the button stays while it is read again. const loadDeletion = useCallback(() => getAccountDeletion(), []); const deletion = useLoad(loadDeletion, Boolean(session), { keep: true }); // Read again each time the tab comes back: an organization deleted in the sheet over it is gone from the list. @@ -101,27 +74,13 @@ export default function Account() { setBusy(""); } } - /** The switch moves at once, and goes back if the phone or OpenBot refuses. */ - function setNotifications(on: boolean) { - setPushOn(on); - void act("push", async () => { - try { - if (on) await registerPush(); - else await unregisterPush(); - } catch (failure) { - setPushOn(!on); - throw failure; - } - }); - } /** What a row offers when it is swiped: the way out of that organization, asked about before it is done. */ function swipe(organization: ListedOrganization): SwipeAction | undefined { const name = organization.name ?? organization.id; const way = wayOut(organization); if (way === "delete") return { - label: "Delete", - accessibilityLabel: `Delete ${name}`, + label: `Delete ${name}`, icon: IconTrash, tone: "danger", // The sheet says what goes with it, and waits for its name to be typed. @@ -133,8 +92,7 @@ export default function Account() { }; if (way === "leave") return { - label: "Leave", - accessibilityLabel: `Leave ${name}`, + label: `Leave ${name}`, icon: IconLogout, onPress: () => Alert.alert( @@ -162,15 +120,15 @@ export default function Account() { // The OpenBot this phone is signed in to, as its address reads without the scheme. const server = serverUrl.replace(/^https?:\/\//, "").replace(/\/$/, ""); return ( - - - - - + + + + + {person} {session?.user.name && session.user.email ? ( - + {session.user.email} ) : null} @@ -183,9 +141,14 @@ export default function Account() { ) : null} {listed.length > 0 ? ( <> - + {listed.length > 1 ? "Organizations" : "Organization"} - + {listed.map((organization) => { const current = organization.id === organizations.data?.currentId; const name = organization.name ?? organization.id; @@ -198,7 +161,6 @@ export default function Account() { } title={name} - description={current ? "You're working here" : undefined} accessibilityLabel={ current ? `${name}, you're working here` : `Work in ${name}` } @@ -233,25 +195,7 @@ export default function Account() { })} ) : null} - This phone - } - title="Notifications" - description={ - pushOn - ? "Bots tell you when they finish or need you." - : "Get told when a Bot finishes or needs you." - } - trailing={ - - } - /> - + - - {`Signed in to ${server}`} - - - {deletion.data ? ( - + {deletion.data ? ( - - ) : null} + ) : null} + + {`Signed in to ${server}`} + + ); } diff --git a/mobile/app/(tabs)/(more)/_layout.tsx b/mobile/app/(tabs)/(more)/_layout.tsx index a11c9ed1c2..2ac464c879 100644 --- a/mobile/app/(tabs)/(more)/_layout.tsx +++ b/mobile/app/(tabs)/(more)/_layout.tsx @@ -2,7 +2,7 @@ import { Stack } from "expo-router"; import { tabRoot, useHeaderOptions } from "../../../src/header"; /** - * More's stack: the list. What it opens (Routines, Memory, Skills, Connections, the approval inbox) + * More's stack: the list. What it opens (Routines, Memory, Skills, Connections, Notifications) * lives in the app's own stack, so a Bot's page opens the same screens, and nothing stacks. */ export default function MoreLayout() { diff --git a/mobile/app/(tabs)/(more)/more.tsx b/mobile/app/(tabs)/(more)/more.tsx index e82811c778..6e9331b073 100644 --- a/mobile/app/(tabs)/(more)/more.tsx +++ b/mobile/app/(tabs)/(more)/more.tsx @@ -12,9 +12,9 @@ import { Text, } from "../../../src/components"; import { + IconBell, IconBook, IconBrain, - IconChecks, IconChevronRight, IconClock, IconPlug, @@ -26,7 +26,7 @@ import { useLoad } from "../../../src/use-load"; /** Each part's glyph in the app's own set, which what is inside a screen is drawn with. */ const ICONS: Record = { routines: IconClock, - approvals: IconChecks, + notifications: IconBell, memory: IconBrain, skills: IconBook, connections: IconPlug, @@ -34,8 +34,8 @@ const ICONS: Record = { /** * More: the parts of the app that don't have a tab (src/more-items.ts). The routines Bots run, what every Bot - * remembers, knows and connects to, and the approval inbox. Android's tab. On iOS the same list is a menu that - * rises from the tab bar (src/more-menu.tsx), and this screen is not opened. + * remembers, knows and connects to, and Notifications. Android's tab. On iOS the same list is the system's menu + * over the tab bar's last button (app/(tabs)/_layout.tsx), and this screen opens only if that press is missed. */ export default function More() { const { data: session } = authClient.useSession(); @@ -57,17 +57,17 @@ export default function More() { icon={ICONS[item.key]} title={item.title} description={ - item.key === "approvals" && waiting + item.key === "notifications" && waiting ? `${waiting} waiting for you` : item.description } accessibilityLabel={ - item.key === "approvals" && waiting + item.key === "notifications" && waiting ? `${item.title}, ${waiting} waiting` : item.title } trailing={ - item.key === "approvals" && waiting ? ( + item.key === "notifications" && waiting ? ( ) : undefined } diff --git a/mobile/app/(tabs)/_layout.tsx b/mobile/app/(tabs)/_layout.tsx index 4c5cfffeef..d0e8294ac1 100644 --- a/mobile/app/(tabs)/_layout.tsx +++ b/mobile/app/(tabs)/_layout.tsx @@ -1,23 +1,23 @@ import { usePathname } from "expo-router"; import { NativeTabs } from "expo-router/native-tabs"; -import { useState } from "react"; -import { Platform, Pressable, useWindowDimensions, View } from "react-native"; +import { Platform, useWindowDimensions, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useCSSVariable } from "uniwind"; import { MoreMenu } from "../../src/more-menu"; import { useNeedsYouCount } from "../../src/needs-you-count"; /** - * More is a menu on iOS: the bar's last button opens it over the tab the person is on, and what they pick opens - * in the app's stack (src/more-menu.tsx). The tab is told not to open, and still says it was pressed. Android - * keeps More as a tab with its list, where a menu rising from the navigation bar is not the platform's way. + * More is a menu on iOS: the bar's last button opens the system's own menu over the tab the person is on, and + * what they pick opens in the app's stack (src/more-menu.tsx). A tab can't be told to open a menu, so the menu's + * own clear button lies over the tab's, and takes the press. A press that misses it opens More as a tab with + * the same list, which is what Android has: a menu rising from the navigation bar is not that platform's way. */ const MORE_IS_A_MENU = Platform.OS === "ios"; /** * Where iOS draws the bar's buttons, measured on the phone: the five share the bar's width less this much, the - * bar is this tall, and it sits this far into the room the home indicator keeps. For the press that is caught - * over More, below. + * bar is this tall, and it sits this far into the room the home indicator keeps. For the menu's button, which + * lies over More, below. */ const BAR_SIDES = 57; const BAR_HEIGHT = 62; @@ -40,7 +40,6 @@ const ORB_FILLED = require("../../assets/tab-orb-filled.png"); export default function TabsLayout() { // Read again on each move between tabs, so starting or hiding something in Needs you shows here. const waiting = useNeedsYouCount(true, usePathname()); - const [menuOpen, setMenuOpen] = useState(false); const insets = useSafeAreaInsets(); const { width } = useWindowDimensions(); const [foreground, muted, background, highlight, danger] = useCSSVariable([ @@ -53,13 +52,6 @@ export default function TabsLayout() { return ( { - // The route's key starts with its name: only More's press opens the menu. - if (MORE_IS_A_MENU && event.target?.startsWith("(more)")) - setMenuOpen(true); - }, - }} // The open tab in the text color, the rest in the quieter one: the scheme has no brand blue. tintColor={foreground} iconColor={{ default: muted, selected: foreground }} @@ -114,35 +106,23 @@ export default function TabsLayout() { ) : null} - + {MORE_IS_A_MENU ? ( - <> - {/* - * The press on More is caught here, over the button, before the bar has it. A tab that is told not to - * open still slid the bar's highlight to itself and back on every press. The tab stays told not to - * open, for a screen reader, which presses the tab itself, and for a bar laid out another way. - */} - setMenuOpen(true)} - style={{ - position: "absolute", - right: BAR_SIDES / 2, - width: (width - BAR_SIDES) / 5, - height: BAR_HEIGHT, - bottom: Math.max(insets.bottom - BAR_INTO_HOME_ROOM, 8), - }} - /> - setMenuOpen(false)} /> - + // Over the bar's last button, at its size: the press opens the menu before the bar has it, so the + // bar's highlight stays on the tab the person is on. + ) : null} ); diff --git a/mobile/app/_layout.tsx b/mobile/app/_layout.tsx index efda1414d5..c529295e27 100644 --- a/mobile/app/_layout.tsx +++ b/mobile/app/_layout.tsx @@ -177,7 +177,7 @@ function Layout() { /> diff --git a/mobile/app/approvals.tsx b/mobile/app/approvals.tsx index 72fef337ef..e422173fce 100644 --- a/mobile/app/approvals.tsx +++ b/mobile/app/approvals.tsx @@ -2,7 +2,7 @@ import { Redirect, useLocalSearchParams } from "expo-router"; import { Button } from "heroui-native/button"; import { TextArea } from "heroui-native/text-area"; import { TextField } from "heroui-native/text-field"; -import { type ReactNode, useCallback, useState } from "react"; +import { type ReactNode, useCallback, useEffect, useState } from "react"; import { View } from "react-native"; import { everyBot, loadApprovalInbox, ME, ORGANIZATION_ID } from "../src/api"; import { @@ -23,17 +23,26 @@ import { BotOrb, cn, EmptyState, + ListRow, Notice, + RowGlyph, ScrollScreen, Text, + Toggle, } from "../src/components"; -import { IconChecks } from "../src/icons"; +import { IconBell, IconChecks } from "../src/icons"; +import { + pushTurnedOn, + registerPush, + unregisterPush, +} from "../src/notifications"; import { useLoad } from "../src/use-load"; /** - * The approval inbox: what the person's Bots want to do and asked first about, each with only the - * answers the server takes, and the questions they asked. Each is a row like a chat's, under its - * Bot's orb, with hairlines between them. A notification opens it at one of them, which is ringed. + * Notifications: whether this phone is told, and what waits on the person. The phone's own switch is the first + * row. Under it, what the person's Bots want to do and asked first about, each with only the answers the + * server takes, and the questions they asked. Each is a row like a chat's, under its Bot's orb, with hairlines + * between them. A notification opens it at one of them, which is ringed. */ export default function ApprovalsScreen() { const { requestId } = useLocalSearchParams<{ requestId?: string }>(); @@ -41,6 +50,26 @@ export default function ApprovalsScreen() { const [error, setError] = useState(""); const [busy, setBusy] = useState(""); const [answers, setAnswers] = useState>({}); + const [pushOn, setPushOn] = useState(false); + // Said as it is on this phone, not as it was before the app last started. + useEffect(() => { + void pushTurnedOn() + .then(setPushOn) + .catch(() => {}); + }, []); + /** The switch moves at once, and goes back if the phone or OpenBot refuses. */ + function setNotifications(on: boolean) { + setPushOn(on); + setError(""); + void (on ? registerPush() : unregisterPush()).catch((failure) => { + setPushOn(!on); + setError( + failure instanceof Error + ? failure.message + : "Couldn't change notifications. Try again.", + ); + }); + } const load = useCallback(() => loadApprovalInbox(), []); const inbox = useLoad(load, Boolean(session)); // Each Bot by its name: the list carries only its id. @@ -102,6 +131,32 @@ export default function ApprovalsScreen() { ) : null} + } + title="Allow notifications" + description={ + pushOn + ? "Bots tell you when they finish or need you." + : "Get told when a Bot finishes or needs you." + } + trailing={ + + } + /> + {pending?.length || questions.length ? ( + + Waiting for you + + ) : null} {pending?.map((request, index) => { // In the web card's words: what the Bot wants to do, why it asks, and what would change. const change = approvalChange(request.action.target); diff --git a/mobile/app/gallery.tsx b/mobile/app/gallery.tsx index 0a58f7347d..f5ef492563 100644 --- a/mobile/app/gallery.tsx +++ b/mobile/app/gallery.tsx @@ -335,7 +335,7 @@ export default function Gallery() { /> {}, diff --git a/mobile/package-lock.json b/mobile/package-lock.json index 7b19412fa7..9b6f7250c8 100644 --- a/mobile/package-lock.json +++ b/mobile/package-lock.json @@ -27,7 +27,6 @@ "expo-document-picker": "~58.0.5", "expo-file-system": "~58.0.14", "expo-font": "~58.0.12", - "expo-glass-effect": "~58.0.5", "expo-image-picker": "~58.0.10", "expo-linking": "~58.0.17", "expo-network": "~58.0.5", diff --git a/mobile/package.json b/mobile/package.json index ca19cae44c..0b5897e539 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -34,7 +34,6 @@ "expo-document-picker": "~58.0.5", "expo-file-system": "~58.0.14", "expo-font": "~58.0.12", - "expo-glass-effect": "~58.0.5", "expo-image-picker": "~58.0.10", "expo-linking": "~58.0.17", "expo-network": "~58.0.5", diff --git a/mobile/src/components/screen.tsx b/mobile/src/components/screen.tsx index 442b04ea6a..4d9d190fcb 100644 --- a/mobile/src/components/screen.tsx +++ b/mobile/src/components/screen.tsx @@ -7,17 +7,25 @@ import { useCallback, useContext, useEffect, + useMemo, useRef, useState, } from "react"; import { FlatList, type FlatListProps, + type NativeScrollEvent, + type NativeSyntheticEvent, RefreshControl, type RefreshControlProps, View, } from "react-native"; import { KeyboardAwareScrollView } from "react-native-keyboard-controller"; +import Animated, { + useAnimatedStyle, + useSharedValue, + withTiming, +} from "react-native-reanimated"; import { SafeAreaProvider, useSafeAreaFrame, @@ -36,12 +44,24 @@ const ABOVE_KEYBOARD = 24; /** How far above the header's edge what scrolls under it fades into the page. */ const FADE = 36; +/** How far a page has to be scrolled before its top counts as under the header. */ +const UNDER = 6; + /** * The top edge of a screen's content: what scrolls up toward the header fades into the page's ground * over a few points, rather than being cut off at a hard line by the bar. + * + * `under` is whether anything has scrolled under the header. A page at rest has nothing there, and the fade + * would only lie over the page's own first lines, so it shows once the page is scrolled. A screen whose list + * doesn't say (`under` is undefined) keeps it always. */ -export function TopFade() { +export function TopFade({ under }: { under?: boolean }) { const background = useCSSVariable("--color-background") as string | undefined; + const shown = useSharedValue(under === false ? 0 : 1); + useEffect(() => { + shown.value = withTiming(under === false ? 0 : 1, { duration: 160 }); + }, [under, shown]); + const fading = useAnimatedStyle(() => ({ opacity: shown.value })); // The header's bottom edge, from the top of the window (it counts the status bar). Some screens' content runs // under the header and some starts below it, so where this screen starts is measured, and the fade sits at the // header's edge either way: never inside the content, never hidden behind the bar. @@ -73,10 +93,12 @@ export function TopFade() { onLayout={measure} /> {top === null ? null : ( - @@ -91,49 +113,71 @@ export function TopFade() { - + )} ); } /** - * How tall the part of a screen is that no bar covers: under the header, over the tab bar and the home - * indicator. A list as tall as this at least has room to put what it says while it is empty in the middle of - * what the person sees (`EmptyState`), and is never made taller than the screen by it. + * What the phone's bars leave of a screen: how tall the part is that none covers (under the header, over the + * tab bar and the home indicator), and how far the header reaches into the screen from its top. */ -const SeenHeight = createContext(undefined); +type Seen = { height: number; top: number }; -/** {@link SeenHeight} for the screen this is drawn in: undefined until the phone has said. */ -function useSeenHeight(): number | undefined { - return useContext(SeenHeight); -} +/** + * What a `Screen` tells the list inside it (`ScreenList`): the room it has ({@link Seen}), so a list as tall as + * that at least can put what it says while it is empty in the middle of what the person sees (`EmptyState`) and + * is never made taller than the screen by it, and where to say how far it is scrolled, for the fade at the top. + */ +const ScreenRoom = createContext< + { height: number | undefined; scrolledTo: (y: number) => void } | undefined +>(undefined); -/** Says the height once the phone knows it, and again each time a bar grows or goes. */ -function Seen({ onChange }: { onChange: (height: number) => void }) { +/** Says what the bars leave once the phone knows it, and again each time a bar grows or goes. */ +function SeenReader({ onChange }: { onChange: (seen: Seen) => void }) { const frame = useSafeAreaFrame(); const insets = useSafeAreaInsets(); const height = Math.max(0, frame.height - insets.top - insets.bottom); - useEffect(() => onChange(height), [height, onChange]); + const top = insets.top; + useEffect(() => onChange({ height, top }), [height, top, onChange]); return null; } /** - * Measures {@link SeenHeight} for the screen it lies over. The phone knows how far its bars reach into a view, and - * a safe area provider of the screen's own reads that for this screen: the app's one provider, at the root, knows + * Measures {@link Seen} for the screen it lies over. The phone knows how far its bars reach into a view, and a + * safe area provider of the screen's own reads that for this screen: the app's one provider, at the root, knows * only the status bar and the home indicator. It draws nothing and takes no touch, and nothing is drawn inside * it, so what the screen's own parts read as the safe area stays the app's. */ -function SeenProbe({ onChange }: { onChange: (height: number) => void }) { +function SeenProbe({ onChange }: { onChange: (seen: Seen) => void }) { return ( - + ); } +/** + * A screen's room, and whether its page is scrolled under the header. A page at rest starts where the header + * ends: scrolled to minus the header's reach where the page runs under the header, and to nothing where it + * starts below it. `under` is undefined until a list has said where it is. + */ +function useScreenRoom() { + const [seen, setSeen] = useState(); + const [under, setUnder] = useState(); + // Read when a list says where it is, so what says it stays the same as the header grows and shrinks. + const top = useRef(0); + top.current = seen?.top ?? 0; + const scrolledTo = useCallback( + (y: number) => setUnder(y + top.current > UNDER), + [], + ); + return { seen, setSeen, under, scrolledTo }; +} + /** A screen's ground: the scheme's `background`, under the native header the route draws. */ export function Screen({ children, @@ -145,12 +189,16 @@ export function Screen({ /** False in a sheet, which has no header for its content to fade under. */ fade?: boolean; }) { - const [seen, setSeen] = useState(); + const { seen, setSeen, under, scrolledTo } = useScreenRoom(); + const room = useMemo( + () => ({ height: seen?.height, scrolledTo }), + [seen?.height, scrolledTo], + ); return ( - {children} + {children} - {fade ? : null} + {fade ? : null} ); } @@ -176,7 +224,7 @@ export function ScrollScreen({ /** False in a sheet, which has no header for its content to fade under. */ fade?: boolean; }) { - const [seen, setSeen] = useState(); + const { seen, setSeen, under, scrolledTo } = useScreenRoom(); // Inside a View: as the screen's own first child, the scroll view leaves an iOS 26 large title blank. return ( @@ -184,11 +232,14 @@ export function ScrollScreen({ className="flex-1" contentContainerClassName={cn("gap-6 px-4 pt-6 pb-12", className)} // As tall as what the person sees, so a page with nothing on it yet says so in the middle (`EmptyState`). - contentContainerStyle={{ minHeight: seen }} + contentContainerStyle={{ minHeight: seen?.height }} contentInsetAdjustmentBehavior="automatic" keyboardShouldPersistTaps="handled" keyboardDismissMode="interactive" bottomOffset={ABOVE_KEYBOARD} + onScroll={(event: NativeSyntheticEvent) => + scrolledTo(event.nativeEvent.contentOffset.y) + } refreshControl={ onRefresh ? ( @@ -198,21 +249,35 @@ export function ScrollScreen({ {children} - {fade ? : null} + {/* A page that hasn't been scrolled yet is at rest: nothing is under the header. */} + {fade ? : null} ); } /** - * A `Screen`'s long list: a `FlatList` as tall as what the person sees at least ({@link SeenHeight}), so what - * it says while it is empty stands in the middle of the screen. It takes what a `FlatList` takes. + * A `Screen`'s long list: a `FlatList` as tall as what the person sees at least ({@link ScreenRoom}), so what + * it says while it is empty stands in the middle of the screen, and one that says how far it is scrolled, so + * the fade at the top shows only over what has scrolled under the header. It takes what a `FlatList` takes. */ export function ScreenList(props: FlatListProps) { - const seen = useSeenHeight(); + const room = useContext(ScreenRoom); + const scrolledTo = room?.scrolledTo; + // At rest until it scrolls. + useEffect(() => scrolledTo?.(Number.NEGATIVE_INFINITY), [scrolledTo]); + const { onScroll } = props; return ( { + scrolledTo?.(event.nativeEvent.contentOffset.y); + onScroll?.(event); + }} + contentContainerStyle={[ + { minHeight: room?.height }, + props.contentContainerStyle, + ]} /> ); } diff --git a/mobile/src/components/swipe-row.tsx b/mobile/src/components/swipe-row.tsx index c6f02fbf77..be4051765a 100644 --- a/mobile/src/components/swipe-row.tsx +++ b/mobile/src/components/swipe-row.tsx @@ -11,20 +11,18 @@ import { useCSSVariable } from "uniwind"; import type { TablerIcon } from "../icons"; import { cn } from "./cn"; import { Icon } from "./icon"; -import { Text } from "./text"; /** What a row offers when it is swiped: `danger` for what deletes. */ export type SwipeAction = { + /** What a screen reader calls it, with the row's name in it ("Delete HillClimbing"). Never drawn. */ label: string; - /** What a screen reader calls it: the label names no row ("Delete HillClimbing"). */ - accessibilityLabel?: string; icon: TablerIcon; tone?: "default" | "danger"; onPress: () => void; }; -/** How wide the action's button is, and the room on each side of it. */ -const WIDTH = 76; +/** The action's button: a square of this size, with its glyph alone. */ +const SIZE = 52; /** The one row whose action shows, so swiping a second row puts the first away, as the phone's lists do. */ let shown: { close: () => void } | null = null; @@ -49,27 +47,19 @@ function Action({ - - {action.label} - @@ -112,7 +102,7 @@ export function SwipeRow({ ref={swipeable} enabled={!disabled} overshootRight={false} - rightThreshold={WIDTH / 2} + rightThreshold={SIZE / 2} childrenContainerStyle={{ backgroundColor: ground }} onSwipeableWillOpen={() => { if (shown !== self) shown?.close(); @@ -126,12 +116,7 @@ export function SwipeRow({ )} > {children} diff --git a/mobile/src/more-items.ts b/mobile/src/more-items.ts index 7842975296..3d00a8d2b9 100644 --- a/mobile/src/more-items.ts +++ b/mobile/src/more-items.ts @@ -1,12 +1,12 @@ /** * The parts of the app that have no tab of their own, in the order they are listed: what the More menu offers - * on iOS (./more-menu.tsx) and what the More screen lists on Android (app/(tabs)/(more)/more.tsx). One list, so - * the two never say different things. + * on iOS (app/(tabs)/_layout.tsx) and what the More screen lists on Android (app/(tabs)/(more)/more.tsx). One + * list, so the two never say different things. * * It imports nothing, so it can be tested without a phone. */ export type MoreItem = { - key: "routines" | "approvals" | "memory" | "skills" | "connections"; + key: "routines" | "notifications" | "memory" | "skills" | "connections"; title: string; /** What the screen's row says under the title. The menu has no room for it. */ description: string; @@ -28,11 +28,12 @@ export const MORE_ITEMS: readonly MoreItem[] = [ yourBots: false, }, { - key: "approvals", - title: "Approval inbox", - description: "What your Bots asked you to approve", + // What the Bots ask the person (approvals and questions), and whether this phone is told: one place. + key: "notifications", + title: "Notifications", + description: "What your Bots ask you, and this phone's alerts", route: "/approvals", - sf: "checkmark.circle", + sf: "bell.badge", yourBots: false, }, { @@ -61,8 +62,14 @@ export const MORE_ITEMS: readonly MoreItem[] = [ }, ]; -/** How many wait in the approval inbox, as a row says it: nothing for none, and no more than two digits. */ +/** How many wait in Notifications, as a row says it: nothing for none, and no more than two digits. */ export function waitingLabel(count: number): string | undefined { if (count <= 0) return undefined; return count > 99 ? "99+" : String(count); } + +/** The same, as the menu says it under Notifications: "3 waiting". Nothing for none. */ +export function waitingLine(count: number): string | undefined { + const label = waitingLabel(count); + return label ? `${label} waiting` : undefined; +} diff --git a/mobile/src/more-menu.android.tsx b/mobile/src/more-menu.android.tsx new file mode 100644 index 0000000000..c55b3a4fa0 --- /dev/null +++ b/mobile/src/more-menu.android.tsx @@ -0,0 +1,6 @@ +import type { StyleProp, ViewStyle } from "react-native"; + +/** Android keeps More as a tab with its list (app/(tabs)/(more)/more.tsx): there is no menu to draw. */ +export function MoreMenu(_: { style: StyleProp }) { + return null; +} diff --git a/mobile/src/more-menu.tsx b/mobile/src/more-menu.tsx index a14e30e3ec..1697ba3f6e 100644 --- a/mobile/src/more-menu.tsx +++ b/mobile/src/more-menu.tsx @@ -1,226 +1,111 @@ /** - * The More menu: what has no tab of its own (./more-items.ts), in a small menu that rises from the tab bar's - * last button and opens the screen that is picked. On iOS, where a tab that only held a list of five links + * The More menu on iOS: what has no tab of its own (./more-items.ts), in the system's own menu, opened by the + * tab bar's last button. What is picked opens in the app's stack. A tab that only held a list of five links * cost a screen and a second tap. * - * It is the platform's chrome, so it is drawn as iOS draws a menu: its own glass where the phone has it (iOS 26) - * and its blur material before that, SF Symbols, and a row to a line. A tap outside puts it away. It grows from - * the corner it was called from, and only fades where the person asked for less motion. + * The menu is iOS's (`Menu`, drawn by SwiftUI): its glass, its type, SF Symbols, the way it opens and is put + * away, and what a screen reader says of it are the phone's, and stay the phone's as iOS changes. Nothing of it + * is drawn here but what it opens from: a clear button the size of the tab bar's own, laid over it + * (app/(tabs)/_layout.tsx), since a tab can't be told to open a menu. */ -import { BlurView } from "expo-blur"; -import { GlassView, isLiquidGlassAvailable } from "expo-glass-effect"; -import { router } from "expo-router"; -import { SymbolView } from "expo-symbols"; -import { type ReactNode, useCallback, useEffect, useState } from "react"; -import { Pressable, StyleSheet, View } from "react-native"; -import Animated, { - Easing, - runOnJS, - useAnimatedStyle, - useReducedMotion, - useSharedValue, - withTiming, -} from "react-native-reanimated"; -import { useSafeAreaInsets } from "react-native-safe-area-context"; -import { useCSSVariable } from "uniwind"; +import { + Button, + Host, + Label, + Menu, + Text as MenuText, + RNHostView, + Section, +} from "@expo/ui/swift-ui"; +import { router, usePathname } from "expo-router"; +import { type ComponentProps, useEffect, useState } from "react"; +import { + AppState, + type StyleProp, + StyleSheet, + View, + type ViewStyle, +} from "react-native"; import { loadApprovalInbox } from "./api"; -import { Text } from "./components"; -import { MORE_ITEMS, type MoreItem, waitingLabel } from "./more-items"; -import { useLoad } from "./use-load"; +import { MORE_ITEMS, type MoreItem, waitingLine } from "./more-items"; -/** How far the tab bar's top edge is above the home indicator's room, and the gap the menu leaves over it. */ -const TAB_BAR = 54; -const GAP = 10; -const WIDTH = 248; -const RADIUS = 26; -const OPEN_MS = 260; -const CLOSE_MS = 150; +/** One of iOS's own glyphs, as its menu takes them. */ +type Symbol = NonNullable["systemImage"]>; /** - * The menu's ground: the phone's own glass, and its blur where there is none. Either stands off the screen by a - * soft shadow under it, on a view of its own: one that clips to its corners would clip its shadow too. On a - * light page glass alone has no edge to see. + * How many approvals and questions wait on the person, for the line under Notifications. A menu doesn't say when + * it opens, so it is read when the tabs open, each time the person moves between screens, and when the app comes + * back to the front. A count that fails to read keeps the last one. */ -function Ground({ children }: { children: ReactNode }) { - // A hairline in the scheme's border: on a light page, glass over white has no edge of its own to see. - const edge = useCSSVariable("--color-border") as string | undefined; - return ( - - {isLiquidGlassAvailable() ? ( - - {children} - - ) : ( - - - {children} - - )} - - ); +function useWaiting(): number { + const [count, setCount] = useState(0); + const pathname = usePathname(); + // biome-ignore lint/correctness/useExhaustiveDependencies: pathname only says when to read again + useEffect(() => { + let current = true; + const read = () => + loadApprovalInbox().then( + (inbox) => { + if (current) + setCount( + inbox.requests.filter((request) => request.status === "pending") + .length + inbox.questions.length, + ); + }, + () => {}, + ); + void read(); + const appState = AppState.addEventListener("change", (state) => { + if (state === "active") void read(); + }); + return () => { + current = false; + appState.remove(); + }; + }, [pathname]); + return count; } -export function MoreMenu({ - open, - onClose, -}: { - open: boolean; - onClose: () => void; -}) { - const insets = useSafeAreaInsets(); - const reduceMotion = useReducedMotion(); - const [foreground, border] = useCSSVariable([ - "--color-foreground", - "--color-border", - ]) as (string | undefined)[]; - // Drawn until it has finished leaving, so closing is seen. - const [drawn, setDrawn] = useState(open); - const shown = useSharedValue(0); - useEffect(() => { - if (open) { - setDrawn(true); - shown.value = withTiming(1, { - duration: OPEN_MS, - easing: Easing.out(Easing.exp), - }); - return; - } - shown.value = withTiming( - 0, - { duration: CLOSE_MS, easing: Easing.in(Easing.quad) }, - (finished) => { - if (finished) runOnJS(setDrawn)(false); - }, +/** `style` places it over the tab bar's last button, at that button's size. */ +export function MoreMenu({ style }: { style: StyleProp }) { + const waiting = waitingLine(useWaiting()); + const { width, height } = StyleSheet.flatten(style) ?? {}; + const item = (item: MoreItem) => { + const open = () => router.push(item.route); + const line = item.key === "notifications" ? waiting : undefined; + return line ? ( + // A second line in a menu's button is drawn under its name, as the phone's own menus do. + + ) : ( + - ) : ( -