Color Your Apps in React Native Using Material Palette

Authors
Raul Gomez Acuna
Software Engineer
@
Callstack

Successful apps invest in good visual design. That’s essential for a pleasant user experience, where our eyes are delighted with every interaction that occurs inside. Material design meant a big step forward on that matter, providing a visual language that synthesises the classic principles of good design with the innovation and possibility of technology and science. Material as a metaphor, graphically intentional and motion as a way of providing meaning are some of the principles they established to layout beautiful experiences.

With the release of Android 7.0 Nougat, the Palette API was born. It allows you to extract prominent colors from images to help you create visually engaging apps. Mobile apps like WhatsApp leverage it (see the contact details page) and whether you are building an application following material design spec or not, that’s a really powerful feature you can make use of.

Today, I’m excited to announce react-native-material-palette, a library which wraps the Palette API in a nice JS API to use in React Native.

Which colors can I get?

According to the specification, the palette API defines by default six color profiles for a given image, being those:

  • Light Vibrant
  • Vibrant
  • Dark Vibrant
  • Light Muted
  • Muted
  • Dark Muted

Probably that sounds to you like a hieroglyph, like it did for me the first time I saw them. Let’s try to get a better insight by understanding how are they calculated.

The profiles are determined by analyzing the HSL (Hue, Saturation and Luminosity) color profile of the pixels on the image, based on predefined target ranges for luminance, saturation, and population (how many pixels in the image are represented by that particular profile). It uses a weighted average calculation with preference given to luminance, then it comes saturation and finally population.

Generally speaking, vibrant colors are more saturated than muted colors and the light/dark variations of the profiles operate on luminosity.

Enough technicalities, let’s move to the library itself.

The React Native module

Let me highlight some of the features the library offers in terms of implementation details.

Kotlin

Since Google announced on their keynote the support of Kotlin as first class language for developing Android apps, we wanted to give it a try for implementing the native part. Kotlin is certainly an awesome language to work with, very easy to set up and the runtime library is less than 1KB. Also, as of RN 0.47, react-native link works for modules developed in Kotlin, so you don’t have to worry about manually setting up project dependencies.

100% test coverage

We have created this library having in mind robustness but also future external contributions. The JS logic is fully tested with Jest, so not only we make sure the functionality works as expected, but also external contributions can be speeded up by just committing to the test suite we put into place.

Caching

We use Fresco on the native side to automatically cache images downloaded from the internet, so that we have a good performance in our applications.

Use cases

Our API supports basically two use cases, which are image galleries and styling screen color schemes based on a particular image. A picture paints a thousand words so here you have a visual cue of what you can achieve with the library:

Image gallery library material pallet

Styling screen color scheme based on an image

Styling screen color screen

Future plans

There are still some limitations that we are planning to overcome for the upcoming future:

iOS support

At the moment the library only supports Android. However it’s feasible to extend the functionality to iOS as well, since the algorithm is open source and there’s been already successful attempts to port it to other environments, such as web. If you would like to help out on that, PRs are more than welcome!

Customizing your own profiles

The API provides six color targets by default. Sometimes, a given image has no colors fulfilling the criteria of the predefined profiles. It’d be useful to define some custom targets in addition to the existing ones, with different weighting and target lightness and saturation values, in order to increase the chance of finding a useful color. It’s in our roadmap to support that as well.

Example app

You can find the whole API in the github repository. We also have an example app available for you so that you can play with it immediately :)

What are you waiting for? Take the brush and enjoy! You can also discover services offered by our React Native development company.

Insights

Learn more about Open Source

cover

Aug 7Article

Visualizing Open Source Licenses to Analyze Compliance and Reduce Legal Risk

Discover how license-kit visualize maps and analyzes your dependency graph, helping you spot license issues, duplicates, and restrictive packages with interactive views, stats, and AI-powered summaries.

cover

Mar 26Podcast

How Definitely Typed Changed TypeScript Forever

Discover the story behind Definitely Typed with its creator, Boris Yankov, and learn how it became essential for type-safe JavaScript in the TypeScript ecosystem.

cover

Oct 14Article

Introducing the OMH Cloud Storage Module

Discover the OMH Cloud Storage Module. This open-source solution simplifies cloud storage integration for React Native apps.

cover

Jul 12Article

Introduction to the React Native OMH Maps Library

Discover how the React Native OMH Maps library simplifies map integration with cross-platform compatibility, ease of use, and customization options.

cover

Apr 22Podcast

Behind the Scenes of React Native 0.74 Release

Join the release crew members to find out what new features and improvements React Native 0.74 brings to the cross-platform development world.

cover

Apr 27Podcast

Callstack OSS Update

April 2023 Callstack OSS Update: RFC for Expo Config Plugins, Re.Pack & Paper news.

cover

Dec 6Article

React Native Paper 5.0 - What’s New?

React Native Paper 5.0 is here! Dive into the latest updates and improvements.

cover

Feb 8Article

Stripe React Native: the Most Common Questions - Tipsi Migration Guide, Part 5

Check out the list of the most common questions about Stripe react Native Library prepared by Jakub Kłobus, software engineer at Callstack.

cover

Feb 6Article

Stripe React Native Migration Function by Function - Tipsi Migration Guide, Part 3

In the third part of the Tipsi Migration Guide we describe the Stripe React Native migration function by function.

cover

Mar 19Tutorial

The Hard Way vs. The React Native AI SDK Way: Stop Writing Custom Modules for Every Model

Learn how React Native AI uses a unified provider model to switch between cloud and on-device LLMs without rewriting application logic, enabling reliable AI experiences online and offline.

cover

Mar 12Tutorial

Build Smarter Apps: Tool Calling & AI Orchestration Explained

Learn how on-device models in React Native can call tools, interact with external APIs, and return structured outputs you can use directly in application logic.

cover

Mar 5Tutorial

MLC LLM + React Native: On-Device AI Without the Pain

Learn how to run third-party on-device LLMs in React Native using MLC LLM. Choose your models, run them efficiently across platforms, and keep a unified JavaScript API with React Native AI.

cover

Feb 24Tutorial

Intelligent Fallbacks with Apple Intelligence in React Native

Learn how to use Apple’s built-in Foundation Models in React Native apps, reduce memory usage, and enable fast, fully on-device AI with React Native AI Apple.

cover

Feb 10Tutorial

What Is the React Native AI SDK? A Complete Intro & Quickstart

Learn why on-device AI matters for React Native apps, how local LLMs behave offline, and what problems React Native AI is designed to solve from day one.

cover

Jan 29Tutorial

Implementing an Android TurboModule with Kotlin

Learn how to implement a React Native TurboModule on Android, from the TypeScript spec and Codegen to the Kotlin implementation and package registration.

cover

Jan 19Tutorial

Working with Different Threads in Swift TurboModules

Learn how JavaScript, native module, background, and main threads interact in React Native TurboModules, and how to use GCD queues to run async work safely in Swift.

cover

Jan 9Tutorial

How to Add Type-Safe Constants to Swift TurboModules

Learn how to expose typed, immutable constants from a Swift TurboModule using Codegen, and get full end-to-end type safety between native and JavaScript.

cover

Dec 30Tutorial

Adding Event Emitters to Your TurboModule in Swift

Learn how to emit native events from a Swift TurboModule and subscribe to them in JavaScript, including proper memory management and Codegen integration.

cover

Dec 22Tutorial

Writing Your First TurboModule in Swift

Learn how to build a fully working TurboModule in Swift, integrate it with Codegen, and bridge it through Objective‑C inside an Expo app.