-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
508 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
import { useState } from "react"; | ||
import type { ImageURISource } from "react-native"; | ||
import { getAppIcon, setAppIcon } from "expo-dynamic-app-icon"; | ||
import { Check } from "@tamagui/lucide-icons"; | ||
import { Image, ListItem, View, YGroup, YStack } from "tamagui"; | ||
|
||
import { Container } from "../../components/container"; | ||
|
||
const DarkIcon = require("../../assets/images/default.png") as ImageURISource; | ||
const DefaultIcon = require("../../assets/images/default.png") as ImageURISource; | ||
const LightIcon = require("../../assets/images/light.png") as ImageURISource; | ||
|
||
const icons = [ | ||
{ | ||
name: "Default", | ||
value: "default", | ||
source: DefaultIcon, | ||
}, | ||
{ | ||
name: "Light", | ||
value: "light", | ||
source: LightIcon, | ||
}, | ||
{ | ||
name: "Dark", | ||
value: "dark", | ||
source: DarkIcon, | ||
}, | ||
] as const; | ||
|
||
const AppIcon = () => { | ||
const [activeIcon, setActiveIcon] = useState(getAppIcon().toLowerCase()); | ||
|
||
const setIcon = (value: (typeof icons)[number]["value"]) => { | ||
setActiveIcon(value); | ||
setAppIcon(value); | ||
}; | ||
|
||
return ( | ||
<Container paddingVertical={"$4"}> | ||
<YStack space="$3"> | ||
<YGroup alignSelf="center" bordered size="$4"> | ||
{icons.map((icon) => ( | ||
<YGroup.Item key={icon.value}> | ||
<ListItem | ||
hoverTheme | ||
pressTheme | ||
icon={ | ||
<View backgroundColor="$gray5" borderRadius={"$3"} padding="$2"> | ||
<Image source={icon.source} style={{ width: 36, height: 36 }} /> | ||
</View> | ||
} | ||
onPress={() => { | ||
void setIcon(icon.value); | ||
}} | ||
iconAfter={activeIcon === icon.value ? <Check size={18} strokeWidth={2.5} /> : undefined} | ||
> | ||
<ListItem.Text>{icon.name}</ListItem.Text> | ||
</ListItem> | ||
</YGroup.Item> | ||
))} | ||
</YGroup> | ||
</YStack> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default AppIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
import { Check, Moon, Smartphone, Sun } from "@tamagui/lucide-icons"; | ||
import { ListItem, View, YGroup, YStack } from "tamagui"; | ||
|
||
import { Container } from "../../components/container"; | ||
import { useTheme } from "../../components/theme-provider"; | ||
import { themeTypes } from "../../theme/theme-builder"; | ||
|
||
const Theme = () => { | ||
const { theme, setTheme, autoTheme } = useTheme(); | ||
return ( | ||
<Container paddingVertical={"$4"}> | ||
<YStack space="$3"> | ||
<YGroup alignSelf="center" bordered size="$4"> | ||
{(["auto", ...themeTypes] as const).map((themeType) => ( | ||
<YGroup.Item key={themeType}> | ||
<ListItem | ||
hoverTheme | ||
pressTheme | ||
icon={ | ||
<View backgroundColor="$gray5" borderRadius={"$3"} padding="$2"> | ||
{themeType === "light" ? ( | ||
<Sun size={24} /> | ||
) : themeType === "auto" ? ( | ||
<Smartphone size={24} /> | ||
) : ( | ||
<Moon size={24} /> | ||
)} | ||
</View> | ||
} | ||
onPress={() => { | ||
setTheme(themeType); | ||
}} | ||
iconAfter={ | ||
(autoTheme && themeType === "auto") || (theme === themeType && !autoTheme) ? ( | ||
<Check size={18} strokeWidth={2.5} /> | ||
) : undefined | ||
} | ||
> | ||
<ListItem.Text> | ||
{themeType === "light" ? "Light" : themeType === "auto" ? "Auto" : "Dark"} | ||
</ListItem.Text> | ||
</ListItem> | ||
</YGroup.Item> | ||
))} | ||
</YGroup> | ||
</YStack> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Theme; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createContext, useContext, useEffect, useRef, useState } from "react"; | ||
import { useColorScheme } from "react-native"; | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
import { Theme } from "tamagui"; | ||
|
||
export const ThemeContext = createContext<{ | ||
theme: ThemeType; | ||
setTheme: (theme: ThemeType | "auto") => void; | ||
autoTheme: boolean; | ||
}>({ | ||
theme: "light", | ||
setTheme: () => { | ||
console.warn("Missing ThemeProvider"); | ||
}, | ||
autoTheme: false, | ||
}); | ||
|
||
export type ThemeType = "light" | "dark"; | ||
|
||
export const useTheme = () => useContext(ThemeContext); | ||
|
||
export const ThemeProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [theme, setThemeState] = useState<ThemeType>("light"); | ||
const [autoTheme, setAutoTheme] = useState<boolean>(false); | ||
|
||
const colorScheme = useColorScheme(); | ||
const [currentColorScheme, setCurrentColorScheme] = useState(colorScheme); | ||
const onColorSchemeChange = useRef<NodeJS.Timeout>(); | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
if (colorScheme !== currentColorScheme) { | ||
onColorSchemeChange.current = setTimeout(() => setCurrentColorScheme(colorScheme), 1000); | ||
} else if (onColorSchemeChange.current) { | ||
clearTimeout(onColorSchemeChange.current); | ||
} | ||
const storedTheme = await AsyncStorage.getItem("theme"); | ||
setThemeState(storedTheme as ThemeType); | ||
if (storedTheme === "auto") { | ||
setThemeState(colorScheme === "dark" ? "dark" : "light"); | ||
} | ||
}; | ||
void init(); | ||
}, [colorScheme, currentColorScheme]); | ||
|
||
const setTheme = (theme: ThemeType | "auto") => { | ||
if (theme === "auto") { | ||
setThemeState(colorScheme === "dark" ? "dark" : "light"); | ||
} else { | ||
setThemeState(theme); | ||
} | ||
setAutoTheme(theme === "auto"); | ||
void AsyncStorage.setItem("theme", theme); | ||
}; | ||
return ( | ||
<ThemeContext.Provider value={{ theme, setTheme, autoTheme }}> | ||
<Theme name={theme}>{children}</Theme> | ||
</ThemeContext.Provider> | ||
); | ||
}; |
Oops, something went wrong.