Skip to content

Commit

Permalink
implement
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Mar 11, 2024
1 parent d7c79a1 commit 7ed3cbd
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Sources/LiveKitComponents/Layouts/ParticipantLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import SwiftUI

struct ParticipantLayout<Data: RandomAccessCollection, Content: View>: View where Data.Element: Identifiable, Data.Index: Hashable {
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

private let data: Data
private let spacing: CGFloat?
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKitComponents/Prebuilt/ConnectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftUI

public struct ConnectView: View {
@EnvironmentObject var room: Room
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

@AppStorage("url") var url: String = ""
@AppStorage("token") var token: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import LiveKit
import SwiftUI

public struct VideoConferenceView: View {
@EnvironmentObject var ui: UIPreference
@EnvironmentObject var room: Room
@Environment(\.uiPreference) var ui: UIPreference

public init() {}

Expand Down
14 changes: 13 additions & 1 deletion Sources/LiveKitComponents/Scopes/ComponentsScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
import LiveKit
import SwiftUI

public struct LiveKitComponentsEnvironmentKey: EnvironmentKey {
// This is the default value that SwiftUI will fallback to if you don't pass the object
public static var defaultValue: UIPreference = .init()
}

public extension EnvironmentValues {
var uiPreference: UIPreference {
get { self[LiveKitComponentsEnvironmentKey.self] }
set { self[LiveKitComponentsEnvironmentKey.self] = newValue }
}
}

public struct ComponentsScope<Content: View>: View {
var content: () -> Content
let preference: UIPreference
Expand All @@ -30,6 +42,6 @@ public struct ComponentsScope<Content: View>: View {

public var body: some View {
content()
.environmentObject(preference)
.environment(\.uiPreference, preference)
}
}
94 changes: 48 additions & 46 deletions Sources/LiveKitComponents/UIPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,87 +33,89 @@ open class UIPreference: ObservableObject {
/// Spacing between ``ParticipantView``s.
var participantViewSpacing: CGFloat { 8 }

public init() {}

/// Placeholder view when the video is disabled or not available.
public func videoDisabledView(geometry: GeometryProxy) -> some View {
Image(systemName: "video.slash")
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(Color(.lightGray))
.frame(width: min(geometry.size.width, geometry.size.height) * 0.3)
.frame(
maxWidth: .infinity,
maxHeight: .infinity
)
public func videoDisabledView(geometry: GeometryProxy) -> AnyView {
AnyView(
Image(systemName: "video.slash")
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(Color(.lightGray))
.frame(width: min(geometry.size.width, geometry.size.height) * 0.3)
.frame(
maxWidth: .infinity,
maxHeight: .infinity
))
}

func micEnabledView() -> some View {
Image(systemName: "mic.fill")
.foregroundColor(.orange)
func micEnabledView() -> AnyView {
AnyView(Image(systemName: "mic.fill")
.foregroundColor(.orange))
}

/// Placeholder view when the microphone is disabled or not available.
func micDisabledView() -> some View {
Image(systemName: "mic.slash.fill")
.foregroundColor(.red)
open func micDisabledView() -> AnyView {
AnyView(Image(systemName: "mic.slash.fill")
.foregroundColor(.red))
}

func enableVideoView() -> some View {
Image(systemName: "video.slash.fill")
open func enableVideoView() -> AnyView {
AnyView(Image(systemName: "video.slash.fill"))
}

func disableVideoView() -> some View {
Image(systemName: "video.fill")
.foregroundColor(.green)
func disableVideoView() -> AnyView {
AnyView(Image(systemName: "video.fill")
.foregroundColor(.green))
}

func enableMicrophoneView() -> some View {
Image(systemName: "mic.slash.fill")
open func enableMicrophoneView() -> AnyView {
AnyView(Image(systemName: "mic.slash.fill"))
}

func disableMicrophoneView() -> some View {
Image(systemName: "mic.fill")
.foregroundColor(.orange)
func disableMicrophoneView() -> AnyView {
AnyView(Image(systemName: "mic.fill")
.foregroundColor(.orange))
}

func disconnectView() -> some View {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.red)
func disconnectView() -> AnyView {
AnyView(Image(systemName: "xmark.circle.fill")
.foregroundColor(.red))
}

func textFieldContainer(_ childView: () -> some View, label: () -> some View) -> some View {
VStack(alignment: .leading, spacing: 10.0) {
func textFieldContainer(_ childView: () -> some View, label: () -> some View) -> AnyView {
AnyView(VStack(alignment: .leading, spacing: 10.0) {
label()

childView()
.padding()
.overlay(RoundedRectangle(cornerRadius: 10.0)
.strokeBorder(Color.white.opacity(0.3),
style: StrokeStyle(lineWidth: 1.0)))
}
})
}

func textField(for text: Binding<String>, type _: TextFieldType) -> some View {
TextField("", text: text)
func textField(for text: Binding<String>, type _: TextFieldType) -> AnyView {
AnyView(TextField("", text: text)
.textFieldStyle(PlainTextFieldStyle())
.disableAutocorrection(true)
// TODO: add iOS unique view modifiers
#if os(iOS)
.autocapitalization(.none)
// .keyboardType(type.toiOSType())
#endif
// TODO: add iOS unique view modifiers
#if os(iOS)
.autocapitalization(.none)
// .keyboardType(type.toiOSType())
#endif)
}

func button(_ action: @escaping () -> Void, label: () -> some View) -> some View {
Button(action: action, label: label)
func button(_ action: @escaping () -> Void, label: () -> some View) -> AnyView {
AnyView(Button(action: action, label: label))
}

func connectionQualityIndicatorBuilder(connectionQuality: ConnectionQuality) -> some View {
func connectionQualityIndicatorBuilder(connectionQuality: ConnectionQuality) -> AnyView {
if case .excellent = connectionQuality {
return Image(systemName: "wifi").foregroundColor(.green)
return AnyView(Image(systemName: "wifi").foregroundColor(.green))
} else if case .good = connectionQuality {
return Image(systemName: "wifi").foregroundColor(Color.orange)
return AnyView(Image(systemName: "wifi").foregroundColor(Color.orange))
}

return Image(systemName: "wifi.exclamationmark").foregroundColor(Color.red)
return AnyView(Image(systemName: "wifi.exclamationmark").foregroundColor(Color.red))
}
}
2 changes: 1 addition & 1 deletion Sources/LiveKitComponents/Views/LocalCameraPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import LiveKit
import SwiftUI

public struct LocalCameraPreview: View {
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

let localVideoTrack: LocalVideoTrack

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftUI

public struct ConnectionQualityIndicatorView: View {
@EnvironmentObject var participant: Participant
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

public var body: some View {
ui.connectionQualityIndicatorBuilder(connectionQuality: participant.connectionQuality)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftUI

public struct ParticipantInformationView: View {
@EnvironmentObject var participant: Participant
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

public var body: some View {
HStack(spacing: ui.paddingSmall) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftUI

public struct ParticipantView: View {
@EnvironmentObject var participant: Participant
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

let showInformation: Bool

Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKitComponents/Views/Room/ControlsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import SwiftUI

public struct ControlsView: View {
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

public var body: some View {
CameraToggleButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftUI

public struct LocalCameraVideoView: View {
@EnvironmentObject var room: Room
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

public init() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftUI

public struct VideoTrackView: View {
@EnvironmentObject var trackReference: TrackReference
@EnvironmentObject var ui: UIPreference
@Environment(\.uiPreference) var ui: UIPreference

var layoutMode: VideoView.LayoutMode = .fill
var mirrorMode: VideoView.MirrorMode = .auto
Expand Down

0 comments on commit 7ed3cbd

Please sign in to comment.