Open In App

React Native Pressable Component

Last Updated : 07 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UIs for both platforms.

Prerequisites:

In this article, We are going to see how to use Pressable component of react-native. Pressable acts a wrapper to the component inside it. Pressable uses React Native’s Pressability API. 

In our project we will wrap text and image separately with Pressable component to show its functionality. We will see the approach step-by-step.

Creating React Native App:

Step 1: Create a react-native project:

npx react-native init DemoProject

Step 2: Start the server using the following command:

npx react-native run-android

Step 3: Now go to your project and create a components folder. Inside the components folder, create a file PressableComponent.js.

Project Structure: The project should look like this:

Projject Structure

Copy Generated Ide URL

App.js




import React from 'react';
import type { Node } from 'react';
import { View } from 'react-native';
import PressableExample from './components/PressableComponent';
  
const App: () => Node = () => {
  return (
    <View>
      <PressableExample />
    </View>
  );
};
  
export default App;


Step to run the application: Run the application using the following command:

npx react-native run-android

Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads