Open source CapCut alternative.
TypeScript
feat(ios): camera fill light and the last-recording well
David Lee9467c94b077
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swiftindex fb0aaaec..47ddf11c 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift@@ -65,9 +65,18 @@ public final class CameraModel {controller?.setZoom(display: display)}+ /// True when the flash button does anything: the hardware torch, or the+ /// screen fill light on cameras without one.+ public var flashAvailable: Bool { hasTorch || facing == .front }++ /// The screen stands in for a torch the current camera lacks.+ public var isFillLightOn: Bool { isTorchOn && !hasTorch }+public func toggleTorch() {isTorchOn.toggle()- controller?.setTorch(isTorchOn)+ if hasTorch {+ controller?.setTorch(isTorchOn)+ }}public func update(_ transform: (inout CameraSettings) -> Void) {diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swiftindex 9d75bde5..48f6f0d0 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift@@ -1,20 +1,26 @@#if os(iOS)import SwiftUI+import UIKitimport DonkeyKitModelsstruct CameraScreen<CameraPreview: View>: View {@Bindable var camera: CameraModelvar ideas: IdeasModel+ var media: MediaModellet cameraPreview: () -> CameraPreview@State private var showsZoomPicker = false@State private var showsQualityPopover = false@State private var showsTeleSettings = false@State private var showsNotePicker = false+ @State private var playingRecording: Recording?var body: some View {ZStack {stage+ if camera.isFillLightOn, camera.availability == .running {+ FillLightOverlay()+ }if camera.isRecording, camera.teleprompter.hasScript {TeleprompterOverlay(camera: camera)}@@ -28,6 +34,9 @@ struct CameraScreen<CameraPreview: View>: View {showsNotePicker = false}}+ .fullScreenCover(item: $playingRecording) { recording in+ RecordingPlayerView(url: media.movieURL(for: recording))+ }}@ViewBuilder private var stage: some View {@@ -66,11 +75,49 @@ struct CameraScreen<CameraPreview: View>: View {}Spacer()}+ // Fill the screen so the leading/bottom overlays anchor to its edges;+ // without this the stack hugs its content and the rail floats mid-screen.+ .frame(maxWidth: .infinity, maxHeight: .infinity).overlay(alignment: .leading) { rail }.overlay(alignment: .bottom) { recordButton }+ .overlay(alignment: .bottomLeading) { thumbnailWell }+ .animation(.spring(duration: 0.45), value: media.recordings.first?.id)+ .animation(.spring(duration: 0.45), value: camera.isRecording).padding(.top, 8)}+ /// The last recording, docked in the corner the way the system camera+ /// does it; tapping plays it.+ @ViewBuilder private var thumbnailWell: some View {+ if !camera.isRecording, let recording = media.recordings.first {+ Button {+ playingRecording = recording+ } label: {+ ZStack {+ if let url = media.thumbnailURL(for: recording),+ let image = UIImage(contentsOfFile: url.path()) {+ Image(uiImage: image)+ .resizable()+ .scaledToFill()+ } else {+ Rectangle().fill(.fill.secondary)+ Image(systemName: "play.fill")+ .foregroundStyle(.white)+ }+ }+ .frame(width: 54, height: 54)+ .clipShape(RoundedRectangle(cornerRadius: 10))+ .overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.white.opacity(0.5), lineWidth: 1))+ }+ .buttonStyle(.plain)+ .padding(.leading, 20)+ .padding(.bottom, 44)+ .id(recording.id)+ .transition(.scale(scale: 0.25, anchor: .bottomLeading).combined(with: .opacity))+ .accessibilityLabel("Play last recording")+ }+ }+private var rail: some View {GlassEffectContainer {VStack(spacing: 16) {@@ -105,8 +152,8 @@ struct CameraScreen<CameraPreview: View>: View {.frame(width: 40, height: 40)}.glassEffect(.regular.interactive())- .disabled(!camera.hasTorch)- .opacity(camera.hasTorch ? 1 : 0.4)+ .disabled(!camera.flashAvailable)+ .opacity(camera.flashAvailable ? 1 : 0.4)Button {camera.flip()@@ -236,6 +283,18 @@ struct CameraScreen<CameraPreview: View>: View {}}+/// A bright frame around the preview: the screen fill light for cameras+/// without a torch.+struct FillLightOverlay: View {+ var body: some View {+ Rectangle()+ .strokeBorder(.white.opacity(0.95), lineWidth: 64)+ .blur(radius: 22)+ .ignoresSafeArea()+ .allowsHitTesting(false)+ }+}+struct RecordingTimer: View {var camera: CameraModel