0
0
React Nativemobile~20 mins

Gesture Handler integration in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gesture Handler Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when you tap the button wrapped with TapGestureHandler?

Consider this React Native code using Gesture Handler:

import { TapGestureHandler } from 'react-native-gesture-handler';
import { View, Text } from 'react-native';

export default function App() {
  const onSingleTap = () => alert('Tapped!');

  return (
    
      
        Tap me
      
    
  );
}

What is the expected behavior when the user taps the text?

React Native
import { TapGestureHandler } from 'react-native-gesture-handler';
import { View, Text } from 'react-native';

export default function App() {
  const onSingleTap = () => alert('Tapped!');

  return (
    <TapGestureHandler onActivated={onSingleTap}>
      <View style={{ padding: 20, backgroundColor: '#ddd' }}>
        <Text>Tap me</Text>
      </View>
    </TapGestureHandler>
  );
}
AThe text changes color but no alert appears.
BAn alert with message 'Tapped!' appears when the user taps the text.
CNothing happens because TapGestureHandler requires a double tap to activate.
DThe app crashes because onActivated is not a valid prop for TapGestureHandler.
Attempts:
2 left
💡 Hint

Check the onActivated prop of TapGestureHandler and what it triggers.

lifecycle
intermediate
2:00remaining
When does the onGestureEvent callback fire in PanGestureHandler?

In React Native Gesture Handler, the PanGestureHandler has an onGestureEvent prop.

When does this callback get called?

React Native
import { PanGestureHandler } from 'react-native-gesture-handler';
import { View } from 'react-native';

export default function App() {
  const onGestureEvent = event => {
    console.log('Gesture event:', event.nativeEvent.translationX);
  };

  return (
    <PanGestureHandler onGestureEvent={onGestureEvent}>
      <View style={{ flex: 1, backgroundColor: '#eee' }} />
    </PanGestureHandler>
  );
}
AIt fires continuously as the user moves their finger during the pan gesture.
BIt fires only once when the pan gesture starts.
CIt fires only when the pan gesture ends.
DIt never fires unless the gesture is a double tap.
Attempts:
2 left
💡 Hint

Think about how dragging your finger on the screen updates position continuously.

📝 Syntax
advanced
2:00remaining
Which code correctly imports and wraps the app with GestureHandlerRootView?

To use React Native Gesture Handler properly, the app root must be wrapped with GestureHandlerRootView.

Which option shows the correct import and usage?

A
import { GestureHandlerRootView } from 'react-native-gesture-handler';

export default function App() {
  return (
    &lt;View style={{ flex: 1 }}&gt;
      &lt;GestureHandlerRootView&gt;
        {/* app content */}
      &lt;/GestureHandlerRootView&gt;
    &lt;/View&gt;
  );
}
B
import GestureHandlerRootView from 'react-native-gesture-handler';

export default function App() {
  return (
    &lt;GestureHandlerRootView style={{ flex: 1 }}&gt;
      {/* app content */}
    &lt;/GestureHandlerRootView&gt;
  );
}
C
import { GestureHandlerRootView } from 'react-native-gesture-handler';

export default function App() {
  return (
    &lt;GestureHandlerRootView style={{ flex: 1 }}&gt;
      {/* app content */}
    &lt;/GestureHandlerRootView&gt;
  );
}
D
import { GestureHandlerRootView } from 'react-native-gesture-handler';

export default function App() {
  return (
    &lt;GestureHandlerRootView&gt;
      {/* app content */}
    &lt;/GestureHandlerRootView&gt;
  );
}
Attempts:
2 left
💡 Hint

Check the import syntax and the style prop on GestureHandlerRootView.

navigation
advanced
2:00remaining
How to combine Gesture Handler with React Navigation for swipe back gesture?

You want to enable swipe back gesture on iOS using React Navigation and Gesture Handler.

Which approach correctly integrates them?

AWrap the navigation container with GestureHandlerRootView and enable gestureEnabled on stack screens.
BUse PanGestureHandler inside each screen component to detect swipe and call navigation.goBack().
CDisable GestureHandlerRootView and rely only on React Navigation's default gestures.
DWrap each screen with TapGestureHandler to detect taps and trigger navigation.goBack().
Attempts:
2 left
💡 Hint

Think about where GestureHandlerRootView should be placed and React Navigation's gesture options.

🔧 Debug
expert
2:00remaining
Why does the PanGestureHandler not respond to gestures in this code?

Look at this React Native code snippet:

import { PanGestureHandler } from 'react-native-gesture-handler';
import { View } from 'react-native';

export default function App() {
  const onGestureEvent = event => console.log(event.nativeEvent.translationX);

  return (
    
      
        
      
    
  );
}

The red square does not respond to pan gestures. What is the most likely cause?

React Native
import { PanGestureHandler } from 'react-native-gesture-handler';
import { View } from 'react-native';

export default function App() {
  const onGestureEvent = event => console.log(event.nativeEvent.translationX);

  return (
    <View style={{ flex: 1 }}>
      <PanGestureHandler onGestureEvent={onGestureEvent}>
        <View style={{ width: 100, height: 100, backgroundColor: 'red' }} />
      </PanGestureHandler>
    </View>
  );
}
AThe PanGestureHandler child View has no flex or position style, so it does not receive touch events.
BThe onGestureEvent callback is incorrectly defined and causes a runtime error.
CThe PanGestureHandler must be wrapped inside a ScrollView to work.
DThe GestureHandlerRootView is missing, so gestures are not recognized.
Attempts:
2 left
💡 Hint

Remember the required root wrapper for Gesture Handler to work properly.