Skip to content

Commit

Permalink
Implement button to switch camera instead of dbltap
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 21, 2024
1 parent b4b2970 commit a858fe5
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions Monal/Classes/AVCallUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct AVCallUI: View {
y: UIScreen.main.bounds.size.height/5.0/2.0 + 16.0
)
@State private var cameraPosition: AVCaptureDevice.Position = .front
@State private var cameraPositionButtonVisible = false
private var ringingPlayer: AVAudioPlayer!
private var busyPlayer: AVAudioPlayer!
private var errorPlayer: AVAudioPlayer!
Expand Down Expand Up @@ -176,22 +177,36 @@ struct AVCallUI: View {
if MLCallType(rawValue:call.callType) == .video && MLCallState(rawValue:call.state) == .connected {
VideoView(renderer:self.remoteRenderer)

VideoView(renderer:self.localRenderer)
//this will sometimes only honor the width and ignore the height
.frame(width: UIScreen.main.bounds.size.width/5.0, height: UIScreen.main.bounds.size.height/5.0)
.position(localRendererLocation)
.gesture(DragGesture().onChanged { value in
self.localRendererLocation = value.location
})
.onTapGesture(count: 2) {
if cameraPosition == .front {
cameraPosition = .back
} else {
cameraPosition = .front
}
call.obj.stopCaptureLocalVideo()
maybeStartRenderer()
ZStack {
VideoView(renderer:self.localRenderer)
//this will sometimes only honor the width and ignore the height
.frame(width: UIScreen.main.bounds.size.width/5.0, height: UIScreen.main.bounds.size.height/5.0)

if cameraPositionButtonVisible {
Button(action: {
if cameraPosition == .front {
cameraPosition = .back
} else {
cameraPosition = .front
}
call.obj.stopCaptureLocalVideo()
maybeStartRenderer()
cameraPositionButtonVisible = false
}, label: {
Image(systemName: "arrow.triangle.2.circlepath.camera.fill")
.resizable()
.frame(width: 32.0, height: 32.0)
.foregroundColor(.primary)
})
}
}
.position(localRendererLocation)
.gesture(DragGesture().onChanged { value in
self.localRendererLocation = value.location
})
.onTapGesture(count: 1) {
cameraPositionButtonVisible = !cameraPositionButtonVisible
}
}

if MLCallType(rawValue:call.callType) == .audio ||
Expand Down Expand Up @@ -545,6 +560,7 @@ struct AVCallUI: View {
}
.onTapGesture(count: 1) {
controlsVisible = !controlsVisible
cameraPositionButtonVisible = false
}
.alert(isPresented: $showMicAlert) {
Alert(
Expand Down

0 comments on commit a858fe5

Please sign in to comment.