Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Apr 30, 2024
1 parent 26ee5ed commit a9bfa79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Sources/StreamVideoSwiftUI/CallView/CornerDraggableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ public struct CornerDraggableView<Content: View>: View {
public var body: some View {
content(availableFrame)
.overlay(
// SwiftUI seems to remove any interaction of views that not
// getting rendered (e.g. an empty GeometryReader, a VStack
// with a Spacer, an EmptyView, a Color.clear or a Shape
// with clear fill). If we use a simple button here then the
// interaction happening is slower because than what we have now.
Color.black.opacity(0.01)
// This is to avoid conflicts with buttons on the top and bottom
// part of the participant view.
.padding(.vertical, 30)
.onTapGesture { onTap() }
)
Expand Down Expand Up @@ -106,12 +113,15 @@ public struct CornerDraggableView<Content: View>: View {
return placement
}

// Calculate the center of the frame
let centerX = frame.origin.x + frame.size.width / 2
let centerY = frame.origin.y + frame.size.height / 2
let centerPoint = CGPoint(x: centerX, y: centerY)

// Calculate the Euclidean distance to the location
let distance = sqrt(pow(centerPoint.x - location.x, 2) + pow(centerPoint.y - location.y, 2))

// Check if this is the closest placement so far
if minDistance == nil {
minDistance = distance
closestPlacement = placement
Expand All @@ -121,7 +131,7 @@ public struct CornerDraggableView<Content: View>: View {
}
}

return closestPlacement ?? .topTrailing
return closestPlacement ?? .topTrailing // default to .topTrailing if for some reason no placement was closer
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/StreamVideoSwiftUI/CallView/VideoRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ extension VideoRenderer {
)
add(track: track)
DispatchQueue.global(qos: .userInteractive).asyncAfter(deadline: .now() + 0.01) { [weak self] in
guard let self = self else { return }
guard let self else { return }
let prev = participant.trackSize
if let viewSize = self.viewSize, prev != viewSize {
if let viewSize, prev != viewSize {
log.debug(
"Update trackSize of \(track.kind) track for \(participant.name) on \(type(of: self)):\(self.identifier)), \(prev)\(viewSize)",
"Update trackSize of \(track.kind) track for \(participant.name) on \(type(of: self)):\(identifier)), \(prev)\(viewSize)",
subsystems: .webRTC
)
onTrackSizeUpdate(viewSize, participant)
Expand Down

0 comments on commit a9bfa79

Please sign in to comment.