When Screen.ScreenOrientationChanged Doesn't Do Anything

Hello... I have 8 images in my project. When the phone is held in portrait mode, I want the images to be in 2 columns (and 4 rows). When the phone is held in landscape mode, I want the images to be in 4 columns (and 2 rows). I thought the "When Screen1.ScreenOrientationChanged do" would fire when the screen orientation changed. This doesn't seem to be the case. The value of Screen1.ScreenOrientation is always "unspecified." I'm assuming that since this value never changes, the when... changed event never fires.

So... I guess my question is ultimately how do I make things different when a user rotates their phone back and forth between portrait and landscape?

And... of course, apologies if this was already asked.

Thanks in advance.

This probably allows the user to set the orientation:

If not, the pulldown has lots of options to try.

The Screen1.OrientationChanged event would probably be a good place to compare Screen1 Width and Height to determine which of 2 Arrangements (one for Portrait and one for Landscape) to make Visible, and which Images to populate with your 8 Pictures.

P.S. Table Arrangements are buggier than a baby buggy. Use nested horizontal and vertical Arrangements.

1 Like

Thanks ABG! But still no luck. I tried setting that on screen1.initialize. But it didn't help. To test things, I wrote up an app that has 1 button and a text box. The coding is 1 procedure ("only") and 2 "when" events: when button1.clicked do "only" and when screen1.screenorientationchanged do "only." "Only" writes the screen height, screen width and screenorientation value to the text box. Rotating my phone doesn't cause "only" to fire. (With or without the set screen1.screenorientation to "user.") The only way to get "only" to run is to click the button.

So... my question is how do I get "only" to fire when the screen is rotated?

I set up my new smartphone for the first time with AI2, and ran some tests.

I discovered a time delay before the new Height and Width were available after the Orientation Changed event.,
so I added a special purpose one shot Clock to delay the orientation test.

I needed to use Sensor as my initial Screen1.Orientation value.

Designer screen_orientation.aia (2.5 KB)

(I have not yet taken screen shots with my new device).

1 Like

Nothing yet. I downloaded/imported the aia you provided and nothing happens. I get the screen height and width at initialization, but then nothing after that.

Does it matter if I'm using an iPhone vs something else? I'm on an iPhone 11 Pro Max running IOS 14.x (when I first had this issue) and now on IOS 15.1.

I appreciate the help a TON! Sorry for being such a pain in the neck!

Yes.

I'm on Android, so there's nothing more I can do to test this.

1 Like

Thanks, again, ABG. Has anyone else had any problems with the screenorientationchanged event on an iPhone?

Hey Taifun,

You posted some responses to the first thread linked below (a year ago!). I'm having similar problems now so I wanted to reach out to you. See the 2nd link for the full thread, but the short version is that when screenorientationchanged never fires. I'm starting to suspect it's because I'm on an iPhone and not an Andriod, but that's just a guess at this point.

Thanks in advance for any help/advice/thoughts you have on this.

Chris

you are using iOS, which means, this is a different issue... I only use Android... sorry, I can't help...
Taifun

The ScreenOrientation property has never returned the current orientation, it's always the developer-specified (desired) orientation. I think what we probably need to do is provide a CurrentOrientation property that could be checked if the layout needs to be modified. You could also compare the screen's Width/Height properties in the event handler, although I don't know off the top of my head whether at that point in time they reflect the old orientation or the new.

Screenshots

On iOS - iPhone 6s:

Yes it is not triggered on iOS. So don't disable the Clock (as I've shown in my blocks).

After reviewing the code, it does look like we are not calling the event handler when the screen orientations. It seems to me like a straightforward fix based on the documentation I've read.

Oof... What's the process to request improvements to app inventor? Recognizing / reacting to a screen orientation change on an iPhone seems like something that should happen without running a timer in the background.

you have done it :slight_smile:

Yes, may be, but that was never possible with AI2 nor one of its distros.

:musical_note:For What It's Worth :musical_note: (Buffalo Springfield 1966) :musical_note:

This is what I discovered.
NOTE: it sure would be nice to be able to set: Button.Width="Automatic"

Yes there is something happening here and what it is isn't exactly clear :wink:

Button.width = -1

1 Like

WOW Thanks ! @TIMAI2