Screen width in React Native

前端 未结 10 950
独厮守ぢ
独厮守ぢ 2020-12-13 08:33

How do I get screen width in React native?

(I need it because I use some absolute components that overlap and their position on screen changes with different device

10条回答
  •  天命终不由人
    2020-12-13 09:02

    Simply declare this code to get device width

    let deviceWidth = Dimensions.get('window').width
    

    Maybe it's obviously but, Dimensions is an react-native import

    import { Dimensions } from 'react-native'
    

    Dimensions will not work without that

提交回复
热议问题