Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After rotation Dimensions remain the same #3

Closed
navy1978 opened this issue Aug 10, 2015 · 4 comments
Closed

After rotation Dimensions remain the same #3

navy1978 opened this issue Aug 10, 2015 · 4 comments

Comments

@navy1978
Copy link

Hi The dimension of the page is not affected by the rotation, so for example calling this in Landscape:
Dimensions.get('window').height has the same result of calling it in Portrait

@yamill
Copy link
Owner

yamill commented Aug 21, 2015

@navy1978 this is because the Dimensions module doesn't update when the orientation changes. I think the RN team is working on this to make it better.

@ptmt
Copy link

ptmt commented Sep 21, 2015

As a temporary solution:

RCT_EXPORT_METHOD(getDimensions:(RCTResponseSenderBlock)callback)
{
  UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];

  NSDictionary *dimensions = @{
                               @"window": @{
                                   @"width": @(root.view.frame.size.width),
                                   @"height": @(root.view.frame.size.height)
                               }
  };

  callback(@[[NSNull null], dimensions]);
}

Of course, no more Dimensions module, window sizes become part of the global state and should be passed via properties.

@yamill
Copy link
Owner

yamill commented Nov 20, 2015

You can use the onLayout event to resolve this issue. I will close this issue now.

@yamill yamill closed this as completed Nov 20, 2015
@hamidjafari
Copy link

i've use this code to get the correct height/width after rotation.

onLayout(evt){
var height = evt.nativeEvent.layout.height;
var width = evt.nativeEvent.layout.width;
// do something with these values...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants