Control X, Y reversed

I spent quite a bit of time debugging my app today, only to discover that the controls are reporting incorrect dimensions and coordinates when queried in the OrientationChanged and Resized events.

Left = Top
Top = Left
Width = Height
Height = Width

In this screenshot, the label sets the size of a full screen canvas and the current screen during OrientationChanged. Note the incorrect Width, Height on the canvas.

OrientationChanged fires after the device orientation changes but before the controls are adjusted. Is this a bug or designed behavior?

Found another bug in MobileScreen, where Resized fires before Opening. And another verified bug in the feedback system related to Resized:

There’s also an issue (maybe related to the report above) where Resized is fired at launch when all controls are still in their default state (100 width, 100 height) before the first layout update:


I’ve created a MobileScreen subclass, TRMobileScreen, that only fires Resized and OrientationChanged after it fires Opening and only when “when the layout is good.”

Download here:

Here’s the same project when using TRMobileScreen:

After Opening, the instance of the Screen subclass creates a hidden Canvas the same size as the screen. When it receives the Resized and OrientationChanged events, it starts a timer and checks for the hidden Canvas to be updated to the correct size. Only then does it fire Resized and/or OrientationChanged (the subclass remembers which events will need to be fired.)

1 Like

That’s not a bug. Resizing fires then because that’s what happens in the underlying framework.

Should Resized be documented?


Yes it definitely should…


I have updated my MobileScreen subclass project; it gives a consistent experience for Opening, Resized and OrientationChanged events—These events will only fire after the layout engine has initialized or updated the controls on the screen:

Developing this workaround class revealed a couple XOJO bugs; upvotes would be great if they affect you. The repo project works around this bug:

Using TRMobileScreen will trigger this next XOJO bug; I’m currently working on a workaround and will update the repo if I find one:

The repo’s readme describes a workaround.