Skip to content

Commit

Permalink
mobile: Add dark mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Apr 17, 2024
1 parent bb44ebc commit c46482c
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 56 deletions.
27 changes: 21 additions & 6 deletions apps/mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
"version": "1.3.2",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"userInterfaceStyle": "automatic",
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "app.hoarder.hoardermobile",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff",
"dark": {
"image": "./assets/splash-white.png",
"resizeMode": "contain",
"backgroundColor": "#000000"
}
},
"config": {
"usesNonExemptEncryption": false
},
Expand All @@ -31,6 +36,16 @@
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#000000"
},
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff",
"dark": {
"image": "./assets/splash-white.png",
"resizeMode": "contain",
"backgroundColor": "#000000"
}
},
"package": "app.hoarder.hoardermobile",
"versionCode": 2
},
Expand Down
16 changes: 13 additions & 3 deletions apps/mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import { useRouter } from "expo-router";
import { Stack } from "expo-router/stack";
import { ShareIntentProvider, useShareIntent } from "expo-share-intent";
import { StatusBar } from "expo-status-bar";
import { StyledStack } from "@/components/navigation/stack";
import { Providers } from "@/lib/providers";
import { cn } from "@/lib/utils";
import { useColorScheme } from "nativewind";

export default function RootLayout() {
const router = useRouter();
const { hasShareIntent } = useShareIntent();
const { colorScheme } = useColorScheme();

useEffect(() => {
if (hasShareIntent) {
Expand All @@ -24,8 +28,14 @@ export default function RootLayout() {
return (
<ShareIntentProvider>
<Providers>
<View className="w-full flex-1 bg-background">
<Stack
<View
className={cn(
"w-full flex-1 bg-gray-100 text-foreground dark:bg-background",
colorScheme == "dark" ? "dark" : "light",
)}
>
<StyledStack
contentClassName="bg-gray-100 dark:bg-background"
screenOptions={{
headerShown: false,
}}
Expand All @@ -37,7 +47,7 @@ export default function RootLayout() {
presentation: "modal",
}}
/>
</Stack>
</StyledStack>
<StatusBar style="auto" />
</View>
</Providers>
Expand Down
16 changes: 6 additions & 10 deletions apps/mobile/app/dashboard/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import React, { useEffect } from "react";
import { Platform } from "react-native";
import * as NavigationBar from "expo-navigation-bar";
import React from "react";
import { Tabs } from "expo-router";
import { StyledTabs } from "@/components/navigation/tabs";
import { ClipboardList, Home, Search, Settings } from "lucide-react-native";

export default function TabLayout() {
useEffect(() => {
if (Platform.OS == "android") {
NavigationBar.setBackgroundColorAsync("white");
}
}, []);
return (
<Tabs
<StyledTabs
tabBarClassName="bg-gray-100 dark:bg-background pt-3"
sceneContainerClassName="bg-gray-100 dark:bg-background"
screenOptions={{
headerShown: false,
}}
Expand Down Expand Up @@ -44,6 +40,6 @@ export default function TabLayout() {
tabBarIcon: ({ color }) => <Settings color={color} />,
}}
/>
</Tabs>
</StyledTabs>
);
}
4 changes: 2 additions & 2 deletions apps/mobile/app/dashboard/(tabs)/lists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export default function Lists() {
}}
renderItem={(l) => (
<Link asChild key={l.item.id} href={l.item.href}>
<Pressable className="mx-2 flex flex-row justify-between rounded-xl border border-gray-100 bg-white px-4 py-2">
<Text className="text-lg">
<Pressable className="mx-2 flex flex-row justify-between rounded-xl border border-input bg-white px-4 py-2 dark:bg-accent">
<Text className="text-lg text-accent-foreground">
{l.item.logo} {l.item.name}
</Text>
<ChevronRight color="rgb(0, 122, 255)" />
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/app/dashboard/(tabs)/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function Search() {
<PageTitle title="Search" />
<Input
placeholder="Search"
className="mx-4 bg-white"
className="mx-4"
value={search}
onChangeText={setSearch}
autoFocus
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/app/dashboard/(tabs)/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default function Dashboard() {
<CustomSafeAreaView>
<PageTitle title="Settings" />
<View className="flex h-full w-full items-center gap-4 px-4 py-2">
<View className="w-full rounded-lg bg-white px-4 py-2">
<Text className="text-lg">
<View className="w-full rounded-lg bg-white px-4 py-2 dark:bg-accent">
<Text className="text-lg text-accent-foreground">
{isLoading ? "Loading ..." : data?.email}
</Text>
</View>
Expand Down
8 changes: 6 additions & 2 deletions apps/mobile/app/dashboard/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect } from "react";
import { AppState, Platform } from "react-native";
import { useRouter } from "expo-router";
import { Stack } from "expo-router/stack";
import { StyledStack } from "@/components/navigation/stack";
import { useIsLoggedIn } from "@/lib/session";
import { focusManager } from "@tanstack/react-query";

Expand All @@ -29,7 +30,10 @@ export default function Dashboard() {
}, []);

return (
<Stack>
<StyledStack
contentClassName="bg-gray-100 dark:bg-background"
headerClassName="bg-gray-100 dark:bg-background text-foreground"
>
<Stack.Screen
name="(tabs)"
options={{ headerShown: false, title: "Home" }}
Expand Down Expand Up @@ -64,6 +68,6 @@ export default function Dashboard() {
presentation: "modal",
}}
/>
</Stack>
</StyledStack>
);
}
1 change: 0 additions & 1 deletion apps/mobile/app/dashboard/add-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default function AddNote() {
<Text className="w-full text-center text-red-500">{error}</Text>
)}
<Input
className="bg-white"
value={text}
onChangeText={setText}
placeholder="Link"
Expand Down
1 change: 0 additions & 1 deletion apps/mobile/app/dashboard/add-note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default function AddNote() {
<Text className="w-full text-center text-red-500">{error}</Text>
)}
<Input
className="bg-white"
value={text}
onChangeText={setText}
multiline
Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/app/sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {

return (
<View className="flex flex-row gap-3">
<Text className="text-4xl">Hoarding</Text>
<Text className="text-4xl text-foreground">Hoarding</Text>
<ActivityIndicator />
</View>
);
Expand All @@ -83,11 +83,11 @@ export default function Sharing() {
break;
}
case "success": {
comp = <Text className="text-4xl">Hoarded!</Text>;
comp = <Text className="text-4xl text-foreground">Hoarded!</Text>;
break;
}
case "error": {
comp = <Text className="text-4xl">Error!</Text>;
comp = <Text className="text-4xl text-foreground">Error!</Text>;
break;
}
}
Expand Down
12 changes: 11 additions & 1 deletion apps/mobile/app/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "react-native";
import { Redirect } from "expo-router";
import Logo from "@/components/Logo";
import { TailwindResolver } from "@/components/TailwindResolver";
import { Button } from "@/components/ui/Button";
import { Input } from "@/components/ui/Input";
import useAppSettings from "@/lib/settings";
Expand Down Expand Up @@ -57,7 +58,16 @@ export default function Signin() {
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View className="flex h-full flex-col justify-center gap-2 px-4">
<View className="items-center">
<Logo height={150} width={200} />
<TailwindResolver
className="color-foreground"
comp={(styles) => (
<Logo
height={150}
width={200}
fill={styles?.color?.toString()}
/>
)}
/>
</View>
{error && (
<Text className="w-full text-center text-red-500">{error}</Text>
Expand Down
Binary file added apps/mobile/assets/splash-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions apps/mobile/components/TailwindResolver.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TextStyle, ViewStyle } from "react-native";
import { cssInterop } from "nativewind";

function TailwindResolverImpl({
comp,
style,
}: {
comp: (style?: ViewStyle & TextStyle) => React.ReactNode;
style?: ViewStyle & TextStyle;
}) {
return comp(style);
}

export const TailwindResolver = cssInterop(TailwindResolverImpl, {
className: "style",
});
41 changes: 32 additions & 9 deletions apps/mobile/components/bookmarks/BookmarkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
useUpdateBookmark,
} from "@hoarder/shared-react/hooks/bookmarks";

import { TailwindResolver } from "../TailwindResolver";
import { Divider } from "../ui/Divider";
import { Skeleton } from "../ui/Skeleton";
import { useToast } from "../ui/Toast";
Expand Down Expand Up @@ -162,9 +163,11 @@ function TagList({ bookmark }: { bookmark: ZBookmark }) {
{tags.map((t) => (
<View
key={t.id}
className="rounded-full border border-gray-200 px-2.5 py-0.5 text-xs font-semibold"
className="rounded-full border border-accent px-2.5 py-0.5 text-xs font-semibold"
>
<Link href={`dashboard/tags/${t.id}`}>{t.name}</Link>
<Link className="text-foreground" href={`dashboard/tags/${t.id}`}>
{t.name}
</Link>
</View>
))}
</View>
Expand Down Expand Up @@ -198,15 +201,17 @@ function LinkCard({ bookmark }: { bookmark: ZBookmark }) {
{imageComp}
<View className="flex gap-2 p-2">
<Text
className="line-clamp-2 text-xl font-bold"
className="line-clamp-2 text-xl font-bold text-foreground"
onPress={() => WebBrowser.openBrowserAsync(url)}
>
{bookmark.title ?? bookmark.content.title ?? parsedUrl.host}
</Text>
<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">
<Text className="my-auto line-clamp-1">{parsedUrl.host}</Text>
<Text className="my-auto line-clamp-1 text-foreground">
{parsedUrl.host}
</Text>
<ActionBar bookmark={bookmark} />
</View>
</View>
Expand All @@ -218,13 +223,29 @@ function TextCard({ bookmark }: { bookmark: ZBookmark }) {
if (bookmark.content.type !== "text") {
throw new Error("Wrong content type rendered");
}
const content = bookmark.content.text;
return (
<View className="flex max-h-96 gap-2 p-2">
{bookmark.title && (
<Text className="line-clamp-2 text-xl font-bold">{bookmark.title}</Text>
<Text className="line-clamp-2 text-xl font-bold text-foreground">
{bookmark.title}
</Text>
)}
<View className="max-h-56 overflow-hidden p-2">
<Markdown>{bookmark.content.text}</Markdown>
<View className="max-h-56 overflow-hidden p-2 text-foreground">
<TailwindResolver
className="text-foreground"
comp={(styles) => (
<Markdown
style={{
text: {
color: styles?.color?.toString(),
},
}}
>
{content}
</Markdown>
)}
/>
</View>
<TagList bookmark={bookmark} />
<Divider orientation="vertical" className="mt-2 h-0.5 w-full" />
Expand Down Expand Up @@ -256,7 +277,9 @@ function AssetCard({ bookmark }: { bookmark: ZBookmark }) {
/>
<View className="flex gap-2 p-2">
{title && (
<Text className="line-clamp-2 text-xl font-bold">{title}</Text>
<Text className="line-clamp-2 text-xl font-bold text-foreground">
{title}
</Text>
)}
<TagList bookmark={bookmark} />
<Divider orientation="vertical" className="mt-2 h-0.5 w-full" />
Expand Down Expand Up @@ -307,5 +330,5 @@ export default function BookmarkCard({
break;
}

return <View className="border-b border-gray-300 bg-white">{comp}</View>;
return <View className="border-b border-accent bg-background">{comp}</View>;
}
2 changes: 1 addition & 1 deletion apps/mobile/components/bookmarks/BookmarkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function BookmarkList({
renderItem={(b) => <BookmarkCard bookmark={b.item} />}
ListEmptyComponent={
<View className="items-center justify-center pt-4">
<Text className="text-xl">No Bookmarks</Text>
<Text className="text-xl text-foreground">No Bookmarks</Text>
</View>
}
data={bookmarks}
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/components/bookmarks/UpdatingBookmarkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { api } from "@/lib/trpc";
import type { ZGetBookmarksRequest } from "@hoarder/trpc/types/bookmarks";

import FullPageSpinner from "../ui/FullPageSpinner";
import BookmarkList2 from "./BookmarkList";
import BookmarkList from "./BookmarkList";

export default function UpdatingBookmarkList({
query,
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function UpdatingBookmarkList({
};

return (
<BookmarkList2
<BookmarkList
bookmarks={data.pages.flatMap((p) => p.bookmarks)}
header={header}
onRefresh={onRefresh}
Expand Down
Loading

0 comments on commit c46482c

Please sign in to comment.