React-native: On iOS, orientation changes don't animate in a way that "looks native"

Created on 21 Sep 2017  路  16Comments  路  Source: facebook/react-native

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 8.4.0
Yarn: 1.0.1
npm: 5.4.1
Watchman: 4.5.0
Xcode: Xcode 8.3.3 Build version 8E3004b
Android Studio: 2.3 AI-162.3934792

Packages: (wanted => installed)
react: 16.0.0-alpha.12 => 16.0.0-alpha.12
react-native: 0.48.3 => 0.48.3

Steps to Reproduce

  1. Create a react native app w/ react native init
  2. Run it on an iOS device or the iOS simulator
  3. (If on a simulator) Turn on slow animations (CMD+T) so the issue will be more obvious.
  4. Rotate the device a few times to landscape and portrait
  5. Observe that immediately after the orientation changes, the view is resized to the dimensions of the new orientation, and THEN the rotation animation begins. The view's contents and dimensions are not _smoothly_ resized while the view is being rotated.

Expected Behavior

In a regular native iOS app, when the orientation of the device changes, the view's contents and dimensions smoothly resize while the view is also rotated at the same time.

Here is a animated gif. This is a simple native app written in swift, see how the view resizes and rotates smoothly (at the same time) on orientation changes:

native_rotation

Actual Behavior

On orientation changes, the view's dimensions and contents are resized once at the very beginning of the change, and then the rotation animation happens.

Here is another animated git. This is a simple RN app, with a red border applied to the view so you can see how the view's dimensions are immediately changed (not smoothly animated).

rn_rotation

Reproducible Demo

Sadly I can't seem to get the expo app to handle rotations so I guess having a Snack wouldn't be useful.

But you can see if yourself pretty easily if you:

  1. Use react-native init to create a new app
  2. Edit index.ios.js and add to the container's styles (line ~40):
    borderColor: 'red',
    borderWidth: 10,
  1. Then run it, turn on slow animations in the simulator (CMD+T), and change the orientation a few times.
Bug Help Wanted Author Provided Repro iOS

Most helpful comment

This issue is becoming a blocker for us for using react-native. Also applies to Android.
I would love to see it fixed, and can help if necessary.

All 16 comments

My guess is that Apple wraps the whole rotation reflow in a UIView animation block. Maybe you could try experimenting with that inside of a device rotation handler that triggers Yoga to do a relayout?

@ide thanks for the tip, but I am a bit of a newb here. :)

Can you give me some pointers or examples for trying out what you are suggesting?

e.g.

  • which RN files are you suggesting I modify
  • do you have an example of rotation reflow in a UI animation block in a device rotation handler
  • triggering yoga to do a relayout
  • etc

Can someone confirm whether this is missing functionality or just a bug?

I think this is just an enhancement kind of issue?

Its a visual problem, but this feels like a bug to me. Though I admit I dont entirely know what the boundary for bug / enhancement is in react-native :)

But yeah this is ugly compared to native apps and feels kinda defective.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

Well, thats unfortunate... is there a way to reopen this or clone it into a new issue?

Re-opening since this is still an issue. To set expectations fairly, though, the best way to move this forward is to figure out the fundamental issue and write a low-maintenance PR that fixes it from first principles.

Thanks @ide that makes sense.

The hurdle for me there is that I have virtually zero native iOS dev experience. Thanks for offering some advice in a comment above here. I could use some more elaboration on that if you have time to provide it (see my prior comment in response to your comment).

@aarondail The gist is that Apple's CoreAnimation can tween automatically and perhaps iOS uses that during rotations. Someone who worked at Apple or has debugged this in Instruments might be better suited to answer that though. There are a lot of specifics that involve CoreAnimation and UIKit (many of which I'm unfamiliar with) and tbh a lot of the people I've met/talked to who know this stuff in and out have spent years with it or were part of the teams who built it. It isn't necessary to have all of that knowledge to fix this issue (I certainly don't have it) but I suspect it's hard to identify which path to take with almost no iOS experience.

Some resources:

Would love for this to be smooth. When building something that rotates this always bothers me! :)

Has this been tested in Android? I would love to help, but I honestly don't see the difference. Maybe I've been behind a screen for too long today :wink:

Is this going to be solved. I am making a video player app and I like to open the player in landscape mode. And when I force the app to show in landcape. The animation is horrible.
ezgif com-optimize

Thanks

This issue is becoming a blocker for us for using react-native. Also applies to Android.
I would love to see it fixed, and can help if necessary.

Hi,

We are playing video using RN. The animation when the orientation changes is very horrible. Any ideas on how to fix it?

@acollazomayer how you fixed it?

@learnyst I did not fixed it. Changed company. Sorry I can not help.

Was this page helpful?
0 / 5 - 0 ratings