Skip to content

Commit

Permalink
refactor!: Deprecate and remove some unused orientation code
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Aug 14, 2024
1 parent 0c8725a commit 6ed6fc4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 72 deletions.
63 changes: 0 additions & 63 deletions CordovaLib/Classes/Public/CDVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ @interface CDVViewController () <CDVWebViewEngineConfigurationDelegate> { }

@implementation CDVViewController

@synthesize supportedOrientations;
@synthesize pluginObjects, pluginsMap, startupPluginNames;
@synthesize configParser, settings;
@synthesize wwwFolderName, startPage, initialized, openURL;
Expand Down Expand Up @@ -84,9 +83,6 @@ - (void)__init
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onWebViewPageDidLoad:)
name:CDVPageDidLoadNotification object:nil];

// read from UISupportedInterfaceOrientations (or UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist
self.supportedOrientations = [self parseInterfaceOrientations:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]];

self.initialized = YES;
}
Expand Down Expand Up @@ -351,65 +347,6 @@ -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVie
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewWillTransitionToSizeNotification object:[NSValue valueWithCGSize:size]]];
}

- (NSArray*)parseInterfaceOrientations:(NSArray*)orientations
{
NSMutableArray* result = [[NSMutableArray alloc] init];

if (orientations != nil) {
NSEnumerator* enumerator = [orientations objectEnumerator];
NSString* orientationString;

while (orientationString = [enumerator nextObject]) {
if ([orientationString isEqualToString:@"UIInterfaceOrientationPortrait"]) {
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortrait]];
} else if ([orientationString isEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) {
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]];
} else if ([orientationString isEqualToString:@"UIInterfaceOrientationLandscapeLeft"]) {
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]];
} else if ([orientationString isEqualToString:@"UIInterfaceOrientationLandscapeRight"]) {
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]];
}
}
}

// default
if ([result count] == 0) {
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortrait]];
}

return result;
}

- (BOOL)shouldAutorotate
{
return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
NSUInteger ret = 0;

if ([self supportsOrientation:UIInterfaceOrientationPortrait]) {
ret = ret | (1 << UIInterfaceOrientationPortrait);
}
if ([self supportsOrientation:UIInterfaceOrientationPortraitUpsideDown]) {
ret = ret | (1 << UIInterfaceOrientationPortraitUpsideDown);
}
if ([self supportsOrientation:UIInterfaceOrientationLandscapeRight]) {
ret = ret | (1 << UIInterfaceOrientationLandscapeRight);
}
if ([self supportsOrientation:UIInterfaceOrientationLandscapeLeft]) {
ret = ret | (1 << UIInterfaceOrientationLandscapeLeft);
}

return ret;
}

- (BOOL)supportsOrientation:(UIInterfaceOrientation)orientation
{
return [self.supportedOrientations containsObject:@(orientation)];
}

/// Retrieves the view from a newwly initialized webViewEngine
/// @param bounds The bounds with which the webViewEngine will be initialized
- (nonnull UIView*)newCordovaViewWithFrame:(CGRect)bounds
Expand Down
1 change: 1 addition & 0 deletions CordovaLib/include/Cordova/CDVScreenOrientationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#import <Foundation/Foundation.h>

CDV_DEPRECATED(8, "Unused")
@protocol CDVScreenOrientationDelegate <NSObject>

- (UIInterfaceOrientationMask)supportedInterfaceOrientations;
Expand Down
13 changes: 4 additions & 9 deletions CordovaLib/include/Cordova/CDVViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@

@end

@interface CDVViewController : UIViewController <CDVScreenOrientationDelegate>{
/*!
@abstract The main view controller for Cordova web content.
*/
@interface CDVViewController : UIViewController {
@protected
id <CDVWebViewEngineProtocol> _webViewEngine;
@protected
Expand All @@ -73,20 +76,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly, strong) id <CDVWebViewEngineProtocol> webViewEngine;
@property (nonatomic, readonly, strong) id <CDVCommandDelegate> commandDelegate;

/**
Takes/Gives an array of UIInterfaceOrientation (int) objects
ex. UIInterfaceOrientationPortrait
*/
@property (nonatomic, readwrite, strong) NSArray* supportedOrientations;

- (UIView*)newCordovaViewWithFrame:(CGRect)bounds;

- (nullable NSString*)appURLScheme;
- (nullable NSURL*)errorURL;

- (NSArray*)parseInterfaceOrientations:(NSArray*)orientations;
- (BOOL)supportsOrientation:(UIInterfaceOrientation)orientation;

- (nullable id)getCommandInstance:(NSString*)pluginName;
- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className;
- (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName;
Expand Down

0 comments on commit 6ed6fc4

Please sign in to comment.