Screen width in React Native

前端 未结 10 959
独厮守ぢ
独厮守ぢ 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:11

    If you have a Style component that you can require from your Component, then you could have something like this at the top of the file:

    const Dimensions = require('Dimensions');
    
    const window = Dimensions.get('window');
    

    And then you could provide fulscreen: {width: window.width, height: window.height}, in your Style component. Hope this helps

提交回复
热议问题