Skip to content

Commit 75598c0

Browse files
ximximlazerblastersalexbrazier
authored
feat: Add ability to set custom theme (#60)
* chore: added capability to change theme completely and tintColor for share button on header * Fix lint and types Co-authored-by: lazerblasters <[email protected]> Co-authored-by: Alex Brazier <[email protected]>
1 parent 71046eb commit 75598c0

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/components/Header.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ const themedStyles = (theme: Theme) =>
5656
marginHorizontal: 10,
5757
color: theme.colors.text,
5858
},
59-
shareIcon: { width: 24, height: 24, marginRight: 10 },
59+
shareIcon: {
60+
width: 24,
61+
height: 24,
62+
marginRight: 10,
63+
tintColor: theme.colors.text,
64+
},
6065
container: {
6166
justifyContent: 'space-between',
6267
flexDirection: 'row',

src/components/NetworkLogger.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import React, { useEffect, useState, useCallback } from 'react';
22
import { Alert, View, StyleSheet, BackHandler } from 'react-native';
33
import logger from '../loggerSingleton';
44
import NetworkRequestInfo from '../NetworkRequestInfo';
5-
import { ThemeContext, ThemeName } from '../theme';
5+
import { Theme, ThemeContext, ThemeName } from '../theme';
66
import RequestList from './RequestList';
77
import RequestDetails from './RequestDetails';
88
import { setBackHandler } from '../backHandler';
99
import Unmounted from './Unmounted';
1010

1111
interface Props {
12-
theme?: ThemeName;
12+
theme?: ThemeName | Partial<Theme>;
1313
sort?: 'asc' | 'desc';
1414
}
1515

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export const clearRequests = () => logger.clearRequests();
1313

1414
export { getBackHandler } from './backHandler';
1515

16-
export { ThemeName } from './theme';
16+
export { ThemeName, Theme } from './theme';

src/theme.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React, { useContext } from 'react';
22

33
export type ThemeName = 'light' | 'dark';
4-
export const ThemeContext = React.createContext<ThemeName>('light');
4+
export const ThemeContext = React.createContext<ThemeName | Partial<Theme>>(
5+
'light'
6+
);
57
type Themes = { [key in ThemeName]: Theme };
68

79
export type Theme = {
@@ -54,9 +56,11 @@ const themes: Themes = {
5456
};
5557

5658
export const useTheme = () => {
57-
const themeName = useContext(ThemeContext);
59+
const themeValue = useContext(ThemeContext);
5860

59-
return themes[themeName];
61+
return typeof themeValue === 'string'
62+
? themes[themeValue]
63+
: { ...lightTheme, ...themeValue };
6064
};
6165

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

0 commit comments

Comments
 (0)