Challenge - 5 Problems
Parallax Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediateWhat is the visible effect of this parallax scroll code?
Consider a React Native ScrollView with an Animated.Image that moves slower than the scroll content. What visual effect will the user see when scrolling?
React Native
import React from 'react'; import { Animated, ScrollView, View, Text, Dimensions } from 'react-native'; const { height } = Dimensions.get('window'); export default function ParallaxExample() { const scrollY = React.useRef(new Animated.Value(0)).current; const translateY = scrollY.interpolate({ inputRange: [0, height], outputRange: [0, -height / 2], extrapolate: 'clamp', }); return ( <View style={{ flex: 1 }}> <Animated.Image source={{ uri: 'https://example.com/image.jpg' }} style={{ height: height / 2, width: '100%', transform: [{ translateY }] }} accessibilityLabel="Background parallax image" /> <ScrollView onScroll={Animated.event( [{ nativeEvent: { contentOffset: { y: scrollY } } }], { useNativeDriver: true } )} scrollEventThrottle={16} style={{ flex: 1, marginTop: height / 2 }} > <Text style={{ fontSize: 24, padding: 20 }}>Scroll Content</Text> <View style={{ height: 1000 }} /> </ScrollView> </View> ); }
Attempts:
2 left
💡 Hint
Think about how the translateY value changes relative to scrollY.
✗ Incorrect
The image's translateY moves at half the speed of the scroll, so it lags behind the content, creating a parallax depth effect.
❓ lifecycle
intermediateWhen does the Animated.event listener update the parallax effect?
In React Native, when using Animated.event with useNativeDriver:true on ScrollView's onScroll, when is the scrollY Animated.Value updated?
Attempts:
2 left
💡 Hint
Consider what useNativeDriver:true does to animation updates.
✗ Incorrect
With useNativeDriver:true, the animation updates run on the native UI thread continuously during scrolling, ensuring smooth parallax effect.
🔧 Debug
advancedWhy does this parallax image flicker or jump during scroll?
Given this code snippet, the parallax image flickers or jumps unexpectedly during scroll.
const translateY = scrollY.interpolate({
inputRange: [0, height],
outputRange: [0, -height / 2],
extrapolate: 'extend',
});
React Native
const translateY = scrollY.interpolate({
inputRange: [0, height],
outputRange: [0, -height / 2],
extrapolate: 'extend',
});Attempts:
2 left
💡 Hint
Check how extrapolate affects values outside the input range.
✗ Incorrect
'extrapolate: extend' allows values beyond inputRange, which can cause sudden jumps if scrollY goes beyond expected range. 'clamp' prevents this by limiting output values.
advanced
How to preserve parallax scroll position when navigating back?
In a React Native app with parallax scrolling on a screen, how can you preserve the scroll position and parallax effect when navigating back to that screen?
Attempts:
2 left
💡 Hint
Think about how to keep scroll position across navigation events.
✗ Incorrect
Saving scrollY in a shared state or context and restoring it on screen focus keeps the scroll and parallax consistent when returning.
🧠 Conceptual
expertWhy is useNativeDriver recommended for parallax animations?
Why should you use useNativeDriver:true in Animated.event for parallax scrolling animations in React Native?
Attempts:
2 left
💡 Hint
Consider performance and thread usage in React Native animations.
✗ Incorrect
useNativeDriver:true runs animations on the native UI thread, avoiding JS thread bottlenecks and improving smoothness of parallax effects.
