0
0
React Nativemobile~20 mins

ScrollView component in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ScrollView Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
ScrollView content visibility
What will be visible on the screen when this React Native ScrollView renders?
React Native
import React from 'react';
import { ScrollView, Text, View } from 'react-native';

export default function App() {
  return (
    <ScrollView style={{height: 100}}>
      <View style={{height: 50, backgroundColor: 'red'}}><Text>Red Box</Text></View>
      <View style={{height: 50, backgroundColor: 'green'}}><Text>Green Box</Text></View>
      <View style={{height: 50, backgroundColor: 'blue'}}><Text>Blue Box</Text></View>
    </ScrollView>
  );
}
AOnly the Red and Green boxes are visible; Blue box is hidden until scrolled.
BOnly the Red box is visible; Green and Blue boxes are clipped and not scrollable.
CAll three boxes (Red, Green, Blue) are visible at once without scrolling.
DThe ScrollView will not render any boxes due to missing flex styles.
Attempts:
2 left
💡 Hint
The ScrollView height limits visible content; content larger than height can be scrolled.
lifecycle
intermediate
2:00remaining
ScrollView onScroll event behavior
Which option correctly describes what happens when the user scrolls the ScrollView below?
React Native
import React, { useState } from 'react';
import { ScrollView, Text } from 'react-native';

export default function App() {
  const [scrollY, setScrollY] = useState(0);

  return (
    <ScrollView onScroll={event => setScrollY(event.nativeEvent.contentOffset.y)} scrollEventThrottle={16} style={{height: 100}}>
      <Text style={{height: 300}}>Scroll me</Text>
      <Text>Scrolled Y: {scrollY.toFixed(0)}</Text>
    </ScrollView>
  );
}
AThe scrollY state updates but shows horizontal scroll position instead of vertical.
BThe scrollY state updates only once when scrolling starts, then stops updating.
CThe scrollY state never updates because onScroll requires a different event prop.
DThe scrollY state updates continuously as the user scrolls, showing the vertical scroll position.
Attempts:
2 left
💡 Hint
scrollEventThrottle controls how often onScroll fires during scrolling.
navigation
advanced
2:00remaining
ScrollView nested inside another ScrollView
What happens when you nest a vertical ScrollView inside another vertical ScrollView as shown below?
React Native
import React from 'react';
import { ScrollView, Text, View } from 'react-native';

export default function App() {
  return (
    <ScrollView style={{height: 200}}>
      <Text>Outer ScrollView Content</Text>
      <ScrollView style={{height: 100}}>
        <Text>Inner ScrollView Content</Text>
        <View style={{height: 300, backgroundColor: 'lightgray'}} />
      </ScrollView>
    </ScrollView>
  );
}
ABoth ScrollViews scroll simultaneously causing erratic scrolling behavior.
BScrolling inside the inner ScrollView works independently; outer ScrollView scrolls only when inner is at top or bottom.
CScrolling inside the inner ScrollView is disabled; only outer ScrollView scrolls.
DThe app crashes due to nested ScrollViews with vertical orientation.
Attempts:
2 left
💡 Hint
Nested ScrollViews handle scroll gestures with gesture responder system.
📝 Syntax
advanced
2:00remaining
Correct ScrollView horizontal scrolling syntax
Which option correctly enables horizontal scrolling in a React Native ScrollView?
React Native
import React from 'react';
import { ScrollView, Text } from 'react-native';

export default function App() {
  return (
    <ScrollView horizontal={true} style={{height: 100}}>
      <Text style={{width: 300}}>Swipe me horizontally</Text>
    </ScrollView>
  );
}
Ahorizontal={true}
BscrollDirection="horizontal"
Cdirection="horizontal"
DenableHorizontalScroll={true}
Attempts:
2 left
💡 Hint
Check the official ScrollView props for horizontal scrolling.
🔧 Debug
expert
2:00remaining
Why does ScrollView content not scroll on Android?
Given this ScrollView code, why might the content not scroll on Android devices?
React Native
import React from 'react';
import { ScrollView, Text, View } from 'react-native';

export default function App() {
  return (
    <ScrollView style={{flex: 1}}>
      <View style={{height: 300}}><Text>Box 1</Text></View>
      <View style={{height: 300}}><Text>Box 2</Text></View>
    </ScrollView>
  );
}
AAndroid does not support ScrollView with flex: 1 style.
BScrollView requires the prop scrollEnabled={true} explicitly on Android.
CThe parent container does not have a fixed height, so ScrollView expands and disables scrolling.
DThe View components inside ScrollView must have flex: 1 to enable scrolling.
Attempts:
2 left
💡 Hint
ScrollView needs a bounded height to know when to scroll.