Skip to content

Open source CapCut alternative.

TypeScript

fix(ios): the prompter runs the whole script down the screen

David Le180e857c43c4
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift
index ac92d995..47a044cc 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CameraModel.swift
@@ -118,6 +118,12 @@ public final class CameraModel {
teleprompter.isCardShown = true
}
+ /// Clears the card and runs the script from the top at the set pace.
+ public func startTeleprompterTest() {
+ teleprompter.isCardShown = false
+ teleprompter.testStartedAt = .now
+ }
+
// MARK: Controller events
public func sessionDidStart(zoomMapping: ZoomMapping, hasTorch: Bool, effective: CameraSettings) {
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift
index 35d2ed73..95a3c558 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Ideas.swift
@@ -56,13 +56,11 @@ nonisolated public struct Note: Identifiable, Equatable, Sendable {
self.updatedAt = updatedAt
}
- /// 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.
+ /// The text a teleprompter reads for this note: what is written in it. A
+ /// title names the note, so it is read only when it is all the note has.
public var script: String {
- [title, body]
- .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
- .filter { !$0.isEmpty }
- .joined(separator: "\n\n")
+ let written = body.trimmingCharacters(in: .whitespacesAndNewlines)
+ return written.isEmpty ? title.trimmingCharacters(in: .whitespacesAndNewlines) : written
}
}
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift
index 9c034c59..dc00aab1 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift
@@ -60,6 +60,8 @@ nonisolated public struct TeleprompterState: Equatable, Sendable {
public var script: String = ""
public var isCardShown = false
public var settings = TeleprompterSettings()
+ /// When a test run was asked for, so the script starts from the top.
+ public var testStartedAt: Date?
public init() {}
@@ -73,13 +75,17 @@ nonisolated public struct TeleprompterState: Equatable, Sendable {
/// Seconds the whole script takes at the set pace.
public var duration: TimeInterval { readDuration(of: script, wordsPerMinute: settings.wordsPerMinute) }
+ /// Where the first line sits before the script starts moving, as a share
+ /// of the prompter's height.
+ public static let leadShare = 0.25
+
/// Vertical offset of the script at `elapsed` seconds into a recording.
- /// The text starts 60% down the overlay and travels its own rendered
- /// height plus that lead-in over the read duration, so the last words
- /// leave the top exactly when the speaker should be finishing them.
+ /// The text starts a quarter down the prompter and travels its own
+ /// rendered height plus that lead-in over the read duration, so the last
+ /// words leave the top exactly when the speaker should be finishing them.
/// Paragraph gaps are part of the height, so they read as natural pauses.
public func scrollOffset(elapsed: TimeInterval, overlayHeight: Double, textHeight: Double) -> Double {
- let lead = overlayHeight * 0.6
+ let lead = overlayHeight * Self.leadShare
let total = duration
guard total > 0 else { return lead }
let speed = (textHeight + lead) / total
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift
index b33554e2..c6778dd6 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift
@@ -437,6 +437,14 @@ struct TeleprompterCard: View {
Button(action: onUseNote) {
Image(systemName: "note.text")
}
+ // A run of the script at the current pace, without spending a
+ // take on finding out whether it reads right.
+ Button {
+ camera.startTeleprompterTest()
+ } label: {
+ Image(systemName: "play.fill")
+ }
+ .disabled(!camera.teleprompter.hasScript)
Spacer()
Button {
camera.teleprompter.isCardShown = false
@@ -501,16 +509,25 @@ struct TeleprompterOverlay: View {
@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 }
+ /// Room kept at the foot of the screen for the record button and the tabs.
+ private static var controlsInset: Double { 190 }
var body: some View {
GeometryReader { geometry in
- let height = geometry.size.height * 0.42
+ // The script gets the screen, stopping short of the controls.
+ let height = max(geometry.size.height - Self.controlsInset, 0)
TimelineView(.animation) { context in
let elapsed = elapsed(at: context.date)
Text(camera.teleprompter.displayScript)
.font(.system(size: camera.teleprompter.settings.textSize, weight: .heavy))
.foregroundStyle(.white)
.lineSpacing(4)
+ .shadow(color: .black.opacity(0.7), radius: 6, y: 1)
+ // The window the script scrolls through is a fraction of
+ // the screen, and a Text offered that height lays out only
+ // what fits and ends the last line in an ellipsis. The
+ // script is laid out whole and scrolled past the window.
+ .fixedSize(horizontal: false, vertical: true)
.frame(maxWidth: .infinity, alignment: .leading)
.onGeometryChange(for: Double.self, of: { $0.size.height }) { textHeight = $0 }
.offset(
@@ -525,12 +542,15 @@ struct TeleprompterOverlay: View {
.frame(height: height, alignment: .top)
.clipped()
.background(
+ // A scrim over the top of the frame, where the status bar and
+ // the brightest part of most rooms are. Past it the script
+ // carries its own shadow and the picture stays the picture.
LinearGradient(
- colors: [.black.opacity(0.75), .black.opacity(0)],
+ colors: [.black.opacity(0.6), .black.opacity(0)],
startPoint: .top,
endPoint: .bottom
)
- .frame(height: height),
+ .frame(height: height * 0.35),
alignment: .top
)
}
@@ -539,14 +559,16 @@ struct TeleprompterOverlay: View {
}
/// Seconds into the script. A take counts from the moment recording
- /// started; idle, the script runs the same pass on a loop.
+ /// started; idle, the script runs the same pass on a loop, from the top
+ /// again each time the test button is pressed.
private func elapsed(at now: Date) -> TimeInterval {
if let startedAt = camera.recordingStartedAt {
return now.timeIntervalSince(startedAt)
}
+ let anchor = camera.teleprompter.testStartedAt ?? previewStart
let pass = camera.teleprompter.duration + Self.previewGap
guard pass > 0 else { return 0 }
- return now.timeIntervalSince(previewStart).truncatingRemainder(dividingBy: pass)
+ return now.timeIntervalSince(anchor).truncatingRemainder(dividingBy: pass)
}
}
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/NoteEditorView.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/NoteEditorView.swift
index 2b9c6611..59156963 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/NoteEditorView.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/NoteEditorView.swift
@@ -7,7 +7,9 @@ struct NoteEditorView: View {
@Bindable var ideas: IdeasModel
let onRecordNote: (Note) -> Void
- @FocusState private var bodyFocused: Bool
+ private enum Field { case title, body }
+
+ @FocusState private var focused: Field?
var body: some View {
let color = ideas.draft?.color ?? .butter
@@ -37,12 +39,13 @@ struct NoteEditorView: View {
.font(.system(size: 32, weight: .bold))
.padding(.horizontal, 22)
.padding(.top, 12)
+ .focused($focused, equals: .title)
TextEditor(text: bodyBinding)
.font(.system(size: 20, weight: .medium))
.scrollContentBackground(.hidden)
.padding(.horizontal, 18)
- .focused($bodyFocused)
+ .focused($focused, equals: .body)
.overlay(alignment: .topLeading) {
if (ideas.draft?.body ?? "").isEmpty {
Text("Write down an idea...")
@@ -93,7 +96,16 @@ struct NoteEditorView: View {
.foregroundStyle(Color.notePaperInk)
.tint(Color.notePaperInk)
.background(color.backgroundColor, ignoresSafeAreaEdges: .all)
- .task { bodyFocused = true }
+ .toolbar {
+ // Opening a note is reading it as often as writing it, so the
+ // keyboard comes and goes on the writer's word.
+ ToolbarItemGroup(placement: .keyboard) {
+ Spacer()
+ Button("Done") { focused = nil }
+ .font(.body.weight(.bold))
+ }
+ }
+ .task { if ideas.draft?.isNew == true { focused = .body } }
.animation(.easeInOut(duration: 0.2), value: color)
}
diff --git a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
index 54441fdf..c0d611e6 100644
--- a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
+++ b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
@@ -65,20 +65,20 @@ import Testing
var state = TeleprompterState()
state.settings.wordsPerMinute = 120
state.script = Array(repeating: "word", count: 120).joined(separator: " ")
- // 120 words at 120 wpm = 60s. Lead-in is 60% of the overlay; the text
- // travels its own height plus the lead over the minute.
+ // 120 words at 120 wpm = 60s. Lead-in is a quarter of the prompter;
+ // the text travels its own height plus the lead over the minute.
#expect(state.duration == 60)
let start = state.scrollOffset(elapsed: 0, overlayHeight: 300, textHeight: 420)
- #expect(start == 180)
+ #expect(start == 75)
let mid = state.scrollOffset(elapsed: 30, overlayHeight: 300, textHeight: 420)
- #expect(mid == 180 - (420 + 180) / 2)
+ #expect(mid == 75 - (420.0 + 75.0) / 2)
let end = state.scrollOffset(elapsed: 60, overlayHeight: 300, textHeight: 420)
#expect(end == -420)
}
@Test func emptyScriptHoldsAtLead() {
let state = TeleprompterState()
- #expect(state.scrollOffset(elapsed: 5, overlayHeight: 300, textHeight: 0) == 180)
+ #expect(state.scrollOffset(elapsed: 5, overlayHeight: 300, textHeight: 0) == 75)
}
@Test func hasScriptIgnoresWhitespace() {
@@ -448,13 +448,12 @@ import Testing
#expect(model.notes[1].body == "edited")
}
- @Test func scriptReadsTheWholeNote() {
+ @Test func scriptIsWhatTheNoteSays() {
+ // The title names the note; the prompter reads what is written in it.
let note = Note(title: "Title", body: "Body", color: .butter)
- #expect(note.script == "Title\n\nBody")
+ #expect(note.script == "Body")
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 26617b0b..16c4cbf2 100644
--- a/docs/guides/ios-app.md
+++ b/docs/guides/ios-app.md
@@ -65,10 +65,14 @@ 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.
+A note is read for what is written in it — its body, or its title when that is
+all it has. The script is laid out whole and scrolled past the screen, so
+length is never a reason for a note to arrive half-read.
+
+Closing the card hands the screen to the prompter, which runs the script on a
+loop until the take starts, and the card's test button restarts that run from
+the top. A speed and a size are something a person watches before they commit
+to them.
## How It Is Put Together