0
0
React Nativemobile~20 mins

Platform-specific styles in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Platform Style Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Identify the platform-specific background color
Given this React Native style code, what background color will the View have on Android devices?
React Native
import { StyleSheet, View, Platform } from 'react-native';

const styles = StyleSheet.create({
  container: {
    backgroundColor: Platform.select({
      ios: 'blue',
      android: 'green',
      default: 'gray'
    }),
    flex: 1
  }
});

export default function App() {
  return <View style={styles.container} />;
}
AGreen
BBlue
CGray
DWhite
Attempts:
2 left
💡 Hint
Check the Platform.select object for the android key.
📝 Syntax
intermediate
2:00remaining
Correct usage of Platform.OS in styles
Which option correctly applies a red text color only on iOS devices using Platform.OS?
React Native
import { StyleSheet, Platform } from 'react-native';

const styles = StyleSheet.create({
  text: {
    color: /* fill here */
  }
});
APlatform.OS == 'android' ? 'red' : 'black'
BPlatform.OS = 'ios' ? 'red' : 'black'
CPlatform.OS === 'android' ? 'red' : 'black'
DPlatform.OS === 'ios' ? 'red' : 'black'
Attempts:
2 left
💡 Hint
Use triple equals for comparison and check for 'ios'.
lifecycle
advanced
2:00remaining
Effect of platform-specific styles on re-render
If you use Platform.select inside a style object in a React Native component, when will the style update if the app switches from iOS to Android at runtime?
AThe style updates automatically without reloading the app
BThe style updates when the component re-renders due to state change
CThe style updates only after the app reloads or restarts
DThe style never updates once set
Attempts:
2 left
💡 Hint
Platform.OS is fixed at app start and does not change dynamically.
🧠 Conceptual
advanced
2:00remaining
Understanding Platform.select fallback behavior
What background color will the View have on a web platform if this style is applied? const styles = StyleSheet.create({ container: { backgroundColor: Platform.select({ ios: 'yellow', android: 'orange', default: 'purple' }) } });
APurple
BOrange
CYellow
DTransparent
Attempts:
2 left
💡 Hint
Check the 'default' key in Platform.select for unknown platforms.
🔧 Debug
expert
2:00remaining
Identify the error in platform-specific style usage
What error will this code cause? const styles = StyleSheet.create({ button: { backgroundColor: Platform.select({ ios: 'blue', android: 'green', default: 'red' })() } });
ASyntaxError: Unexpected token '('
BTypeError: Platform.select(...) is not a function
CTypeError: Platform.select is not a function
DNo error, works correctly
Attempts:
2 left
💡 Hint
Look carefully at the parentheses after Platform.select call.