How to add Color Picker in React Native ?
Last Updated :
31 Jul, 2024
React Native is a popular cross-platform framework for mobile app development using JavaScript. It enables code reuse for iOS and Android platforms and frequently involves incorporating a color picker component. In this article, we'll see how to add a color picker in React native application by using the react-native-color-picker library
A color picker component is commonly used in mobile app development to allow users to choose and interact with colors visually. The `react-native-color-picker` library offers a customizable solution for implementing a color picker component in React Native apps.
Prerequisites
Creating React Native App
Step 1: Install Expo CLI globally by running this command in your terminal: It only works on version v46.0.0
npm install -g [email protected]
Step 2: Create React Native Application With Expo CLI
expo init color-picker-native
Step 3: Navigate to the project directory by using this command:
cd color-picker-native
Project Structure

Step 4: Install Required Dependencies
npm install react-native-color-picker
Approach
To add a color picker in a React Native app, follow these steps: Set up a React Native project, install the `react-native-color-picker` library, import components and define the `ColorPicker` component, create a reference with `useRef`, implement color selection and clipboard functions, render the color picker and run the app.
JavaScript
import React, { useRef } from 'react';
import { StyleSheet, Text, View, Clipboard,
TextInput } from 'react-native';
import { ColorPicker } from 'react-native-color-picker';
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f5f5f5',
alignItems: 'center',
justifyContent: 'center',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
},
colorPicker: {
width: 300,
height: 500,
borderRadius: 10,
marginBottom: 20,
},
input: {
color: 'black',
fontWeight: 'bold',
fontSize: 20,
},
});
export default function App() {
const colorPickerRef = useRef(null);
const handleColorSelected = (color) => {
// Copy the color to the clipboard
Clipboard.setString(color);
// Alert the user
alert(`Color selected: ${color} (Copied to clipboard)`);
};
return (
<View style={styles.container}>
<Text style={styles.title}>Color Picker</Text>
<ColorPicker
ref={colorPickerRef}
onColorSelected={handleColorSelected}
style={styles.colorPicker}
/>
<TextInput
style={styles.input}
placeholder="Paste The Color Code"
/>
</View>
);
}
Step 6: To run the react native application, open the Terminal and enter the command listed below.
npx expo start
To run on Android:
npx react-native run-android
To run on Ios:
npx react-native run-ios
Output:
Similar Reads
How to Create Emoji Picker in React Native ? React Native is a popular cross-platform framework for mobile app development. Emojis have become common in modern applications, providing personalization and enhancing user engagement. In this article, we'll see how we can add an emoji picker to a React Native application.React Native doesn't have
3 min read
How to add Floating Buttons in React Native ? React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows, and UWP by enabling developers to use the React framework along with native platform capabilities.In this article, we will
2 min read
React Native Picker Component In this article, We are going to see how to create a picker in react-native. For this, we are going to use the Picker component. It is used to select a particular item from multiple given options. Basically, it's just like a dropdown list.Syntax:<Picker> <Picker.Item /> <Picker.Item /
3 min read
How to get user preferred color scheme in React Native ? React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows, and UWP by enabling developers to use the React framework along with native platform capabilities. In this article, we wil
2 min read
How to Add Phone Number Input in React Native ? React Native is a JavaScript framework for cross-platform mobile app development. In this article, we'll see how to add a phone number input field in a React Native app using Expo CLI.âAdding a phone number input field in React Native is helpful for collecting user phone numbers during registration
3 min read
How to Create Calendar App in React Native ? In this article, we will see how to add a Calendar to a React Native App. Discover how to enhance your React Native application by integrating a calendar using the powerful react-native-calendars library. With React Native's ability to facilitate cross-platform mobile app development using JavaScrip
7 min read