react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Orientation] Re-Layout on orientation change

Open nick opened this issue 11 years ago • 67 comments

How should I re-layout the page when the orientation of the device changes? I noticed none of the demo apps seem to support this yet. If I refresh the app in a different orientation it lays out fine though.

nick avatar Feb 01 '15 23:02 nick

This is on our radar, but not implemented yet. Ideally we can bake support directly into the layout system.

On Feb 1, 2015, at 4:09 PM, Nick Poulden [email protected] wrote:

How should I re-layout the page when the orientation of the device changes? I noticed none of the demo apps seem to support this yet. If I refresh the app in a different orientation it lays out fine though.

— Reply to this email directly or view it on GitHub.

sahrens avatar Feb 02 '15 20:02 sahrens

Supporting orientation change is crucial, especially for tablets.

Something like styles : { landscape : {}, portrait : {} } could work from the JS Implementation perspective.

jaygarcia avatar Feb 14 '15 14:02 jaygarcia

I think it would be more generic to handle resize events, with an orientation hint. Some devices are likely to support side-by-side apps now or in the near future. Adaptive layout is key, and the flex system is good at supporting it.

joewood avatar Mar 29 '15 00:03 joewood

The UIExplorer example does handle rotation now - it's simplistic, but a start :)

On Saturday, March 28, 2015, Joe Wood [email protected] wrote:

I think it would be more generic to handle resize events, with an orientation hint. Some devices are likely to support side-by-side apps now or in the near future. Adaptive layout is key, and the flex system is good at supporting it.

— Reply to this email directly or view it on GitHub https://github.com/facebook/react-native/issues/25#issuecomment-87331904 .

sahrens avatar Mar 29 '15 03:03 sahrens

@sahrens Where in the UIExplorer example do you handle rotation? It seems like I can't find it. As I'm trying to add rotation detection support to my npm module this could be really usefull.

PS: maybe the inline documentation in the Dimensions.js utility should be changed, because the width and height don't change on device rotation (Probably because they are set as constants here on application start?)

GertjanReynaert avatar May 10 '15 17:05 GertjanReynaert

The docs say the values may change, but they currently don't because we never implemented that :(

I'm not sure exactly how the UIExplorer rotation works, but I think there is a riot VC that rotates and whenever the root view bounds changes it triggers a layout update, which works (if you don't use Dimensions, which you shouldn't for 99% of layout - use flex/stretch instead).

I think @nicklockwood has more details on existing rotation support.

On May 10, 2015, at 10:28 AM, Gertjan Reynaert [email protected] wrote:

@sahrens Where in the UIExplorer example do you handle rotation? It seems like I can't find it. As I'm trying to add rotation detection support to my npm module this could be really usefull.

PS: maybe the inline documentation in the Dimensions.js utility should be changed, because the width and height don't change on device rotation (Probably because they are set as constants here on application start?)

— Reply to this email directly or view it on GitHub.

sahrens avatar May 11 '15 00:05 sahrens

@nick Did you get a chance to resolve this issue?

This might help get the job done.

https://github.com/kkjdaniel/react-native-device-display

christopherdro avatar Jul 20 '15 19:07 christopherdro

The original issue was resolved a couple of months ago - if the root view is resized (e.g by an orientation change) then it triggers a re-layout of the react view tree.

nicklockwood avatar Jul 20 '15 19:07 nicklockwood

@nicklockwood In which react-native version is this fixed? As of 0.8.0, my app does not seem to re-layout subviews on rotation change.

jeffreywescott avatar Aug 06 '15 19:08 jeffreywescott

It was definitely implemented prior to version 0.8.0. What happens when you rotate the screen? Do the example projects rotate correctly when you try them?

nicklockwood avatar Aug 06 '15 22:08 nicklockwood

Sorry -- my mistake. As it turns out, all of the layout changes seem to get swallowed by the JS-based Navigator component. :-(

jeffreywescott avatar Aug 06 '15 22:08 jeffreywescott

Same here on 0.11.0-rc. View inside renderScene doesn't react on orientation change.

ptmt avatar Sep 17 '15 16:09 ptmt

@jeffreywescott Did you find out how to get past the layout changes getting swallowed by the Navigator component?

gudmundurmar avatar Oct 01 '15 15:10 gudmundurmar

Nope. I gave up. Sorry, @gudmundurmar

jeffreywescott avatar Oct 20 '15 17:10 jeffreywescott

@gudmundurmar, did you make progress on this? Is autorotation broken for Navigator for you?

andrewljohnson avatar Feb 22 '16 04:02 andrewljohnson

@andrewljohnson Rotation works fine for me now. It was a {flex:1} issue on the View that held my NavBar. Was using {width: deviceWidth, height: deviceHeight}

gudmundurmar avatar Feb 23 '16 14:02 gudmundurmar

@gudmundurmar can you provide some sample code of how you are detecting a change in the devices orientation?

ericmasiello avatar Mar 05 '16 20:03 ericmasiello

Looks like this is related to https://github.com/facebook/react-native/issues/2111

grittathh avatar Mar 06 '16 04:03 grittathh

When I try to change orientation for <View style={{flex: 1, backgroundColor: 'green'}} /> I got this simulator screen shot 1 2016 11 20 55

It resizes to fullscreen when I open Inspector How to fix it?

stereodenis avatar Sep 01 '16 08:09 stereodenis

@stereodenis: what platform (iOS, android, ?)? Can you provide more context and code? @andreicoman11 is looking at this in Android right now but it should work in iOS.

sahrens avatar Sep 01 '16 16:09 sahrens