Skip to content

Commit 93fe0fb

Browse files
Clamp local video view position to screen
1 parent 3c7b741 commit 93fe0fb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Monal/Classes/AVCallUI.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ struct DraggablePiPVideoView<StackedView: View>: View {
8282
}
8383

8484
var body: some View {
85-
let width = UIScreen.main.bounds.size.width / 3
85+
//size of our video
86+
let width = UIScreen.main.bounds.size.width / 3.0
8687
let height = width / observer.aspectRatio
8788

8889
let initialX = (UIScreen.main.bounds.size.width - width) / 2 - rightPadding
8990
let initialY = -(UIScreen.main.bounds.size.height - height) / 2 + topPadding
91+
92+
//used for clamping
93+
let minX = -(UIScreen.main.bounds.size.width + width) / 2 + rightPadding * 2
94+
let maxY = (UIScreen.main.bounds.size.height - height) - topPadding * 2
9095

9196
ZStack {
9297
RTCVideoContainerView(
@@ -115,12 +120,10 @@ struct DraggablePiPVideoView<StackedView: View>: View {
115120
}.onEnded { value in
116121
offset.width += value.translation.width
117122
offset.height += value.translation.height
118-
119-
// let maxX = (UIScreen.main.bounds.size.width - width) / 2 - rightPadding
120-
// let maxY = (UIScreen.main.bounds.size.height - height) / 2 - topPadding
121-
//
122-
// offset.width = min(max(offset.width, -maxX), maxX)
123-
// offset.height = min(max(offset.height, -maxY), maxY)
123+
124+
//clamp values
125+
offset.width = max(min(offset.width, 0), minX)
126+
offset.height = min(max(offset.height, 0), maxY)
124127
})
125128
.animation(.spring(response: 0.3, dampingFraction: 0.8), value: offset)
126129
.frame(maxWidth: .infinity, maxHeight: .infinity)

0 commit comments

Comments
 (0)