Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9cb0980

Browse files
jaredhmsRaj Seshasankaran
authored andcommitted
Make sure UIAlertViews are always rendered vertically (#2652)
WoCDisplayMode uses a 'presentationTransform' to rotate the presentation surface for certan apps, but we don't want to use that transform to rotate UIAlertViews (else they render sideways if the app is rotated). This will be handled automatically when we move UIAlertView over Xaml (as we've already done for UIActionSheet), but for now we need to undo the 'presentationTransform' rotation for UIAlertViews. Fixes #2611.
1 parent 14031c7 commit 9cb0980

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Frameworks/UIKit/UIAlertView.mm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#import <UIKit/UILabel.h>
2929
#import <UIKit/UIScreen.h>
3030
#import <UIKit/UIView.h>
31+
#import <UIKit/UIWindow.h>
3132

3233
#import <Foundation/NSString.h>
3334
#import <Foundation/NSMutableArray.h>
@@ -396,6 +397,32 @@ - (BOOL)isVisible {
396397
return alertPriv->_isVisible;
397398
}
398399

400+
- (void) _handleRotation {
401+
// We need to offset the 'presentationTransform' used in WOCDispalyMode, because we always want to render alerts vertically.
402+
// TODO: We'll remove this when we switch UIAlertView over to a Xaml ContentDialog, since rotation will be handled for us.
403+
const float c_angleToRadian = kPi / 180.0;
404+
switch ([[UIApplication displayMode] presentationTransform]) {
405+
case UIInterfaceOrientationLandscapeRight:
406+
[self setTransform:CGAffineTransformMakeRotation(-static_cast<float>(DisplayProperties::ScreenRotation90Clockwise) * c_angleToRadian)];
407+
break;
408+
409+
case UIInterfaceOrientationPortrait:
410+
[self setTransform:CGAffineTransformMakeTranslation(0.0f, 0.0f)];
411+
break;
412+
413+
case UIInterfaceOrientationLandscapeLeft:
414+
[self setTransform:CGAffineTransformMakeRotation(-static_cast<float>(DisplayProperties::ScreenRotation90CounterClockwise) * c_angleToRadian)];
415+
break;
416+
417+
case UIInterfaceOrientationPortraitUpsideDown:
418+
[self setTransform:CGAffineTransformMakeRotation(-static_cast<float>(DisplayProperties::ScreenRotation180) * c_angleToRadian)];
419+
break;
420+
421+
default:
422+
break;
423+
}
424+
}
425+
399426
/**
400427
@Status Interoperable
401428
*/
@@ -550,6 +577,9 @@ - (BOOL)isVisible {
550577
frame.size.height = curHeight;
551578
[self initWithFrame:frame];
552579

580+
// Make sure we're not rotated even if WOCDisplayMode rotates the presentation surface
581+
[self _handleRotation];
582+
553583
id image;
554584
image = [[UIImage imageNamed:@"/img/[email protected]"] stretchableImageWithLeftCapWidth:25 topCapHeight:30];
555585
UIImageSetLayerContents([self layer], image);

0 commit comments

Comments
 (0)