Skip to content

Commit

Permalink
feat: Add ability to set custom theme (#60)
Browse files Browse the repository at this point in the history
* chore: added capability to change theme completely and tintColor for share button on header

* Fix lint and types

Co-authored-by: lazerblasters <40807667+lazerblasters@users.noreply.github.com>
Co-authored-by: Alex Brazier <aejbrazier.apps@gmail.com>
  • Loading branch information
3 people committed Oct 16, 2021
1 parent 71046eb commit 75598c0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ const themedStyles = (theme: Theme) =>
marginHorizontal: 10,
color: theme.colors.text,
},
shareIcon: { width: 24, height: 24, marginRight: 10 },
shareIcon: {
width: 24,
height: 24,
marginRight: 10,
tintColor: theme.colors.text,
},
container: {
justifyContent: 'space-between',
flexDirection: 'row',
Expand Down
4 changes: 2 additions & 2 deletions src/components/NetworkLogger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React, { useEffect, useState, useCallback } from 'react';
import { Alert, View, StyleSheet, BackHandler } from 'react-native';
import logger from '../loggerSingleton';
import NetworkRequestInfo from '../NetworkRequestInfo';
import { ThemeContext, ThemeName } from '../theme';
import { Theme, ThemeContext, ThemeName } from '../theme';
import RequestList from './RequestList';
import RequestDetails from './RequestDetails';
import { setBackHandler } from '../backHandler';
import Unmounted from './Unmounted';

interface Props {
theme?: ThemeName;
theme?: ThemeName | Partial<Theme>;
sort?: 'asc' | 'desc';
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export const clearRequests = () => logger.clearRequests();

export { getBackHandler } from './backHandler';

export { ThemeName } from './theme';
export { ThemeName, Theme } from './theme';
10 changes: 7 additions & 3 deletions src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useContext } from 'react';

export type ThemeName = 'light' | 'dark';
export const ThemeContext = React.createContext<ThemeName>('light');
export const ThemeContext = React.createContext<ThemeName | Partial<Theme>>(
'light'
);
type Themes = { [key in ThemeName]: Theme };

export type Theme = {
Expand Down Expand Up @@ -54,9 +56,11 @@ const themes: Themes = {
};

export const useTheme = () => {
const themeName = useContext(ThemeContext);
const themeValue = useContext(ThemeContext);

return themes[themeName];
return typeof themeValue === 'string'
? themes[themeValue]
: { ...lightTheme, ...themeValue };
};

export const useThemedStyles = <T>(styles: (theme: Theme) => T) => {
Expand Down

0 comments on commit 75598c0

Please sign in to comment.