UNPKG

@ramses-superapp/ramses-ui

Version:
60 lines (58 loc) 1.9 kB
"use strict"; import { createContext, useContext } from 'react'; import { TouchableWithoutFeedback, useColorScheme, SafeAreaView, View, KeyboardAvoidingView, Platform, Keyboard, StatusBar } from 'react-native'; import LightTheme from "../styles/themes/LightTheme.js"; import DarkTheme from "../styles/themes/DarkTheme.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const ThemeContext = /*#__PURE__*/createContext(LightTheme); export const ThemeProvider = ({ children, mode = 'auto', customLightTheme, customDarkTheme }) => { const colorScheme = useColorScheme(); // Choose theme based on mode and custom themes let theme; if (mode === 'light') { theme = customLightTheme || LightTheme; } else if (mode === 'dark') { theme = customDarkTheme || DarkTheme; } else { theme = colorScheme === 'dark' ? customDarkTheme || DarkTheme : customLightTheme || LightTheme; } return /*#__PURE__*/_jsx(ThemeContext.Provider, { value: theme, children: /*#__PURE__*/_jsxs(SafeAreaView, { style: { flex: 1, backgroundColor: theme.Background.screen }, children: [/*#__PURE__*/_jsx(StatusBar, { barStyle: theme.StatusBar.barStyle, backgroundColor: theme.Background.screen }), /*#__PURE__*/_jsx(TouchableWithoutFeedback, { style: { flex: 1 }, onPress: () => { Keyboard.dismiss(); }, children: /*#__PURE__*/_jsx(KeyboardAvoidingView, { behavior: Platform.OS === 'ios' ? 'padding' : 'height', style: { flex: 1 }, children: /*#__PURE__*/_jsx(View, { style: { flex: 1 }, children: children }) }) })] }) }); }; export const useTheme = () => useContext(ThemeContext); //# sourceMappingURL=ThemeProvider.js.map