Skip to content

Commit

Permalink
Updating colors and typography to use theme objects
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewrmarshall committed Jun 8, 2022
1 parent 784e153 commit 6d9df45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
24 changes: 12 additions & 12 deletions app/util/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import React, { useContext } from 'react';
import { useColorScheme, StatusBar, ColorSchemeName } from 'react-native';
import { Colors, AppThemeKey, Theme } from './models';
import { useSelector } from 'react-redux';
import { colors as colorTheme, typography } from '@metamask/design-tokens';
import { lightTheme, darkTheme } from '@metamask/design-tokens';
import Device from '../device';

/**
* This is needed to make our unit tests pass since Enzyme doesn't support contextType
* TODO: Convert classes into functional components and remove contextType
*/
export const mockTheme = {
colors: colorTheme.light,
colors: lightTheme.colors,
themeAppearance: 'light',
typography,
typography: lightTheme.typography,
};

export const ThemeContext = React.createContext<any>(undefined);
Expand Down Expand Up @@ -65,47 +65,47 @@ export const useAppTheme = (): Theme => {
const setDarkStatusBar = () => {
StatusBar.setBarStyle('light-content', true);
Device.isAndroid() &&
StatusBar.setBackgroundColor(colorTheme.dark.background.default);
StatusBar.setBackgroundColor(darkTheme.colors.background.default);
};

const setLightStatusBar = () => {
StatusBar.setBarStyle('dark-content', true);
Device.isAndroid() &&
StatusBar.setBackgroundColor(colorTheme.light.background.default);
StatusBar.setBackgroundColor(lightTheme.colors.background.default);
};

switch (appTheme) {
/* eslint-disable no-fallthrough */
case AppThemeKey.os: {
if (osThemeName === AppThemeKey.light) {
colors = colorTheme.light;
colors = lightTheme.colors;
setLightStatusBar();
break;
} else if (osThemeName === AppThemeKey.dark) {
colors = colorTheme.dark;
colors = darkTheme.colors;
setDarkStatusBar();
break;
} else {
// Cover cases where OS returns undefined
colors = colorTheme.light;
colors = lightTheme.colors;
setLightStatusBar();
}
}
case AppThemeKey.light:
colors = colorTheme.light;
colors = lightTheme.colors;
setLightStatusBar();
break;
case AppThemeKey.dark:
colors = colorTheme.dark;
colors = darkTheme.colors;
setDarkStatusBar();
break;
default:
// Default uses light theme
colors = colorTheme.light;
colors = lightTheme.colors;
setLightStatusBar();
}

return { colors, themeAppearance, typography };
return { colors, themeAppearance, typography: lightTheme.typography };
};

export const useAppThemeFromContext = (): Theme => {
Expand Down
9 changes: 2 additions & 7 deletions app/util/theme/models.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { ThemeTypography } from '@metamask/design-tokens/dist/js/typography/types';

// TODO: This should probably be defined from @metamask/design-token library
export type Colors = any;
import { Theme as DesignTokenTheme } from '@metamask/design-tokens';

export enum AppThemeKey {
os = 'os',
light = 'light',
dark = 'dark',
}
export interface Theme {
colors: Colors;
typography: ThemeTypography;
export interface Theme extends DesignTokenTheme {
themeAppearance: AppThemeKey.light | AppThemeKey.dark;
}

0 comments on commit 6d9df45

Please sign in to comment.