Open source CapCut alternative.
TypeScript
feat(ios): the take lands in a corner well
David Le7a56a631a39a
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swiftindex c0dec77c..36c4edf4 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift@@ -3,7 +3,17 @@ import SwiftUIimport UIKitimport DonkeyKitModels+/// The clip parked in the corner after a take: the poster the flight+/// animation carries down, and the recording the well opens.+private struct CornerClip: Identifiable {+ var recording: Recording+ var poster: UIImage?++ var id: UUID { recording.id }+}+struct CameraScreen<CameraPreview: View>: View {+ var app: AppModel@Bindable var camera: CameraModelvar ideas: IdeasModelvar media: MediaModel@@ -14,6 +24,17 @@ struct CameraScreen<CameraPreview: View>: View {@State private var showsTeleSettings = false@State private var showsNotePicker = false@State private var playingRecording: Recording?+ /// The take that just finished, docked in the corner until it is watched+ /// or `Self.wellLifetime` passes.+ @State private var corner: CornerClip?+ /// True while the poster is still flying from the stage into the well.+ @State private var isFlying = false+ /// The well's rectangle in stage coordinates — the flight's landing spot.+ @State private var wellFrame: CGRect = .zero++ private static var stageSpace: String { "cameraStage" }+ private static var wellSide: CGFloat { 54 }+ private static var wellLifetime: Duration { .seconds(30) }var body: some View {ZStack {@@ -25,23 +46,52 @@ struct CameraScreen<CameraPreview: View>: View {TeleprompterOverlay(camera: camera)}controls+ if isFlying, let poster = corner?.poster, wellFrame != .zero {+ CaptureFlight(poster: poster, landing: wellFrame, corner: 10) {+ isFlying = false+ }+ }}+ .coordinateSpace(.named(Self.stageSpace)).background(.black, ignoresSafeAreaEdges: .all)// The stage is live video: the chrome is dark whatever the app-wide// appearance says. Setting the environment (not a color-scheme// preference) keeps the root appearance choice from overriding it..environment(\.colorScheme, .dark)+ .onChange(of: media.recordings.first?.id) { _, _ in dockLatestTake() }+ // The docked clip keeps itself to one appearance: watching it or+ // waiting out the timer both retire it.+ .task(id: corner?.id) {+ guard corner != nil else { return }+ try? await Task.sleep(for: Self.wellLifetime)+ guard !Task.isCancelled else { return }+ corner = nil+ }.sheet(isPresented: $showsNotePicker) {NotePickerSheet(ideas: ideas) { note incamera.loadTeleprompter(script: note.script)showsNotePicker = false}}- .fullScreenCover(item: $playingRecording) { recording in- RecordingPlayerView(url: media.movieURL(for: recording))+ .fullScreenCover(item: $playingRecording, onDismiss: { corner = nil }) { recording in+ RecordingPlayerView(url: media.movieURL(for: recording)) {+ playingRecording = nil+ app.selectedTab = .media+ }}}+ private func dockLatestTake() {+ // The head of the list also changes when a clip is deleted over in the+ // Library; only a take that just finished gets docked.+ guard let recording = media.recordings.first,+ recording.createdAt.timeIntervalSinceNow > -5 else { return }+ let poster = media.thumbnailURL(for: recording)+ .flatMap { UIImage(contentsOfFile: $0.localPath) }+ corner = CornerClip(recording: recording, poster: poster)+ isFlying = poster != nil && wellFrame != .zero+ }+@ViewBuilder private var stage: some View {switch camera.availability {case .running, .starting:@@ -84,41 +134,51 @@ struct CameraScreen<CameraPreview: View>: View {.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: corner?.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.localPath) {- Image(uiImage: image)- .resizable()- .scaledToFill()- } else {- Rectangle().fill(.fill.secondary)- Image(systemName: "play.fill")- .foregroundStyle(.white)- }+ /// Where the take lands. The slot holds its place whether or not a clip+ /// is docked, so the flight always has a measured rectangle to fly to.+ private var thumbnailWell: some View {+ Color.clear+ .frame(width: Self.wellSide, height: Self.wellSide)+ .onGeometryChange(for: CGRect.self) { proxy in+ proxy.frame(in: .named(Self.stageSpace))+ } action: { wellFrame = $0 }+ .overlay {+ if let corner, !camera.isRecording, !isFlying {+ wellButton(corner)}- .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 func wellButton(_ clip: CornerClip) -> some View {+ Button {+ playingRecording = clip.recording+ } label: {+ ZStack {+ if let poster = clip.poster {+ Image(uiImage: poster)+ .resizable()+ .scaledToFill()+ } else {+ Rectangle().fill(.fill.secondary)+ Image(systemName: "play.fill")+ .foregroundStyle(.white)+ }+ }+ .frame(width: Self.wellSide, height: Self.wellSide)+ .clipShape(RoundedRectangle(cornerRadius: 10))+ .overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.white.opacity(0.5), lineWidth: 1))}+ .buttonStyle(.plain)+ .id(clip.id)+ .transition(.scale(scale: 0.25, anchor: .bottomLeading).combined(with: .opacity))+ .accessibilityLabel("Play last recording")}private var rail: some View {@@ -286,6 +346,35 @@ struct CameraScreen<CameraPreview: View>: View {}}+/// The take shrinking from the stage into the corner well, the way a+/// screenshot drops to the bottom of the screen.+private struct CaptureFlight: View {+ let poster: UIImage+ let landing: CGRect+ let corner: CGFloat+ let onLanded: () -> Void++ @State private var landed = false++ var body: some View {+ GeometryReader { proxy in+ let frame = landed ? landing : CGRect(origin: .zero, size: proxy.size)+ Image(uiImage: poster)+ .resizable()+ .scaledToFill()+ .frame(width: frame.width, height: frame.height)+ .clipShape(RoundedRectangle(cornerRadius: landed ? corner : 0, style: .continuous))+ .position(x: frame.midX, y: frame.midY)+ }+ .allowsHitTesting(false)+ .task {+ withAnimation(.spring(response: 0.5, dampingFraction: 0.72)) { landed = true }+ try? await Task.sleep(for: .milliseconds(620))+ onLanded()+ }+ }+}+/// A bright frame around the preview: the screen fill light for cameras/// without a torch.struct FillLightOverlay: View {diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swiftindex a6696bd7..e4df46b4 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swift@@ -136,6 +136,10 @@ struct SyncBadge: View {struct RecordingPlayerView: View {let url: URL+ /// Set when the player was opened from the camera. The leading control+ /// then reads "< Library" and goes there, the way the system camera's+ /// viewer walks back into Photos; the close button moves to the right.+ var onOpenLibrary: (() -> Void)?@State private var player: AVPlayer?@Environment(\.dismiss) private var dismiss@@ -147,22 +151,34 @@ struct RecordingPlayerView: View {VideoPlayer(player: player).ignoresSafeArea()}- HStack {- Button {- dismiss()- } label: {- Image(systemName: "xmark")- .font(.title3.weight(.bold))- .frame(width: 40, height: 40)- }- .glassEffect(.regular.interactive())- Spacer()- ShareLink(item: url) {- Image(systemName: "square.and.arrow.up")- .font(.title3.weight(.bold))- .frame(width: 40, height: 40)+ GlassEffectContainer {+ HStack(spacing: 10) {+ if let onOpenLibrary {+ Button(action: onOpenLibrary) {+ HStack(spacing: 3) {+ Image(systemName: "chevron.left")+ .font(.subheadline.weight(.bold))+ Text("Library")+ .font(.subheadline.weight(.semibold))+ }+ .padding(.horizontal, 14)+ .frame(height: 40)+ }+ .glassEffect(.regular.interactive())+ } else {+ closeButton+ }+ Spacer()+ ShareLink(item: url) {+ Image(systemName: "square.and.arrow.up")+ .font(.title3.weight(.bold))+ .frame(width: 40, height: 40)+ }+ .glassEffect(.regular.interactive())+ if onOpenLibrary != nil {+ closeButton+ }}- .glassEffect(.regular.interactive())}.padding(16)}@@ -173,5 +189,17 @@ struct RecordingPlayerView: View {}.onDisappear { player?.pause() }}++ private var closeButton: some View {+ Button {+ dismiss()+ } label: {+ Image(systemName: "xmark")+ .font(.title3.weight(.bold))+ .frame(width: 40, height: 40)+ }+ .glassEffect(.regular.interactive())+ .accessibilityLabel("Close")+ }}#endifdiff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/RootView.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/RootView.swiftindex 6885cafd..74d2871d 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/RootView.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/RootView.swift@@ -50,7 +50,7 @@ public struct RootView<CameraPreview: View>: View {ProjectsScreen(app: app, projects: projects, auth: auth)}Tab("Camera", systemImage: "camera", value: .camera) {- CameraScreen(camera: camera, ideas: ideas, media: media, cameraPreview: cameraPreview)+ CameraScreen(app: app, camera: camera, ideas: ideas, media: media, cameraPreview: cameraPreview)}}.tabViewStyle(.sidebarAdaptable)diff --git a/docs/guides/ios-app.md b/docs/guides/ios-app.mdindex 643c002c..4833b3cd 100644--- a/docs/guides/ios-app.md+++ b/docs/guides/ios-app.md@@ -41,6 +41,15 @@ Every request carries an `x-donkey-cut-client: ios` header. The serverremembers accounts it has seen it from, and the desktop shows its phonesurfaces (Camera Roll and Notes tabs) only to those accounts.+## Camera++A finished take flies from the stage down into a well in the bottom-left+corner, the way a screenshot shrinks to the edge of the screen. Tapping it+plays the clip, with a "< Library" control in the player that carries on into+the Library tab. The well holds one take and retires it once it has been+watched or thirty seconds pass, so the viewfinder goes back to being a+viewfinder.+## TeleprompterThe teleprompter paces raw notes by itself. Reading speed is words per