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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@assembless/react-native-material-you

v1.0.0-beta.4

Published

👩‍🎨 Material You native module for React Native

Downloads

57

Readme

react-native-material-you

Bring newest Android 12 feature Material You to your React Native app. This package enables you to use the from wallpaper generated colors in your app.

RNMY Thumbnail npm (tag) GitHub issues GitHub last commit NPM npm

Features

  • 🎨 Generate a palette based on dominant wallpaper colors
  • 🪝 Supports React hooks
  • 🕒 Provides fallback palette for older Android versions
  • ♻️ Refreshes palette when the wallpaper changes

How to install

Yarn

yarn add @assembless/react-native-material-you

NPM

npm install @assembless/react-native-material-you

How to use

React Context + Hook

In order to get the colors always refreshed when the palette is being regenerated on the native side, it's necessary to wrap your app with MaterialYouService and get the palette from the context, by using useMaterialYouPalette or useMaterialYouContext hooks. The service subscribes to palette changes on the native side and updates the context when the palette is changed. fallbackPalette is optional.

import { MaterialYouService, useMaterialYouPalette, defaultPalette } from '@assembless/react-native-material-you';

const App = () => (
    <MaterialYouService fallbackPalette={defaultPalette}>
        {...}
    </MaterialYouService>
)

const MyComponent = () => {
    const palette = useMaterialYouPalette();

    return (
        <View style={{ backgroundColor: palette.system_neutral2[2] }}>
            <Text style={{ color: palette.system_accent1[6] }}>Hello World</Text>
        </View>
    );
}

React Hook

Alternatively, you can use the useMaterialYou hook that returns the system generated color palette. In order to get the newest palette, run the _refresh method exposed by the hook. fallbackPalette is optional.

import { useMaterialYou, defaultPalette } from '@assembless/react-native-material-you';

const MyComponent = () => {
    const { palette } = useMaterialYou({ fallbackPalette: defaultPalette });

    return (
        <View style={{ backgroundColor: palette.system_neutral2[2] }}>
            <Text style={{ color: palette.system_accent1[6] }}>Hello World</Text>
        </View>
    );
}

Static methods

Get palette synchronously

The getPaletteSync function returns a rich palette of 5 system generated colors (system_accent1, system_accent2, system_accent3, system_neutral1, system_neutral2) and each containing 12 shades of Material color in hex strings that are used to determine the hues closest to the user’s wallpaper. The color constants are passed from the native module. Check out the Android documentation for more details about system generated colors.

import { getPaletteSync } from '@assembless/react-native-material-you';

const palette = getPaletteSync();

const theme = {
    palette: {
        primary: palette.system_accent1[6],
        background: palette.system_neutral2[2],
        ...
    }
}

⚠️ This function only returns constant colors generated at runtime once. If you want to get the colors regenerated while the app is already running, you need to use the getPalette function which is asynchronous.

Get palette asynchronously

import { getPalette } from '@assembless/react-native-material-you';

const createTheme = async () => {
    const palette = await getPalette();

    return ({
        palette: {
            primary: palette.system_accent1[6],
            background: palette.system_neutral2[2],
            ...
        }
    })
}

Documentation

The documentation has been generated from JSDoc.

Documentation website

How to debug

  1. Install dependencies (in root dir and ./example dir)
  2. Open the example directory project in Android Studio, build and run the project. (./example/android)
  3. Run yarn start in the example directory.

Special thanks

We're very thankful to our genius testers and contributors helping us get this package to perfection. Thank you! :heart: