diff --git a/Example/SwiftWebVCExample.xcodeproj/project.pbxproj b/Example/SwiftWebVCExample.xcodeproj/project.pbxproj index 283ba5c..1306d14 100644 --- a/Example/SwiftWebVCExample.xcodeproj/project.pbxproj +++ b/Example/SwiftWebVCExample.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 00FFF85E1E09977500015C59 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00FFF85C1E09977500015C59 /* Main.storyboard */; }; 00FFF8601E09977500015C59 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 00FFF85F1E09977500015C59 /* Assets.xcassets */; }; 00FFF8631E09977500015C59 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00FFF8611E09977500015C59 /* LaunchScreen.storyboard */; }; + C7F2B30A2044309100DB7E6D /* ObjcViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C7F2B3092044309100DB7E6D /* ObjcViewController.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -46,6 +47,9 @@ 00FFF85F1E09977500015C59 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 00FFF8621E09977500015C59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 00FFF8641E09977500015C59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C7F2B3072044309100DB7E6D /* SwiftWebVCExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SwiftWebVCExample-Bridging-Header.h"; sourceTree = ""; }; + C7F2B3082044309100DB7E6D /* ObjcViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ObjcViewController.h; sourceTree = ""; }; + C7F2B3092044309100DB7E6D /* ObjcViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ObjcViewController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -116,10 +120,21 @@ 00FFF85F1E09977500015C59 /* Assets.xcassets */, 00FFF8611E09977500015C59 /* LaunchScreen.storyboard */, 00FFF8641E09977500015C59 /* Info.plist */, + C7F2B30C20444D3200DB7E6D /* Objective C VC */, ); path = SwiftWebVCExample; sourceTree = ""; }; + C7F2B30C20444D3200DB7E6D /* Objective C VC */ = { + isa = PBXGroup; + children = ( + C7F2B3082044309100DB7E6D /* ObjcViewController.h */, + C7F2B3092044309100DB7E6D /* ObjcViewController.m */, + C7F2B3072044309100DB7E6D /* SwiftWebVCExample-Bridging-Header.h */, + ); + name = "Objective C VC"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -209,6 +224,7 @@ 0055F7A81E259F1A000ECD54 /* SwiftModalWebVC.swift in Sources */, 00FFF85B1E09977500015C59 /* ViewController.swift in Sources */, 0055F7AC1E259F1A000ECD54 /* SwiftWebVCActivitySafari.swift in Sources */, + C7F2B30A2044309100DB7E6D /* ObjcViewController.m in Sources */, 00FFF8591E09977500015C59 /* AppDelegate.swift in Sources */, 0055F7A91E259F1A000ECD54 /* SwiftWebVC.swift in Sources */, 0055F7AA1E259F1A000ECD54 /* SwiftWebVCActivity.swift in Sources */, @@ -366,11 +382,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = SwiftWebVCExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftweb.SwiftWebVCExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.0; }; name = Debug; @@ -379,11 +398,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = SwiftWebVCExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftweb.SwiftWebVCExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h"; SWIFT_VERSION = 4.0; }; name = Release; diff --git a/Example/SwiftWebVCExample/Base.lproj/Main.storyboard b/Example/SwiftWebVCExample/Base.lproj/Main.storyboard index 2aaa149..452e470 100644 --- a/Example/SwiftWebVCExample/Base.lproj/Main.storyboard +++ b/Example/SwiftWebVCExample/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -38,7 +38,7 @@ + @@ -67,10 +75,12 @@ + + @@ -80,13 +90,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/Example/SwiftWebVCExample/ObjcViewController.h b/Example/SwiftWebVCExample/ObjcViewController.h new file mode 100644 index 0000000..0fd83a9 --- /dev/null +++ b/Example/SwiftWebVCExample/ObjcViewController.h @@ -0,0 +1,13 @@ +// +// ObjcViewController.h +// SwiftWebVCExample +// +// Created by L4grange on 26/02/2018. +// Copyright © 2018 Myles Ringle. All rights reserved. +// + +#import + +@interface ObjcViewController : UIViewController + +@end diff --git a/Example/SwiftWebVCExample/ObjcViewController.m b/Example/SwiftWebVCExample/ObjcViewController.m new file mode 100644 index 0000000..db7bc36 --- /dev/null +++ b/Example/SwiftWebVCExample/ObjcViewController.m @@ -0,0 +1,47 @@ +// +// ObjcViewController.m +// SwiftWebVCExample +// +// Created by L4grange on 26/02/2018. +// Copyright © 2018 Myles Ringle. All rights reserved. +// + +#import "ObjcViewController.h" +#import "SwiftWebVCExample-Swift.h" + +@interface ObjcViewController () + +@end + +@implementation ObjcViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (IBAction)pushButtonPressed:(UIButton *)sender { + SwiftWebVC *webVC = [[SwiftWebVC alloc] initWithUrlString:@"https://www.google.com" sharingEnabled:YES]; + webVC.delegate = self; + [self.navigationController pushViewController:webVC animated:YES]; +} + +- (IBAction)modalButtonPressed:(UIButton *)sender { + SwiftModalWebVC *webVC = [[SwiftModalWebVC alloc] initWithUrlString:@"https://www.google.com" sharingEnabled:YES]; + [self presentViewController:webVC animated:YES completion:nil]; +} + +-(void)didStartLoading { + NSLog(@"ObjC: Started loading."); +} + +-(void)didFinishLoadingWithSuccess:(BOOL)success { + NSLog(@"ObjC: Finished loading. Success: %@.", success ? @"YES" : @"NO" ); +} + +@end diff --git a/Example/SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h b/Example/SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h new file mode 100644 index 0000000..1b2cb5d --- /dev/null +++ b/Example/SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h @@ -0,0 +1,4 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + diff --git a/SwiftWebVC/SwiftModalWebVC.swift b/SwiftWebVC/SwiftModalWebVC.swift index 22ff7ef..8b4db1e 100755 --- a/SwiftWebVC/SwiftModalWebVC.swift +++ b/SwiftWebVC/SwiftModalWebVC.swift @@ -10,16 +10,16 @@ import UIKit public class SwiftModalWebVC: UINavigationController { - public enum SwiftModalWebVCTheme { + @objc public enum SwiftModalWebVCTheme: Int { case lightBlue, lightBlack, dark } - public enum SwiftModalWebVCDismissButtonStyle { + @objc public enum SwiftModalWebVCDismissButtonStyle: Int { case arrow, cross } - weak var webViewDelegate: UIWebViewDelegate? = nil + @objc weak var webViewDelegate: UIWebViewDelegate? = nil - public convenience init(urlString: String, sharingEnabled: Bool = true) { + @objc public convenience init(urlString: String, sharingEnabled: Bool = true) { var urlString = urlString if !urlString.hasPrefix("https://") && !urlString.hasPrefix("http://") { urlString = "https://"+urlString @@ -27,19 +27,19 @@ public class SwiftModalWebVC: UINavigationController { self.init(pageURL: URL(string: urlString)!, sharingEnabled: sharingEnabled) } - public convenience init(urlString: String, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) { + @objc public convenience init(urlString: String, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) { self.init(pageURL: URL(string: urlString)!, theme: theme, dismissButtonStyle: dismissButtonStyle, sharingEnabled: sharingEnabled) } - public convenience init(pageURL: URL, sharingEnabled: Bool = true) { + @objc public convenience init(pageURL: URL, sharingEnabled: Bool = true) { self.init(request: URLRequest(url: pageURL), sharingEnabled: sharingEnabled) } - public convenience init(pageURL: URL, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) { + @objc public convenience init(pageURL: URL, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) { self.init(request: URLRequest(url: pageURL), theme: theme, dismissButtonStyle: dismissButtonStyle, sharingEnabled: sharingEnabled) } - public init(request: URLRequest, theme: SwiftModalWebVCTheme = .lightBlue, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle = .arrow, sharingEnabled: Bool = true) { + @objc public init(request: URLRequest, theme: SwiftModalWebVCTheme = .lightBlue, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle = .arrow, sharingEnabled: Bool = true) { let webViewController = SwiftWebVC(aRequest: request) webViewController.sharingEnabled = sharingEnabled webViewController.storedStatusColor = UINavigationBar.appearance().barStyle diff --git a/SwiftWebVC/SwiftWebVC.swift b/SwiftWebVC/SwiftWebVC.swift index 584e273..1b5f4fd 100755 --- a/SwiftWebVC/SwiftWebVC.swift +++ b/SwiftWebVC/SwiftWebVC.swift @@ -8,14 +8,14 @@ import WebKit -public protocol SwiftWebVCDelegate: class { +@objc public protocol SwiftWebVCDelegate: class { func didStartLoading() func didFinishLoading(success: Bool) } public class SwiftWebVC: UIViewController { - public weak var delegate: SwiftWebVCDelegate? + @objc public weak var delegate: SwiftWebVCDelegate? var storedStatusColor: UIBarStyle? var buttonColor: UIColor? = nil var titleColor: UIColor? = nil @@ -88,7 +88,7 @@ public class SwiftWebVC: UIViewController { webView.navigationDelegate = nil; } - public convenience init(urlString: String, sharingEnabled: Bool = true) { + @objc public convenience init(urlString: String, sharingEnabled: Bool = true) { var urlString = urlString if !urlString.hasPrefix("https://") && !urlString.hasPrefix("http://") { urlString = "https://"+urlString @@ -96,11 +96,11 @@ public class SwiftWebVC: UIViewController { self.init(pageURL: URL(string: urlString)!, sharingEnabled: sharingEnabled) } - public convenience init(pageURL: URL, sharingEnabled: Bool = true) { + @objc public convenience init(pageURL: URL, sharingEnabled: Bool = true) { self.init(aRequest: URLRequest(url: pageURL), sharingEnabled: sharingEnabled) } - - public convenience init(aRequest: URLRequest, sharingEnabled: Bool = true) { + + @objc public convenience init(aRequest: URLRequest, sharingEnabled: Bool = true) { self.init() self.sharingEnabled = sharingEnabled self.request = aRequest @@ -163,6 +163,14 @@ public class SwiftWebVC: UIViewController { super.viewDidDisappear(true) UIApplication.shared.isNetworkActivityIndicatorVisible = false } + + public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + + coordinator.animate(alongsideTransition: nil) { [weak self] context in + self?.updateBottomInset() //Fix the bottom insets after rotating the device + } + } //////////////////////////////////////////////// // Toolbar @@ -211,8 +219,13 @@ public class SwiftWebVC: UIViewController { toolbarItems = items as? [UIBarButtonItem] } } + updateBottomInset() } - + + func updateBottomInset() { + // Leave space for the toolbar at the bottom + webView.scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: navigationController?.toolbar.frame.height ?? 0, right: 0) + } //////////////////////////////////////////////// // Target Actions @@ -354,7 +367,6 @@ extension SwiftWebVC: WKNavigationDelegate { } decisionHandler(.allow) - } func openCustomApp(urlScheme: String, additional_info:String){