Open source CapCut alternative.
TypeScript
feat(ios): the reader places the prompter's script
David Le26117efa4b42
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swiftindex dc00aab1..9fd90745 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Teleprompter.swift@@ -77,12 +77,12 @@ nonisolated public struct TeleprompterState: Equatable, Sendable {/// Where the first line sits before the script starts moving, as a share/// of the prompter's height.- public static let leadShare = 0.25+ public static let leadShare = 0.5/// Vertical offset of the script at `elapsed` seconds into a recording.- /// 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.+ /// The text starts halfway 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 * Self.leadSharediff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swiftindex c6778dd6..857f526a 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/CameraScreen.swift@@ -507,6 +507,11 @@ struct TeleprompterOverlay: View {/// 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.+ @State private var dragged: Double = 0+ @GestureState private var dragging: Double = 0/// 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.@@ -535,7 +540,7 @@ struct TeleprompterOverlay: View {elapsed: elapsed,overlayHeight: height,textHeight: textHeight- )+ ) + dragged + dragging).padding(.horizontal, 24)}@@ -553,9 +558,20 @@ struct TeleprompterOverlay: View {.frame(height: height * 0.35),alignment: .top)+ // The reader places the words: a drag anywhere over the picture+ // moves the script. The rail and the record button sit above this+ // in the stack, so they still take their own touches.+ .contentShape(Rectangle())+ .gesture(+ DragGesture(minimumDistance: 6)+ .updating($dragging) { value, state, _ in state = value.translation.height }+ .onEnded { dragged += $0.translation.height }+ )}.ignoresSafeArea()- .allowsHitTesting(false)+ // 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 }}/// Seconds into the script. A take counts from the moment recordingdiff --git a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swiftindex c0d611e6..fb197442 100644--- a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift+++ b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift@@ -65,20 +65,20 @@ import Testingvar state = TeleprompterState()state.settings.wordsPerMinute = 120state.script = Array(repeating: "word", count: 120).joined(separator: " ")- // 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.+ // 120 words at 120 wpm = 60s. The script starts halfway down the+ // prompter and travels its own height plus that lead over the minute.#expect(state.duration == 60)let start = state.scrollOffset(elapsed: 0, overlayHeight: 300, textHeight: 420)- #expect(start == 75)+ #expect(start == 150)let mid = state.scrollOffset(elapsed: 30, overlayHeight: 300, textHeight: 420)- #expect(mid == 75 - (420.0 + 75.0) / 2)+ #expect(mid == 150 - (420.0 + 150.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) == 75)+ #expect(state.scrollOffset(elapsed: 5, overlayHeight: 300, textHeight: 0) == 150)}@Test func hasScriptIgnoresWhitespace() {diff --git a/docs/guides/ios-app.md b/docs/guides/ios-app.mdindex 16c4cbf2..13e2a506 100644--- a/docs/guides/ios-app.md+++ b/docs/guides/ios-app.md@@ -74,6 +74,11 @@ loop until the take starts, and the card's test button restarts that run fromthe top. A speed and a size are something a person watches before they committo them.+The script starts halfway down the screen, and a drag moves it: the nudge+rides along with the pacing, so the words land where the reader wants them and+the pace carries on. Each run puts the script back where the pacing wants+it.+## How It Is Put TogetherThe app follows the Swift Guide's MVC split across two layers: