Lädt...

🔧 Building a Beautiful Carousel with Left-Right Partial Visibility in React Native


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Carousels are a fantastic way to showcase images, product listings, or content in a sleek, interactive manner. In this blog, we'll build a React Native Carousel that allows users to scroll horizontally while keeping partial visibility of the next and previous images—a design commonly seen in modern UI/UX.

Image description

What We'll Build
We will use FlatList to create a horizontally scrollable carousel where:

✔ The currently selected image is centered.
✔ The previous and next images remain partially visible.
✔ The scrolling feels smooth and snaps to each image perfectly.

import {Dimensions, FlatList, Image, StyleSheet, View} from 'react-native';
import React from 'react';
import {metaData} from '../../screens/CarouselBackgroundAnimation/data';

const {width} = Dimensions.get('screen');

const _imageWidth = width * 0.7;
const _imageHeight = _imageWidth * 1.76;
const _spacing = 12;

const CarouselWithLeftRightPartialVisible = () => {
  return (
    <View style={styles.container}>
      <FlatList
        data={metaData}
        renderItem={(item, index) => <Photo item={item} index={index} />}
        horizontal
        style={{flexGrow: 0}}
        pagingEnabled
        snapToInterval={_imageWidth + _spacing}
        decelerationRate={'fast'}
        contentContainerStyle={{
          gap: _spacing,
          paddingHorizontal: (width - _imageWidth) / 2,
        }}
        showsHorizontalScrollIndicator={false}
      />
    </View>
  );
};

export default CarouselWithLeftRightPartialVisible;

const Photo = ({item, index}) => {
  return (
    <View
      style={{
        width: _imageWidth,
        height: _imageHeight,
        overflow: 'hidden',
        borderRadius: 16,
      }}>
      <Image source={{uri: item.item}} style={{flex: 1, resizeMode: 'cover'}} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});

Enhancements & Customization Ideas

Want to take it further? Here are some improvements:

🔹 Auto-scrolling: Add an interval to slide automatically.
🔹 Indicators: Show small dots to indicate the current position.
🔹 Animations: Use react-native-reanimated for smooth transitions.
🔹 Click Events: Allow users to tap and enlarge an image.

Conclusion

In this tutorial, we built a modern horizontal carousel in React Native with a partially visible left and right design. We used FlatList, snapToInterval, and simple styles to achieve a beautiful and smooth scrolling effect.

🚀 Try it in your own projects and tweak it to match your app's design!

👉 What’s next? Drop a comment if you want more tutorials on animations, gestures, or UI components in React Native. 🎨🔥

Happy coding! 🚀

...

🔧 Building a Stunning Animated Image Carousel in React Native


📈 33.51 Punkte
🔧 Programmierung

🕵️ Low CVE-2015-9434: Kiwi-logo-carousel project Kiwi-logo-carousel


📈 31.9 Punkte
🕵️ Sicherheitslücken

🔧 React Native Animation: Building Play/Pause Controls with Lottie in React Native


📈 29.85 Punkte
🔧 Programmierung

🔧 Building a Modern Document Website for React Native Library Like React Native ECharts


📈 29.85 Punkte
🔧 Programmierung

🔧 Add a Beautiful Product Carousel to Your WooCommerce Store in Minutes


📈 29 Punkte
🔧 Programmierung

🔧 React Native Carousel With Pagination, Auto Play and Infinite Loop Fully Customisable


📈 28.24 Punkte
🔧 Programmierung

🔧 ⚡ MySecondApp - React Native with Expo (P3)- Add Slide Carousel


📈 28.24 Punkte
🔧 Programmierung

🔧 Architecture Guide: Building Scalable React (or React Native) Apps with Zustand &amp; React Query


📈 28.07 Punkte
🔧 Programmierung

🔧 Implementing infinite scroll in React with React Snap Carousel


📈 26.46 Punkte
🔧 Programmierung

🔧 Zenml for beautiful beautiful orchestration pt 3: Mlflow Aliases/Tags


📈 26.09 Punkte
🔧 Programmierung

🔧 Zenml for beautiful beautiful orchestration


📈 26.09 Punkte
🔧 Programmierung

🍏 Acefast Fast Charge Power Bank M1 review: Beautiful exterior with a not so beautiful price


📈 26.09 Punkte
🍏 iOS / Mac OS

🔧 ✨ [18] - 🔥 Build a Beautiful Login Screen in React Native Expo | Step-by-Step Guide 🔥


📈 25.33 Punkte
🔧 Programmierung

🔧 Detecting Page Visibility Changes with the Page Visibility API


📈 24.66 Punkte
🔧 Programmierung

🔧 #🔥 React Native Auto Skeleton – Lightweight Skeleton Loader for React Native


📈 24.58 Punkte
🔧 Programmierung

🔧 Integrate DeepSeek AI into React Native app: Full guide for Generative AI in React Native


📈 24.58 Punkte
🔧 Programmierung

🔧 What's New in React Native 0.78: Performance, Native Integration, and React 19 Support 🚀


📈 24.58 Punkte
🔧 Programmierung

🔧 🚀 TaskMate: A Simple React Native To-Do App Built with React Native &amp; Expo 📝


📈 24.58 Punkte
🔧 Programmierung

🔧 Implementing Long Press Functionality Using React Native Gesture Handler in React Native Application


📈 24.58 Punkte
🔧 Programmierung

🔧 How to Implement Face Detection in React Native Using React Native Vision Camera


📈 24.58 Punkte
🔧 Programmierung

🔧 React Native Networking – How To Perform API Requests In React Native using the FetchAPI


📈 24.58 Punkte
🔧 Programmierung

🔧 The State of React Native Tooling (React Native CLI - The Ultimate Guide)


📈 24.58 Punkte
🔧 Programmierung

matomo