I'm trying to make a script that adjusts the SafeArea of my Canvas when the device is rotated. I've got it almost working and it looks great on-launch, but I'm getting a weird result after rotating that I can't understand: the SafeArea is different depending on whether the app launched in Portrait or Landscape mode.
When I log out the value of Screen.safeArea
on an iPhone 12 Pro, for example, I get the following values:
- Portrait on launch: (x:0.00, y:102.00, width:1170.00, height:2289.00)
- Portrait rotated to Landscape: (x:0.00, y:102.00, width:2532.00, height:927.00)
- Landscape on launch: (x:141.00, y:63.00, width:2250.00, height:1107.00)
- Landscape rotated to Portrait: (x:141.00, y:63.00, width:888.00, height:2469.00)
The Width/Height values are changing on rotation, which makes sense, but the X/Y offsets are not. Given the particular nature of the iPhone 12, that means there is a big empty space at the top when launching in Portrait and rotating to Landscape but overflowing the notch to the side, and big empty spaces on both sides when launching in Landscape and rotating to Portrait but overflowing the notch to the top.
Is this the expected behavior? I would have thought the "launching in Portrait" and "rotated to Portrait" safeAreas should be the same, right? Is there a way to force-refresh the safeArea or something, to get the proper X/Y values? Or am I misunderstanding how this is supposed to work?