0
0
React Nativemobile~20 mins

Custom tab bars in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Tab Bar Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Custom Tab Bar Button Behavior
You have a custom tab bar in React Native. Which option correctly changes the tab when a custom button is pressed?
React Native
function CustomTabBar({ state, navigation }) {
  return (
    <View style={{ flexDirection: 'row' }}>
      {state.routes.map((route, index) => (
        <TouchableOpacity
          key={route.key}
          onPress={() => {
            // What should go here?
          }}
        >
          <Text>{route.name}</Text>
        </TouchableOpacity>
      ))}
    </View>
  );
}
Anavigation.goBack(route.name)
Bnavigation.navigate(route.name)
Cnavigation.push(route.name)
Dnavigation.popToTop(route.name)
Attempts:
2 left
💡 Hint
Think about how to switch tabs by name using navigation.
📝 Syntax
intermediate
2:00remaining
Correct JSX for Custom Tab Bar
Which option correctly renders a custom tab bar with accessible buttons in React Native?
React Native
function CustomTabBar({ state, navigation }) {
  return (
    <View style={{ flexDirection: 'row' }}>
      {state.routes.map((route, index) => (
        // Fill in the correct JSX here
      ))}
    </View>
  );
}
A<Button key={route.key} title={route.name} onPress={navigation.navigate(route.name)} />
B<View key={route.key} onPress={() => navigation.navigate(route.name)}><Text>{route.name}</Text></View>
C<TouchableOpacity key={route.key} accessibilityRole="button" onPress={() => navigation.navigate(route.name)}><Text>{route.name}</Text></TouchableOpacity>
D<TouchableHighlight key={route.key} onPress={navigation.navigate(route.name)}><Text>{route.name}</Text></TouchableHighlight>
Attempts:
2 left
💡 Hint
TouchableOpacity supports onPress and accessibilityRole for buttons.
lifecycle
advanced
2:00remaining
Updating Custom Tab Bar on Navigation State Change
In a custom tab bar component, which React hook ensures the tab bar updates when the navigation state changes?
React Native
function CustomTabBar({ state, navigation }) {
  // Which hook to use here?
  return <View>{/* tab buttons */}</View>;
}
AuseEffect(() => { /* update UI */ }, [state.index])
BuseRef(() => { /* update UI */ }, [state.index])
CuseCallback(() => { /* update UI */ }, [])
DuseMemo(() => { /* update UI */ }, [])
Attempts:
2 left
💡 Hint
You want to run code when the selected tab index changes.
navigation
advanced
2:00remaining
Handling Tab Press with Custom Behavior
You want to run custom code before switching tabs in a custom tab bar. Which option correctly intercepts the tab press event?
React Native
function CustomTabBar({ state, navigation }) {
  return (
    <View style={{ flexDirection: 'row' }}>
      {state.routes.map((route, index) => {
        const isFocused = state.index === index;
        return (
          <TouchableOpacity
            key={route.key}
            onPress={() => {
              // Custom code here
            }}
          >
            <Text>{route.name}</Text>
          </TouchableOpacity>
        );
      })}
    </View>
  );
}
Anavigation.goBack(); navigation.emit({ type: 'tabPress', target: route.key });
Bnavigation.navigate(route.name); navigation.emit({ type: 'tabPress', target: route.key });
Cnavigation.dispatch({ type: 'tabPress', target: route.key }); navigation.navigate(route.name);
Dconst event = navigation.emit({ type: 'tabPress', target: route.key, canPreventDefault: true }); if (!event.defaultPrevented) navigation.navigate(route.name);
Attempts:
2 left
💡 Hint
Emit tabPress event and check if default was prevented before navigating.
🧠 Conceptual
expert
2:00remaining
Why Use Custom Tab Bars Instead of Default?
What is the main reason developers create custom tab bars in React Native apps?
ATo fully control the tab bar appearance and behavior beyond default styles
BBecause default tab bars do not support navigation
CTo improve app performance by avoiding built-in components
DBecause custom tab bars automatically handle accessibility without extra work
Attempts:
2 left
💡 Hint
Think about customization needs beyond what default tab bars offer.