Skip to content

Commit

Permalink
Merge pull request #100 from albbus-stack/theme-toggle
Browse files Browse the repository at this point in the history
Added ThemeToggle component
  • Loading branch information
albbus-stack authored Nov 1, 2023
2 parents ad19746 + 1935637 commit 6c5a3b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/app/features/home/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SolitoImage } from 'solito/image'
import { trpc } from 'app/utils/trpc'
import { useSupabase } from 'app/utils/supabase/hooks/useSupabase'
import { useUser } from 'app/utils/supabase/hooks/useUser'
import { ThemeToggle } from '@t4/ui/src/ThemeToggle'

export function HomeScreen() {
const utils = trpc.useContext()
Expand Down Expand Up @@ -77,7 +78,10 @@ export function HomeScreen() {
</Anchor>
</Paragraph>

<Button onPress={() => Linking.openURL('https://t4stack.com/')}>Learn More...</Button>
<XStack gap="$5">
<Button onPress={() => Linking.openURL('https://t4stack.com/')}>Learn More...</Button>
<ThemeToggle/>
</XStack>

<H3>🦮🐴 App Demos</H3>
<YStack space="$2">
Expand Down
29 changes: 29 additions & 0 deletions packages/ui/src/ThemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useState } from "react";
import { useThemeSetting } from "@tamagui/next-theme";
import { Monitor, Sun, Moon } from "@tamagui/lucide-icons";
import type { ButtonProps } from "tamagui";
import { Button, useIsomorphicLayoutEffect } from "tamagui";

const icons = {
system: Monitor,
light: Sun,
dark: Moon
}
export const ThemeToggle = (props: ButtonProps) => {
const themeSetting = useThemeSetting()!;
const [clientTheme, setClientTheme] = useState("system");

useIsomorphicLayoutEffect(() => {
setClientTheme(themeSetting.current || "system");
}, [themeSetting.current]);

return (
<Button
size="$4"
onPress={themeSetting.toggle}
aria-label="Toggle color scheme"
icon={icons[clientTheme]}
{...props}
/>
);
};

1 comment on commit 6c5a3b8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔ EAS production build completed

  • 🤖 Android build failed ❌
  • 🍏 IOS build failed ❌
Android QR IOS QR

Please sign in to comment.