Complete the code to import the Dimensions API from React Native.
import [1] from 'react-native';
The Dimensions API is imported from 'react-native' to access screen size information.
Complete the code to get the screen width using Dimensions.
const screenWidth = Dimensions.[1]('window').width;
The get method of Dimensions returns an object with width and height of the screen.
Fix the error in the code to correctly get the screen height.
const screenHeight = Dimensions.get('window').[1];
The correct property name is height to get the screen height.
Fill both blanks to create a style that sets width and height to half the screen size.
const styles = StyleSheet.create({
box: {
width: screenWidth [1] 2,
height: screenHeight [2] 2
}
});To get half the screen size, divide the width and height by 2 using the / operator.
Fill all three blanks to create a responsive square view with side length equal to screen width minus 40.
const boxSize = screenWidth [1] 40; const styles = StyleSheet.create({ square: { width: boxSize, height: [2], backgroundColor: 'skyblue' } }); // Use <View style=[3] /> to render
Subtract 40 from screenWidth to get boxSize. Set height equal to boxSize for a square. Use styles.square to style the View.