diff --git a/ExampleProject/JDStatusBarNotificationExample.xcodeproj/project.pbxproj b/ExampleProject/JDStatusBarNotificationExample.xcodeproj/project.pbxproj index 814eb0b8..c9754211 100644 --- a/ExampleProject/JDStatusBarNotificationExample.xcodeproj/project.pbxproj +++ b/ExampleProject/JDStatusBarNotificationExample.xcodeproj/project.pbxproj @@ -75,6 +75,9 @@ 7EA91CBC284EF3AF00F32F09 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D264F8901820213200DA0E53 /* Foundation.framework */; }; 7EA91CBE284EF3AF00F32F09 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7E8B9AEE283B6FD300507BC1 /* Launch Screen.storyboard */; }; 7EA91CBF284EF3AF00F32F09 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D264F8A21820213200DA0E53 /* Images.xcassets */; }; + 7EB914D02ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB914CF2ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift */; }; + 7EB914D12ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB914CF2ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift */; }; + 7EB914D22ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB914CF2ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift */; }; 7EBE34122844CA2D0096CD55 /* UIApplication+JDSB_MainWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EBE340D2844CA2D0096CD55 /* UIApplication+JDSB_MainWindow.m */; }; 7EBE34132844CA2D0096CD55 /* UIApplication+JDSB_MainWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EBE340D2844CA2D0096CD55 /* UIApplication+JDSB_MainWindow.m */; }; 7EBE34162844CA2D0096CD55 /* JDSBNotificationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EBE340F2844CA2D0096CD55 /* JDSBNotificationViewController.m */; }; @@ -129,6 +132,7 @@ 7EA91CC3284EF3AF00F32F09 /* JDSBN_LayoutDebugging.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JDSBN_LayoutDebugging.app; sourceTree = BUILT_PRODUCTS_DIR; }; 7EB82C4B2A31BACE004E2B19 /* JDStatusBarNotification.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; name = JDStatusBarNotification.podspec; path = ../../JDStatusBarNotification.podspec; sourceTree = ""; }; 7EB82C4C2A31BACE004E2B19 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../../Package.swift; sourceTree = ""; }; + 7EB914CF2ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JDStatusBarNotificationPresenter.swift; sourceTree = ""; }; 7EBE340C2844CA2D0096CD55 /* JDSBNotificationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JDSBNotificationViewController.h; sourceTree = ""; }; 7EBE340D2844CA2D0096CD55 /* UIApplication+JDSB_MainWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+JDSB_MainWindow.m"; sourceTree = ""; }; 7EBE340F2844CA2D0096CD55 /* JDSBNotificationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JDSBNotificationViewController.m; sourceTree = ""; }; @@ -231,6 +235,7 @@ 7E8C519528585BE400C7C003 /* JDStatusBarNotification.h */, 7E8C519428585BE400C7C003 /* JDStatusBarNotificationPresenter.h */, 7E8C519828585BE400C7C003 /* JDStatusBarNotificationPresenter.m */, + 7EB914CF2ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift */, 7E8C519628585BE400C7C003 /* JDStatusBarNotificationPresenterPrepareStyleBlock.h */, 7E8C519328585BE400C7C003 /* JDStatusBarNotificationStyle.h */, 7E8C519728585BE400C7C003 /* JDStatusBarNotificationStyle.m */, @@ -546,6 +551,7 @@ 7EA91CB3284EF3AF00F32F09 /* ExamplesScreen.swift in Sources */, 7E8C519E28585BE400C7C003 /* JDStatusBarNotificationPresenter.m in Sources */, 7E6FBC24285EF3B100A63FEF /* ExampleStyle.swift in Sources */, + 7EB914D22ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift in Sources */, 7EA91CB4284EF3AF00F32F09 /* SBAppDelegate.m in Sources */, 7EA91CB5284EF3AF00F32F09 /* UIApplication+JDSB_MainWindow.m in Sources */, 7EA91CB6284EF3AF00F32F09 /* main.m in Sources */, @@ -573,6 +579,7 @@ 7E67050E284A4BE900AD58E1 /* ExamplesScreen.swift in Sources */, 7E8C519D28585BE400C7C003 /* JDStatusBarNotificationPresenter.m in Sources */, 7E6FBC23285EF3B100A63FEF /* ExampleStyle.swift in Sources */, + 7EB914D12ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift in Sources */, 7EFD77A828434A0B000BFBF1 /* SBAppDelegate.m in Sources */, 7EBE34132844CA2D0096CD55 /* UIApplication+JDSB_MainWindow.m in Sources */, 7EFD77A728434A03000BFBF1 /* main.m in Sources */, @@ -600,6 +607,7 @@ 7E8C519C28585BE400C7C003 /* JDStatusBarNotificationPresenter.m in Sources */, 7E2F3BBB284F6144002B2181 /* ObservableCustomStyle.swift in Sources */, 7E8C51A02858857200C7C003 /* TextStyleEditorView.swift in Sources */, + 7EB914D02ADC11F4004B3435 /* JDStatusBarNotificationPresenter.swift in Sources */, 7E8C519928585BE400C7C003 /* JDStatusBarNotificationStyle.m in Sources */, 7ED140922847557600593D6F /* JDSBNotificationWindow.m in Sources */, 7EBE34122844CA2D0096CD55 /* UIApplication+JDSB_MainWindow.m in Sources */, diff --git a/ExampleProject/JDStatusBarNotificationExample/ExamplesScreen.swift b/ExampleProject/JDStatusBarNotificationExample/ExamplesScreen.swift index 7351b1c8..8825af8b 100644 --- a/ExampleProject/JDStatusBarNotificationExample/ExamplesScreen.swift +++ b/ExampleProject/JDStatusBarNotificationExample/ExamplesScreen.swift @@ -3,6 +3,7 @@ import Foundation import SwiftUI +import JDStatusBarNotification @available(iOS 15.0, *) class ExamplesScreenFactory: NSObject { @@ -196,7 +197,7 @@ struct ExamplesScreen: View { NotificationPresenter.shared().present(customView: button, style: styleName) } - cell(title: "Present with icon", subtitle: "A custom left view") { + cell(title: "Present custom left icon", subtitle: "A custom left view") { // create icon let image = UIImageView(image: UIImage(systemName: "gamecontroller.fill")) @@ -206,6 +207,42 @@ struct ExamplesScreen: View { NotificationPresenter.shared().displayLeftView(image) NotificationPresenter.shared().dismiss(afterDelay: 2.5) } + + cell(title: "SwiftUI View", subtitle: "A custom view displaying a Swift View") { + + let styleName = NotificationPresenter.shared().addStyle(styleName: "tmp", basedOnIncludedStyle: .defaultStyle) { style in + style.backgroundStyle.backgroundType = backgroundType + style.backgroundStyle.backgroundColor = .orange + return style + } + + NotificationPresenter.shared().presentSwiftView(style: styleName) { + HStack { + Spacer() + + Image(systemName: "swift") + + Spacer() + .frame(width: 10.0) + + VStack(alignment: .leading, spacing: 0.0) { + Text("Swift Views!") + .font(.caption) + .bold() + Text("Easy custom layouts") + .font(.caption) + .foregroundColor(.secondary) + .lineLimit(1) + } + + Spacer() + } + .padding(6.0) + .padding([.leading, .trailing], 10.0) + } + + NotificationPresenter.shared().dismiss(afterDelay: 2.5) + } } Section("Sequencing Example") { diff --git a/JDStatusBarNotification/Private/JDSBNotificationView.m b/JDStatusBarNotification/Private/JDSBNotificationView.m index a7d97642..f1674ed0 100644 --- a/JDStatusBarNotification/Private/JDSBNotificationView.m +++ b/JDStatusBarNotification/Private/JDSBNotificationView.m @@ -516,21 +516,23 @@ - (void)layoutSubviews { _subtitleLabel.textAlignment = textAlignment; // update masks (after layout is done) - [self setupLayerMasksForPillStyleIfNeeded]; + [self setupClippingAndLayerMasksForSubviews]; } -- (void)setupLayerMasksForPillStyleIfNeeded { +- (void)setupClippingAndLayerMasksForSubviews { // mask progress view & custom subview to pill size & shape switch (_style.backgroundStyle.backgroundType) { case JDStatusBarNotificationBackgroundTypeFullWidth: { _progressView.layer.mask = nil; _customSubview.layer.mask = nil; + _customSubview.clipsToBounds = YES; break; } case JDStatusBarNotificationBackgroundTypePill: { if (_progressView) { _progressView.layer.mask = roundRectMaskForRectAndRadius([_progressView convertRect:_pillView.frame fromView:_pillView.superview]); } + _customSubview.clipsToBounds = NO; if (_customSubview) { _customSubview.layer.mask = roundRectMaskForRectAndRadius([_customSubview convertRect:_pillView.frame fromView:_pillView.superview]); } diff --git a/JDStatusBarNotification/Public/JDStatusBarNotificationPresenter.swift b/JDStatusBarNotification/Public/JDStatusBarNotificationPresenter.swift new file mode 100644 index 00000000..257063b8 --- /dev/null +++ b/JDStatusBarNotification/Public/JDStatusBarNotificationPresenter.swift @@ -0,0 +1,20 @@ +// +// JDStatusBarNotificationPresenter_Private.h +// +// Created by Markus Emrich on 10/15/23. +// Copyright 2023 Markus Emrich. All rights reserved. +// + +import JDStatusBarNotification +import SwiftUI + +extension NotificationPresenter { + + func presentSwiftView(style: String? = nil, + @ViewBuilder viewBuilder: () -> some View, + completion: NotificationPresenterCompletion? = nil) { + let controller = UIHostingController(rootView: viewBuilder()) + controller.view.backgroundColor = .clear + self.present(customView: controller.view, style: style, completion: completion) + } +}