2022-04-09 15:48:01 +02:00
|
|
|
import { BlurView, BlurViewProperties } from '@react-native-community/blur';
|
2021-02-11 23:43:21 +01:00
|
|
|
import { THEME_COLOR } from 'CONSTANTS';
|
2022-04-09 15:48:01 +02:00
|
|
|
import React, { PropsWithChildren } from 'react';
|
2021-02-13 12:14:57 +01:00
|
|
|
import { useContext } from 'react';
|
2022-05-04 22:46:19 +02:00
|
|
|
import { ColorSchemeName, Platform, StyleSheet, useColorScheme } from 'react-native';
|
|
|
|
|
|
|
|
|
|
const majorPlatformVersion = typeof Platform.Version === 'string' ? parseInt(Platform.Version, 10) : Platform.Version;
|
2021-02-11 23:43:21 +01:00
|
|
|
|
2021-02-13 12:14:57 +01:00
|
|
|
/**
|
|
|
|
|
* Function for generating both the dark and light stylesheets, so that they
|
|
|
|
|
* don't have to be generate on every individual component render
|
|
|
|
|
*/
|
|
|
|
|
function generateStyles(scheme: ColorSchemeName) {
|
2021-02-11 23:43:21 +01:00
|
|
|
return StyleSheet.create({
|
|
|
|
|
text: {
|
|
|
|
|
color: scheme === 'dark' ? '#fff' : '#000',
|
2022-04-09 15:48:01 +02:00
|
|
|
fontSize: 14,
|
|
|
|
|
fontFamily: 'Inter',
|
2021-02-11 23:43:21 +01:00
|
|
|
},
|
|
|
|
|
textHalfOpacity: {
|
|
|
|
|
color: scheme === 'dark' ? '#ffffff88' : '#00000088',
|
2022-04-09 15:48:01 +02:00
|
|
|
fontSize: 14,
|
|
|
|
|
// fontFamily: 'Inter',
|
|
|
|
|
},
|
|
|
|
|
textQuarterOpacity: {
|
|
|
|
|
color: scheme === 'dark' ? '#ffffff44' : '#00000044',
|
|
|
|
|
fontSize: 14,
|
2021-02-11 23:43:21 +01:00
|
|
|
},
|
|
|
|
|
view: {
|
2022-04-09 15:48:01 +02:00
|
|
|
backgroundColor: scheme === 'dark' ? '#111' : '#fff',
|
2021-02-11 23:43:21 +01:00
|
|
|
},
|
|
|
|
|
border: {
|
|
|
|
|
borderColor: scheme === 'dark' ? '#262626' : '#ddd',
|
|
|
|
|
},
|
|
|
|
|
activeBackground: {
|
2022-01-02 23:03:15 +01:00
|
|
|
backgroundColor: `${THEME_COLOR}${scheme === 'dark' ? '26' : '16'}`,
|
2021-02-11 23:43:21 +01:00
|
|
|
},
|
|
|
|
|
imageBackground: {
|
2022-05-17 23:04:45 +02:00
|
|
|
backgroundColor: scheme === 'dark' ? '#191919' : '#eee',
|
2022-05-16 22:16:45 +02:00
|
|
|
borderWidth: 0.5,
|
2022-05-16 22:28:13 +02:00
|
|
|
borderColor: scheme === 'dark' ? '#262626' : '#ddd',
|
2021-02-11 23:43:21 +01:00
|
|
|
},
|
|
|
|
|
modal: {
|
2022-05-11 22:13:42 +02:00
|
|
|
backgroundColor: scheme === 'dark' ? '#000' : '#fff',
|
2021-02-11 23:43:21 +01:00
|
|
|
},
|
|
|
|
|
modalInner: {
|
|
|
|
|
backgroundColor: scheme === 'dark' ? '#000' : '#fff',
|
|
|
|
|
},
|
|
|
|
|
button: {
|
2022-05-16 22:28:13 +02:00
|
|
|
backgroundColor: scheme === 'dark' ? '#ffffff09' : '#00000009',
|
2021-02-11 23:43:21 +01:00
|
|
|
},
|
|
|
|
|
input: {
|
2022-05-17 23:04:45 +02:00
|
|
|
backgroundColor: scheme === 'dark' ? '#191919' : '#f3f3f3',
|
2021-02-11 23:43:21 +01:00
|
|
|
color: scheme === 'dark' ? '#fff' : '#000',
|
|
|
|
|
},
|
2021-02-13 15:34:43 +01:00
|
|
|
stackHeader: {
|
|
|
|
|
color: scheme === 'dark' ? 'white' : 'black'
|
2022-05-10 23:52:58 +02:00
|
|
|
},
|
|
|
|
|
icon: {
|
|
|
|
|
color: scheme === 'dark' ? '#ffffff4d' : '#0000004d',
|
|
|
|
|
},
|
|
|
|
|
divider: {
|
2022-05-10 23:56:20 +02:00
|
|
|
backgroundColor: scheme === 'dark' ? '#333' : '#eee',
|
2022-05-10 23:52:58 +02:00
|
|
|
},
|
2022-05-16 22:16:45 +02:00
|
|
|
filter: {
|
2022-05-17 23:04:45 +02:00
|
|
|
backgroundColor: scheme === 'dark' ? '#191919' : '#f3f3f3',
|
2022-05-16 22:16:45 +02:00
|
|
|
},
|
2021-02-11 23:43:21 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-13 12:14:57 +01:00
|
|
|
// Prerender both stylesheets
|
|
|
|
|
export const themes: Record<'dark' | 'light', ReturnType<typeof generateStyles>> = {
|
|
|
|
|
'dark': generateStyles('dark'),
|
|
|
|
|
'light': generateStyles('light'),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Create context for supplying the theming information
|
|
|
|
|
export const ColorSchemeContext = React.createContext(themes.dark);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the default styles object in hook form
|
|
|
|
|
*/
|
|
|
|
|
export default function useDefaultStyles() {
|
|
|
|
|
return useContext(ColorSchemeContext);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 23:43:21 +01:00
|
|
|
interface DefaultStylesProviderProps {
|
|
|
|
|
children: (defaultStyles: ReturnType<typeof useDefaultStyles>) => JSX.Element;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-13 12:14:57 +01:00
|
|
|
/**
|
|
|
|
|
* A render props component to supply the defaultStyles object.
|
|
|
|
|
*/
|
2021-02-11 23:43:21 +01:00
|
|
|
export function DefaultStylesProvider(props: DefaultStylesProviderProps) {
|
|
|
|
|
const defaultStyles = useDefaultStyles();
|
|
|
|
|
|
|
|
|
|
return props.children(defaultStyles);
|
2022-04-09 15:48:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ColoredBlurView(props: PropsWithChildren<BlurViewProperties>) {
|
|
|
|
|
const scheme = useColorScheme();
|
|
|
|
|
|
|
|
|
|
return (
|
2022-05-04 22:46:19 +02:00
|
|
|
<BlurView
|
|
|
|
|
{...props}
|
|
|
|
|
blurType={Platform.OS === 'ios' && majorPlatformVersion >= 13
|
|
|
|
|
? 'material'
|
|
|
|
|
: scheme === 'dark' ? 'extraDark' : 'xlight'
|
|
|
|
|
} />
|
2022-04-09 15:48:01 +02:00
|
|
|
);
|
2021-02-11 23:43:21 +01:00
|
|
|
}
|