Skip to content

Commit

Permalink
Make sure UIAlertViews are always rendered vertically (#2652)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jaredhms authored and Raj Seshasankaran committed May 10, 2017
1 parent 14031c7 commit 9cb0980
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Frameworks/UIKit/UIAlertView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import <UIKit/UILabel.h>
#import <UIKit/UIScreen.h>
#import <UIKit/UIView.h>
#import <UIKit/UIWindow.h>

#import <Foundation/NSString.h>
#import <Foundation/NSMutableArray.h>
Expand Down Expand Up @@ -396,6 +397,32 @@ - (BOOL)isVisible {
return alertPriv->_isVisible;
}

- (void) _handleRotation {
// We need to offset the 'presentationTransform' used in WOCDispalyMode, because we always want to render alerts vertically.
// TODO: We'll remove this when we switch UIAlertView over to a Xaml ContentDialog, since rotation will be handled for us.
const float c_angleToRadian = kPi / 180.0;
switch ([[UIApplication displayMode] presentationTransform]) {
case UIInterfaceOrientationLandscapeRight:
[self setTransform:CGAffineTransformMakeRotation(-static_cast<float>(DisplayProperties::ScreenRotation90Clockwise) * c_angleToRadian)];
break;

case UIInterfaceOrientationPortrait:
[self setTransform:CGAffineTransformMakeTranslation(0.0f, 0.0f)];
break;

case UIInterfaceOrientationLandscapeLeft:
[self setTransform:CGAffineTransformMakeRotation(-static_cast<float>(DisplayProperties::ScreenRotation90CounterClockwise) * c_angleToRadian)];
break;

case UIInterfaceOrientationPortraitUpsideDown:
[self setTransform:CGAffineTransformMakeRotation(-static_cast<float>(DisplayProperties::ScreenRotation180) * c_angleToRadian)];
break;

default:
break;
}
}

/**
@Status Interoperable
*/
Expand Down Expand Up @@ -550,6 +577,9 @@ - (BOOL)isVisible {
frame.size.height = curHeight;
[self initWithFrame:frame];

// Make sure we're not rotated even if WOCDisplayMode rotates the presentation surface
[self _handleRotation];

id image;
image = [[UIImage imageNamed:@"/img/[email protected]"] stretchableImageWithLeftCapWidth:25 topCapHeight:30];
UIImageSetLayerContents([self layer], image);
Expand Down

0 comments on commit 9cb0980

Please sign in to comment.