Challenge - 5 Problems
ScrollView Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2: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> ); }
Attempts:
2 left
💡 Hint
The ScrollView height limits visible content; content larger than height can be scrolled.
✗ Incorrect
The ScrollView has a fixed height of 100. Each box is 50 height, so only two boxes fit without scrolling. The third box is hidden until user scrolls.
❓ lifecycle
intermediate2: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> ); }
Attempts:
2 left
💡 Hint
scrollEventThrottle controls how often onScroll fires during scrolling.
✗ Incorrect
onScroll fires repeatedly during scrolling. The event's nativeEvent.contentOffset.y gives vertical scroll offset, which updates scrollY state.
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> ); }
Attempts:
2 left
💡 Hint
Nested ScrollViews handle scroll gestures with gesture responder system.
✗ Incorrect
The inner ScrollView scrolls independently. When inner reaches top or bottom, outer ScrollView can scroll. This prevents gesture conflicts.
📝 Syntax
advanced2: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> ); }
Attempts:
2 left
💡 Hint
Check the official ScrollView props for horizontal scrolling.
✗ Incorrect
The ScrollView prop to enable horizontal scrolling is horizontal={true}. Other props do not exist or have no effect.
🔧 Debug
expert2: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> ); }
Attempts:
2 left
💡 Hint
ScrollView needs a bounded height to know when to scroll.
✗ Incorrect
If ScrollView's parent or itself expands to full height without limit, it shows all content without scrolling. On Android, flex:1 alone may cause this if parent has no height limit.