Skip to content

Open source CapCut alternative.

TypeScript

fix(ios): the prompter reads the whole note and previews before the take

David Le0b8d76fb74a8
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift
index edf6bc40..35d2ed73 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift
@@ -56,8 +56,14 @@ nonisolated public struct Note: Identifiable, Equatable, Sendable {
self.updatedAt = updatedAt
}
- /// The text a teleprompter reads for this note.
- public var script: String { body.isEmpty ? title : body }
+ /// The text a teleprompter reads for this note: the whole of it, title
+ /// first. What a person wrote in the note is what they meant to say.
+ public var script: String {
+ [title, body]
+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
+ .filter { !$0.isEmpty }
+ .joined(separator: "\n\n")
+ }
}
nonisolated public enum InspirationKind: Equatable, Sendable {
@@ -166,9 +172,11 @@ public final class IdeasModel {
let title = draft.title.trimmingCharacters(in: .whitespaces)
let body = draft.body.trimmingCharacters(in: .whitespaces)
let existing = notes.first(where: { $0.id == draft.id })
+ // A stand-in title would be read out by the prompter, so an untitled
+ // note stays untitled and the card shows the placeholder.
let note = Note(
id: draft.id,
- title: title.isEmpty ? "Untitled" : title,
+ title: title,
body: body,
color: draft.color,
createdAt: existing?.createdAt ?? .now,
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift
index 2b057eff..b33554e2 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift
@@ -42,7 +42,10 @@ struct CameraScreen<CameraPreview: View>: View {
if camera.isFillLightOn, camera.availability == .running {
FillLightOverlay()
}
- if camera.isRecording, camera.teleprompter.hasScript {
+ // 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 {
TeleprompterOverlay(camera: camera)
}
controls
@@ -425,6 +428,11 @@ struct TeleprompterCard: View {
.popover(isPresented: $showsSettings, arrowEdge: .top) {
TeleprompterSettingsView(camera: camera)
.presentationCompactAdaptation(.popover)
+ // The popover's own chrome follows the phone's
+ // appearance, so in light mode it drew a pale panel
+ // under the camera chrome's white type. It carries the
+ // stage's dark instead.
+ .presentationBackground(Color.black.opacity(0.78))
}
Button(action: onUseNote) {
Image(systemName: "note.text")
@@ -488,12 +496,17 @@ 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
+ /// Beat between the end of a preview pass and the top of the next one.
+ private static var previewGap: TimeInterval { 1.5 }
var body: some View {
GeometryReader { geometry in
let height = geometry.size.height * 0.42
TimelineView(.animation) { context in
- let elapsed = camera.recordingStartedAt.map { context.date.timeIntervalSince($0) } ?? 0
+ let elapsed = elapsed(at: context.date)
Text(camera.teleprompter.displayScript)
.font(.system(size: camera.teleprompter.settings.textSize, weight: .heavy))
.foregroundStyle(.white)
@@ -524,6 +537,17 @@ struct TeleprompterOverlay: View {
.ignoresSafeArea()
.allowsHitTesting(false)
}
+
+ /// Seconds into the script. A take counts from the moment recording
+ /// started; idle, the script runs the same pass on a loop.
+ private func elapsed(at now: Date) -> TimeInterval {
+ if let startedAt = camera.recordingStartedAt {
+ return now.timeIntervalSince(startedAt)
+ }
+ let pass = camera.teleprompter.duration + Self.previewGap
+ guard pass > 0 else { return 0 }
+ return now.timeIntervalSince(previewStart).truncatingRemainder(dividingBy: pass)
+ }
}
struct NotePickerSheet: View {
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
index acb42154..3316b4c7 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
@@ -163,8 +163,10 @@ struct NoteCard: View {
var body: some View {
VStack(alignment: .leading, spacing: 6) {
- Text(note.title)
- .font(.subheadline.weight(.bold))
+ if !note.title.isEmpty {
+ Text(note.title)
+ .font(.subheadline.weight(.bold))
+ }
Text(note.body)
.font(.footnote)
.opacity(0.75)
diff --git a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
index e9a0e29f..54441fdf 100644
--- a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
+++ b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
@@ -414,7 +414,10 @@ import Testing
model.openEditor()
model.draft?.body = "Hey there this is cool"
let note = model.saveDraft()
- #expect(note?.title == "Untitled")
+ // A note nobody titled carries no title, so the prompter never reads
+ // a stand-in out loud.
+ #expect(note?.title == "")
+ #expect(note?.script == "Hey there this is cool")
#expect(model.notes.count == 1)
#expect(model.draft == nil)
}
@@ -445,11 +448,13 @@ import Testing
#expect(model.notes[1].body == "edited")
}
- @Test func scriptPrefersBody() {
+ @Test func scriptReadsTheWholeNote() {
let note = Note(title: "Title", body: "Body", color: .butter)
- #expect(note.script == "Body")
+ #expect(note.script == "Title\n\nBody")
let titleOnly = Note(title: "Title", body: "", color: .butter)
#expect(titleOnly.script == "Title")
+ let bodyOnly = Note(title: "", body: "Body", color: .butter)
+ #expect(bodyOnly.script == "Body")
}
@Test func inspirationLinkRoundTrips() throws {
diff --git a/docs/guides/ios-app.md b/docs/guides/ios-app.md
index 28d239dd..26617b0b 100644
--- a/docs/guides/ios-app.md
+++ b/docs/guides/ios-app.md
@@ -65,6 +65,11 @@ paragraph breaks, and long unbroken paragraphs wrap into short lines at
clause boundaries. Speed and text size persist across sessions — set once,
kept forever.
+A note is read whole: its title, then its body. Closing the card hands the
+screen to the prompter, which runs the script on a loop until the take starts,
+so a speed and size are something a person watches before they commit to
+them.
+
## How It Is Put Together
The app follows the Swift Guide's MVC split across two layers: