Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

feat(mobile): add different mobile layouts to the mobile app (#2837)

Mohamed Bassembc29d61dbda9
diff --git a/apps/mobile/app/dashboard/(tabs)/(home)/_layout.tsx b/apps/mobile/app/dashboard/(tabs)/(home)/_layout.tsx
index 44a2d8f3..18fa50a2 100644
--- a/apps/mobile/app/dashboard/(tabs)/(home)/_layout.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/(home)/_layout.tsx
@@ -1,6 +1,7 @@
import { Stack } from "expo-router/stack";
import { tabScreenOptions } from "@/lib/tabScreenOptions";
import { Platform } from "react-native";
+import BookmarkListHeader from "@/components/bookmarks/BookmarkListHeader";
import { ProfileAvatarButton } from "@/components/settings/ProfileAvatarButton";
export default function Layout() {
@@ -10,6 +11,7 @@ export default function Layout() {
...tabScreenOptions,
...Platform.select({
ios: {
+ headerLeft: () => <BookmarkListHeader />,
headerRight: () => <ProfileAvatarButton />,
},
android: {
diff --git a/apps/mobile/app/dashboard/(tabs)/(home)/index.tsx b/apps/mobile/app/dashboard/(tabs)/(home)/index.tsx
index 8fece487..12ee5f90 100644
--- a/apps/mobile/app/dashboard/(tabs)/(home)/index.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/(home)/index.tsx
@@ -3,6 +3,7 @@ import { Platform, PlatformColor, View } from "react-native";
import * as Haptics from "expo-haptics";
import * as ImagePicker from "expo-image-picker";
import { router } from "expo-router";
+import BookmarkListHeader from "@/components/bookmarks/BookmarkListHeader";
import UpdatingBookmarkList from "@/components/bookmarks/UpdatingBookmarkList";
import InlineSearch from "@/components/search/InlineSearch";
import { ProfileAvatarButton } from "@/components/settings/ProfileAvatarButton";
@@ -121,6 +122,7 @@ export default function Home() {
label="Search bookmarks..."
onPress={() => setSearchActive(true)}
rightElement={<ProfileAvatarButton />}
+ trailingElement={<BookmarkListHeader />}
/>
)}
<UpdatingBookmarkList query={{ archived: false }} />
diff --git a/apps/mobile/app/dashboard/lists/[slug]/index.tsx b/apps/mobile/app/dashboard/lists/[slug]/index.tsx
index 88ab1a0d..0ddad6eb 100644
--- a/apps/mobile/app/dashboard/lists/[slug]/index.tsx
+++ b/apps/mobile/app/dashboard/lists/[slug]/index.tsx
@@ -1,6 +1,7 @@
import { Alert, Platform, View } from "react-native";
import * as Haptics from "expo-haptics";
import { router, Stack, useLocalSearchParams } from "expo-router";
+import { useBookmarkListLayoutMenu } from "@/components/bookmarks/BookmarkListHeader";
import UpdatingBookmarkList from "@/components/bookmarks/UpdatingBookmarkList";
import FullPageError from "@/components/FullPageError";
import FullPageSpinner from "@/components/ui/FullPageSpinner";
@@ -64,6 +65,7 @@ function ListActionsMenu({
const api = useTRPC();
const { colors } = useColorScheme();
const { menuIconColor, destructiveMenuIconColor } = useMenuIconColors();
+ const { layoutActions, handleLayoutAction } = useBookmarkListLayoutMenu();
const { mutate: deleteList } = useMutation(
api.lists.delete.mutationOptions({
onSuccess: () => {
@@ -116,6 +118,7 @@ function ListActionsMenu({
return (
<MenuView
actions={[
+ ...layoutActions,
{
id: "edit",
title: "Edit List",
@@ -159,6 +162,10 @@ function ListActionsMenu({
},
]}
onPressAction={({ nativeEvent }) => {
+ if (handleLayoutAction(nativeEvent.event)) {
+ return;
+ }
+
if (nativeEvent.event === "delete_list") {
handleDelete();
} else if (nativeEvent.event === "leave") {
diff --git a/apps/mobile/app/dashboard/tags/[slug].tsx b/apps/mobile/app/dashboard/tags/[slug].tsx
index 32cffaaa..4906d058 100644
--- a/apps/mobile/app/dashboard/tags/[slug].tsx
+++ b/apps/mobile/app/dashboard/tags/[slug].tsx
@@ -1,4 +1,5 @@
import { Stack, useLocalSearchParams } from "expo-router";
+import BookmarkListHeader from "@/components/bookmarks/BookmarkListHeader";
import UpdatingBookmarkList from "@/components/bookmarks/UpdatingBookmarkList";
import FullPageError from "@/components/FullPageError";
import FullPageSpinner from "@/components/ui/FullPageSpinner";
@@ -27,6 +28,7 @@ export default function TagView() {
options={{
headerTitle: tag?.name ?? "",
headerBackTitle: "Back",
+ headerRight: () => <BookmarkListHeader />,
}}
/>
{error ? (
diff --git a/apps/mobile/components/bookmarks/BookmarkCard.tsx b/apps/mobile/components/bookmarks/BookmarkCard.tsx
index 0742e378..510acd75 100644
--- a/apps/mobile/components/bookmarks/BookmarkCard.tsx
+++ b/apps/mobile/components/bookmarks/BookmarkCard.tsx
@@ -1,6 +1,7 @@
import { Text } from "@/components/ui/Text";
import useAppSettings from "@/lib/settings";
import { buildApiHeaders } from "@/lib/utils";
+import { useWhoAmI } from "@karakeep/shared-react/hooks/users";
import { useQuery } from "@tanstack/react-query";
import { Image } from "expo-image";
import { useRouter } from "expo-router";
@@ -21,7 +22,6 @@ import {
BookmarkCardContainer,
BookmarkCardContext,
} from "./card/BookmarkCard";
-import { useWhoAmI } from "@karakeep/shared-react/hooks/users";
import TagList from "./card/TagList";
import { Divider } from "../ui/Divider";
import ActionBar from "./card/ActionBar";
@@ -78,8 +78,34 @@ function useLinkCardContext({
);
}
+ const compactMedia = (
+ <View className="h-28 w-24 overflow-hidden rounded-lg bg-muted">
+ <Image
+ source={
+ imageUrl
+ ? imageUrl.localAsset
+ ? {
+ uri: `${settings.address}${imageUrl.url}`,
+ headers: buildApiHeaders(
+ settings.apiKey,
+ settings.customHeaders,
+ ),
+ }
+ : {
+ uri: imageUrl.url,
+ }
+ : // oxlint-disable-next-line no-require-imports
+ require("@/assets/blur.jpeg")
+ }
+ style={{ width: "100%", height: "100%" }}
+ contentFit="cover"
+ />
+ </View>
+ );
+
return {
media: contentComp,
+ compactMedia,
title: bookmark.title ?? bookmark.content.title ?? parsedUrl.host,
footerExtras: (
<Text className="my-auto shrink" numberOfLines={1}>
@@ -105,6 +131,11 @@ function useTextCardContext({
<BookmarkTextMarkdown text={content} />
</View>
),
+ compactBody: (
+ <Text className="text-sm leading-5 text-foreground" numberOfLines={3}>
+ {content}
+ </Text>
+ ),
title: bookmark.title ?? undefined,
};
}
@@ -130,10 +161,87 @@ function useAssetCardContext({
className="h-56 min-h-56 w-full"
/>
),
+ compactMedia: (
+ <BookmarkAssetImage
+ assetId={assetImage}
+ className="h-28 w-24 overflow-hidden rounded-lg bg-muted"
+ />
+ ),
title: title ?? undefined,
};
}
+function CardLayout({ ctx }: { ctx: BookmarkCardContext }) {
+ return (
+ <BookmarkCardContainer.Provider value={ctx}>
+ <BookmarkCardContainer.Root>
+ <View className="flex gap-2">
+ <BookmarkCardContainer.Media />
+ <View className="flex gap-2 p-2">
+ <BookmarkCardContainer.Title />
+ <BookmarkCardContainer.Body />
+ <BookmarkCardContainer.NoteSection />
+ <TagList bookmark={ctx.bookmark} />
+ <Divider orientation="vertical" className="mt-2 h-0.5 w-full" />
+ <View className="mt-2 flex flex-row justify-between px-2 pb-2">
+ <BookmarkCardContainer.FooterExtras />
+ <ActionBar bookmark={ctx.bookmark} />
+ </View>
+ </View>
+ </View>
+ </BookmarkCardContainer.Root>
+ </BookmarkCardContainer.Provider>
+ );
+}
+
+function ListLayout({ ctx }: { ctx: BookmarkCardContext }) {
+ const hasCompactMedia = Boolean(ctx.compactMedia ?? ctx.media);
+
+ return (
+ <BookmarkCardContainer.Provider value={ctx}>
+ <BookmarkCardContainer.Root>
+ <View className={hasCompactMedia ? "flex-row p-3" : "flex gap-2 p-3"}>
+ {hasCompactMedia && (
+ <View className="justify-start">
+ <BookmarkCardContainer.CompactMedia />
+ </View>
+ )}
+ <View
+ className={
+ hasCompactMedia
+ ? "ml-3 min-h-28 flex-1 gap-1.5 overflow-hidden"
+ : "gap-2"
+ }
+ >
+ <View className="flex-row items-start gap-2">
+ <View className="min-w-0 flex-1 gap-0.5">
+ {ctx.title && (
+ <Text
+ className="text-base font-semibold leading-5 text-foreground"
+ numberOfLines={2}
+ onPress={ctx.titleOnPress}
+ >
+ {ctx.title}
+ </Text>
+ )}
+ <BookmarkCardContainer.FooterExtras />
+ </View>
+ </View>
+ <BookmarkCardContainer.CompactBody />
+ <BookmarkCardContainer.NoteSection />
+ <View className="h-7 overflow-hidden">
+ <TagList bookmark={ctx.bookmark} />
+ </View>
+ <View className="flex-row justify-end pt-0.5">
+ <ActionBar bookmark={ctx.bookmark} compact />
+ </View>
+ </View>
+ </View>
+ </BookmarkCardContainer.Root>
+ </BookmarkCardContainer.Provider>
+ );
+}
+
export default function BookmarkCard({
bookmark: initialData,
}: {
@@ -187,10 +295,11 @@ export default function BookmarkCard({
const textContext = useTextCardContext({ bookmark });
const assetContext = useAssetCardContext({ bookmark });
const ctx = linkContext ?? textContext ?? assetContext;
+ const Layout = settings.bookmarkLayout === "list" ? ListLayout : CardLayout;
return (
- <BookmarkCardContainer.Provider
- value={{
+ <Layout
+ ctx={{
...ctx,
isOwner: currentUser?.id === bookmark.userId,
bookmark,
@@ -198,23 +307,6 @@ export default function BookmarkCard({
bodyOnPress: () => onOpenBookmark(bookmark),
titleOnPress: () => onOpenBookmark(bookmark),
}}
- >
- <BookmarkCardContainer.Root>
- <View className="flex gap-2">
- <BookmarkCardContainer.Media />
- <View className="flex gap-2 p-2">
- <BookmarkCardContainer.Title />
- <BookmarkCardContainer.Body />
- <BookmarkCardContainer.NoteSection />
- <TagList bookmark={bookmark} />
- <Divider orientation="vertical" className="mt-2 h-0.5 w-full" />
- <View className="mt-2 flex flex-row justify-between px-2 pb-2">
- <BookmarkCardContainer.FooterExtras />
- <ActionBar bookmark={bookmark} />
- </View>
- </View>
- </View>
- </BookmarkCardContainer.Root>
- </BookmarkCardContainer.Provider>
+ />
);
}
diff --git a/apps/mobile/components/bookmarks/BookmarkList.tsx b/apps/mobile/components/bookmarks/BookmarkList.tsx
index 98e15388..5640e44b 100644
--- a/apps/mobile/components/bookmarks/BookmarkList.tsx
+++ b/apps/mobile/components/bookmarks/BookmarkList.tsx
@@ -34,9 +34,9 @@ export default function BookmarkList({
contentInsetAdjustmentBehavior="automatic"
ListHeaderComponent={header}
contentContainerStyle={{
- gap: 15,
+ gap: 12,
marginHorizontal: 15,
- marginBottom: 15,
+ paddingBottom: 160,
}}
renderItem={(b) => <BookmarkCard bookmark={b.item} />}
ListEmptyComponent={
diff --git a/apps/mobile/components/bookmarks/BookmarkListHeader.tsx b/apps/mobile/components/bookmarks/BookmarkListHeader.tsx
new file mode 100644
index 00000000..0feba583
--- /dev/null
+++ b/apps/mobile/components/bookmarks/BookmarkListHeader.tsx
@@ -0,0 +1,75 @@
+import { Platform, View } from "react-native";
+import { MenuAction, MenuView } from "@react-native-menu/menu";
+import { MoreHorizontal } from "lucide-react-native";
+
+import useAppSettings from "@/lib/settings";
+import { useMenuIconColors } from "@/lib/useMenuIconColors";
+
+function useBookmarkListLayoutMenu(): {
+ layoutActions: MenuAction[];
+ handleLayoutAction: (event: string) => boolean;
+ menuIconColor: string;
+} {
+ const { settings, setSettings } = useAppSettings();
+ const { menuIconColor } = useMenuIconColors();
+
+ const layoutActions: MenuAction[] = [
+ {
+ id: "layout",
+ title: "Layout",
+ image: Platform.select({ ios: "rectangle.grid.1x2" }),
+ imageColor: Platform.select({ ios: menuIconColor }),
+ subactions: [
+ {
+ id: "card",
+ title: "Card",
+ state: settings.bookmarkLayout === "card" ? "on" : "off",
+ image: Platform.select({ ios: "rectangle.grid.1x2" }),
+ imageColor: Platform.select({ ios: menuIconColor }),
+ },
+ {
+ id: "list",
+ title: "List",
+ state: settings.bookmarkLayout === "list" ? "on" : "off",
+ image: Platform.select({ ios: "list.bullet" }),
+ imageColor: Platform.select({ ios: menuIconColor }),
+ },
+ ],
+ },
+ ];
+
+ const handleLayoutAction = (event: string) => {
+ if (event !== "card" && event !== "list") {
+ return false;
+ }
+
+ setSettings({
+ ...settings,
+ bookmarkLayout: event,
+ });
+ return true;
+ };
+
+ return { layoutActions, handleLayoutAction, menuIconColor };
+}
+
+export default function BookmarkListHeader() {
+ const { layoutActions, handleLayoutAction, menuIconColor } =
+ useBookmarkListLayoutMenu();
+
+ return (
+ <MenuView
+ onPressAction={({ nativeEvent }) => {
+ handleLayoutAction(nativeEvent.event);
+ }}
+ actions={layoutActions}
+ shouldOpenOnLongPress={false}
+ >
+ <View className="h-9 w-9 items-center justify-center rounded-full bg-card">
+ <MoreHorizontal size={20} color={menuIconColor} />
+ </View>
+ </MenuView>
+ );
+}
+
+export { useBookmarkListLayoutMenu };
diff --git a/apps/mobile/components/bookmarks/card/ActionBar.tsx b/apps/mobile/components/bookmarks/card/ActionBar.tsx
index 2d4f02be..ef3fb602 100644
--- a/apps/mobile/components/bookmarks/card/ActionBar.tsx
+++ b/apps/mobile/components/bookmarks/card/ActionBar.tsx
@@ -1,4 +1,5 @@
import useAppSettings from "@/lib/settings";
+import { shareBookmark } from "@/lib/shareBookmark";
import { useMenuIconColors } from "@/lib/useMenuIconColors";
import { MenuView } from "@react-native-menu/menu";
import * as Haptics from "expo-haptics";
@@ -20,9 +21,14 @@ import { useWhoAmI } from "@karakeep/shared-react/hooks/users";
import type { ZBookmark } from "@karakeep/shared/types/bookmarks";
import { useToast } from "../../ui/Toast";
-import { shareBookmark } from "@/lib/shareBookmark";
-export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
+export default function ActionBar({
+ bookmark,
+ compact = false,
+}: {
+ bookmark: ZBookmark;
+ compact?: boolean;
+}) {
const { toast } = useToast();
const { settings } = useAppSettings();
const { data: currentUser } = useWhoAmI();
@@ -142,7 +148,7 @@ export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
}
return (
- <View className="flex flex-row gap-4">
+ <View className={compact ? "flex flex-row gap-3" : "flex flex-row gap-4"}>
{(isArchivePending || isDeletionPending) && <ActivityIndicator />}
{isOwner && (
<Pressable
@@ -155,9 +161,9 @@ export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
}}
>
{(variables ? variables.favourited : bookmark.favourited) ? (
- <Star fill="#ebb434" color="#ebb434" />
+ <Star fill="#ebb434" color="#ebb434" size={compact ? 20 : 24} />
) : (
- <Star color="gray" />
+ <Star color="gray" size={compact ? 20 : 24} />
)}
</Pressable>
)}
@@ -168,7 +174,7 @@ export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
handleShare();
}}
>
- <ShareIcon color="gray" />
+ <ShareIcon color="gray" size={compact ? 20 : 24} />
</Pressable>
{isOwner && menuActions.length > 0 && (
@@ -193,7 +199,11 @@ export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
actions={menuActions}
shouldOpenOnLongPress={false}
>
- <Ellipsis onPress={() => Haptics.selectionAsync()} color="gray" />
+ <Ellipsis
+ onPress={() => Haptics.selectionAsync()}
+ color="gray"
+ size={compact ? 20 : 24}
+ />
</MenuView>
)}
</View>
diff --git a/apps/mobile/components/bookmarks/card/BookmarkCard.tsx b/apps/mobile/components/bookmarks/card/BookmarkCard.tsx
index aea86ae6..efd30d0d 100644
--- a/apps/mobile/components/bookmarks/card/BookmarkCard.tsx
+++ b/apps/mobile/components/bookmarks/card/BookmarkCard.tsx
@@ -1,15 +1,18 @@
+import { Text } from "@/components/ui/Text";
import useAppSettings from "@/lib/settings";
-import { ZBookmark } from "@karakeep/shared/types/bookmarks";
+import type { ZBookmark } from "@karakeep/shared/types/bookmarks";
import { createContext, useContext } from "react";
-import { NotePreview } from "../NotePreview";
import { Pressable, View } from "react-native";
-import { Text } from "@/components/ui/Text";
+
+import { NotePreview } from "../NotePreview";
export interface BookmarkCardContext {
bookmark: ZBookmark;
title?: string;
media?: React.ReactNode;
+ compactMedia?: React.ReactNode;
body?: React.ReactNode;
+ compactBody?: React.ReactNode;
footerExtras?: React.ReactNode;
isOwner?: boolean;
mediaOnPress?: () => void;
@@ -72,6 +75,19 @@ function Media() {
return <PressableSlot onPress={mediaOnPress}>{media}</PressableSlot>;
}
+function CompactMedia() {
+ const ctx = useContext(BookmarkCardContext);
+ if (!ctx) {
+ return null;
+ }
+ const media = ctx.compactMedia ?? ctx.media;
+ if (!media) {
+ return null;
+ }
+
+ return <PressableSlot onPress={ctx.mediaOnPress}>{media}</PressableSlot>;
+}
+
function Body() {
const ctx = useContext(BookmarkCardContext);
if (!ctx) {
@@ -85,6 +101,19 @@ function Body() {
return <PressableSlot onPress={bodyOnPress}>{body}</PressableSlot>;
}
+function CompactBody() {
+ const ctx = useContext(BookmarkCardContext);
+ if (!ctx) {
+ return null;
+ }
+ const body = ctx.compactBody ?? ctx.body;
+ if (!body) {
+ return null;
+ }
+
+ return <PressableSlot onPress={ctx.bodyOnPress}>{body}</PressableSlot>;
+}
+
function Title() {
const ctx = useContext(BookmarkCardContext);
if (!ctx) {
@@ -123,7 +152,9 @@ const BookmarkCardContainer = {
NoteSection,
FooterExtras,
Media,
+ CompactMedia,
Body,
+ CompactBody,
Title,
Root,
};
diff --git a/apps/mobile/components/ui/AndroidSearchBar.tsx b/apps/mobile/components/ui/AndroidSearchBar.tsx
index 1848cbf1..1d8863ae 100644
--- a/apps/mobile/components/ui/AndroidSearchBar.tsx
+++ b/apps/mobile/components/ui/AndroidSearchBar.tsx
@@ -9,10 +9,12 @@ export default function AndroidSearchBar({
label,
onPress,
rightElement,
+ trailingElement,
}: {
label: string;
onPress: () => void;
rightElement?: React.ReactNode;
+ trailingElement?: React.ReactNode;
}) {
const insets = useSafeAreaInsets();
const isFocused = useIsFocused();
@@ -26,20 +28,25 @@ export default function AndroidSearchBar({
}}
className="bg-background px-4 pb-2 pt-2"
>
- <Pressable
- className="flex flex-row items-center gap-4 rounded-full border-input bg-card px-4 py-2"
- style={{ minHeight: 56 }}
- onPress={onPress}
- >
- <TailwindResolver
- className="text-muted"
- comp={(styles) => (
- <Search size={24} color={styles?.color?.toString()} />
- )}
- />
- <Text className="flex-1 text-[17px] text-muted">{label}</Text>
- {rightElement}
- </Pressable>
+ <View className="flex-row items-center gap-2">
+ <Pressable
+ className="min-w-0 flex-1 flex-row items-center gap-4 rounded-full border-input bg-card px-4 py-2"
+ style={{ minHeight: 56 }}
+ onPress={onPress}
+ >
+ <TailwindResolver
+ className="text-muted"
+ comp={(styles) => (
+ <Search size={24} color={styles?.color?.toString()} />
+ )}
+ />
+ <Text className="flex-1 text-[17px] text-muted" numberOfLines={1}>
+ {label}
+ </Text>
+ {rightElement}
+ </Pressable>
+ {trailingElement}
+ </View>
</View>
);
}
diff --git a/apps/mobile/lib/settings.ts b/apps/mobile/lib/settings.ts
index 1252e5e7..c7120475 100644
--- a/apps/mobile/lib/settings.ts
+++ b/apps/mobile/lib/settings.ts
@@ -44,6 +44,7 @@ const zSettingsSchema = z.object({
.enum(["reader", "browser", "externalBrowser"])
.optional()
.default("reader"),
+ bookmarkLayout: z.enum(["card", "list"]).optional().default("card"),
showNotes: z.boolean().optional().default(false),
keepScreenOnWhileReading: z.boolean().optional().default(false),
customHeaders: z.record(z.string(), z.string()).optional().default({}),
@@ -78,6 +79,7 @@ const useSettings = create<AppSettingsState>((set, get) => ({
imageQuality: 0.2,
theme: "system",
defaultBookmarkView: "reader",
+ bookmarkLayout: "card",
showNotes: false,
keepScreenOnWhileReading: false,
customHeaders: {},