Rocket.Chat.ReactNative/app/theme.tsx

24 lines
764 B
TypeScript
Raw Normal View History

import React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
interface IThemeContextProps {
theme: string;
themePreferences?: {
currentTheme: 'automatic' | 'light';
darkLevel: string;
};
setTheme?: (newTheme?: {}) => void;
}
export const ThemeContext = React.createContext<IThemeContextProps>({ theme: 'light' });
2021-10-13 21:09:50 +00:00
export function withTheme(Component: React.ComponentType<any>): (props: any) => JSX.Element {
const ThemedComponent = (props: any) => (
<ThemeContext.Consumer>{contexts => <Component {...props} {...contexts} />}</ThemeContext.Consumer>
);
hoistNonReactStatics(ThemedComponent, Component);
return ThemedComponent;
}
2021-10-13 21:09:50 +00:00
export const useTheme = (): Partial<IThemeContextProps> => React.useContext(ThemeContext);