FrontEnd/React Native
[react native] 화면 크기 가져오기
무무둥
2023. 2. 24. 23:38
https://reactnative.dev/docs/dimensions
Dimensions · React Native
useWindowDimensions is the preferred API for React components. Unlike Dimensions, it updates as the window's dimensions update. This works nicely with the React paradigm.
reactnative.dev
import {Dimensions} from 'react-native';
const windowWidth = Dimensions.get('window').width;
const windowHeight = Dimensions.get('window').height;
// 다른 표현 방법
const {width: windowWidth, height: windowHeight} = Dimensions.get('window');
// style에 적용
const styles = StyleSheet.create({
test : {
width: windowWidth,
height: windowHeight
}
});