0
0
React Nativemobile~20 mins

Parallax scrolling in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parallax Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What 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>
  );
}
AThe background image moves slower than the scroll content, creating a depth effect.
BThe background image moves faster than the scroll content, making it appear in front.
CThe background image stays fixed and does not move during scrolling.
DThe background image disappears when scrolling starts.
Attempts:
2 left
💡 Hint
Think about how the translateY value changes relative to scrollY.
lifecycle
intermediate
1:30remaining
When 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?
AContinuously during scrolling, on every frame, without blocking the JS thread.
BOnly once when scrolling starts, then stops updating.
CAfter scrolling ends, in a batch update.
DOnly when the user lifts their finger from the screen.
Attempts:
2 left
💡 Hint
Consider what useNativeDriver:true does to animation updates.
🔧 Debug
advanced
2:30remaining
Why 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',
});
AThe inputRange values are reversed and should be [height, 0].
BUsing 'extrapolate: extend' causes values outside inputRange to produce unexpected jumps.
CThe outputRange values must be positive numbers for translateY.
DThe scrollY Animated.Value is not initialized properly.
Attempts:
2 left
💡 Hint
Check how extrapolate affects values outside the input range.
navigation
advanced
3:00remaining
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?
AReset scrollY to zero on every screen mount to avoid glitches.
BDisable parallax effect when navigating back to improve performance.
CStore scrollY value in a state or context and restore it on screen focus.
DUse a static image instead of Animated.Image to avoid scroll position issues.
Attempts:
2 left
💡 Hint
Think about how to keep scroll position across navigation events.
🧠 Conceptual
expert
2:30remaining
Why is useNativeDriver recommended for parallax animations?
Why should you use useNativeDriver:true in Animated.event for parallax scrolling animations in React Native?
AIt disables user interaction during animations to prevent glitches.
BIt enables animations to run only when the app is in the foreground.
CIt automatically caches images used in parallax backgrounds.
DIt offloads animation calculations to native UI thread, making animations smoother and less janky.
Attempts:
2 left
💡 Hint
Consider performance and thread usage in React Native animations.