@@ -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