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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-material-palette

v0.2.0

Published

Extract prominent colors from images using Android Palette API

Readme

react-native-material-palette

Build Status Code Coverage Version MIT License

PRs Welcome Chat Code of Conduct

Android Palette API brought to react native. It extracts prominent colors from images to help you create visually engaging apps.

The library only supports Android and requires new architecture to work.

Installation

npm install react-native-material-palette

Usage

createPalette

Extract prominent color swatches from an image:

import { createPalette } from 'react-native-material-palette';

const palette = await createPalette({ uri: 'https://example.com/photo.jpg' });

Or with local image:

const palette = await createPalette(require('./photo.jpg'));

The returned PaletteResult has the following properties, each of which is a PaletteSwatch or undefined:

| Property | Description | | -------------- | ------------------------------ | | vibrant | A vibrant color from the image | | lightVibrant | A light and vibrant color | | darkVibrant | A dark and vibrant color | | muted | A muted color from the image | | lightMuted | A light and muted color | | darkMuted | A dark and muted color |

Each PaletteSwatch has the following properties:

| Property | Type | Description | | ---------------- | -------- | ----------------------------------------------------- | | color | string | The main color of the swatch (hex format) | | population | number | The number of pixels represented by this swatch | | bodyTextColor | string | A color suitable for body text over the swatch color | | titleTextColor | string | A color suitable for title text over the swatch color |

Options

region

Specifies a rectangular area of the image to use for palette generation. Coordinates are in pixels.

const palette = await createPalette(source, {
  region: {
    left: 0,
    top: 0,
    right: 100,
    bottom: 100,
  },
});
maximumColorCount

Maximum colors in the palette. The default value is 16, and the optimal value depends on the source image. For landscapes, optimal values range from 8-16, while pictures with faces usually have values from 24-32.

createPaletteForTarget

Extract a single swatch using a custom target for fine-grained control over color matching:

import { createPaletteForTarget } from 'react-native-material-palette';

const swatch = await createPaletteForTarget(source, {
  targetLightness: 0.5,
  minimumLightness: 0.2,
  maximumLightness: 0.8,
  targetSaturation: 0.7,
  minimumSaturation: 0.3,
  maximumSaturation: 1.0,
  lightnessWeight: 0.6,
  saturationWeight: 0.3,
  populationWeight: 0.1,
  exclusive: true,
});

It accepts the same region and maximumColorCount options as createPalette in an optional third argument.

usePaletteSwatch

A hook for using palette colors in components. It extracts a single swatch based on the type option:

import { usePaletteSwatch } from 'react-native-material-palette';

function MyComponent() {
  const swatch = usePaletteSwatch(source, { type: 'vibrant' });

  return (
    <View style={{ backgroundColor: swatch?.color ?? 'white' }}>
      <Text style={{ color: swatch?.bodyTextColor ?? 'black' }}>Hello</Text>
    </View>
  );
}

The type option can be one of the 6 built-in targets ('vibrant', 'lightVibrant', 'darkVibrant', 'muted', 'lightMuted', 'darkMuted') or a custom target object.

Returns undefined while loading or if generation fails.

[!TIP] To avoid delays due to async palette generation, you can preload the palette by calling createPalette with the same image and options ahead of time.

Palette.View

A component that uses a palette swatch color as its background:

import { Palette } from 'react-native-material-palette';

function MyComponent() {
  return (
    <Palette.View source={imageSource} type="vibrant">
      {/* your content */}
    </Palette.View>
  );
}

It accepts the same options as usePaletteSwatch and an optional fallback prop with a PaletteSwatch to use while loading or if generation fails.

By default, it uses the color property of the swatch as its background color. You can customize which swatch color to use with the variant prop:

  • color (default) — main swatch color
  • titleTextColor — title text color
  • bodyTextColor — body text color

It renders a regular View when not used on Android.

Palette.Text

A component that uses palette swatch colors for text:

import { Palette } from 'react-native-material-palette';

function MyComponent() {
  return (
    <Palette.Text source={imageSource} type="vibrant">
      Hello, World!
    </Palette.Text>
  );
}

By default, it uses the bodyTextColor property of the swatch as its text color. You can customize which swatch color to use with the variant prop:

  • color — main swatch color
  • titleTextColor — title text color
  • bodyTextColor (default) — body text color

When nested inside Palette.View, it automatically uses the swatch from the parent without needing to provide source and type props:

import { Palette } from 'react-native-material-palette';

function MyComponent() {
  return (
    <Palette.View source={imageSource} type="vibrant">
      <Palette.Text>Hello, World!</Palette.Text>
    </Palette.View>
  );
}

The source and type props can still be provided explicitly to override the parent swatch.

It renders a regular Text when not used on Android.

Contributing

License

MIT


Made with create-react-native-library