Skip to content

Commit

Permalink
Convert ScreenSharingView to SwiftUI
Browse files Browse the repository at this point in the history
This PR converts ScreenSharingView to SwiftUI

MOB-2720
  • Loading branch information
rasmustautsglia authored and github-review-helper committed Oct 4, 2023
1 parent 70802eb commit 29b34f2
Show file tree
Hide file tree
Showing 35 changed files with 409 additions and 407 deletions.
62 changes: 30 additions & 32 deletions GliaWidgets.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion GliaWidgets/Public/Glia/Glia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public class Glia {
uiConfig: { [weak self] in self?.uiConfig },
assetsBuilder: { [weak self] in self?.assetsBuilder ?? .standard },
getCurrentEngagement: environment.coreSdk.getCurrentEngagement,
eventHandler: onEvent
eventHandler: onEvent,
orientationManager: environment.orientationManager
)
)
var rootCoordinator: EngagementCoordinator?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private extension SecureConversations.ConfirmationViewSwiftUI {
.frame(width: model.orientation.isPortrait ? 100.0 : 70.0)
.foregroundColor(SwiftUI.Color(model.style.confirmationImageTint))
.padding(.bottom, model.orientation.isPortrait ? 32 : 8)
.accessibility(hidden: true)
.migrationAccessibilityHidden(true)
}

@ViewBuilder
Expand Down Expand Up @@ -80,8 +80,8 @@ private extension SecureConversations.ConfirmationViewSwiftUI {
.background(SwiftUI.Color(model.style.checkMessagesButtonStyle.backgroundColor))
.cornerRadius(4)
}
.accessibility(identifier: "secureConversations_confirmationCheckMessages_button")
.accessibility(label: Text(model.style.checkMessagesButtonStyle.accessibility.label))
.accessibility(hint: Text(model.style.checkMessagesButtonStyle.accessibility.hint))
.migrationAccessibilityIdentifier("secureConversations_confirmationCheckMessages_button")
.migrationAccessibilityLabel(model.style.checkMessagesButtonStyle.accessibility.label)
.migrationAccessibilityHint(model.style.checkMessagesButtonStyle.accessibility.hint)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ extension SecureConversations {
final class ConfirmationViewController: UIViewController {
private let model: ConfirmationViewSwiftUI.Model

init(
model: ConfirmationViewSwiftUI.Model
) {
init(model: ConfirmationViewSwiftUI.Model) {
self.model = model
super.init(nibName: nil, bundle: nil)
}
Expand All @@ -20,11 +18,10 @@ extension SecureConversations {
override func loadView() {
super.loadView()
let hostingController: UIHostingController<ConfirmationViewSwiftUI>
let confirmationView = ConfirmationViewSwiftUI(
model: model
)
let confirmationView = ConfirmationViewSwiftUI(model: model)

hostingController = UIHostingController(rootView: confirmationView)
hostingController.willMove(toParent: self)
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.didMove(toParent: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ extension CallVisualizer {
var assetsBuilder: () -> RemoteConfiguration.AssetsBuilder
var getCurrentEngagement: CoreSdkClient.GetCurrentEngagement
var eventHandler: ((GliaEvent) -> Void)?
var orientationManager: OrientationManager
}
}
3 changes: 2 additions & 1 deletion GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public final class CallVisualizer {
case .maximized:
self?.environment.eventHandler?(.maximized)
}
}
},
orientationManager: environment.orientationManager
)
)
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ extension CallVisualizer.Coordinator {
var date: () -> Date
var engagedOperator: () -> CoreSdkClient.Operator?
var eventHandler: (DelegateEvent) -> Void
var orientationManager: OrientationManager
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ extension CallVisualizer {
let coordinator = ScreenSharingCoordinator(
environment: .init(
theme: environment.viewFactory.theme,
screenShareHandler: environment.screenShareHandler
screenShareHandler: environment.screenShareHandler,
orientationManager: environment.orientationManager
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ extension CallVisualizer.Environment {
engagedOperator: { .mock() },
uiConfig: { nil },
assetsBuilder: { .standard },
getCurrentEngagement: CoreSdkClient.mock.getCurrentEngagement
getCurrentEngagement: CoreSdkClient.mock.getCurrentEngagement,
orientationManager: .mock()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if DEBUG
import SwiftUI

extension CallVisualizer.ScreenSharingView.Model {
static func mock(
style: ScreenSharingViewStyle = .mock(),
screenSharingHandler: ScreenShareHandler = .mock
) -> CallVisualizer.ScreenSharingView.Model {
.init(
style: style,
environment: .init(
orientationManager: .mock(),
uiApplication: .mock,
screenShareHandler: screenSharingHandler
)
)
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ extension CallVisualizer.ScreenSharingCoordinator {
struct Environment {
let theme: Theme
let screenShareHandler: ScreenShareHandler
let orientationManager: OrientationManager
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension CallVisualizer {
var delegate: ((DelegateEvent) -> Void)?

private let environment: Environment
private var viewModel: ScreenSharingViewModel?
private var viewModel: ScreenSharingView.Model?
var viewController: ScreenSharingViewController?

// MARK: - Initialization
Expand All @@ -24,40 +24,31 @@ extension CallVisualizer {
// MARK: - Private

private func showEndScreenSharingViewController() -> ViewController {
let viewModel = ScreenSharingViewModel(
style: environment.theme.screenSharing,
environment: .init(screenShareHandler: environment.screenShareHandler)
let environment: ScreenSharingView.Model.Environment = .init(
orientationManager: self.environment.orientationManager,
uiApplication: .live,
screenShareHandler: environment.screenShareHandler
)
let model: ScreenSharingView.Model = .init(
style: self.environment.theme.screenSharing,
environment: environment
)

self.viewModel = viewModel
self.viewModel = model

let viewController = ScreenSharingViewController(props: viewModel.props())
let viewController: ScreenSharingViewController = .init(model: model)
viewController.modalPresentationStyle = .overFullScreen
self.viewController = viewController

viewModel.delegate = .init { [weak self, weak viewController] event in
model.delegate = .init { [weak self, weak viewController] event in
switch event {
case .close:
case .closeTapped:
viewController?.dismiss(animated: true)
self?.delegate?(.close)
}
}

return viewController
}

private static func createHeaderProps(with header: HeaderStyle) -> Header.Props {
let backButton = header.backButton.map { HeaderButton.Props(style: $0) }

return .init(
title: "",
effect: .none,
endButton: .init(),
backButton: backButton,
closeButton: .init(style: header.closeButton),
endScreenshareButton: .init(style: header.endScreenShareButton),
style: header
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import SwiftUI
import Combine

extension CallVisualizer.ScreenSharingView {
final class Model: ObservableObject {
@Published private(set) var orientation: UIInterfaceOrientation
let style: ScreenSharingViewStyle
let environment: Environment
let orientationManager: OrientationManager
var delegate: Command<DelegateEvent> = .nop
var cancellables: Set<AnyCancellable> = []

init(style: ScreenSharingViewStyle, environment: Environment) {
self.style = style
self.environment = environment
self.orientationManager = environment.orientationManager
self.orientation = orientationManager.orientation

orientationManager.$orientation
.sink { [weak self] orientation in
self?.orientation = orientation
}
.store(in: &self.cancellables)
}
}
}

extension CallVisualizer.ScreenSharingView.Model {
func event(_ event: Event) {
switch event {
case .closeTapped:
delegate(.closeTapped)
case .endScreenShareTapped:
endScreenSharing()
}
}

func makeHeaderModel() -> HeaderSwiftUI.Model {
let endButtonProps: ActionButtonSwiftUI.Model = .init(
style: style.header.endButton,
accessibilityIdentifier: "header_end_button",
isEnabled: false,
isHidden: true
)

var backButton: HeaderButtonSwiftUI.Model?
if let endButtonStyle = style.header.backButton {
backButton = .init(
tap: Cmd { [weak self] in
self?.delegate(.closeTapped)
},
style: endButtonStyle,
accessibilityIdentifier: "header_back_button",
size: .init(width: 20, height: 20),
isEnabled: true,
isHidden: false
)
}

let closeButtonProps: HeaderButtonSwiftUI.Model = .init(
style: style.header.closeButton,
accessibilityIdentifier: "header_close_button",
isEnabled: false,
isHidden: true
)

let endScreenShareButtonProps: HeaderButtonSwiftUI.Model = .init(
style: style.header.endScreenShareButton,
accessibilityIdentifier: "header_end_screen_sharing_button",
isEnabled: false,
isHidden: true
)

let environment: HeaderSwiftUI.Environment = .init(uiApplication: environment.uiApplication)

return .init(
title: style.title,
effect: .none,
endButton: endButtonProps,
backButton: backButton,
closeButton: closeButtonProps,
endScreenshareButton: endScreenShareButtonProps,
style: style.header,
environment: environment
)
}
}

private extension CallVisualizer.ScreenSharingView.Model {
func endScreenSharing() {
environment.screenShareHandler.stop(nil)
}
}

extension CallVisualizer.ScreenSharingView.Model {
struct Environment {
let orientationManager: OrientationManager
let uiApplication: UIKitBased.UIApplication
let screenShareHandler: ScreenShareHandler
}

enum DelegateEvent {
case closeTapped
}

enum Event {
case closeTapped
case endScreenShareTapped
}
}
Loading

0 comments on commit 29b34f2

Please sign in to comment.