From 26cc0eec83047d083b0e33890869e1ac0388b87c Mon Sep 17 00:00:00 2001 From: Leo Natan Date: Thu, 15 Oct 2020 00:20:35 +0300 Subject: [PATCH] Only require popup bar layout fixes only when a SwiftUI view is used as popup content Demo project improvements --- .../project.pbxproj | 12 +++++++ LNPopupUIExample/LNPopupUIExample/Info.plist | 5 +++ .../IntroWebView/WebController.swift | 34 +++++++++++++++++++ .../LNPopupUIExample/SceneSelection.swift | 25 +++----------- Package.swift | 7 ++-- .../Private/LNPopupProxyViewController.swift | 4 ++- 6 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 LNPopupUIExample/LNPopupUIExample/IntroWebView/WebController.swift diff --git a/LNPopupUIExample/LNPopupUIExample.xcodeproj/project.pbxproj b/LNPopupUIExample/LNPopupUIExample.xcodeproj/project.pbxproj index 26174f5..707e47c 100644 --- a/LNPopupUIExample/LNPopupUIExample.xcodeproj/project.pbxproj +++ b/LNPopupUIExample/LNPopupUIExample.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 396B439624DC8EF100D84FC7 /* LoremIpsum in Frameworks */ = {isa = PBXBuildFile; productRef = 396B439524DC8EF100D84FC7 /* LoremIpsum */; }; 398404EA25003925006C9011 /* SceneSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 398404E925003925006C9011 /* SceneSelection.swift */; }; 398404EE2500451E006C9011 /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 398404ED2500451E006C9011 /* MapView.swift */; }; + 3985A1E525378E73004AA4D7 /* WebController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3985A1E425378E73004AA4D7 /* WebController.swift */; }; 398DB7AD250400BE00CD89DB /* NavDemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 398DB7AC250400BE00CD89DB /* NavDemoView.swift */; }; 39AAAA6C25040FA900E5FD41 /* TabNavView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39AAAA6B25040FA900E5FD41 /* TabNavView.swift */; }; 39AAAA6E25040FF400E5FD41 /* ConstraintsDemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39AAAA6D25040FF400E5FD41 /* ConstraintsDemoView.swift */; }; @@ -54,6 +55,7 @@ 395781F224DC692300A604D1 /* PlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerView.swift; sourceTree = ""; }; 398404E925003925006C9011 /* SceneSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneSelection.swift; sourceTree = ""; }; 398404ED2500451E006C9011 /* MapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = ""; }; + 3985A1E425378E73004AA4D7 /* WebController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebController.swift; sourceTree = ""; }; 398DB7AC250400BE00CD89DB /* NavDemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavDemoView.swift; sourceTree = ""; }; 39AAAA6B25040FA900E5FD41 /* TabNavView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabNavView.swift; sourceTree = ""; }; 39AAAA6D25040FF400E5FD41 /* ConstraintsDemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintsDemoView.swift; sourceTree = ""; }; @@ -99,6 +101,7 @@ 398DB7AF250401DB00CD89DB /* DemoScenes */, 398DB7B0250401E300CD89DB /* MusicScene */, 398DB7B1250401F800CD89DB /* MapScene */, + 3985A1E325378E57004AA4D7 /* IntroWebView */, 395781D424DC5D2700A604D1 /* AppDelegate.swift */, 395781D624DC5D2700A604D1 /* SceneDelegate.swift */, 398404E925003925006C9011 /* SceneSelection.swift */, @@ -125,6 +128,14 @@ name = Frameworks; sourceTree = ""; }; + 3985A1E325378E57004AA4D7 /* IntroWebView */ = { + isa = PBXGroup; + children = ( + 3985A1E425378E73004AA4D7 /* WebController.swift */, + ); + path = IntroWebView; + sourceTree = ""; + }; 398DB7AF250401DB00CD89DB /* DemoScenes */ = { isa = PBXGroup; children = ( @@ -233,6 +244,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3985A1E525378E73004AA4D7 /* WebController.swift in Sources */, 395781D524DC5D2700A604D1 /* AppDelegate.swift in Sources */, 398404EE2500451E006C9011 /* MapView.swift in Sources */, 39AAAA72250415E800E5FD41 /* ViewDemoView.swift in Sources */, diff --git a/LNPopupUIExample/LNPopupUIExample/Info.plist b/LNPopupUIExample/LNPopupUIExample/Info.plist index 4cc1339..385b2b2 100644 --- a/LNPopupUIExample/LNPopupUIExample/Info.plist +++ b/LNPopupUIExample/LNPopupUIExample/Info.plist @@ -20,6 +20,11 @@ 1 LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes diff --git a/LNPopupUIExample/LNPopupUIExample/IntroWebView/WebController.swift b/LNPopupUIExample/LNPopupUIExample/IntroWebView/WebController.swift new file mode 100644 index 0000000..2608e17 --- /dev/null +++ b/LNPopupUIExample/LNPopupUIExample/IntroWebView/WebController.swift @@ -0,0 +1,34 @@ +// +// WebController.swift +// LNPopupUIExample +// +// Created by Leo Natan on 10/14/20. +// + +import UIKit +import WebKit + +class WebController: UIViewController { + private let webView = WKWebView() + + override func viewDidLoad() { + super.viewDidLoad() + + webView.load(URLRequest(url: URL(string: "https://github.com/LeoNatan/LNPopupUI")!)) + webView.translatesAutoresizingMaskIntoConstraints = false + + view.addSubview(webView) + NSLayoutConstraint.activate([ + view.topAnchor.constraint(equalTo: webView.topAnchor), + view.bottomAnchor.constraint(equalTo: webView.bottomAnchor), + view.leadingAnchor.constraint(equalTo: webView.leadingAnchor), + view.trailingAnchor.constraint(equalTo: webView.trailingAnchor), + ]) + + popupItem.title = "Welcome to LNPopupUI" + popupItem.image = UIImage(named: "genre10") + popupItem.barButtonItems = [ + UIBarButtonItem(image: UIImage(systemName: "suit.heart.fill"), style: .done, target: nil, action: nil) + ] + } +} diff --git a/LNPopupUIExample/LNPopupUIExample/SceneSelection.swift b/LNPopupUIExample/LNPopupUIExample/SceneSelection.swift index 97e3024..6d7492c 100644 --- a/LNPopupUIExample/LNPopupUIExample/SceneSelection.swift +++ b/LNPopupUIExample/LNPopupUIExample/SceneSelection.swift @@ -8,6 +8,8 @@ import SwiftUI import LNPopupUI +fileprivate let introWebController = WebController() + struct SceneSelection: View { @State var tabnavPresented: Bool = false @State var tabPresented: Bool = false @@ -96,27 +98,8 @@ struct SceneSelection: View { } .navigationViewStyle(StackNavigationViewStyle()) .ignoresSafeArea() - .popup(isBarPresented: Binding.constant(true)) { - SafeAreaDemoView(offset: true) - .popupTitle("Welcome to LNPopupUI!") - .popupImage(Image("genre10")) - .popupBarItems({ - HStack(spacing: 20) { - Button(action: { - print("Play") - }) { - Image(systemName: "play.fill") - } - - Button(action: { - print("Next") - }) { - Image(systemName: "forward.fill") - } - } - .font(.system(size: 20)) - }) - } + .popup(isBarPresented: Binding.constant(true), popupContentController: introWebController) + .popupCloseButtonStyle(.round) .popupBarMarqueeScrollEnabled(true) } } diff --git a/Package.swift b/Package.swift index 8ce55b9..024bc16 100644 --- a/Package.swift +++ b/Package.swift @@ -1,5 +1,4 @@ // swift-tools-version:5.1 -// The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -21,12 +20,14 @@ let package = Package( ], dependencies: [ // .package(path: "../LNPopupController") - .package(url: "https://github.com/LeoNatan/LNPopupController.git", from: Version(stringLiteral: "2.10.16")) + .package(url: "https://github.com/LeoNatan/LNPopupController.git", from: Version(stringLiteral: "2.10.20")) ], targets: [ .target( name: "LNPopupUI", - dependencies: ["LNPopupController-Static"], + dependencies: [ + .product(name: "LNPopupController-Static", package: "LNPopupController") + ], exclude: [ "LNPopupUIExample", "Supplements" diff --git a/Sources/LNPopupUI/Private/LNPopupProxyViewController.swift b/Sources/LNPopupUI/Private/LNPopupProxyViewController.swift index d8aefe7..9c0d354 100644 --- a/Sources/LNPopupUI/Private/LNPopupProxyViewController.swift +++ b/Sources/LNPopupUI/Private/LNPopupProxyViewController.swift @@ -122,7 +122,9 @@ internal class LNPopupProxyViewController : UIHostingCont let popupContentHandler = state.content != nil ? viewHandler(state) : viewControllerHandler(state) let handler : (Bool) -> Void = { animated in - self.target.popupBar.setValue(true, forKey: "_applySwiftUILayoutFixes") + if state.content != nil { + self.target.popupBar.setValue(true, forKey: "_applySwiftUILayoutFixes") + } self.target.popupContentView.popupCloseButtonStyle = self.currentPopupState.closeButtonStyle self.target.popupPresentationDelegate = self self.target.popupInteractionStyle = self.currentPopupState.interactionStyle