npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-dynamic-theme

v0.3.4

Published

A React Native library to retrieve the dynamic theme from android devices

Readme

React Native Dynamic Theme 🎨

Bring Material 3 Dynamic Theming to Your React Native Apps

A powerful React Native library that enables seamless Material 3 dynamic theming, automatically adapting to your users' system preferences and wallpaper colors on Android 12+.

npm version npm downloads License: MIT

✨ Features

  • 📱 System-Aware: Automatically adapts to light/dark mode
  • 🎨 Material You Support: Leverages Android's dynamic theming for native feel
  • 🎯 Complete Color Palettes: Access to full tonal palettes with all contrast levels
  • Performance Optimized: Efficient hooks and memoization
  • 🔧 Custom Color Generation: Create themes from any source color
  • 📦 TypeScript Support: Fully typed for better development experience
  • 🌈 Extended Schemes: Medium and high contrast variants included

🚀 Quick Start

Installation

npm install react-native-dynamic-theme

or

yarn add react-native-dynamic-theme

Basic Usage

import React from 'react';
import { View, Text, useColorScheme } from 'react-native';
import { getDynamicColorScheme } from 'react-native-dynamic-theme';

const App = () => {
  const systemColorScheme = useColorScheme();
  const dynamicColors = getDynamicColorScheme('#006971');
  
  const colors = systemColorScheme === 'dark' 
    ? dynamicColors.dark 
    : dynamicColors.light;
  
  return (
    <View style={{ backgroundColor: colors.background, flex: 1 }}>
      <Text style={{ color: colors.onBackground }}>
        Hello Material You! 🎨
      </Text>
    </View>
  );
};

export default App;

📖 Documentation

📚 Complete Documentation

🎯 Key Functions

getDynamicColorScheme(fallbackColor?: string)

Retrieves the dynamic color scheme from the device or generates one from a fallback color.

// Uses device wallpaper colors on Android 12+, fallback on older versions
const colors = getDynamicColorScheme('#006971');

// Returns null if no fallback provided and device doesn't support dynamic theming  
const colors = getDynamicColorScheme();

getExtendedDynamicScheme(fallbackColor?: string)

Gets extended scheme with contrast variants and tonal palettes.

const extendedScheme = getExtendedDynamicScheme('#006971');

// Access different contrast levels
const standardColors = extendedScheme.schemes.light;
const highContrastColors = extendedScheme.schemes.lightHighContrast;

// Access tonal palettes
const primaryPalette = extendedScheme.palettes.primary;

getExtendedDynamicSchemeFromSourceColor(sourceColor: string)

Generate complete theme from any source color.

const customScheme = getExtendedDynamicSchemeFromSourceColor('#FF5722');

🎨 Example: Theme Switcher

import React, { useState } from 'react';
import { View, TouchableOpacity, Text, useColorScheme } from 'react-native';
import { getExtendedDynamicSchemeFromSourceColor } from 'react-native-dynamic-theme';

const ThemeSwitcher = () => {
  const systemColorScheme = useColorScheme();
  const [sourceColor, setSourceColor] = useState('#006971');
  
  const colorOptions = ['#006971', '#FF5722', '#2196F3', '#9C27B0'];
  const dynamicScheme = getExtendedDynamicSchemeFromSourceColor(sourceColor);
  const colors = systemColorScheme === 'dark' 
    ? dynamicScheme.dark 
    : dynamicScheme.light;

  return (
    <View style={{ backgroundColor: colors.background, flex: 1, padding: 20 }}>
      <Text style={{ color: colors.onBackground, fontSize: 24, marginBottom: 20 }}>
        Pick a Color Theme
      </Text>
      
      <View style={{ flexDirection: 'row', marginBottom: 20 }}>
        {colorOptions.map((color) => (
          <TouchableOpacity
            key={color}
            style={{
              backgroundColor: color,
              width: 50,
              height: 50,
              borderRadius: 25,
              marginRight: 10,
              borderWidth: sourceColor === color ? 3 : 0,
              borderColor: colors.outline,
            }}
            onPress={() => setSourceColor(color)}
          />
        ))}
      </View>
      
      <View style={{
        backgroundColor: colors.primaryContainer,
        padding: 16,
        borderRadius: 12,
      }}>
        <Text style={{ color: colors.onPrimaryContainer }}>
          This container adapts to your selected color!
        </Text>
      </View>
    </View>
  );
};

🔧 Platform Support

  • React Native: 0.60+
  • Android: API 21+ (dynamic colors on API 31+)
  • iOS: 11.0+ (custom color generation)
  • TypeScript: 4.0+

Platform Behavior

  • Android 12+: Uses actual device wallpaper colors via Material You
  • Android < 12: Generates theme from fallback color
  • iOS: Generates theme from fallback color (Material You not available)

🎨 Material 3 Color System

The library provides access to the complete Material 3 color system:

Semantic Color Roles

  • Primary, Secondary, Tertiary colors and their containers
  • Error colors and containers
  • Background and surface colors
  • Surface containers at different elevation levels
  • Outline colors for borders and dividers

Example Color Usage

const { colors } = useTheme();

// Main actions
backgroundColor: colors.primary
color: colors.onPrimary

// Supporting actions  
backgroundColor: colors.secondaryContainer
color: colors.onSecondaryContainer

// Error states
backgroundColor: colors.errorContainer
color: colors.onErrorContainer

// Surfaces
backgroundColor: colors.surface
color: colors.onSurface

🛠 Advanced Usage

Theme Provider Pattern

import React, { createContext, useContext } from 'react';
import { useColorScheme } from 'react-native';
import { getDynamicColorScheme } from 'react-native-dynamic-theme';

const ThemeContext = createContext();

export const ThemeProvider = ({ children }) => {
  const systemColorScheme = useColorScheme();
  const dynamicColors = getDynamicColorScheme('#006971');
  
  const colors = systemColorScheme === 'dark' 
    ? dynamicColors.dark 
    : dynamicColors.light;
  
  return (
    <ThemeContext.Provider value={{ colors, isDark: systemColorScheme === 'dark' }}>
      {children}
    </ThemeContext.Provider>
  );
};

export const useTheme = () => useContext(ThemeContext);

Performance Optimization

import { useMemo } from 'react';

const MyComponent = ({ sourceColor }) => {
  // Memoize expensive color calculations
  const colors = useMemo(() => {
    return getDynamicColorScheme(sourceColor);
  }, [sourceColor]);
  
  return <View style={{ backgroundColor: colors.light.background }} />;
};

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support


Made with ❤️ by Fouad Magdy