diff --git a/OnCue/OnCue.entitlements b/OnCue/OnCue.entitlements index 9f5c100..0c67376 100644 --- a/OnCue/OnCue.entitlements +++ b/OnCue/OnCue.entitlements @@ -1,16 +1,5 @@ - - aps-environment - development - com.apple.developer.icloud-container-identifiers - - iCloud.xyz.breadone.oncue - - com.apple.developer.icloud-services - - CloudKit - - + diff --git a/OnCue/View/TeleprompterView.swift b/OnCue/View/TeleprompterView.swift index 13c2182..74be5ab 100644 --- a/OnCue/View/TeleprompterView.swift +++ b/OnCue/View/TeleprompterView.swift @@ -20,6 +20,11 @@ struct TeleprompterView: View { .font(.system(size: textSize)) .padding(.horizontal, horizPadding) } +// AutoScrollView { +// Text(project.script) +// .font(.system(size: textSize)) +// .padding(.horizontal, horizPadding) +// } .toolbar { ToolbarItem(placement: .topBarTrailing) { Menu { overflowMenu } label: { diff --git a/Shared/AutoScrollView.swift b/Shared/AutoScrollView.swift index 46a096e..8ba701b 100644 --- a/Shared/AutoScrollView.swift +++ b/Shared/AutoScrollView.swift @@ -8,34 +8,87 @@ import SwiftUI import SwiftData +//struct AutoScrollView: View { +// let content: Content +// var scrollSpeed: Double = 15.0 +// +// @State private var offset: Double = 0.0 +// +// init(scrollSpeed: Double = 0, @ViewBuilder _ content: () -> Content) { +// self.content = content() +// self.scrollSpeed = scrollSpeed +// } +// +// var body: some View { +// ScrollView { +// content +// .offset(y: offset) +// } +// } +// +// func startScrolling() { +// +// } +// +// func stopScrolling() { +// +// } +// +// mutating func setScrollSpeed(_ speed: Double) { +// self.scrollSpeed = speed +// } +//} + struct AutoScrollView: View { + @State private var scrollOffset: CGFloat = 0 + @State private var timer: Timer? = nil + let content: Content - var scrollSpeed: Double = 15.0 + var scrollSpeed: CGFloat = 0.5 // Adjust this value to control the scroll speed - @State private var offset: Double = 0.0 - - init(scrollSpeed: Double = 0, @ViewBuilder _ content: () -> Content) { + init(scrollSpeed: Double = 0.7, @ViewBuilder _ content: () -> Content) { self.content = content() self.scrollSpeed = scrollSpeed } - + var body: some View { ScrollView { - content - .offset(y: offset) + VStack { + content + .padding() + .background(GeometryReader { geo in + Color.clear.onAppear { + // Calculate the height of the content + let contentHeight = geo.size.height + startTimer(contentHeight: contentHeight) + } + }) + .offset(y: -scrollOffset) + } + } + .onDisappear { + stopTimer() } } - - func startScrolling() { - + + private func startTimer(contentHeight: CGFloat) { + timer?.invalidate() // Invalidate any existing timer + timer = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true) { _ in + // Update the scroll offset + withAnimation { + scrollOffset += scrollSpeed + } + + // Reset scroll offset when it reaches the end + if scrollOffset >= contentHeight { + scrollOffset = 0 + } + } } - - func stopScrolling() { - - } - - mutating func setScrollSpeed(_ speed: Double) { - self.scrollSpeed = speed + + private func stopTimer() { + timer?.invalidate() + timer = nil } }