Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"react-native-screens": "^4.24.0",
"react-native-shimmer-placeholder": "^2.0.9",
"react-native-tab-view": "^4.3.0",
"react-native-theme-switch-animation": "^0.8.0",
"react-native-url-polyfill": "^3.0.0",
"react-native-webview": "^13.16.1",
"react-native-worklets": "^0.8.1",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/components/SegmentedControl/SegmentedControl.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react';
import { View, Text, Pressable, StyleSheet } from 'react-native';
import {
View,
Text,
StyleSheet,
Pressable,
GestureResponderEvent,
} from 'react-native';
import MaterialCommunityIcons from '@react-native-vector-icons/material-design-icons';
import { ThemeColors } from '@theme/types';

Expand All @@ -12,7 +18,7 @@ export interface SegmentedControlOption<T extends string = string> {
export interface SegmentedControlProps<T extends string = string> {
options: SegmentedControlOption<T>[];
value: T;
onChange: (value: T) => void;
onChange: (value: T, event: GestureResponderEvent) => void;
theme: ThemeColors;
showCheckIcon?: boolean;
}
Expand Down Expand Up @@ -52,7 +58,7 @@ export function SegmentedControl<T extends string = string>({
<View key={option.value} style={buttonStyles}>
<Pressable
style={styles.segmentPressable}
onPress={() => onChange(option.value)}
onPress={e => onChange(option.value, e)}
android_ripple={{
color: theme.rippleColor,
borderless: false,
Expand Down
192 changes: 102 additions & 90 deletions src/components/ThemePicker/ThemePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react';
import { View, Text, StyleSheet, Pressable } from 'react-native';
import {
View,
Text,
StyleSheet,
Pressable,
GestureResponderEvent,
} from 'react-native';
import { overlay } from 'react-native-paper';
import color from 'color';
import MaterialCommunityIcons from '@react-native-vector-icons/material-design-icons';
Expand All @@ -8,128 +14,134 @@ import { ThemeColors } from '@theme/types';
interface ThemePickerProps {
theme: ThemeColors;
currentTheme: ThemeColors;
onPress: () => void;
onPress: (event: GestureResponderEvent) => void;
horizontal?: boolean;
isDark?: boolean;
}

export const ThemePicker = ({
theme,
currentTheme,
onPress,
horizontal = false,
}: ThemePickerProps) => (
<View style={[styles.container, horizontal && styles.horizontalContainer]}>
<View
style={[
styles.card,
{
backgroundColor: theme.background,
borderColor:
currentTheme.id === theme.id
? theme.primary
: currentTheme.background,
},
]}
>
<Pressable style={styles.flex1} onPress={onPress}>
{currentTheme.id === theme.id ? (
<MaterialCommunityIcons
name="check"
color={theme.onPrimary}
size={15}
style={[styles.checkIcon, { backgroundColor: theme.primary }]}
/>
) : null}
<View
style={[
styles.topBar,
{
backgroundColor: overlay(2, theme.surface),
},
]}
>
<View
style={[styles.topBarAccent, { backgroundColor: theme.onSurface }]}
/>
</View>
<View style={styles.content}>
}: ThemePickerProps) => {
return (
<View style={[styles.container, horizontal && styles.horizontalContainer]}>
<View
style={[
styles.card,
{
borderColor:
currentTheme.id === theme.id
? theme.primary
: currentTheme.background,
backgroundColor: theme.background,
},
]}
>
<Pressable style={styles.flex1} onPress={onPress}>
{currentTheme.id !== theme.id ? null : (
<MaterialCommunityIcons
name="check"
color={theme.onPrimary}
size={15}
style={[styles.checkIcon, { backgroundColor: theme.primary }]}
/>
)}
<View
style={[
styles.titleBar,
{ backgroundColor: theme.onSurfaceVariant },
styles.topBar,
{
backgroundColor: overlay(2, theme.surface),
},
]}
/>
<View style={styles.row}>
<View
style={[styles.rowAccent, { backgroundColor: theme.onSurface }]}
/>
>
<View
style={[
styles.rowAccentSmall,
{ backgroundColor: theme.primary },
styles.topBarAccent,
{ backgroundColor: theme.onSurface },
]}
/>
</View>
<View style={styles.row}>
<View
style={[
styles.rowAccentShort,
{ backgroundColor: theme.onSurfaceVariant },
]}
/>
<View style={styles.content}>
<View
style={[
styles.rowAccentShort,
styles.marginLeft,
styles.titleBar,
{ backgroundColor: theme.onSurfaceVariant },
]}
/>
<View style={styles.row}>
<View
style={[styles.rowAccent, { backgroundColor: theme.onSurface }]}
/>
<View
style={[
styles.rowAccentSmall,
{ backgroundColor: theme.primary },
]}
/>
</View>
<View style={styles.row}>
<View
style={[
styles.rowAccentShort,
{ backgroundColor: theme.onSurfaceVariant },
]}
/>
<View
style={[
styles.rowAccentShort,
styles.marginLeft,
{ backgroundColor: theme.onSurfaceVariant },
]}
/>
</View>
</View>
</View>
<View
style={[
styles.bottomBar,
{
backgroundColor: color(theme.primary).alpha(0.08).string(),
},
]}
>
<View style={styles.bottomBarContent}>
<View
style={[
styles.dot,
styles.opacityDot,
{ backgroundColor: theme.onSurface },
]}
/>
<View style={[styles.dot, { backgroundColor: theme.primary }]} />
<View
style={[
styles.dot,
styles.opacityDot,
{ backgroundColor: theme.onSurface },
]}
/>
<View
style={[
styles.bottomBar,
{
backgroundColor: color(theme.primary).alpha(0.08).string(),
},
]}
>
<View style={styles.bottomBarContent}>
<View
style={[
styles.dot,
styles.opacityDot,
{ backgroundColor: theme.onSurface },
]}
/>
<View style={[styles.dot, { backgroundColor: theme.primary }]} />
<View
style={[
styles.dot,
styles.opacityDot,
{ backgroundColor: theme.onSurface },
]}
/>
</View>
</View>
</View>
</Pressable>
</Pressable>
</View>
<Text style={[styles.themeName, { color: currentTheme.onSurface }]}>
{theme.name}
</Text>
</View>
<Text style={[styles.themeName, { color: currentTheme.onSurface }]}>
{theme.name}
</Text>
</View>
);
);
};

const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
paddingBottom: 8,
width: '33%',
},
horizontalContainer: {
width: undefined,
marginHorizontal: 4,
paddingBottom: 0,
},
card: {
borderWidth: 3.6,
Expand All @@ -143,7 +155,7 @@ const styles = StyleSheet.create({
shadowOpacity: 0.2,
shadowRadius: 4,
// Elevation for Android
elevation: 2,
//elevation: 2,
},
flex1: {
flex: 1,
Expand Down
44 changes: 36 additions & 8 deletions src/hooks/persisted/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { overlay } from 'react-native-paper';
import Color from 'color';

import { defaultTheme } from '@theme/md3/defaultTheme';
import { ThemeColors } from '@theme/types';
import { darkThemes, lightThemes } from '@theme/md3';

Expand Down Expand Up @@ -62,17 +61,46 @@ const findThemeById = (
isDark: boolean,
): ThemeColors => {
const themeList = isDark ? darkThemes : lightThemes;

let theme: ThemeColors | undefined;
if (themeId !== undefined) {
const theme = themeList.find(t => t.id === themeId);
if (theme) {
return theme;
}
const id = transformThemeId(themeId, isDark);
theme = themeList.find(t => t.id === id);
}

return isDark ? defaultTheme.dark : defaultTheme.light;
return theme ?? themeList[0];
};

// transforms legacy theme IDs to new IDs
function transformThemeId(themeId: number, isDark: boolean): number {
if (themeId > 99) return themeId;
const lightIdMap: Record<number, number> = {
'1': 100,
'8': 102,
'9': 108,
'10': 101,
'12': 103,
'14': 104,
'16': 105,
'18': 106,
'20': 107,
};
const darkIdMap: Record<number, number> = {
'2': 100,
'9': 102,
'10': 108,
'11': 101,
'13': 103,
'15': 104,
'17': 105,
'19': 106,
'21': 107,
};
if (isDark) {
return darkIdMap[themeId] ?? themeId;
}
return lightIdMap[themeId] ?? themeId;
}

const getBaseTheme = (
themeMode: string,
themeId: number | undefined,
Expand All @@ -95,7 +123,7 @@ export const useTheme = (): ThemeColors => {
const [customAccent] = useMMKVString('CUSTOM_ACCENT_COLOR');

const [systemColorScheme, setSystemColorScheme] = useState<ColorSchemeName>(
Appearance.getColorScheme(),
Appearance.getColorScheme() ?? 'unspecified',
);

useEffect(() => {
Expand Down
Loading
Loading