What is the purpose of the Dimensions API in React Native?
The Dimensions API provides the width and height of the device screen or window, helping developers create layouts that adapt to different screen sizes.
Click to reveal answer
beginner
How do you import the Dimensions API in a React Native component?
You import it using: <code>import { Dimensions } from 'react-native';</code>
Click to reveal answer
beginner
What method do you use to get the screen width using the Dimensions API?
Use Dimensions.get('window').width to get the current width of the device's window.
Click to reveal answer
beginner
Why is it better to use Dimensions API values instead of fixed numbers for width and height?
Because fixed numbers may not fit all screen sizes, using Dimensions API values makes your app layout flexible and responsive on different devices.
Click to reveal answer
intermediate
How can you listen for screen size changes using the Dimensions API?
You can add an event listener with Dimensions.addEventListener('change', handler) to update your layout when the screen size changes, like on device rotation.
Click to reveal answer
Which of these returns the height of the device screen in React Native?
ADimensions.get('screen').width
BDimensions.screen.height
CDimensions.height
DDimensions.get('window').height
✗ Incorrect
Use Dimensions.get('window').height to get the current height of the device window.
What does the 'window' parameter in Dimensions.get('window') represent?
AThe entire device screen including status bar
BThe visible area available for your app excluding status bar
CThe app's navigation bar size
DThe keyboard height
✗ Incorrect
'window' gives the visible area available for your app, excluding areas like the status bar.
How do you update your layout when the device orientation changes?