Skip to content

Commit

Permalink
Add EntryWidget embedded view
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rasmustautsglia authored and github-review-helper committed Sep 29, 2024
1 parent bd25f43 commit be40424
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 43 deletions.
4 changes: 4 additions & 0 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,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 */; };
Expand Down Expand Up @@ -1976,6 +1977,7 @@
C0F3DE472C6E468400DE6D7B /* PoweredByView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PoweredByView.swift; sourceTree = "<group>"; };
C0F7EA372CA1D6D40038019C /* CustomPresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPresentationController.swift; sourceTree = "<group>"; };
C0F7EA392CA1D7050038019C /* EntryWidget.SizeConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryWidget.SizeConstraints.swift; sourceTree = "<group>"; };
C0F7EA3B2CA581E70038019C /* Glia+EntryWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Glia+EntryWidget.swift"; sourceTree = "<group>"; };
C4119E05268F41D1004DFEFB /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
C42463732673ABE10082C135 /* ScreenShareHandler.Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenShareHandler.Interface.swift; sourceTree = "<group>"; };
C43C12F82694B14900C37E1B /* GliaPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GliaPresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3609,6 +3611,7 @@
755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */,
AFC7ABB72C2D93A0006F15AA /* Glia+RestoreEngagement.swift */,
215A258F2CA44D8A0013023E /* Glia+EngagementLauncher.swift */,
C0F7EA3B2CA581E70038019C /* Glia+EntryWidget.swift */,
);
path = Glia;
sourceTree = "<group>";
Expand Down Expand Up @@ -6099,6 +6102,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 */,
Expand Down
15 changes: 15 additions & 0 deletions GliaWidgets/Public/Glia/Glia+EntryWidget.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 0 additions & 4 deletions GliaWidgets/Public/Glia/Glia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -160,7 +157,6 @@ public class Glia {
viewFactory: viewFactory
)
)
entryWidget = .init(theme: theme)
}

/// Setup SDK using specific engagement configuration without starting the engagement.
Expand Down
12 changes: 7 additions & 5 deletions GliaWidgets/Sources/EntryWidget/EntryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,16 +78,18 @@ 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)
}
)
let view = makeView(model: model)
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
Expand All @@ -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
)
}
Expand All @@ -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
Expand All @@ -131,7 +135,6 @@ private extension EntryWidget {

func calculateHeight(
channels: [Channel],
showPoweredBy: Bool,
sizeConstraints: SizeConstraints
) -> CGFloat {
var appliedHeight: CGFloat = 0
Expand All @@ -155,7 +158,6 @@ extension EntryWidget: UIViewControllerTransitioningDelegate {
) -> UIPresentationController? {
let height = calculateHeight(
channels: channels,
showPoweredBy: theme.showsPoweredBy,
sizeConstraints: sizeConstraints
)
return CustomPresentationController(
Expand Down
8 changes: 6 additions & 2 deletions GliaWidgets/Sources/EntryWidget/EntryWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 23 additions & 6 deletions GliaWidgets/Sources/EntryWidget/EntryWidgetViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion GliaWidgets/Sources/Theme/Theme.EntryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Theme {
let style: EntryWidgetStyle = .init(
channel: channel,
backgroundColor: backgroundColor,
poweredBy: poweredBy,
poweredBy: poweredBy,
draggerColor: color.baseShade
)

Expand Down
Loading

0 comments on commit be40424

Please sign in to comment.