Skip to content

Commit

Permalink
rename, change the default value
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Jan 29, 2020
1 parent 84bf3ff commit 8d033b2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
6 changes: 3 additions & 3 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
static NSString* const INCLUDE_NON_MODAL_ELEMENTS = @"includeNonModalElements";
static NSString* const ACCEPT_ALERT_BUTTON_SELECTOR = @"acceptAlertButtonSelector";
static NSString* const DISMISS_ALERT_BUTTON_SELECTOR = @"dismissAlertButtonSelector";
static NSString* const SKIP_ADJUSTING_SCREENSHOT_ORIENTATION = @"skipAdjustingScreenshotOrientation";
static NSString* const AUTO_ADJUST_SCREENSHOT_ORIENTATION = @"autoAdjustScreenshotOrientation";


@implementation FBSessionCommands
Expand Down Expand Up @@ -328,8 +328,8 @@ + (NSArray *)routes
if (nil != [settings objectForKey:DISMISS_ALERT_BUTTON_SELECTOR]) {
[FBConfiguration setDismissAlertButtonSelector:(NSString *)[settings objectForKey:DISMISS_ALERT_BUTTON_SELECTOR]];
}
if (nil != [settings objectForKey:SKIP_ADJUSTING_SCREENSHOT_ORIENTATION]) {
[FBConfiguration setSkipAdjustingScreenshotOrientation:[[settings objectForKey:SKIP_ADJUSTING_SCREENSHOT_ORIENTATION] boolValue]];
if (nil != [settings objectForKey:AUTO_ADJUST_SCREENSHOT_ORIENTATION]) {
[FBConfiguration setAutoAdjustScreenshotOrientation:[[settings objectForKey:AUTO_ADJUST_SCREENSHOT_ORIENTATION] boolValue]];
}

return [self handleGetSettings:request];
Expand Down
8 changes: 4 additions & 4 deletions WebDriverAgentLib/Utilities/FBConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)dismissAlertButtonSelector;

/**
Skip adjusting the screenshot orientation.
Auto adjust the screenshot orientation.
The adjustment helps to fix the screenshot coordinate when a user change the device orientation.
But the logic sometimes cannot set the screenshot orientation properly. Skiping the logic can fix it.
Xcode versions, OS versions or device models and simulator or real device could influence this logic.
@param isEnabled Set to YES in order to skip adjusting screenshot coordinate. Defaults to false.
@param isEnabled Set to NO in order to skip adjusting screenshot coordinate. Defaults to YES.
*/
+ (void)setSkipAdjustingScreenshotOrientation:(BOOL)isEnabled;
+ (BOOL)skipAdjustingScreenshotOrientation;
+ (void)setAutoAdjustScreenshotOrientation:(BOOL)isEnabled;
+ (BOOL)autoAdjustScreenshotOrientation;


@end
Expand Down
10 changes: 5 additions & 5 deletions WebDriverAgentLib/Utilities/FBConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
static NSString *FBDismissAlertButtonSelector = @"";
static NSString *FBSnapshotMaxDepthKey = @"maxDepth";
static NSMutableDictionary *FBSnapshotRequestParameters;
static BOOL FBSkipAdjustingScreenshotOrientation = NO;
static BOOL FBAutoAdjustScreenshotOrientation = YES;


@implementation FBConfiguration
Expand Down Expand Up @@ -344,14 +344,14 @@ + (NSString *)dismissAlertButtonSelector
return FBDismissAlertButtonSelector;
}

+ (void)setSkipAdjustingScreenshotOrientation:(BOOL)isEnabled
+ (void)setAutoAdjustScreenshotOrientation:(BOOL)isEnabled
{
FBSkipAdjustingScreenshotOrientation = isEnabled;
FBAutoAdjustScreenshotOrientation = isEnabled;
}

+ (BOOL)skipAdjustingScreenshotOrientation
+ (BOOL)autoAdjustScreenshotOrientation
{
return FBSkipAdjustingScreenshotOrientation;
return FBAutoAdjustScreenshotOrientation;
}

#pragma mark Private
Expand Down
30 changes: 16 additions & 14 deletions WebDriverAgentLib/Utilities/FBImageUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ BOOL FBIsPngImage(NSData *imageData)
NSData *FBAdjustScreenshotOrientationForApplication(NSData *screenshotData, UIInterfaceOrientation orientation)
{
UIImageOrientation imageOrientation;
if (SYSTEM_VERSION_LESS_THAN(@"11.0") || FBConfiguration.skipAdjustingScreenshotOrientation) {
// In iOS < 11.0 screenshots are already adjusted properly
imageOrientation = UIImageOrientationUp;
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
imageOrientation = UIImageOrientationLeft;
} else if (orientation == UIInterfaceOrientationLandscapeLeft) {
imageOrientation = UIImageOrientationRight;
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
imageOrientation = UIImageOrientationDown;
} else {
if (FBIsPngImage(screenshotData)) {
return screenshotData;
// Apply auto rotation by default for iOS >= 11.0. In iOS < 11.0 screenshots are already adjusted properly.
if (FBConfiguration.autoAdjustScreenshotOrientation && SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.0")) {
if (orientation == UIInterfaceOrientationLandscapeRight) {
imageOrientation = UIImageOrientationLeft;
} else if (orientation == UIInterfaceOrientationLandscapeLeft) {
imageOrientation = UIImageOrientationRight;
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
imageOrientation = UIImageOrientationDown;
} else {
if (FBIsPngImage(screenshotData)) {
return screenshotData;
}
UIImage *image = [UIImage imageWithData:screenshotData];
return (NSData *)UIImagePNGRepresentation(image);
}
UIImage *image = [UIImage imageWithData:screenshotData];
return (NSData *)UIImagePNGRepresentation(image);
} else {
imageOrientation = UIImageOrientationUp;
}

UIImage *image = [UIImage imageWithData:screenshotData];
Expand Down

0 comments on commit 8d033b2

Please sign in to comment.