From dc17b40fd632c380ba5647c637a91058a3fa682a Mon Sep 17 00:00:00 2001 From: Rasmus Tauts Date: Thu, 26 Sep 2024 14:58:06 +0300 Subject: [PATCH] Add EntryWidget embedded view This PR adds the possibility to embed EntryWidget to a view. Also, as was agreed upon within the team, there is no instance of EntryWidget within Glia. EntryWidget instance will be returned from getEntryWidget method MOB-3479 --- GliaWidgets.xcodeproj/project.pbxproj | 4 + .../Public/Glia/Glia+EntryWidget.swift | 15 ++++ GliaWidgets/Public/Glia/Glia.swift | 4 - .../Sources/EntryWidget/EntryWidget.swift | 12 +-- .../Sources/EntryWidget/EntryWidgetView.swift | 8 +- .../EntryWidget/EntryWidgetViewModel.swift | 29 +++++-- TestingApp/Main.storyboard | 76 +++++++++++++------ .../ViewController/ViewController.swift | 12 ++- 8 files changed, 118 insertions(+), 42 deletions(-) create mode 100644 GliaWidgets/Public/Glia/Glia+EntryWidget.swift diff --git a/GliaWidgets.xcodeproj/project.pbxproj b/GliaWidgets.xcodeproj/project.pbxproj index 189cdc88d..10c811bd5 100644 --- a/GliaWidgets.xcodeproj/project.pbxproj +++ b/GliaWidgets.xcodeproj/project.pbxproj @@ -946,6 +946,7 @@ C0F3DE482C6E468400DE6D7B /* PoweredByView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F3DE472C6E468400DE6D7B /* PoweredByView.swift */; }; C0F7EA382CA1D6D40038019C /* CustomPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F7EA372CA1D6D40038019C /* CustomPresentationController.swift */; }; C0F7EA3A2CA1D7050038019C /* EntryWidget.SizeConstraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F7EA392CA1D7050038019C /* EntryWidget.SizeConstraints.swift */; }; + C0F7EA3C2CA581E70038019C /* Glia+EntryWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0F7EA3B2CA581E70038019C /* Glia+EntryWidget.swift */; }; C4119E06268F41D1004DFEFB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C4119E05268F41D1004DFEFB /* Main.storyboard */; }; C42463742673ABE10082C135 /* ScreenShareHandler.Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42463732673ABE10082C135 /* ScreenShareHandler.Interface.swift */; }; C43C12F92694B14900C37E1B /* GliaPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C43C12F82694B14900C37E1B /* GliaPresenter.swift */; }; @@ -1972,6 +1973,7 @@ C0F3DE472C6E468400DE6D7B /* PoweredByView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PoweredByView.swift; sourceTree = ""; }; C0F7EA372CA1D6D40038019C /* CustomPresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPresentationController.swift; sourceTree = ""; }; C0F7EA392CA1D7050038019C /* EntryWidget.SizeConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryWidget.SizeConstraints.swift; sourceTree = ""; }; + C0F7EA3B2CA581E70038019C /* Glia+EntryWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Glia+EntryWidget.swift"; sourceTree = ""; }; C4119E05268F41D1004DFEFB /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; C42463732673ABE10082C135 /* ScreenShareHandler.Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenShareHandler.Interface.swift; sourceTree = ""; }; C43C12F82694B14900C37E1B /* GliaPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GliaPresenter.swift; sourceTree = ""; }; @@ -3595,6 +3597,7 @@ C0D6CA622C19C59100D4709B /* Glia.OpaqueAuthentication.Environment.swift */, 755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */, AFC7ABB72C2D93A0006F15AA /* Glia+RestoreEngagement.swift */, + C0F7EA3B2CA581E70038019C /* Glia+EntryWidget.swift */, ); path = Glia; sourceTree = ""; @@ -6083,6 +6086,7 @@ C0D2F0332991377C00803B47 /* VideoCallViewController.swift in Sources */, 1A8B61D225C974A1000D780E /* ChatCallUpgradeView.swift in Sources */, 845E2F88283FB49F00C04D56 /* Theme.Survey.BooleanQuestion.Accessibility.swift in Sources */, + C0F7EA3C2CA581E70038019C /* Glia+EntryWidget.swift in Sources */, C06A7584296EC9DC006B69A2 /* NumberSlotStyle.Accessibility.swift in Sources */, 8491AF212A7D1F7900CC3E72 /* ChatView.GvaGallery.swift in Sources */, 847956402ADED7A2004EF60C /* CallVisualizer.Action.swift in Sources */, diff --git a/GliaWidgets/Public/Glia/Glia+EntryWidget.swift b/GliaWidgets/Public/Glia/Glia+EntryWidget.swift new file mode 100644 index 000000000..808010b05 --- /dev/null +++ b/GliaWidgets/Public/Glia/Glia+EntryWidget.swift @@ -0,0 +1,15 @@ +import Foundation + +extension Glia { + /// Retrieves an instance of `EntryWidget`. + /// + /// - Parameters: + /// - queueIds: A list of queue IDs to be used for the engagement launcher. When nil, the default queues will be used. + /// + /// - Returns: + /// - `EntryWidget` instance. + public func getEntryWidget(queueIds: [String]) -> EntryWidget { + // The real implementation will be added once EngagementLauncher is added + .init(theme: theme) + } +} diff --git a/GliaWidgets/Public/Glia/Glia.swift b/GliaWidgets/Public/Glia/Glia.swift index 5e68683ac..16879cc0e 100644 --- a/GliaWidgets/Public/Glia/Glia.swift +++ b/GliaWidgets/Public/Glia/Glia.swift @@ -119,9 +119,6 @@ public class Glia { private(set) var configuration: Configuration? - // Interface for entry widget - public private(set) var entryWidget: EntryWidget - init(environment: Environment) { self.environment = environment self.theme = Theme() @@ -160,7 +157,6 @@ public class Glia { viewFactory: viewFactory ) ) - entryWidget = .init(theme: theme) } /// Setup SDK using specific engagement configuration without starting the engagement. diff --git a/GliaWidgets/Sources/EntryWidget/EntryWidget.swift b/GliaWidgets/Sources/EntryWidget/EntryWidget.swift index 6b9a5879b..30d0dc4e9 100644 --- a/GliaWidgets/Sources/EntryWidget/EntryWidget.swift +++ b/GliaWidgets/Sources/EntryWidget/EntryWidget.swift @@ -53,6 +53,7 @@ private extension EntryWidget { func showView(in parentView: UIView) { parentView.subviews.forEach { $0.removeFromSuperview() } let model = makeViewModel( + showHeader: false, channels: channels, selection: { channel in // Logic for handling this callback will be handled later - MOB-3473 @@ -77,8 +78,10 @@ private extension EntryWidget { func showSheet(in parentViewController: UIViewController) { let model = makeViewModel( + showHeader: true, channels: channels, selection: { channel in + // Logic for handling this callback will be handled later - MOB-3473 print(channel.headline) } ) @@ -86,7 +89,7 @@ private extension EntryWidget { let hostingController = UIHostingController(rootView: view) hostingController.view.backgroundColor = UIColor.white - + // Due to the more modern sheet presenting approach being // available starting from iOS 16, we need to handle cases // where the visitor has either iOS 14 or 15 installed. For @@ -97,7 +100,6 @@ private extension EntryWidget { let smallDetent: UISheetPresentationController.Detent = .custom { _ in return self.calculateHeight( channels: self.channels, - showPoweredBy: self.theme.showsPoweredBy, sizeConstraints: self.sizeConstraints ) } @@ -118,11 +120,13 @@ private extension EntryWidget { } func makeViewModel( + showHeader: Bool, channels: [Channel], selection: @escaping (Channel) -> Void ) -> EntryWidgetView.Model { .init( - style: theme.entryWidgetStyle, + theme: theme, + showHeader: showHeader, sizeConstrainsts: sizeConstraints, channels: channels, channelSelected: selection @@ -131,7 +135,6 @@ private extension EntryWidget { func calculateHeight( channels: [Channel], - showPoweredBy: Bool, sizeConstraints: SizeConstraints ) -> CGFloat { var appliedHeight: CGFloat = 0 @@ -155,7 +158,6 @@ extension EntryWidget: UIViewControllerTransitioningDelegate { ) -> UIPresentationController? { let height = calculateHeight( channels: channels, - showPoweredBy: theme.showsPoweredBy, sizeConstraints: sizeConstraints ) return CustomPresentationController( diff --git a/GliaWidgets/Sources/EntryWidget/EntryWidgetView.swift b/GliaWidgets/Sources/EntryWidget/EntryWidgetView.swift index b25ce0c2e..0ca7e6a3b 100644 --- a/GliaWidgets/Sources/EntryWidget/EntryWidgetView.swift +++ b/GliaWidgets/Sources/EntryWidget/EntryWidgetView.swift @@ -5,9 +5,13 @@ struct EntryWidgetView: View { var body: some View { VStack(spacing: 0) { - headerView() + if model.showHeader { + headerView() + } channelsView() - poweredByView() + if model.showPoweredBy { + poweredByView() + } } .maxSize() .padding(.horizontal) diff --git a/GliaWidgets/Sources/EntryWidget/EntryWidgetViewModel.swift b/GliaWidgets/Sources/EntryWidget/EntryWidgetViewModel.swift index 35fd60a11..2c791a7f7 100644 --- a/GliaWidgets/Sources/EntryWidget/EntryWidgetViewModel.swift +++ b/GliaWidgets/Sources/EntryWidget/EntryWidgetViewModel.swift @@ -2,25 +2,42 @@ import SwiftUI extension EntryWidgetView { class Model: ObservableObject { - let style: EntryWidgetStyle + let theme: Theme let channelSelected: (EntryWidget.Channel) -> Void let channels: [EntryWidget.Channel] let sizeConstraints: EntryWidget.SizeConstraints + let showHeader: Bool + + var style: EntryWidgetStyle { + theme.entryWidgetStyle + } + + var showPoweredBy: Bool { + // Once EntryWidget will be displayed in Secure + // Conversations, additional checks will be added here + guard theme.showsPoweredBy else { return false } + + return true + } init( - style: EntryWidgetStyle, + theme: Theme, + showHeader: Bool, sizeConstrainsts: EntryWidget.SizeConstraints, channels: [EntryWidget.Channel], channelSelected: @escaping (EntryWidget.Channel) -> Void ) { - self.style = style + self.theme = theme self.sizeConstraints = sizeConstrainsts + self.showHeader = showHeader self.channels = channels self.channelSelected = channelSelected } + } +} - func selectChannel(_ channel: EntryWidget.Channel) { - channelSelected(channel) - } +extension EntryWidgetView.Model { + func selectChannel(_ channel: EntryWidget.Channel) { + channelSelected(channel) } } diff --git a/TestingApp/Main.storyboard b/TestingApp/Main.storyboard index cfb197e07..01b84fc9e 100644 --- a/TestingApp/Main.storyboard +++ b/TestingApp/Main.storyboard @@ -21,7 +21,7 @@ - + - + + + + + + + + - + - +