MijickCamera/Sources/Internal/UI/Default Screens/Camera/DefaultCameraScreen+CaptureButton.swift

56 lines
1.6 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// DefaultCameraScreen+CaptureButton.swift of MijickCamera
//
// Created by Tomasz Kurylik. Sending from Kraków!
// - Mail: tomasz.kurylik@mijick.com
// - GitHub: https://github.com/FulcrumOne
// - Medium: https://medium.com/@mijick
//
// Copyright ©2024 Mijick. All rights reserved.
import SwiftUI
extension DefaultCameraScreen { struct CaptureButton: View {
let outputType: CameraOutputType
let isRecording: Bool
let action: () -> ()
var body: some View {
Button(action: action, label: createButtonLabel).buttonStyle(ButtonScaleStyle())
}
}}
private extension DefaultCameraScreen.CaptureButton {
func createButtonLabel() -> some View {
ZStack {
createBackground()
createBorders()
}.frame(width: 72, height: 72)
}
}
private extension DefaultCameraScreen.CaptureButton {
func createBackground() -> some View {
RoundedRectangle(cornerRadius: backgroundCornerRadius, style: .continuous)
.fill(backgroundColor)
.padding(backgroundPadding)
}
func createBorders() -> some View {
Circle().stroke(Color(.mijickBackgroundInverted), lineWidth: 2.5)
}
}
private extension DefaultCameraScreen.CaptureButton {
var backgroundColor: Color { switch outputType {
case .photo: .init(.mijickBackgroundInverted)
case .video: .init(.mijickBackgroundRed)
}}
var backgroundCornerRadius: CGFloat { switch isRecording {
case true: 6
case false: 36
}}
var backgroundPadding: CGFloat { switch isRecording {
case true: 20
case false: 4
}}
}