Skip to content

Commit

Permalink
DemoApp Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Jan 24, 2024
1 parent c68fa3a commit 8e9d423
Show file tree
Hide file tree
Showing 19 changed files with 486 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public struct DemoVideoCallParticipantOptionsModifier: ViewModifier {
Image(systemName: "ellipsis")
.foregroundColor(.white)
.padding(8)
.background(Color.black.opacity(0.6))
.background(appearance.colors.participantInfoBackgroundColor)
.clipShape(Circle())
}

Expand Down
2 changes: 1 addition & 1 deletion DemoApp/Sources/Models/Reaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Foundation

struct Reaction: Identifiable, Codable {
struct Reaction: Identifiable, Codable, Equatable {

enum ID: String, Codable {
case fireworks = ":fireworks:"
Expand Down
73 changes: 20 additions & 53 deletions DemoApp/Sources/Views/CallTopView/DemoCallTopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,68 +23,35 @@ struct DemoCallTopView: View {
}

var body: some View {
HStack {
Menu {
Button {
viewModel.toggleSpeaker()
} label: {
HStack {
Text("Speaker")
if viewModel.callSettings.speakerOn {
Image(systemName: "checkmark")
}
}
}

Button {
if appState.audioFilter == nil {
appState.audioFilter = RobotVoiceFilter(pitchShift: 0.8)
} else {
appState.audioFilter = nil
}
} label: {
HStack {
Text("Robot voice")
if appState.audioFilter != nil {
Image(systemName: "checkmark")
}
}
HStack(spacing: 0) {
HStack {
if viewModel.callParticipants.count > 1 {
LayoutMenuView(viewModel: viewModel)
.opacity(hideLayoutMenu ? 0 : 1)
.accessibility(identifier: "viewMenu")
}

ToggleCameraIconView(viewModel: viewModel)

reactionsList()
} label: {
Image(systemName: "ellipsis")
.foregroundColor(.white)
.font(fonts.bodyBold)
.padding()
Spacer()
}
.frame(maxWidth: .infinity)

if viewModel.recordingState == .recording {
RecordingView()
.accessibility(identifier: "recordingLabel")
HStack(alignment: .center) {
CallDurationView(viewModel)
}
.frame(height: 44)
.frame(maxWidth: .infinity)

Spacer()


if #available(iOS 14, *) {
HStack(spacing: 16) {
LayoutMenuView(viewModel: viewModel)
.opacity(hideLayoutMenu ? 0 : 1)
.accessibility(identifier: "viewMenu")

Button {
viewModel.participantsShown.toggle()
} label: {
images.participants
.foregroundColor(.white)
}
.accessibility(identifier: "participantMenu")
}
.padding(.horizontal)
HStack {
Spacer()
HangUpIconView(viewModel: viewModel)
}
.frame(maxWidth: .infinity)
}
.padding(.horizontal, 16)
.padding(.top)
.frame(maxWidth: .infinity)
.overlay(
viewModel.call?.state.isCurrentUserScreensharing == true ?
SharingIndicator(
Expand Down
2 changes: 2 additions & 0 deletions DemoApp/Sources/Views/CallView/DemoCallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct DemoCallView<ViewFactory: DemoAppViewFactory>: View {

var microphoneChecker: MicrophoneChecker

@ObservedObject var appState: AppState = .shared
@ObservedObject var viewModel: CallViewModel
@ObservedObject var reactionsHelper: ReactionsHelper = AppState.shared.reactionsHelper

Expand Down Expand Up @@ -75,6 +76,7 @@ struct DemoCallView<ViewFactory: DemoAppViewFactory>: View {
.onAppear {
updateMicrophoneChecker()
}
.presentsMoreControls(viewModel: viewModel)
.chat(viewModel: viewModel, chatViewModel: chatViewModel)
}

Expand Down
33 changes: 28 additions & 5 deletions DemoApp/Sources/Views/CallView/DemoChatModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,45 @@

import Foundation
import SwiftUI
import StreamVideo
import StreamVideoSwiftUI

struct ChatModifier: ViewModifier {

@Injected(\.images) var images
@Injected(\.fonts) var fonts
@Injected(\.colors) var colors

@ObservedObject var viewModel: CallViewModel
@ObservedObject var chatViewModel: DemoChatViewModel

func body(content: Content) -> some View {
content
.halfSheetIfAvailable(
isPresented: $chatViewModel.isChatVisible,
onDismiss: {}
.sheet(
isPresented: $chatViewModel.isChatVisible
) {
if let channelController = chatViewModel.channelController {
VStack {
ChatControlsHeader(viewModel: viewModel)
VStack(spacing: 0) {
VStack(alignment: .center) {
DragHandleView()
.padding(.top)
}.frame(maxWidth: .infinity)

HStack {
Text("Chat")
.font(fonts.title3)
.fontWeight(.medium)

Spacer()

ModalButton(image: images.xmark) {
chatViewModel.isChatVisible = false
}
}
.foregroundColor(.white)
.padding(.bottom, 24)
.padding(.top)
.padding(.horizontal)
ChatView(
channelController: channelController,
chatViewModel: chatViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct DemoQRCodeScannerButton: View {
.foregroundColor(.init(appearance.colors.textLowEmphasis))
}
.padding(.trailing)
.halfSheetIfAvailable(isPresented: $isQRScannerPresented) {
.sheet(isPresented: $isQRScannerPresented) {
CodeScannerView(codeTypes: [.qr]) { result in
switch result {
case .success(let scanResult):
Expand Down
107 changes: 51 additions & 56 deletions DemoApp/Sources/Views/Controls/DemoControls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,64 @@ struct AppControlsWithChat: View {
}

var body: some View {
HStack(alignment: .center) {
if let chatViewModel, chatViewModel.isChatEnabled {
ChatIconView(viewModel: chatViewModel)
HStack {
if viewModel.callParticipants.count > 1 {
MoreControlsIconView(viewModel: viewModel)
}
VideoIconView(viewModel: viewModel)
MicrophoneIconView(viewModel: viewModel)
ToggleCameraIconView(viewModel: viewModel)
#if !targetEnvironment(simulator)

#if !targetEnvironment(simulator)
if !ProcessInfo.processInfo.isiOSAppOnMac {
BroadcastIconView(
viewModel: viewModel,
preferredExtension: "io.getstream.iOS.VideoDemoApp.ScreenSharing"
)
}
#endif
HangUpIconView(viewModel: viewModel)
#endif
VideoIconView(viewModel: viewModel)
MicrophoneIconView(viewModel: viewModel)

Spacer()

ParticipantsListButton(viewModel: viewModel)

if let chatViewModel, chatViewModel.isChatEnabled {
ChatIconView(viewModel: chatViewModel)
}
}
.padding()
.frame(maxWidth: .infinity)
.cornerRadius(
cornerRadius,
corners: [.topLeft, .topRight],
backgroundColor: colors.callControlsBackground,
extendToSafeArea: true
)
.padding(.horizontal, 16)
.padding(.bottom)
.onReceive(viewModel.$call) { reactionsHelper.call = $0 }
}
}

struct MoreControlsIconView: View {

@ObservedObject var viewModel: CallViewModel
let size: CGFloat

init(viewModel: CallViewModel, size: CGFloat = 44) {
self.viewModel = viewModel
self.size = size
}

var body: some View {
Button(
action: {
viewModel.moreControlsShown.toggle()
},
label: {
CallIconView(
icon: Image(systemName: "ellipsis"),
size: size,
iconStyle: viewModel.moreControlsShown ? .secondaryActive : .secondary
)
.rotationEffect(.degrees(90))
}
)
.accessibility(identifier: "moreControlsToggle")
}
}

struct ChatControlsHeader: View {

@Injected(\.streamVideo) var streamVideo
Expand Down Expand Up @@ -87,7 +116,7 @@ struct ChatIconView: View {
@ObservedObject var viewModel: DemoChatViewModel
let size: CGFloat

init(viewModel: DemoChatViewModel, size: CGFloat = 50) {
init(viewModel: DemoChatViewModel, size: CGFloat = 44) {
self.viewModel = viewModel
self.size = size
}
Expand All @@ -99,26 +128,12 @@ struct ChatIconView: View {
},
label: {
CallIconView(
icon: viewModel.isChatVisible ? .init(systemName: "message.fill") : .init(systemName: "message"),
icon: .init(systemName: "bubble.left.and.bubble.right.fill"),
size: size,
iconStyle: viewModel.isChatVisible ? .primary : .transparent
iconStyle: viewModel.isChatVisible ? .secondaryActive : .secondary
).overlay(
VStack {
HStack {
Spacer()
if viewModel.unreadCount > 0 {
Text("\(viewModel.unreadCount)")
.font(.caption.monospacedDigit())
.foregroundColor(colors.text)
.padding([.leading, .trailing], 4)
.padding([.top, .bottom], 2)
.background(Color.red)
.clipShape(Capsule())
.clipped()
}
}
Spacer()
}
ControlBadgeView("\(viewModel.unreadCount)")
.opacity(viewModel.unreadCount > 0 ? 1 : 0)
)
}
)
Expand All @@ -144,23 +159,3 @@ struct ChatView: View {
}
}
}

extension View {

@ViewBuilder
func halfSheetIfAvailable<Content>(
isPresented: Binding<Bool>,
onDismiss: (() -> Void)? = nil,
@ViewBuilder content: @escaping () -> Content
) -> some View where Content : View {
if #available(iOS 16.0, *) {
sheet(isPresented: isPresented, onDismiss: onDismiss) {
content()
.presentationDetents([.large])
.presentationDragIndicator(.visible)
}
} else {
sheet(isPresented: isPresented, onDismiss: onDismiss) { content() }
}
}
}
Loading

0 comments on commit 8e9d423

Please sign in to comment.