Lädt...

🔧 Parallax Scroll Effect in React Native with Reanimated


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Introduction

Parallax scrolling is a popular animation technique that creates an illusion of depth by making background images move slower than foreground images. In this tutorial, we will build a beautiful Parallax Scroll Effect in React Native using react-native-reanimated. This effect is great for enhancing the user experience, especially in image carousels, onboarding screens, or feature showcases.

Image description

import {Dimensions, StyleSheet, View} from 'react-native';
import React from 'react';
import {metaData} from '../../screens/CarouselBackgroundAnimation/data';
import Animated, {
  interpolate,
  useAnimatedScrollHandler,
  useAnimatedStyle,
  useSharedValue,
} from 'react-native-reanimated';

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

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

const ParallaxView = () => {
  const scrollX = useSharedValue(0);
  const onScroll = useAnimatedScrollHandler(e => {
    scrollX.value = e.contentOffset.x / (_imageWidth + _spacing);
  });
  return (
    <View style={styles.container}>
      <Animated.FlatList
        data={metaData}
        renderItem={({item, index}) => (
          <Photo item={item} index={index} scrollX={scrollX} />
        )}
        horizontal
        style={{flexGrow: 0}}
        pagingEnabled
        snapToInterval={_imageWidth + _spacing}
        decelerationRate={'fast'}
        contentContainerStyle={{
          gap: _spacing,
          paddingHorizontal: (width - _imageWidth) / 2,
        }}
        showsHorizontalScrollIndicator={false}
        onScroll={onScroll}
        scrollEventThrottle={1000 / 60}
      />
    </View>
  );
};

export default ParallaxView;

const Photo = ({item, index, scrollX}) => {
  const styleZ = useAnimatedStyle(() => {
    return {
      transform: [
        {
          scale: interpolate(
            scrollX.value,
            [index - 1, index, index + 1],
            [1.4, 1, 1.4],
          ),
        },
        {
          rotate: `${interpolate(
            scrollX.value,
            [index - 1, index, index + 1],
            [5, 0, 5],
          )}deg`,
        },
      ],
    };
  });
  return (
    <View
      style={{
        width: _imageWidth,
        height: _imageHeight,
        overflow: 'hidden',
        borderRadius: 16,
      }}>
      <Animated.Image source={{uri: item}} style={[{flex: 1}, styleZ]} />
    </View>
  );
};

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

Conclusion

In this tutorial, we built a Parallax Scroll Effect in React Native using react-native-reanimated. This technique enhances the visual appeal of image carousels, making the user experience more immersive.

Key Takeaways:

  • Used useSharedValue to track the scroll position.
  • Created an animated transformation using interpolate.
  • Applied smooth scaling and rotation effects.

This is just the beginning! You can further customize this effect by adding more animations like opacity changes, blur effects, or background parallax layers.

Happy coding! 🚀

...

🔧 Parallax Scroll Effect in React Native with Reanimated


📈 80.35 Punkte
🔧 Programmierung

🔧 Buttery-Smooth Scroll Animations: Building a High-Performance Canvas Parallax Effect


📈 44.14 Punkte
🔧 Programmierung

🔧 ✨ 2 Parallax Background Effects in CSS - Simple &amp; Horizontal Parallax : Part1


📈 41.76 Punkte
🔧 Programmierung

🎥 Add Scroll Shadows to a Scroll Container | Unleash the power of Scroll-Driven Animations (6/10)


📈 39.36 Punkte
🎥 Video | Youtube

🔧 React Native Reanimated 3: The Ultimate Guide to High-Performance Animations in 2025 🚀


📈 36.22 Punkte
🔧 Programmierung

🔧 Worklets and Threading in Reanimated for Smooth Animations in React Native


📈 36.22 Punkte
🔧 Programmierung

🔧 Implementing Load More Animation in React Native with Reanimated and Lottie


📈 36.22 Punkte
🔧 Programmierung

🔧 🚀 Implementing Pull-to-Refresh in React Native with Reanimated and Lottie 🎉


📈 36.22 Punkte
🔧 Programmierung

🔧 Creating a Smooth Animated Vertical List in React Native with Reanimated


📈 36.22 Punkte
🔧 Programmierung

🔧 Enhancing React Native Animations with Reanimated: A Step-by-Step Guide


📈 36.22 Punkte
🔧 Programmierung

🔧 Enhancing Your React Native App with Reanimated 3 Using Expo


📈 36.22 Punkte
🔧 Programmierung

🕵️ CVE-2022-24373 | react-native-reanimated up to 2.x Parser Colors.js incorrect regex


📈 36.22 Punkte
🕵️ Sicherheitslücken

🔧 Parallax image scroll speed with Nuxt 3 and GSAP 🛣️✨


📈 34 Punkte
🔧 Programmierung

🔧 Parallax Website with Scroll-Triggered Animations


📈 34 Punkte
🔧 Programmierung

🔧 Parallax using scroll driven animations


📈 34 Punkte
🔧 Programmierung

🔧 Professional Smooth Scroll with Locomotive-Scroll, Astro, and React


📈 31.49 Punkte
🔧 Programmierung

🔧 3D Parallax Hover Effect Using TailwindCSS


📈 31.02 Punkte
🔧 Programmierung

🔧 Exploring the Parallax Effect in Web Design


📈 31.02 Punkte
🔧 Programmierung

🔧 Blurry Card with Parallax Effect 💳


📈 31.02 Punkte
🔧 Programmierung

🔧 Slider Parallax Effect


📈 31.02 Punkte
🔧 Programmierung

🔧 An iPhone workaround broke my parallax scrolling effect 📵💔


📈 31.02 Punkte
🔧 Programmierung

🔧 Understanding the Parallax Effect: A Comprehensive Guide


📈 31.02 Punkte
🔧 Programmierung

🔧 How to make a Parallax Effect with Html, Css and JS


📈 31.02 Punkte
🔧 Programmierung

🔧 Implement Smooth Scrolling &amp; Parallax Effect in Next.js using Lenis and GSAP


📈 31.02 Punkte
🔧 Programmierung

📰 Early Windows 10 Redstone 3 Pics Show Eye-Candy UI, iPhone-Like Parallax Effect


📈 31.02 Punkte
📰 IT Security Nachrichten

matomo