Skip to content

Theme Mode Component ​

The ThemeModeComponent provides granular control over theme settings and persistence.

Basic Info ​

Description ​

This component extends theme functionality with custom colors, font scaling, and persistence options.

How to Use ​

1. Web Implementation ​

javascript
import { useThemeMode } from '@bagisto-native/react';

const ThemeSettings = () => {
    const { 
        setThemeMode, 
        getThemeMode,
        setCustomColors,
        setFontScale,
        persistTheme 
    } = useThemeMode();

    const handleModeChange = async () => {
        const mode = await getThemeMode();
        console.log("Current mode:", mode);
    };

    const handleCustomTheme = () => {
        setThemeMode("custom");
        setCustomColors({
            primary: "#FF5722",
            secondary: "#03A9F4",
            background: "#FFFFFF",
            surface: "#F5F5F5"
        });
    };

    const handleFontScale = () => {
        setFontScale(1.2); // 120% scale
    };

    const handlePersist = () => {
        persistTheme(); // Save current theme to storage
    };

    return (
        <div>
            <button onClick={handleModeChange}>Get Mode</button>
            <button onClick={handleCustomTheme}>Custom Theme</button>
            <button onClick={handleFontScale}>Set Font</button>
            <button onClick={handlePersist}>Save Theme</button>
        </div>
    );
};

2. Native Side ​

kotlin
navigator.registerBridgeComponent("themeMode", ThemeModeComponent(this))

API Reference ​

PropertyTypeRequiredDescription
setThemeMode(mode)FunctionNoSet mode: "light", "dark", "system", "custom"
getThemeMode()FunctionNoGet current theme mode
setCustomColors(colors)FunctionNoSet custom color scheme
setFontScale(scale)FunctionNoSet font scale (0.8-2.0)
persistTheme()FunctionNoSave theme to storage

Theme Modes ​

ModeDescription
lightForce light theme
darkForce dark theme
systemFollow system preference
customCustom color scheme

Custom Colors ​

PropertyTypeDescription
primaryStringPrimary color (hex)
secondaryStringSecondary color (hex)
backgroundStringBackground color (hex)
surfaceStringSurface color (hex)
textStringText color (hex)

Next Steps ​

Released under the MIT License.