Skip to content

Theme Component

The ThemeComponent provides native theme support for dark/light mode, custom colors, and system theme detection.

Basic Info

Description

This component manages native theming including system theme detection, manual theme switching, and custom color schemes.

How to Use

1. Web Implementation

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

const ThemeController = () => {
    const { 
        getSystemTheme, 
        setTheme, 
        getCurrentTheme,
        onThemeChange 
    } = useTheme();

    // Get current system theme
    useEffect(() => {
        const systemTheme = getSystemTheme();
        console.log("System theme:", systemTheme);
        
        // Listen for theme changes
        const unsubscribe = onThemeChange((theme) => {
            console.log("Theme changed to:", theme);
            // Update app theme
        });
        
        return () => unsubscribe();
    }, []);

    const handleThemeChange = (mode) => {
        setTheme(mode); // "light", "dark", or "system"
    };

    return (
        <div>
            <button onClick={() => handleThemeChange('light')}>Light</button>
            <button onClick={() => handleThemeChange('dark')}>Dark</button>
            <button onClick={() => handleThemeChange('system')}>System</button>
        </div>
    );
};

2. Native Side

kotlin
navigator.registerBridgeComponent("theme", ThemeComponent(this))

API Reference

PropertyTypeRequiredDescription
getSystemTheme()FunctionNoGet current system theme
setTheme(mode)FunctionNoSet theme: "light", "dark", "system"
getCurrentTheme()FunctionNoGet current active theme
onThemeChange(callback)FunctionNoListen for theme changes

Theme Modes

ModeDescription
lightForce light theme
darkForce dark theme
systemFollow system preference

Next Steps

Released under the MIT License.