UNPKG

@nexara/nativeflow

Version:

Beautiful, responsive, and customizable UI components for React Native – built for performance and seamless experiences.

48 lines (46 loc) 1.29 kB
"use strict"; import React, { createContext, useMemo, useState } from 'react'; import { LightTheme, DarkTheme } from "../../themes/index.js"; import { setGlobalContext } from "./ContextManager.js"; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; export const Context = /*#__PURE__*/createContext({ mode: 'light', theme: { ...LightTheme, toggleThemeMode: () => {} }, scaling: { mode: 'partial' } }); const NativeProvider = ({ children, theme, options }) => { const [mode, setMode] = useState(options?.defaultTheme ?? 'light'); const toggleThemeMode = () => setMode(prev => prev === 'dark' ? 'light' : 'dark'); const setTheme = { ...(theme && theme[mode] || (mode === 'light' ? LightTheme : DarkTheme)), toggleThemeMode }; const value = useMemo(() => ({ theme: setTheme, mode, scaling: { mode: options?.scalingMode ?? 'partial' } }), [theme, mode, options]); // useLayoutEffect(() => { // setGlobalContext(value); // }, [value]); setGlobalContext(value); return /*#__PURE__*/_jsx(_Fragment, { children: /*#__PURE__*/_jsx(Context.Provider, { value: value, children: children }) }); }; export default NativeProvider; //# sourceMappingURL=NativeProvider.js.map