Challenge - 5 Problems
Platform Style Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2: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} />; }
Attempts:
2 left
💡 Hint
Check the Platform.select object for the android key.
✗ Incorrect
Platform.select returns the value for the current platform. On Android, it returns 'green' for backgroundColor.
📝 Syntax
intermediate2: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 */ } });
Attempts:
2 left
💡 Hint
Use triple equals for comparison and check for 'ios'.
✗ Incorrect
Option D correctly compares Platform.OS to 'ios' and returns 'red' if true, else 'black'.
❓ lifecycle
advanced2: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?
Attempts:
2 left
💡 Hint
Platform.OS is fixed at app start and does not change dynamically.
✗ Incorrect
Platform.OS is determined at app launch and does not change during runtime, so styles using it update only after reload.
🧠 Conceptual
advanced2: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'
})
}
});
Attempts:
2 left
💡 Hint
Check the 'default' key in Platform.select for unknown platforms.
✗ Incorrect
Platform.select returns the 'default' value when the platform is not ios or android, so 'purple' is used on web.
🔧 Debug
expert2: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'
})()
}
});
Attempts:
2 left
💡 Hint
Look carefully at the parentheses after Platform.select call.
✗ Incorrect
Platform.select returns a value, not a function, so calling it with () causes a TypeError.