Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
checkInterfaceOrientation(false)
}

// NOTE(1.init): This is needed to compute the initial device orientation
mOrientationSensorsEventListener.enable()

context.addLifecycleEventListener(mLifecycleListener)
mLifecycleListener.setOnHostResumeCallback {
if (!didComputeInitialDeviceOrientation || areOrientationSensorsEnabled) {
Expand All @@ -45,17 +48,17 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
mBroadcastReceiver.register()
}
mLifecycleListener.setOnHostPauseCallback {
if (initialized && areOrientationSensorsEnabled) {
if (!didComputeInitialDeviceOrientation || areOrientationSensorsEnabled) {
mOrientationSensorsEventListener.disable()
mAutoRotationObserver.disable()
}
mAutoRotationObserver.disable()
mBroadcastReceiver.unregister()
}
mLifecycleListener.setOnHostDestroyCallback {
if (areOrientationSensorsEnabled) {
if (!didComputeInitialDeviceOrientation || areOrientationSensorsEnabled) {
mOrientationSensorsEventListener.disable()
mAutoRotationObserver.disable()
}
mAutoRotationObserver.disable()
mBroadcastReceiver.unregister()
}

Expand Down Expand Up @@ -163,8 +166,14 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re

checkInterfaceOrientation()

if (!didComputeInitialDeviceOrientation) {
didComputeInitialDeviceOrientation = true
// NOTE(2.init): This is needed to disable sensors if they were needed just for the initial
// device computation.
if (didComputeInitialDeviceOrientation) {
return
}
didComputeInitialDeviceOrientation = true

if (!areOrientationSensorsEnabled) {
mOrientationSensorsEventListener.disable()
}
}
Expand Down