-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d12617
commit a951508
Showing
208 changed files
with
1,075 additions
and
279 deletions.
There are no files selected for viewing
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
100 changes: 100 additions & 0 deletions
100
Sources/StreamVideoSwiftUI/CallView/CallDurationView.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,100 @@ | ||
// | ||
// Copyright © 2024 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import StreamVideo | ||
|
||
/// A view that presents the call's duration and recording state. | ||
public struct CallDurationView: View { | ||
|
||
@Injected(\.colors) private var colors: Colors | ||
@Injected(\.fonts) private var fonts: Fonts | ||
@Injected(\.images) private var images: Images | ||
@Injected(\.formatters.mediaDuration) private var formatter: MediaDurationFormatter | ||
|
||
@State private var duration: TimeInterval | ||
@ObservedObject private var viewModel: CallViewModel | ||
|
||
@MainActor | ||
public init(_ viewModel: CallViewModel) { | ||
self.viewModel = viewModel | ||
self.duration = viewModel.call?.state.duration ?? 0 | ||
} | ||
|
||
public var body: some View { | ||
Group { | ||
if duration > 0, let formattedDuration = formatter.format(duration) { | ||
HStack(spacing: 4) { | ||
iconView | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
.frame(width: 12) | ||
.foregroundColor( | ||
viewModel.recordingState == .recording | ||
? colors.inactiveCallControl | ||
: colors.onlineIndicatorColor | ||
) | ||
|
||
TimeView(formattedDuration) | ||
.layoutPriority(2) | ||
} | ||
.padding(.horizontal) | ||
.padding(.vertical, 4) | ||
.background(Color(colors.participantBackground)) | ||
.clipShape(Capsule()) | ||
} else { | ||
EmptyView() | ||
} | ||
} | ||
.onReceive(viewModel.call?.state.$duration) { self.duration = $0 } | ||
.accessibility(identifier: accessibilityLabel) | ||
} | ||
|
||
// MARK - Private Helpers | ||
|
||
private var iconView: Image { | ||
viewModel.recordingState == .recording | ||
? images.recordIcon | ||
: images.secureCallIcon | ||
} | ||
|
||
private var accessibilityLabel: String { | ||
var result = "Call duration: \(duration) seconds." | ||
if viewModel.recordingState == .recording { | ||
result += "Recording in progress." | ||
} | ||
|
||
return result | ||
} | ||
} | ||
|
||
fileprivate struct TimeView: View { | ||
|
||
@Injected(\.fonts) private var fonts: Fonts | ||
@Injected(\.colors) private var colors: Colors | ||
|
||
var value: NSMutableAttributedString | ||
|
||
fileprivate init(_ value: String) { | ||
let attributed = NSMutableAttributedString(string: value) | ||
self.value = attributed | ||
self.value.addAttribute(.foregroundColor, value: colors.callDurationColor.withAlphaComponent(0.6), range: .init(location: 0, length: attributed.length - 3)) | ||
self.value.addAttribute(.foregroundColor, value: colors.callDurationColor, range: .init(location: attributed.length - 3, length: 3)) | ||
} | ||
|
||
fileprivate var body: some View { | ||
Group { | ||
if #available(iOS 15.0, *) { | ||
Text(AttributedString(value)) | ||
} else { | ||
Text(value.string) | ||
.foregroundColor(Color.white.opacity(0.6)) | ||
} | ||
} | ||
.font(fonts.bodyBold.monospacedDigit()) | ||
.minimumScaleFactor(0.2) | ||
.lineLimit(1) | ||
} | ||
} |
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
Oops, something went wrong.