DEV Community

Cover image for A carousel example in React Native with zero dependencies
Axel Navarro for Cloud(x);

Posted on

9 1

A carousel example in React Native with zero dependencies

We can create a carousel in React Native using the built-in ScrollView component in horizontal mode.

Carousel demo

The ScrollView renders all its react child components vertically, but we can arrange them horizontally in a row using:



<ScrollView horizontal>


Enter fullscreen mode Exit fullscreen mode

In this example, we show how to overlap the Image component on the header to get a cool effect. The touch is so fluid and fast that the user has a sense of a highly performance application.

I made the example using Expo just to keep it simple to run and focus in the JavaScript and the style sheet.

the entire carousel fit in one component, and the main parts are explained in the README.

You can check the code example in the repository

GitHub logo navarroaxel / react-native-scrollview-carousel-example

The simplest carousel example in React Native using ScrollView horizontal

react-native-scrollview-carousel-example

The simplest carousel example in React Native using the built-in ScrollView in horizontal mode.

Carousel demo

Setting up the development environment

Install the Expo CLI command line utility:

npm install -g expo-cli
Enter fullscreen mode Exit fullscreen mode

Clone the repository and install the dependencies:

git clone https://github.com/navarroaxel/react-native-scrollview-carousel-example.git
cd react-native-scrollview-carousel-example
npm install
Enter fullscreen mode Exit fullscreen mode

Trying the example app

Start the local dev server for the app:

npm start
Enter fullscreen mode Exit fullscreen mode

Then, follow the expo instructions to open the app in your phone or emulator.

How does ScrollView work?

The ScrollView renders all its react child components vertically, but we can arrange them horizontally in a row using:

<ScrollView horizontal>
Enter fullscreen mode Exit fullscreen mode

In this example, we show how to overlap the Image component on the header to get a cool effect. The touch is so fluid and fast that the user has a sense of a highly performance application.

Performance issues

The ScrollView renders all its react child components. If you need…

What carousel component do you use in your app? leave a comment about this!

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools 🔁

Top comments (1)

Collapse
 
gabriiell profile image
Gabriiell

Awesome!

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more