diff --git a/ContainerControllerSwift.podspec b/ContainerControllerSwift.podspec index d0ac693..b3fce93 100644 --- a/ContainerControllerSwift.podspec +++ b/ContainerControllerSwift.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'ContainerControllerSwift' - s.version = '1.1.2' + s.version = '1.1.4' s.summary = 'This is a swipe-panel from application: https://www.apple.com/ios/maps/' # This description is used to generate tags and improve search results. @@ -33,7 +33,7 @@ TODO: Add long description of the pod here. # s.ios.deployment_target = '13.0' s.platform = :ios, "13.0" - s.source_files = 'ContainerControllerSwift/**/*.{swift}' + s.source_files = 'Sources/**/*.{swift}' s.framework = "UIKit" # s.ios.framework = 'UIKit' diff --git a/Example/ContainerControllerSwift/Maps/MapsViewController.swift b/Example/ContainerControllerSwift/Maps/MapsViewController.swift index 4662934..69763d0 100644 --- a/Example/ContainerControllerSwift/Maps/MapsViewController.swift +++ b/Example/ContainerControllerSwift/Maps/MapsViewController.swift @@ -105,8 +105,7 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate, @objc func rotated() { - let orint = UIDevice.current.orientation - if orint == .faceUp || orint == .faceDown || orint == .portraitUpsideDown { return } + if !UIDevice.current.orientation.isRotateAllowed { return } updateMapViewTopPadding() } diff --git a/README.md b/README.md index a619ca4..335d22b 100644 --- a/README.md +++ b/README.md @@ -472,7 +472,7 @@ func containerControllerMove(_ containerController: ContainerController, positio ## Author - 📩| [mrustaa](https://github.com/mrustaa/) + 📩| [mrustaa](https://github.com/mrustaa/) JUNE 2020 ## License diff --git a/Sources/ContainerController/ContainerController.swift b/Sources/ContainerController/ContainerController.swift index 640568e..aa9c0d6 100644 --- a/Sources/ContainerController/ContainerController.swift +++ b/Sources/ContainerController/ContainerController.swift @@ -6,7 +6,10 @@ // Copyright © 2020 mrustaa. All rights reserved. // +#if arch(x86_64) || arch(arm64) + import UIKit +import SwiftUI @available(iOS 13.0, *) open class ContainerController: NSObject { @@ -25,6 +28,8 @@ open class ContainerController: NSObject { public var footerView: UIView? + public var hostingController: UIHostingController? + // MARK: Layout public var layout: ContainerLayout = ContainerLayout() @@ -211,8 +216,7 @@ open class ContainerController: NSObject { @objc func rotated() { - let orint = UIDevice.current.orientation - if orint == .faceUp || orint == .faceDown || orint == .portraitUpsideDown { return } + if !UIDevice.current.orientation.isRotateAllowed { return } if ContainerDevice.orientation == oldOrientation { return } oldOrientation = ContainerDevice.orientation @@ -452,6 +456,30 @@ open class ContainerController: NSObject { calculationViews() } + // MARK: - Add SwiftUI View + + public func removeSwiftUIView() { + self.hostingController?.willMove(toParent: nil) + self.hostingController?.view.removeFromSuperview() + self.hostingController?.removeFromParent() + self.hostingController = nil + } + + public func add(swiftUIView: V, parentViewController: UIViewController? = nil) { + guard let contentView = self.view.contentView else { + return + } + removeSwiftUIView() + let hostingController = UIHostingController(rootView: AnyView(swiftUIView)) + self.hostingController = hostingController + let parent = parentViewController ?? self.controller + parent?.addChild(hostingController) + hostingController.view.frame = contentView.bounds + hostingController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] + contentView.addSubview(hostingController.view) + hostingController.didMove(toParent: parent) + } + // MARK: - Pan Gesture @objc private func handlePan(_ gesture: UIPanGestureRecognizer) { @@ -1351,3 +1379,6 @@ extension ContainerController: UIScrollViewDelegate { } } + +#endif + diff --git a/Sources/ContainerController/ContainerControllerDelegate.swift b/Sources/ContainerController/ContainerControllerDelegate.swift index 8391e34..d680f7f 100644 --- a/Sources/ContainerController/ContainerControllerDelegate.swift +++ b/Sources/ContainerController/ContainerControllerDelegate.swift @@ -6,6 +6,8 @@ // Copyright © 2020 mrustaa. All rights reserved. // +#if arch(x86_64) || arch(arm64) + import UIKit @available(iOS 13.0, *) @@ -36,3 +38,5 @@ public extension ContainerControllerDelegate { } } +#endif + diff --git a/Sources/ContainerController/ContainerDevice.swift b/Sources/ContainerController/ContainerDevice.swift index a394db1..7738823 100644 --- a/Sources/ContainerController/ContainerDevice.swift +++ b/Sources/ContainerController/ContainerDevice.swift @@ -10,7 +10,6 @@ import UIKit @available(iOS 13.0, *) public extension ContainerDevice { - enum Orientation { case portrait case landscapeLeft @@ -85,7 +84,7 @@ open class ContainerDevice { switch UIDevice.current.orientation { case .landscapeLeft, .landscapeRight: portrait = false - case .portrait, .portraitUpsideDown: + case .portrait: portrait = true default: break } @@ -120,6 +119,18 @@ open class ContainerDevice { return .landscapeLeft } } +} + +public extension UIDeviceOrientation { + var isRotateAllowed: Bool { + return !(face || self == .portraitUpsideDown) + } + var face: Bool { + switch self { + case .faceUp, .faceDown: return true + default: return false + } + } }