-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Orientation] Create API to listen to device orientation change events #426
Comments
+1. Would also be nice to control orientation on a per route basis in a Navigator |
Also, it would be nice to be able to "lock" the screen programatically. |
@joewalnes Is this sort of API what you're looking for? (generally mirrors the UIDevice API) DeviceIOS = {
Orientation : {
Unknown
Portrait
PortraitUpsideDown
LandscapeLeft
LandscapeRight
FaceUp
FaceDown
}
getCurrentOrientation
addChangeListener
}
// Flux-esque change callback:
DeviceIOS.addChangeListener(() => {
var currentRotation = RotationStore.getCurrentRotation() // one of DeviceIOS.Orientation
}) @jlevine22 you mean force certain routes to be either landscape or portrait? @randomer unfortunately locking the screen is a private API, can't be used in production apps: http://stackoverflow.com/questions/18388150/lock-screen-on-device-programmatically |
Well, actually I meant locking the orientation, not the screen. Sorry for the confusion |
@randomer - agreed, that would be nice |
@clayallsopp The API looks like a good start. My concern would be the race condition due to the async nature of ReactNative. For example, in between reading the initial device rotation and registering a change listener, the rotation may have been changed on the main thread so an event would be missed. |
@joewalnes is this a thing we're worried about? It looks like |
the pattern I use is to treat these states as eventually consistent in my application code. implementing the JS portion of the module then involves three parts:
the race condition is still there, but it usually isn't an issue as long as the JS app is guaranteed to catch up to the native state. when the race condition is an issue (e.g. you need to make some method calls that only make sense in certain states) then I write a bit of Obj-C that handles the native notifications synchronously. |
@clayallsopp That said if you look into Stringwire app you will see that their streaming view is locked in landscape. However, I suspect they just rotated elements to look like it's landscape. (look at animation when you push/pop view from display) |
👍 |
Related to #2031, @yamill's project https://github.com/yamill/react-native-orientation looks like a good place to look for this - API needs a bit of work but he is on that and you can submit a PR there if you are so inclined 😸 |
Ability to read device orientation and register a listener for when it changes.
The text was updated successfully, but these errors were encountered: