-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert ScreenSharingView to SwiftUI
This PR converts ScreenSharingView to SwiftUI MOB-2720
- Loading branch information
1 parent
70802eb
commit 29b34f2
Showing
35 changed files
with
409 additions
and
407 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
GliaWidgets/Sources/CallVisualizer/Mock/ScreenSharingViewModel.mock.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
GliaWidgets/Sources/CallVisualizer/ScreenSharing/Model/ScreenSharingViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.