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.
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.)
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: