[Android] `StageOrientation.DEFAULT` never triggers on `StageOrientationEvent.ORIENTATION_CHANGING` when event is prevented (`event.preventDefault`)
OS: Android 10
AIR: 51.1.3.6
App Descriptor:
<aspectRatio>any</aspectRatio>
<autoOrients>true</autoOrients>
Aim:
I want to receive the StageOrientationEvent but I don't want the stage to actually rotate.
I'm using event.preventDefault() on StageOrientationEvent.ORIENTATION_CHANGING in order to block the stage from rotating.
Code:
private function init() : void
{
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE,
onChangeStageOrientation);
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING,
onChangingStageOrientation);
}
private function onChangeStageOrientation(event : StageOrientationEvent) : void
{
trace("onChangeStageOrientation " + event.toString());
}
private function onChangingStageOrientation(event : StageOrientationEvent) : void
{
trace("onChangingStageOrientation " + event.toString());
if (event.afterOrientation == StageOrientation.ROTATED_LEFT
|| event.afterOrientation == StageOrientation.ROTATED_RIGHT)
{
event.preventDefault(); // commenting out this line will have all events received correctly!
}
}
Issue:
In onChangingStageOrientation calling event.preventDefault() will cause onChangeStageOrientation to be never called. The function onChangingStageOrientation is also never called with event.afterOrientation == StageOrientation.DEFAULT, though the "prevent event" part should not affect the listener from triggering.
Function onChangingStageOrientation is only called for StageOrientation.ROTATED_LEFT, StageOrientation.ROTATED_RIGHT and StageOrientation.UPSIDE_DOWN when the event is prevented default.
Other Observations:
Using <aspectRatio>portrait</aspectRatio> or <aspectRatio>landscape</aspectRatio> will lead to no events dispatched at all. I would suggest, that both orientation events are always fired, as there can be scenarios, where you need them, no matter if the stage actually rotates or is set to a fixed aspect ratio and even when it does not auto orientate.
Slightly Related: #1892
Just as an aside you can use the device orientation events in the application ane to achieve this: https://docs.airnativeextensions.com/docs/application/device-information/orientation-events
Just as an aside you can use the device orientation events in the application ane to achieve this: https://docs.airnativeextensions.com/docs/application/device-information/orientation-events
Ah, many thanks for pointing out! I'm actually using the Application ANE, so I will just switch to that functionality then 🍻👍
Just as an aside you can use the device orientation events in the application ane to achieve this: https://docs.airnativeextensions.com/docs/application/device-information/orientation-events
I can confirm this is working as intended and the events are dispatched, including the missing "default" orientation.
@ajwfrost : Could you briefly have a look into the missing "default" orientation event for the scenario from above?