Skip to content

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

feat(mobile): adapt layouts for tablets (#3167)

Mohamed Bassem55247937f327
diff --git a/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsx b/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsx
index 52ea1393..0af35832 100644
--- a/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsx
@@ -13,6 +13,7 @@ import QueryPageState from "@/components/QueryPageState";
import ChevronRight from "@/components/ui/ChevronRight";
import { FAB } from "@/components/ui/FAB";
import { Text } from "@/components/ui/Text";
+import { READABLE_CONTENT_MAX_WIDTH } from "@/lib/responsive";
import { useColorScheme } from "@/lib/useColorScheme";
import { condProps } from "@/lib/utils";
import { useQuery, useQueryClient } from "@tanstack/react-query";
@@ -192,7 +193,10 @@ export default function Lists() {
contentContainerStyle={{
gap: 6,
paddingBottom: 20,
- marginHorizontal: 15,
+ paddingHorizontal: 15,
+ width: "100%",
+ maxWidth: READABLE_CONTENT_MAX_WIDTH,
+ alignSelf: "center",
marginBottom: 15,
}}
renderItem={(l) => (
diff --git a/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx b/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
index bb1a9a82..4adba8e5 100644
--- a/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
@@ -14,6 +14,7 @@ import EmptyState from "@/components/ui/EmptyState";
import { FAB } from "@/components/ui/FAB";
import { SearchInput } from "@/components/ui/SearchInput";
import { Text } from "@/components/ui/Text";
+import { READABLE_CONTENT_MAX_WIDTH } from "@/lib/responsive";
import { useQueryClient } from "@tanstack/react-query";
import { Plus, Tag } from "lucide-react-native";
@@ -94,6 +95,9 @@ export default function Tags() {
contentContainerStyle={{
gap: 6,
paddingBottom: 20,
+ width: "100%",
+ maxWidth: READABLE_CONTENT_MAX_WIDTH,
+ alignSelf: "center",
}}
renderItem={(item) => (
<View
diff --git a/apps/mobile/app/signin.tsx b/apps/mobile/app/signin.tsx
index 8c14495f..0503712f 100644
--- a/apps/mobile/app/signin.tsx
+++ b/apps/mobile/app/signin.tsx
@@ -155,6 +155,10 @@ export default function Signin() {
justifyContent: "center",
gap: 24,
paddingHorizontal: 20,
+ // Keep the form phone-sized on tablets.
+ width: "100%",
+ maxWidth: 480,
+ alignSelf: "center",
// Slight upward bias so the block doesn't sit dead centre.
paddingTop: 24,
paddingBottom: 88,
diff --git a/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsx b/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsx
index 9aafb582..93542388 100644
--- a/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsx
+++ b/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsx
@@ -121,7 +121,14 @@ export default function BookmarkHtmlHighlighterDom({
return (
<div
className={isDark ? "dark" : undefined}
- style={{ maxWidth: "100vw", overflowX: "hidden" }}
+ style={{
+ width: "100%",
+ maxWidth: "100vw",
+ overflowX: "hidden",
+ // The content is capped to a readable width on tablets, so paint its
+ // background edge to edge.
+ background: contentStyle?.background,
+ }}
>
<ScrollProgressTracker
onSavePosition={onSavePosition}
diff --git a/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsx b/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsx
index 9c12c389..06d07fa4 100644
--- a/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsx
+++ b/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsx
@@ -15,6 +15,7 @@ import {
useOfflineArticleContent,
} from "@/lib/offlineLibrary";
import { useReaderSettings, WEBVIEW_FONT_FAMILIES } from "@/lib/readerSettings";
+import { READABLE_CONTENT_MAX_WIDTH } from "@/lib/responsive";
import useAppSettings from "@/lib/settings";
import { useColorScheme } from "@/lib/useColorScheme";
import { useQuery } from "@tanstack/react-query";
@@ -195,6 +196,9 @@ export function BookmarkLinkReaderPreview({
color: isDark ? "#e5e7eb" : "#374151",
padding: "16px",
background: isDark ? "#000000" : "#ffffff",
+ // Keep lines at a readable length on tablets.
+ maxWidth: `${READABLE_CONTENT_MAX_WIDTH}px`,
+ margin: "0 auto",
};
return (
diff --git a/apps/mobile/components/bookmarks/BookmarkList.tsx b/apps/mobile/components/bookmarks/BookmarkList.tsx
index 12b2a35f..0c5325a2 100644
--- a/apps/mobile/components/bookmarks/BookmarkList.tsx
+++ b/apps/mobile/components/bookmarks/BookmarkList.tsx
@@ -2,6 +2,8 @@ import { useRef } from "react";
import { ActivityIndicator, Keyboard, View } from "react-native";
import Animated, { LinearTransition } from "react-native-reanimated";
import EmptyState from "@/components/ui/EmptyState";
+import { getGridColumns, useContainerWidth } from "@/lib/responsive";
+import useAppSettings from "@/lib/settings";
import { useScrollToTop } from "expo-router";
import { Bookmark } from "lucide-react-native";
@@ -9,6 +11,9 @@ import type { ZBookmark } from "@karakeep/shared/types/bookmarks";
import BookmarkCard from "./BookmarkCard";
+const HORIZONTAL_MARGIN = 15;
+const GAP = 12;
+
export default function BookmarkList({
bookmarks,
header,
@@ -26,41 +31,64 @@ export default function BookmarkList({
}) {
const flatListRef = useRef(null);
useScrollToTop(flatListRef);
+ const { settings } = useAppSettings();
+ const { width: containerWidth, onLayout } = useContainerWidth();
+ const { numColumns, columnWidth } = getGridColumns({
+ containerWidth,
+ horizontalInset: HORIZONTAL_MARGIN,
+ gap: GAP,
+ minColumnWidth: settings.bookmarkLayout === "list" ? 420 : 340,
+ });
return (
- <Animated.FlatList
- ref={flatListRef}
- itemLayoutAnimation={LinearTransition}
- contentInsetAdjustmentBehavior="automatic"
- ListHeaderComponent={header}
- contentContainerStyle={{
- gap: 12,
- marginHorizontal: 15,
- paddingBottom: 20,
- }}
- renderItem={(b) => <BookmarkCard bookmark={b.item} />}
- ListEmptyComponent={
- <EmptyState
- icon={Bookmark}
- title="No Bookmarks"
- subtitle="Your saved bookmarks will appear here"
- />
- }
- data={bookmarks}
- refreshing={isRefreshing}
- onRefresh={onRefresh}
- onScrollBeginDrag={Keyboard.dismiss}
- keyExtractor={(b) => b.id}
- onEndReached={fetchNextPage}
- ListFooterComponent={
- isFetchingNextPage ? (
- <View className="items-center">
- <ActivityIndicator />
- </View>
- ) : (
- <View />
- )
- }
- />
+ <View className="flex-1" onLayout={onLayout}>
+ <Animated.FlatList
+ ref={flatListRef}
+ // FlatList doesn't support changing numColumns on the fly.
+ key={numColumns}
+ numColumns={numColumns}
+ columnWrapperStyle={numColumns > 1 ? { gap: GAP } : undefined}
+ // Reanimated only supports item layout animations in single-column lists.
+ itemLayoutAnimation={numColumns > 1 ? undefined : LinearTransition}
+ contentInsetAdjustmentBehavior="automatic"
+ ListHeaderComponent={header}
+ contentContainerStyle={{
+ gap: GAP,
+ marginHorizontal: HORIZONTAL_MARGIN,
+ paddingBottom: 20,
+ }}
+ renderItem={(b) =>
+ numColumns > 1 ? (
+ <View style={{ width: columnWidth }}>
+ <BookmarkCard bookmark={b.item} />
+ </View>
+ ) : (
+ <BookmarkCard bookmark={b.item} />
+ )
+ }
+ ListEmptyComponent={
+ <EmptyState
+ icon={Bookmark}
+ title="No Bookmarks"
+ subtitle="Your saved bookmarks will appear here"
+ />
+ }
+ data={bookmarks}
+ refreshing={isRefreshing}
+ onRefresh={onRefresh}
+ onScrollBeginDrag={Keyboard.dismiss}
+ keyExtractor={(b) => b.id}
+ onEndReached={fetchNextPage}
+ ListFooterComponent={
+ isFetchingNextPage ? (
+ <View className="items-center">
+ <ActivityIndicator />
+ </View>
+ ) : (
+ <View />
+ )
+ }
+ />
+ </View>
);
}
diff --git a/apps/mobile/components/bookmarks/BookmarkTextView.tsx b/apps/mobile/components/bookmarks/BookmarkTextView.tsx
index 0f7a7291..788606e6 100644
--- a/apps/mobile/components/bookmarks/BookmarkTextView.tsx
+++ b/apps/mobile/components/bookmarks/BookmarkTextView.tsx
@@ -4,6 +4,7 @@ import BookmarkTextMarkdown from "@/components/bookmarks/BookmarkTextMarkdown";
import { Button } from "@/components/ui/Button";
import { Text } from "@/components/ui/Text";
import { useToast } from "@/components/ui/Toast";
+import { READABLE_CONTENT_MAX_WIDTH } from "@/lib/responsive";
import { useColorScheme } from "nativewind";
import { useUpdateBookmark } from "@karakeep/shared-react/hooks/bookmarks";
@@ -55,7 +56,10 @@ export default function BookmarkTextView({ bookmark }: BookmarkTextViewProps) {
if (isEditing) {
return (
- <View className="flex-1 p-4">
+ <View
+ className="w-full flex-1 self-center p-4"
+ style={{ maxWidth: READABLE_CONTENT_MAX_WIDTH }}
+ >
<View className="flex-row justify-end gap-2 px-4 py-2">
<Button
size="sm"
@@ -96,17 +100,22 @@ export default function BookmarkTextView({ bookmark }: BookmarkTextViewProps) {
}
return (
- <ScrollView className="m-4 flex-1 rounded-lg border border-border bg-card p-2">
- <Pressable onPress={() => setIsEditing(true)}>
- <View className="min-h-[200px] rounded-xl p-4">
- <BookmarkTextMarkdown text={content} />
- {content.trim() === "" && (
- <Text className="italic text-muted-foreground">
- Tap to add text...
- </Text>
- )}
- </View>
- </Pressable>
- </ScrollView>
+ <View
+ className="w-full flex-1 self-center"
+ style={{ maxWidth: READABLE_CONTENT_MAX_WIDTH }}
+ >
+ <ScrollView className="m-4 flex-1 rounded-lg border border-border bg-card p-2">
+ <Pressable onPress={() => setIsEditing(true)}>
+ <View className="min-h-[200px] rounded-xl p-4">
+ <BookmarkTextMarkdown text={content} />
+ {content.trim() === "" && (
+ <Text className="italic text-muted-foreground">
+ Tap to add text...
+ </Text>
+ )}
+ </View>
+ </Pressable>
+ </ScrollView>
+ </View>
);
}
diff --git a/apps/mobile/components/highlights/HighlightList.tsx b/apps/mobile/components/highlights/HighlightList.tsx
index dd7e6570..9894409f 100644
--- a/apps/mobile/components/highlights/HighlightList.tsx
+++ b/apps/mobile/components/highlights/HighlightList.tsx
@@ -2,6 +2,7 @@ import { useRef } from "react";
import { ActivityIndicator, Keyboard, View } from "react-native";
import Animated, { LinearTransition } from "react-native-reanimated";
import EmptyState from "@/components/ui/EmptyState";
+import { getGridColumns, useContainerWidth } from "@/lib/responsive";
import { useScrollToTop } from "expo-router";
import { Highlighter } from "lucide-react-native";
@@ -9,6 +10,9 @@ import type { ZHighlight } from "@karakeep/shared/types/highlights";
import HighlightCard from "./HighlightCard";
+const HORIZONTAL_MARGIN = 15;
+const GAP = 15;
+
export default function HighlightList({
highlights,
header,
@@ -26,41 +30,63 @@ export default function HighlightList({
}) {
const flatListRef = useRef(null);
useScrollToTop(flatListRef);
+ const { width: containerWidth, onLayout } = useContainerWidth();
+ const { numColumns, columnWidth } = getGridColumns({
+ containerWidth,
+ horizontalInset: HORIZONTAL_MARGIN,
+ gap: GAP,
+ minColumnWidth: 340,
+ });
return (
- <Animated.FlatList
- ref={flatListRef}
- itemLayoutAnimation={LinearTransition}
- contentInsetAdjustmentBehavior="automatic"
- ListHeaderComponent={header}
- contentContainerStyle={{
- gap: 15,
- marginHorizontal: 15,
- marginBottom: 15,
- }}
- renderItem={(h) => <HighlightCard highlight={h.item} />}
- ListEmptyComponent={
- <EmptyState
- icon={Highlighter}
- title="No Highlights"
- subtitle="Highlights you create will appear here"
- />
- }
- data={highlights}
- refreshing={isRefreshing}
- onRefresh={onRefresh}
- onScrollBeginDrag={Keyboard.dismiss}
- keyExtractor={(h) => h.id}
- onEndReached={fetchNextPage}
- ListFooterComponent={
- isFetchingNextPage ? (
- <View className="items-center">
- <ActivityIndicator />
- </View>
- ) : (
- <View />
- )
- }
- />
+ <View className="flex-1" onLayout={onLayout}>
+ <Animated.FlatList
+ ref={flatListRef}
+ // FlatList doesn't support changing numColumns on the fly.
+ key={numColumns}
+ numColumns={numColumns}
+ columnWrapperStyle={numColumns > 1 ? { gap: GAP } : undefined}
+ // Reanimated only supports item layout animations in single-column lists.
+ itemLayoutAnimation={numColumns > 1 ? undefined : LinearTransition}
+ contentInsetAdjustmentBehavior="automatic"
+ ListHeaderComponent={header}
+ contentContainerStyle={{
+ gap: GAP,
+ marginHorizontal: HORIZONTAL_MARGIN,
+ marginBottom: 15,
+ }}
+ renderItem={(h) =>
+ numColumns > 1 ? (
+ <View style={{ width: columnWidth }}>
+ <HighlightCard highlight={h.item} />
+ </View>
+ ) : (
+ <HighlightCard highlight={h.item} />
+ )
+ }
+ ListEmptyComponent={
+ <EmptyState
+ icon={Highlighter}
+ title="No Highlights"
+ subtitle="Highlights you create will appear here"
+ />
+ }
+ data={highlights}
+ refreshing={isRefreshing}
+ onRefresh={onRefresh}
+ onScrollBeginDrag={Keyboard.dismiss}
+ keyExtractor={(h) => h.id}
+ onEndReached={fetchNextPage}
+ ListFooterComponent={
+ isFetchingNextPage ? (
+ <View className="items-center">
+ <ActivityIndicator />
+ </View>
+ ) : (
+ <View />
+ )
+ }
+ />
+ </View>
);
}
diff --git a/apps/mobile/components/search/BookmarkSearchResults.tsx b/apps/mobile/components/search/BookmarkSearchResults.tsx
index c5f6289a..89552a09 100644
--- a/apps/mobile/components/search/BookmarkSearchResults.tsx
+++ b/apps/mobile/components/search/BookmarkSearchResults.tsx
@@ -2,6 +2,7 @@ import { FlatList, Pressable, View } from "react-native";
import BookmarkList from "@/components/bookmarks/BookmarkList";
import QueryPageState from "@/components/QueryPageState";
import { Text } from "@/components/ui/Text";
+import { READABLE_CONTENT_MAX_WIDTH } from "@/lib/responsive";
import type { BookmarkSearchState } from "@/lib/useBookmarkSearchState";
@@ -45,6 +46,11 @@ export default function BookmarkSearchResults({
return (
<FlatList
contentInsetAdjustmentBehavior="automatic"
+ contentContainerStyle={{
+ width: "100%",
+ maxWidth: READABLE_CONTENT_MAX_WIDTH,
+ alignSelf: "center",
+ }}
data={filteredHistory}
renderItem={renderHistoryItem}
keyExtractor={(item, index) => `${item}-${index}`}
diff --git a/apps/mobile/lib/responsive.ts b/apps/mobile/lib/responsive.ts
new file mode 100644
index 00000000..eff72a53
--- /dev/null
+++ b/apps/mobile/lib/responsive.ts
@@ -0,0 +1,58 @@
+import type { LayoutChangeEvent } from "react-native";
+import { useState } from "react";
+import { useWindowDimensions } from "react-native";
+
+// Max width for single-column content (lists, forms, reading) so that rows
+// and lines don't stretch across the whole screen on tablets.
+export const READABLE_CONTENT_MAX_WIDTH = 720;
+
+/**
+ * Tracks the width of a container through its `onLayout`. Until the first
+ * layout, it falls back to the window width, which is right for full-screen
+ * views. Measuring matters for views shown in iPad form sheets or split view,
+ * where the container is narrower than the window.
+ *
+ * Put `onLayout` on a plain View wrapping a list, not on the FlatList itself:
+ * FlatList also forwards its `ListEmptyComponent`'s layout to `onLayout`,
+ * which would report the empty state's width instead of the list's.
+ */
+export function useContainerWidth() {
+ const { width: windowWidth } = useWindowDimensions();
+ const [measuredWidth, setMeasuredWidth] = useState<number | null>(null);
+
+ const onLayout = (e: LayoutChangeEvent) => {
+ setMeasuredWidth(e.nativeEvent.layout.width);
+ };
+
+ return { width: measuredWidth ?? windowWidth, onLayout };
+}
+
+/**
+ * Splits the container (minus `horizontalInset` on each side) into as many
+ * columns as fit without any of them getting narrower than `minColumnWidth`.
+ * Phones get a single column; tablets get a grid.
+ */
+export function getGridColumns({
+ containerWidth,
+ horizontalInset,
+ gap,
+ minColumnWidth,
+ maxColumns = 4,
+}: {
+ containerWidth: number;
+ horizontalInset: number;
+ gap: number;
+ minColumnWidth: number;
+ maxColumns?: number;
+}) {
+ const availableWidth = containerWidth - horizontalInset * 2;
+ const numColumns = Math.max(
+ 1,
+ Math.min(
+ maxColumns,
+ Math.floor((availableWidth + gap) / (minColumnWidth + gap)),
+ ),
+ );
+ const columnWidth = (availableWidth - gap * (numColumns - 1)) / numColumns;
+ return { numColumns, columnWidth };
+}