Skip to content

Commit

Permalink
[Improvements]Change available size to available frame (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis authored Oct 6, 2023
1 parent a423ee4 commit ab38e14
Show file tree
Hide file tree
Showing 35 changed files with 274 additions and 264 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### 🔄 Changed
- Factory method for creating `LocalParticipantViewModifier`
- `availableSize` has been replaced by `availableFrame` in most Views.

# [0.3.0](https://github.com/GetStream/stream-video-swift/releases/tag/0.3.0)
_August 25, 2023_
Expand Down
4 changes: 2 additions & 2 deletions DemoApp/Sources/Components/DemoAppViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ final class DemoAppViewFactory: ViewFactory {
func makeVideoCallParticipantModifier(
participant: CallParticipant,
call: Call?,
availableSize: CGSize,
availableFrame: CGRect,
ratio: CGFloat,
showAllInfo: Bool
) -> some ViewModifier {
DemoVideoCallParticipantModifier(
participant: participant,
call: call,
availableSize: availableSize,
availableFrame: availableFrame,
ratio: ratio,
showAllInfo: showAllInfo
)
Expand Down
18 changes: 9 additions & 9 deletions DemoApp/Sources/Examples/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ struct CustomVideoCallParticipantView: View {

let participant: CallParticipant
var id: String
var availableSize: CGSize
var availableFrame: CGRect
var contentMode: UIView.ContentMode
var edgesIgnoringSafeArea: Edge.Set
var onViewUpdate: (CallParticipant, VideoRenderer) -> Void

public init(
participant: CallParticipant,
id: String? = nil,
availableSize: CGSize,
availableFrame: CGRect,
contentMode: UIView.ContentMode,
edgesIgnoringSafeArea: Edge.Set = .all,
onViewUpdate: @escaping (CallParticipant, VideoRenderer) -> Void
) {
self.participant = participant
self.id = id ?? participant.id
self.availableSize = availableSize
self.availableFrame = availableFrame
self.contentMode = contentMode
self.edgesIgnoringSafeArea = edgesIgnoringSafeArea
self.onViewUpdate = onViewUpdate
Expand All @@ -97,7 +97,7 @@ struct CustomVideoCallParticipantView: View {
public var body: some View {
VideoRendererView(
id: id,
size: availableSize,
size: availableFrame.size,
contentMode: contentMode
) { view in
onViewUpdate(participant, view)
Expand All @@ -113,7 +113,7 @@ struct CustomVideoCallParticipantView: View {
startPoint: .top,
endPoint: .bottom
)
.frame(width: availableSize.width)
.frame(width: availableFrame.width)
.opacity(showVideo ? 0 : 1)

ZStack {
Expand Down Expand Up @@ -142,26 +142,26 @@ struct CustomParticipantModifier: ViewModifier {
var participant: CallParticipant
@Binding var pinnedParticipant: CallParticipant?
var participantCount: Int
var availableSize: CGSize
var availableFrame: CGRect
var ratio: CGFloat

public init(
participant: CallParticipant,
pinnedParticipant: Binding<CallParticipant?>,
participantCount: Int,
availableSize: CGSize,
availableFrame: CGRect,
ratio: CGFloat
) {
self.participant = participant
_pinnedParticipant = pinnedParticipant
self.participantCount = participantCount
self.availableSize = availableSize
self.availableFrame = availableFrame
self.ratio = ratio
}

public func body(content: Content) -> some View {
content
.adjustVideoFrame(to: availableSize.width, ratio: ratio)
.adjustVideoFrame(to: availableFrame.width, ratio: ratio)
.overlay(
ZStack {
VStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ struct DemoVideoCallParticipantModifier: ViewModifier {

var participant: CallParticipant
var call: Call?
var availableSize: CGSize
var availableFrame: CGRect
var ratio: CGFloat
var showAllInfo: Bool

init(
participant: CallParticipant,
call: Call?,
availableSize: CGSize,
availableFrame: CGRect,
ratio: CGFloat,
showAllInfo: Bool
) {
self.participant = participant
self.call = call
self.availableSize = availableSize
self.availableFrame = availableFrame
self.ratio = ratio
self.showAllInfo = showAllInfo
}

func body(content: Content) -> some View {
content
.adjustVideoFrame(to: availableSize.width, ratio: ratio)
.adjustVideoFrame(to: availableFrame.size.width, ratio: ratio)
.overlay(
ZStack {
BottomView(content: {
Expand Down Expand Up @@ -83,7 +83,7 @@ struct DemoVideoCallParticipantModifier: ViewModifier {
}
}
)
.modifier(ReactionsViewModifier(participant: participant, availableSize: availableSize))
.modifier(ReactionsViewModifier(participant: participant, availableSize: availableFrame.size))
.onTapGesture(count: 2, perform: {
popoverShown = true
})
Expand Down
20 changes: 10 additions & 10 deletions Sources/StreamVideoSwiftUI/CallView/CallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public struct CallView<Factory: ViewFactory>: View {
viewFactory.makeScreenSharingView(
viewModel: viewModel,
screensharingSession: screenSharingSession,
availableSize: videoFeedProxy.size
availableFrame: videoFeedProxy.frame(in: .global)
)
} else {
participantsView(size: videoFeedProxy.size)
participantsView(bounds: videoFeedProxy.frame(in: .global))
}
}

Expand All @@ -53,7 +53,7 @@ public struct CallView<Factory: ViewFactory>: View {
if (viewModel.call?.state.screenSharingSession == nil || viewModel.call?.state.isCurrentUserScreensharing == true),
viewModel.participantsLayout == .grid, viewModel.participants.count <= 3 {
CornerDragableView(
content: contentDragableView(size: reader.size),
content: contentDragableView(bounds: reader.frame(in: .global)),
proxy: reader
) {
withAnimation {
Expand Down Expand Up @@ -90,7 +90,7 @@ public struct CallView<Factory: ViewFactory>: View {
if viewModel.participantsShown {
viewFactory.makeParticipantsListView(
viewModel: viewModel,
availableSize: reader.size
availableFrame: reader.frame(in: .global)
)
.opacity(viewModel.hideUIElements ? 0 : 1)
.accessibility(identifier: "trailingTopView")
Expand All @@ -108,22 +108,22 @@ public struct CallView<Factory: ViewFactory>: View {
}

@ViewBuilder
private func contentDragableView(size: CGSize) -> some View {
private func contentDragableView(bounds: CGRect) -> some View {
if !viewModel.localVideoPrimary {
localVideoView
.cornerRadius(16)
.padding(.horizontal)
} else {
minimizedView(size: size)
minimizedView(bounds: bounds)
}
}

private func minimizedView(size: CGSize) -> some View {
private func minimizedView(bounds: CGRect) -> some View {
Group {
if !viewModel.participants.isEmpty {
VideoCallParticipantView(
participant: viewModel.participants[0],
availableSize: size,
availableFrame: bounds,
contentMode: .scaleAspectFill,
customData: [:],
call: viewModel.call
Expand Down Expand Up @@ -155,10 +155,10 @@ public struct CallView<Factory: ViewFactory>: View {
}
}

private func participantsView(size: CGSize) -> some View {
private func participantsView(bounds: CGRect) -> some View {
viewFactory.makeVideoParticipantsView(
viewModel: viewModel,
availableSize: size,
availableFrame: bounds,
onChangeTrackVisibility: viewModel.changeTrackVisibility(for:isVisible:)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct MinimizedCallView: View {
if !viewModel.participants.isEmpty {
VideoCallParticipantView(
participant: viewModel.participants[0],
availableSize: proxy.size,
availableFrame: proxy.frame(in: .global),
contentMode: .scaleAspectFill,
customData: [:],
call: viewModel.call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public struct CallParticipantsInfoView: View {

@StateObject var viewModel: CallParticipantsInfoViewModel
@ObservedObject var callViewModel: CallViewModel
var availableSize: CGSize
public init(callViewModel: CallViewModel, availableSize: CGSize) {
var availableFrame: CGRect

public init(callViewModel: CallViewModel, availableFrame: CGRect) {
self.callViewModel = callViewModel
self.availableSize = availableSize
self.availableFrame = availableFrame
_viewModel = StateObject(
wrappedValue: CallParticipantsInfoViewModel(
call: callViewModel.call
Expand All @@ -30,7 +30,7 @@ public struct CallParticipantsInfoView: View {
CallParticipantsView(
viewModel: viewModel,
callViewModel: callViewModel,
maxHeight: availableSize.height - padding
maxHeight: availableFrame.size.height - padding
)
.padding()
.padding(.vertical, padding / 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ public struct ParticipantsFullScreenLayout<Factory: ViewFactory>: View {
var viewFactory: Factory
var participant: CallParticipant
var call: Call?
var size: CGSize
var frame: CGRect
var onChangeTrackVisibility: @MainActor(CallParticipant, Bool) -> Void

public init(
viewFactory: Factory,
participant: CallParticipant,
call: Call?,
size: CGSize,
frame: CGRect,
onChangeTrackVisibility: @escaping @MainActor (CallParticipant, Bool) -> Void
) {
self.viewFactory = viewFactory
self.participant = participant
self.call = call
self.size = size
self.frame = frame
self.onChangeTrackVisibility = onChangeTrackVisibility
}

public var body: some View {
viewFactory.makeVideoParticipantView(
participant: participant,
id: participant.id,
availableSize: size,
availableFrame: frame,
contentMode: .scaleAspectFit,
customData: [:],
call: call
Expand All @@ -41,7 +41,7 @@ public struct ParticipantsFullScreenLayout<Factory: ViewFactory>: View {
viewFactory.makeVideoCallParticipantModifier(
participant: participant,
call: call,
availableSize: size,
availableFrame: frame,
ratio: ratio,
showAllInfo: true
)
Expand All @@ -57,7 +57,7 @@ public struct ParticipantsFullScreenLayout<Factory: ViewFactory>: View {
}

private var ratio: CGFloat {
size.width / size.height
frame.size.width / frame.size.height
}
}

Expand Down
Loading

0 comments on commit ab38e14

Please sign in to comment.