Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating colors and typography to use theme objects #4481

Merged
merged 2 commits into from
Jun 22, 2022
Merged
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
33 changes: 20 additions & 13 deletions app/util/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { useContext } from 'react';
import { useColorScheme, StatusBar, ColorSchemeName } from 'react-native';
import { Colors, AppThemeKey, Theme } from './models';
import { 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 @@ -60,48 +60,55 @@ export const useAppTheme = (): Theme => {
AppThemeKey.light,
AppThemeKey.dark,
);
let colors: Colors;
let colors: Theme['colors'];
let typography: Theme['typography'];
georgewrmarshall marked this conversation as resolved.
Show resolved Hide resolved

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;
typography = lightTheme.typography;
setLightStatusBar();
break;
} else if (osThemeName === AppThemeKey.dark) {
colors = colorTheme.dark;
colors = darkTheme.colors;
typography = darkTheme.typography;
setDarkStatusBar();
break;
} else {
// Cover cases where OS returns undefined
colors = colorTheme.light;
colors = lightTheme.colors;
typography = lightTheme.typography;
setLightStatusBar();
}
}
case AppThemeKey.light:
colors = colorTheme.light;
colors = lightTheme.colors;
typography = lightTheme.typography;
setLightStatusBar();
break;
case AppThemeKey.dark:
colors = colorTheme.dark;
colors = darkTheme.colors;
typography = darkTheme.typography;
setDarkStatusBar();
break;
default:
// Default uses light theme
colors = colorTheme.light;
colors = lightTheme.colors;
typography = lightTheme.typography;
setLightStatusBar();
}

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;
Copy link
Member

Choose a reason for hiding this comment

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

Removing this type is breaking our ts files.
I think it should have been kept as Colors: DesignTokenTheme['colors'];.

We use them in the aggregator views:
Screen Shot 2022-06-28 at 10 38 42

Do we have type check enabled? This should have been caught at that stage.

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;
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
"@keystonehq/bc-ur-registry-eth": "^0.7.7",
"@keystonehq/metamask-airgapped-keyring": "^0.3.0",
"@keystonehq/ur-decoder": "^0.3.0",
"@metamask/controllers": "29.0.1",
"@metamask/contract-metadata": "^1.35.0",
"@metamask/design-tokens": "^1.6.5",
"@metamask/controllers": "29.0.1",
"@metamask/design-tokens": "^1.7.0",
"@metamask/etherscan-link": "^2.0.0",
"@metamask/swaps-controller": "^6.6.0",
"@ngraveio/bc-ur": "^1.1.6",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2395,10 +2395,10 @@
web3 "^0.20.7"
web3-provider-engine "^16.0.3"

"@metamask/design-tokens@^1.6.5":
version "1.6.5"
resolved "https://registry.yarnpkg.com/@metamask/design-tokens/-/design-tokens-1.6.5.tgz#e585b67f73ce301e0218d98ba89e079f7e81c412"
integrity sha512-5eCrUHXrIivXX1xx6kwNtM9s/ejhrPYSATSniFc7YKS9z+TkCK4/n52owOBnDIbrL8W3XxQIiaaqQAM+NQad4w==
"@metamask/design-tokens@^1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@metamask/design-tokens/-/design-tokens-1.7.0.tgz#fab069c0101da9e25d35ae051df2ff6bb5ff7a38"
integrity sha512-ejakgcsnTlLQmMrKb8XixXgExsYuMjlv71lkqJXeT0wa2oe4skVhB2dZul7Y9W4vYvQzTkwsW2NLfaj273eeEw==

"@metamask/eslint-config-typescript@^7.0.0":
version "7.0.1"
Expand Down