Skip to content

Commit

Permalink
Add logging for light/darkl mode color scheme (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
lourou authored Nov 21, 2024
1 parent aad77e1 commit 86574a1
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions theme/useAppTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useMemo,
useState,
} from "react";
import { StyleProp, useColorScheme } from "react-native";
import { Appearance, Platform, StyleProp, useColorScheme } from "react-native";

import { IShadow, shadow } from "@theme/shadow";
import { IAvatarSize, avatarSize } from "./avatar";
Expand All @@ -25,10 +25,12 @@ import { ISpacing, spacing } from "./spacing";
import { Timing, timing } from "./timing";
import { ITypography, typography } from "./typography";

import logger from "@utils/logger";

export type ThemeContexts = "light" | "dark" | undefined;

// The overall Theme object should contain all of the data you need to style your app.
export interface Theme {
export type Theme = {
colors: IColors;
spacing: ISpacing;
borderRadius: IBorderRadius;
Expand All @@ -39,7 +41,7 @@ export interface Theme {
timing: Timing;
shadow: IShadow;
isDark: boolean;
}
};

// Here we define our themes.
export const lightTheme: Theme = {
Expand Down Expand Up @@ -138,7 +140,7 @@ export const useThemeProvider = (initialTheme: ThemeContexts = undefined) => {
};
};

interface UseAppThemeValue {
type UseAppThemeValue = {
// The theme object from react-navigation
navTheme: typeof DefaultTheme;
// A function to set the theme context override (for switching modes)
Expand All @@ -153,7 +155,7 @@ interface UseAppThemeValue {
themed: <T>(
styleOrStyleFn: ThemedStyle<T> | StyleProp<T> | ThemedStyleArray<T>
) => T;
}
};

export type IThemed = ReturnType<typeof useAppTheme>["themed"];

Expand Down Expand Up @@ -182,6 +184,18 @@ export const useAppTheme = (): UseAppThemeValue => {
[themeContext]
);

// TODO: Remove after debugging is done
// Light/dark mode color scheme logging
useEffect(() => {
logger.debug("=== Theme Debug ===", {
systemColorScheme: Appearance.getColorScheme(),
platformVersion: Platform.Version,
themeContext: themeContext,
isDarkTheme: themeVariant.isDark,
navThemeDark: navTheme.dark,
});
}, [themeContext, themeVariant, navTheme]);

const themed = useCallback(
<T>(
styleOrStyleFn: ThemedStyle<T> | StyleProp<T> | ThemedStyleArray<T>
Expand Down

0 comments on commit 86574a1

Please sign in to comment.