Open source CapCut alternative.
TypeScript
fix(ios): the prompter shows only when asked
David Lea19ba042a9b5
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swiftindex 47a044cc..d8b6c48b 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift@@ -119,9 +119,19 @@ public final class CameraModel {}/// Clears the card and runs the script from the top at the set pace.- public func startTeleprompterTest() {+ public func startTeleprompter() {+ guard teleprompter.hasScript else { return }teleprompter.isCardShown = false- teleprompter.testStartedAt = .now+ teleprompter.isRunning = true+ teleprompter.runStartedAt = .now+ }++ /// Takes the prompter off the picture: the card and the running script+ /// both go.+ public func dismissTeleprompter() {+ teleprompter.isCardShown = false+ teleprompter.isRunning = false+ teleprompter.runStartedAt = nil}// MARK: Controller events@@ -139,6 +149,12 @@ public final class CameraModel {public func recordingDidStart() {recordingStartedAt = .now+ // A take starts the script from the top. The card is off screen while+ // recording, so an open card hands its script to the prompter; a+ // dismissed prompter stays dismissed.+ if teleprompter.isRunning || (teleprompter.isCardShown && teleprompter.hasScript) {+ startTeleprompter()+ }}public func recordingDidFinish() {diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swiftindex 0eb46d54..61a530b7 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift@@ -60,9 +60,12 @@ nonisolated public func readDuration(of script: String, wordsPerMinute: Double)nonisolated public struct TeleprompterState: Equatable, Sendable {public var script: String = ""public var isCardShown = false+ /// True while the script runs on screen. Play starts it, closing the+ /// prompter ends it: the words are on the picture only when asked for.+ public var isRunning = falsepublic var settings = TeleprompterSettings()- /// When a test run was asked for, so the script starts from the top.- public var testStartedAt: Date?+ /// When the run was asked for, so the script starts from the top.+ public var runStartedAt: Date?public init() {}diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swiftindex 97ccf991..7a4dd2e0 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift@@ -42,10 +42,10 @@ struct CameraScreen<CameraPreview: View>: View {if camera.isFillLightOn, camera.availability == .running {FillLightOverlay()}- // Closing the card hands the screen to the prompter, recording or- // not: the script runs on a loop so the speed and size a person- // just set are something they can watch before the take.- if camera.teleprompter.hasScript, camera.isRecording || !camera.teleprompter.isCardShown {+ // Play hands the screen to the prompter, recording or not: the+ // script runs on a loop so the speed and size a person just set+ // are something they can watch before the take.+ if camera.teleprompter.hasScript, camera.teleprompter.isRunning {TeleprompterOverlay(camera: camera)}controls@@ -201,12 +201,19 @@ struct CameraScreen<CameraPreview: View>: View {}Button {- camera.teleprompter.isCardShown.toggle()+ if camera.teleprompter.isCardShown {+ camera.dismissTeleprompter()+ } else {+ // A running script comes back to the card to be+ // edited; the picture is clear while it is open.+ camera.teleprompter.isRunning = false+ camera.teleprompter.isCardShown = true+ }} label: {Image(systemName: "text.viewfinder").frame(width: 40, height: 40)}- .glassEffect(camera.teleprompter.isCardShown ? .regular.tint(.white.opacity(0.25)).interactive() : .regular.interactive())+ .glassEffect(camera.teleprompter.isCardShown || camera.teleprompter.isRunning ? .regular.tint(.white.opacity(0.25)).interactive() : .regular.interactive())Spacer().frame(height: 10)@@ -440,14 +447,14 @@ struct TeleprompterCard: View {// A run of the script at the current pace, without spending a// take on finding out whether it reads right.Button {- camera.startTeleprompterTest()+ camera.startTeleprompter()} label: {Image(systemName: "play.fill")}.disabled(!camera.teleprompter.hasScript)Spacer()Button {- camera.teleprompter.isCardShown = false+ camera.dismissTeleprompter()} label: {Image(systemName: "xmark").font(.subheadline.weight(.bold))@@ -504,9 +511,6 @@ struct TeleprompterOverlay: View {/// Rendered height of the paced script, measured off the Text itself so/// the scroll rate can pace the exact copy on screen.@State private var textHeight: Double = 0- /// Where the idle loop counts from, so a preview runs the script the same- /// way a take does.- @State private var previewStart = Date.now/// How far the reader has dragged the script from where the pacing puts/// it. It rides along with the scroll rather than replacing it, so a nudge/// mid-take moves the words and the pace carries on.@@ -582,18 +586,15 @@ struct TeleprompterOverlay: View {}.ignoresSafeArea()// A fresh run puts the script back where the pacing wants it.- .onChange(of: camera.recordingStartedAt) { dragged = 0 }- .onChange(of: camera.teleprompter.testStartedAt) { dragged = 0 }+ .onChange(of: camera.teleprompter.runStartedAt) { dragged = 0 }}- /// Seconds into the script. A take counts from the moment recording- /// started; idle, from when the prompter came up, or from the last press- /// of the test button. The loop itself lives in the offset.+ /// Seconds into the script, counted from the press of play — or from the+ /// top of a take that began while the prompter was up. The loop itself+ /// lives in the offset.private func elapsed(at now: Date) -> TimeInterval {- if let startedAt = camera.recordingStartedAt {- return now.timeIntervalSince(startedAt)- }- return now.timeIntervalSince(camera.teleprompter.testStartedAt ?? previewStart)+ guard let startedAt = camera.teleprompter.runStartedAt else { return 0 }+ return now.timeIntervalSince(startedAt)}}