add os conditionals so the mac app compiles

This commit is contained in:
Satindar Dhillon 2022-10-12 08:32:02 -07:00
parent 460a013554
commit c287eb4a59
20 changed files with 1346 additions and 964 deletions

View file

@ -153,15 +153,6 @@
"version" : "2.1.0"
}
},
{
"identity" : "pspdfkit-sp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/PSPDFKit/PSPDFKit-SP",
"state" : {
"branch" : "master",
"revision" : "e9757beadad1b30de84073d3c33c1cd0f7a94b80"
}
},
{
"identity" : "sovran-swift",
"kind" : "remoteSourceControl",

View file

@ -56,7 +56,7 @@ let package = Package(
var appPackageDependencies: [Target.Dependency] {
var deps: [Target.Dependency] = ["Views", "Services", "Models", "Utils"]
// #if canImport(UIKit)
deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP"))
// deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP"))
// #endif
return deps
}
@ -70,7 +70,7 @@ var dependencies: [Package.Dependency] {
.package(url: "https://github.com/google/GoogleSignIn-iOS", from: "6.2.2")
]
// #if canImport(UIKit)
deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master"))
// deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master"))
// #endif
return deps
}

View file

@ -18,7 +18,11 @@ public final class Services {
let networker = Networker(appEnvironment: appEnvironment)
self.authenticator = Authenticator(networker: networker)
self.dataService = DataService(appEnvironment: appEnvironment, networker: networker)
self.audioController = AudioController(dataService: dataService)
#if os(iOS)
self.audioController = AudioController(dataService: dataService)
#else
self.audioController = AudioController()
#endif
}
}

View file

@ -1,153 +1,153 @@
//
// MiniPlayer.swift
//
//
// Created by Jackson Harper on 8/15/22.
//
#if os(iOS)
import Foundation
import Models
import Services
import SwiftUI
import Views
import Foundation
import Models
import Services
import SwiftUI
import Views
public struct MiniPlayer: View {
@EnvironmentObject var audioController: AudioController
@Environment(\.colorScheme) private var colorScheme: ColorScheme
private let presentingView: AnyView
public struct MiniPlayer: View {
@EnvironmentObject var audioController: AudioController
@Environment(\.colorScheme) private var colorScheme: ColorScheme
private let presentingView: AnyView
@State var expanded = false
@State var offset: CGFloat = 0
@State var showVoiceSheet = false
@State var showLanguageSheet = false
@State var expanded = false
@State var offset: CGFloat = 0
@State var showVoiceSheet = false
@State var showLanguageSheet = false
@State var tabIndex: Int = 0
@Namespace private var animation
@State var tabIndex: Int = 0
@Namespace private var animation
let minExpandedHeight = UIScreen.main.bounds.height / 3
let minExpandedHeight = UIScreen.main.bounds.height / 3
init<PresentingView>(
presentingView: PresentingView
) where PresentingView: View {
self.presentingView = AnyView(presentingView)
}
var isPresented: Bool {
audioController.itemAudioProperties != nil && audioController.state != .stopped
}
var playPauseButtonImage: String {
switch audioController.state {
case .playing:
return "pause.circle"
case .paused:
return "play.circle"
case .reachedEnd:
return "gobackward"
default:
return ""
init<PresentingView>(
presentingView: PresentingView
) where PresentingView: View {
self.presentingView = AnyView(presentingView)
}
}
var playPauseButtonItem: some View {
if let itemID = audioController.itemAudioProperties?.itemID, audioController.isLoadingItem(itemID: itemID) {
return AnyView(ProgressView())
} else {
return AnyView(Button(
var isPresented: Bool {
audioController.itemAudioProperties != nil && audioController.state != .stopped
}
var playPauseButtonImage: String {
switch audioController.state {
case .playing:
return "pause.circle"
case .paused:
return "play.circle"
case .reachedEnd:
return "gobackward"
default:
return ""
}
}
var playPauseButtonItem: some View {
if let itemID = audioController.itemAudioProperties?.itemID, audioController.isLoadingItem(itemID: itemID) {
return AnyView(ProgressView())
} else {
return AnyView(Button(
action: {
switch audioController.state {
case .playing:
audioController.pause()
case .paused:
audioController.unpause()
case .reachedEnd:
audioController.seek(to: 0.0)
audioController.unpause()
default:
break
}
},
label: {
Image(systemName: playPauseButtonImage)
.font(expanded ? .system(size: 56.0, weight: .thin) : .appTitleTwo)
}
))
}
}
var stopButton: some View {
Button(
action: {
switch audioController.state {
case .playing:
audioController.pause()
case .paused:
audioController.unpause()
case .reachedEnd:
audioController.seek(to: 0.0)
audioController.unpause()
default:
break
audioController.stop()
},
label: {
Image(systemName: "xmark")
.font(.appTitleTwo)
}
)
}
var closeButton: some View {
Button(
action: {
withAnimation(.interactiveSpring()) {
self.expanded = false
}
},
label: {
Image(systemName: playPauseButtonImage)
.font(expanded ? .system(size: 56.0, weight: .thin) : .appTitleTwo)
Image(systemName: "chevron.down")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
}
))
)
// .contentShape(Rectangle())
}
}
var stopButton: some View {
Button(
action: {
audioController.stop()
},
label: {
Image(systemName: "xmark")
.font(.appTitleTwo)
}
)
}
var closeButton: some View {
Button(
action: {
withAnimation(.interactiveSpring()) {
self.expanded = false
func viewArticle() {
if let objectID = audioController.itemAudioProperties?.objectID {
NSNotification.pushReaderItem(objectID: objectID)
withAnimation(.easeIn(duration: 0.1)) {
expanded = false
}
},
label: {
Image(systemName: "chevron.down")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
}
)
// .contentShape(Rectangle())
}
func viewArticle() {
if let objectID = audioController.itemAudioProperties?.objectID {
NSNotification.pushReaderItem(objectID: objectID)
withAnimation(.easeIn(duration: 0.1)) {
expanded = false
}
}
}
func defaultArtwork(forDimensions dim: Double) -> some View {
ZStack(alignment: .center) {
Color.appButtonBackground
.frame(width: dim, height: dim)
.cornerRadius(6)
func defaultArtwork(forDimensions dim: Double) -> some View {
ZStack(alignment: .center) {
Color.appButtonBackground
.frame(width: dim, height: dim)
.cornerRadius(6)
Image(systemName: "headphones")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: dim / 2, height: dim / 2)
Image(systemName: "headphones")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: dim / 2, height: dim / 2)
}
}
}
struct SpeechCard: View {
let id: Int
@EnvironmentObject var audioController: AudioController
struct SpeechCard: View {
let id: Int
@EnvironmentObject var audioController: AudioController
var body: some View {
Group {
if id != self.audioController.currentAudioIndex || self.audioController.isLoading {
Text(self.audioController.textItems?[id] ?? "\(id)")
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayTextContrast)
} else {
Group {
Text(audioController.readText)
var body: some View {
Group {
if id != self.audioController.currentAudioIndex || self.audioController.isLoading {
Text(self.audioController.textItems?[id] ?? "\(id)")
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayTextContrast)
+
Text(audioController.unreadText)
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayText)
} else {
Group {
Text(audioController.readText)
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayTextContrast)
+
Text(audioController.unreadText)
.font(.textToSpeechRead.leading(.loose))
.foregroundColor(Color.appGrayText)
}
}
}
.padding(16)
}
init(id: Int) {
self.id = id
}
.padding(16)
}
init(id: Int) {
@ -446,53 +446,161 @@ public struct MiniPlayer: View {
if voice.selected {
Image(systemName: "checkmark")
}
)
Menu {
Button("View Article", action: { viewArticle() })
Button("Change Voice", action: { showVoiceSheet = true })
} label: {
VStack {
Image(systemName: "ellipsis")
.font(.appCallout)
.frame(width: 20, height: 20)
}
.contentShape(Rectangle())
}
.contentShape(Rectangle())
}
.buttonStyle(PlainButtonStyle())
.padding(8)
}.padding(.bottom, 16)
}
}
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.background(
Color.systemBackground
.shadow(color: expanded ? .clear : .gray.opacity(0.33), radius: 8, x: 0, y: 4)
.mask(Rectangle().padding(.top, -20))
)
.onTapGesture {
withAnimation(.easeIn(duration: 0.08)) { expanded = true }
}.sheet(isPresented: $showVoiceSheet) {
NavigationView {
TextToSpeechVoiceSelectionView(forLanguage: audioController.currentVoiceLanguage, showLanguageChanger: true)
.navigationBarTitle("Voice")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showVoiceSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
}
}.sheet(isPresented: $showLanguageSheet) {
NavigationView {
TextToSpeechLanguageView()
.navigationBarTitle("Language")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showLanguageSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
}
}
.padding(.top, 32)
.listStyle(.plain)
Spacer()
}
.navigationBarTitle("Voice")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showVoiceSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
}
}
var scrubbing: Bool {
switch audioController.scrubState {
case .scrubStarted:
return true
default:
return false
}
}
func onDragChanged(value: DragGesture.Value) {
if value.translation.height > 0, expanded, !scrubbing {
offset = value.translation.height
}
}
func onDragEnded(value: DragGesture.Value) {
withAnimation(.interactiveSpring()) {
if value.translation.height > minExpandedHeight, !scrubbing {
expanded = false
func playbackRateButton(rate: Double, title: String, selected: Bool) -> some View {
Button(action: {
audioController.playbackRate = rate
}) {
HStack {
Text(title)
Spacer()
if selected {
Image(systemName: "checkmark")
}
}
.contentShape(Rectangle())
}
.buttonStyle(PlainButtonStyle())
}
public var body: some View {
ZStack(alignment: .center) {
presentingView
if let itemAudioProperties = self.audioController.itemAudioProperties, isPresented {
ZStack(alignment: .bottom) {
Color.systemBackground.edgesIgnoringSafeArea(.bottom)
.frame(height: 88, alignment: .bottom)
VStack {
Spacer(minLength: 0)
playerContent(itemAudioProperties)
.offset(y: offset)
.frame(maxHeight: expanded ? .infinity : 88)
.tint(.appGrayTextContrast)
.gesture(DragGesture().onEnded(onDragEnded(value:)).onChanged(onDragChanged(value:)))
.background(expanded ? .clear : .systemBackground)
}
}
}
}
}
var changeVoiceView: some View {
NavigationView {
VStack {
List {
ForEach(audioController.voiceList ?? [], id: \.key.self) { voice in
Button(action: {
audioController.currentVoice = voice.key
self.showVoiceSheet = false
}) {
HStack {
Text(voice.name)
Spacer()
if voice.selected {
Image(systemName: "checkmark")
}
}
.contentShape(Rectangle())
}
.buttonStyle(PlainButtonStyle())
}
}
.padding(.top, 32)
.listStyle(.plain)
Spacer()
}
.navigationBarTitle("Voice")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(leading: Button(action: { self.showVoiceSheet = false }) {
Image(systemName: "chevron.backward")
.font(.appNavbarIcon)
.tint(.appGrayTextContrast)
})
}
}
var scrubbing: Bool {
switch audioController.scrubState {
case .scrubStarted:
return true
default:
return false
}
}
func onDragChanged(value: DragGesture.Value) {
if value.translation.height > 0, expanded, !scrubbing {
offset = value.translation.height
}
}
func onDragEnded(value: DragGesture.Value) {
withAnimation(.interactiveSpring()) {
if value.translation.height > minExpandedHeight, !scrubbing {
expanded = false
}
offset = 0
}
offset = 0
}
}
}
public extension View {
func miniPlayer() -> some View {
MiniPlayer(presentingView: self)
public extension View {
func miniPlayer() -> some View {
MiniPlayer(presentingView: self)
}
}
}
#endif

View file

@ -1,73 +1,70 @@
//
// ScrubberView.swift
//
//
// Created by Jackson Harper on 9/27/22.
//
#if os(iOS)
import Foundation
import SwiftUI
import Foundation
import SwiftUI
struct ScrubberView: UIViewRepresentable {
typealias UIViewType = UISlider
struct ScrubberView: UIViewRepresentable {
typealias UIViewType = UISlider
@Binding var value: Double
var minValue: Double
var maxValue: Double
var onEditingChanged: (Bool) -> Void
init(value: Binding<Double>, minValue: Double, maxValue: Double, onEditingChanged: @escaping (Bool) -> Void) {
self._value = value
self.minValue = minValue
self.maxValue = maxValue
self.onEditingChanged = onEditingChanged
}
func makeUIView(context: Context) -> UISlider {
let slider = UISlider(frame: .zero)
slider.maximumValue = Float(minValue)
slider.maximumValue = Float(maxValue)
let tintColor = UIColor(Color.appCtaYellow)
let image = UIImage(systemName: "circle.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .small))?
.withTintColor(tintColor)
.withRenderingMode(.alwaysOriginal)
slider.setThumbImage(image, for: .selected)
slider.setThumbImage(image, for: .normal)
slider.minimumTrackTintColor = tintColor
slider.addTarget(context.coordinator,
action: #selector(Coordinator.valueChanged(_:)),
for: .valueChanged)
return slider
}
func updateUIView(_ uiView: UISlider, context _: Context) {
uiView.value = Float(value)
}
func makeCoordinator() -> Coordinator {
let coordinator = Coordinator(value: $value, onEditingChanged: onEditingChanged)
return coordinator
}
class Coordinator: NSObject {
var value: Binding<Double>
@Binding var value: Double
var minValue: Double
var maxValue: Double
var onEditingChanged: (Bool) -> Void
init(value: Binding<Double>, onEditingChanged: @escaping (Bool) -> Void) {
self.value = value
init(value: Binding<Double>, minValue: Double, maxValue: Double, onEditingChanged: @escaping (Bool) -> Void) {
self._value = value
self.minValue = minValue
self.maxValue = maxValue
self.onEditingChanged = onEditingChanged
super.init()
}
@objc func valueChanged(_ sender: UISlider) {
value.wrappedValue = Double(sender.value)
onEditingChanged(sender.isTracking)
func makeUIView(context: Context) -> UISlider {
let slider = UISlider(frame: .zero)
slider.maximumValue = Float(minValue)
slider.maximumValue = Float(maxValue)
let tintColor = UIColor(Color.appCtaYellow)
let image = UIImage(systemName: "circle.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .small))?
.withTintColor(tintColor)
.withRenderingMode(.alwaysOriginal)
slider.setThumbImage(image, for: .selected)
slider.setThumbImage(image, for: .normal)
slider.minimumTrackTintColor = tintColor
slider.addTarget(context.coordinator,
action: #selector(Coordinator.valueChanged(_:)),
for: .valueChanged)
return slider
}
func updateUIView(_ uiView: UISlider, context _: Context) {
uiView.value = Float(value)
}
func makeCoordinator() -> Coordinator {
let coordinator = Coordinator(value: $value, onEditingChanged: onEditingChanged)
return coordinator
}
class Coordinator: NSObject {
var value: Binding<Double>
var onEditingChanged: (Bool) -> Void
init(value: Binding<Double>, onEditingChanged: @escaping (Bool) -> Void) {
self.value = value
self.onEditingChanged = onEditingChanged
super.init()
}
@objc func valueChanged(_ sender: UISlider) {
value.wrappedValue = Double(sender.value)
onEditingChanged(sender.isTracking)
}
}
}
}
#endif

View file

@ -8,13 +8,20 @@ import Views
#if os(macOS)
struct HomeFeedView: View {
@EnvironmentObject var dataService: DataService
@EnvironmentObject var audioController: AudioController
@State private var itemToRemove: LinkedItem?
@State private var confirmationShown = false
@ObservedObject var viewModel: HomeFeedViewModel
func loadItems(isRefresh: Bool) {
Task { await viewModel.loadItems(dataService: dataService, isRefresh: isRefresh) }
Task {
await viewModel.loadItems(
dataService: dataService,
audioController: audioController,
isRefresh: isRefresh
)
}
}
var body: some View {

View file

@ -43,7 +43,9 @@ import Views
// Pop the current selected item if needed
if selectedItem != nil, selectedItem?.objectID != objectID {
// Temporarily disable animation to avoid excessive animations
UIView.setAnimationsEnabled(false)
#if os(iOS)
UIView.setAnimationsEnabled(false)
#endif
linkIsActive = false
selectedItem = nil
@ -54,7 +56,9 @@ import Views
}
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(200)) {
UIView.setAnimationsEnabled(true)
#if os(iOS)
UIView.setAnimationsEnabled(true)
#endif
}
} else {
selectedItem = dataService.viewContext.object(with: objectID) as? LinkedItem

View file

@ -1,204 +1,96 @@
import SwiftUI
#if os(iOS)
import SwiftUI
// Mostly from: https://kavsoft.dev/swiftui_3.0_marquee_text_animation with some customizations
// Mostly from: https://kavsoft.dev/swiftui_3.0_marquee_text_animation with some customizations
struct Marquee: View {
var text: String
var font: UIFont
struct Marquee: View {
var text: String
var font: UIFont
// Storing Text Size
@State var storedSize: CGSize = .zero
@State var offset: CGFloat = 0
@State var animatedText: String = ""
// Storing Text Size
@State var storedSize: CGSize = .zero
@State var offset: CGFloat = 0
@State var animatedText: String = ""
var animationSpeed: Double = 0.03
var delayTime: Double = 3.0
var animationSpeed: Double = 0.03
var delayTime: Double = 3.0
var body: some View {
// Since it scrolls horizontal using ScrollView
GeometryReader { proxy in
var body: some View {
// Since it scrolls horizontal using ScrollView
GeometryReader { proxy in
let size = proxy.size
let size = proxy.size
let condition = textSize(text: text).width < (size.width - 50)
let condition = textSize(text: text).width < (size.width - 50)
ScrollView(condition ? .init() : .horizontal, showsIndicators: false) {
HStack(alignment: .center) {
Spacer(minLength: 0)
Text(condition ? text : animatedText)
.font(Font(font))
.offset(x: condition ? 0 : offset)
.padding(.horizontal, 15)
Spacer(minLength: 0)
ScrollView(condition ? .init() : .horizontal, showsIndicators: false) {
HStack(alignment: .center) {
Spacer(minLength: 0)
Text(condition ? text : animatedText)
.font(Font(font))
.offset(x: condition ? 0 : offset)
.padding(.horizontal, 15)
Spacer(minLength: 0)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
}
.frame(height: storedSize.height)
.overlay(content: {
HStack {
let color: Color = .systemBackground
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)], startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
Spacer()
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)].reversed(), startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
}
})
.disabled(true)
.onAppear {
startAnimation(text: text)
}
.onReceive(Timer.publish(every: (animationSpeed * storedSize.width) + delayTime,
on: .main,
in: .default).autoconnect()
) { _ in
offset = 0
withAnimation(.linear(duration: animationSpeed * storedSize.width).delay(delayTime)) {
offset = -storedSize.width
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
}
.frame(height: storedSize.height)
.overlay(content: {
HStack {
let color: Color = .systemBackground
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)], startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
Spacer()
LinearGradient(colors: [color, color.opacity(0.7), color.opacity(0.5), color.opacity(0.3)].reversed(), startPoint: .leading, endPoint: .trailing)
.frame(width: 8)
.onChange(of: text) { newValue in
animatedText = ""
offset = 0
startAnimation(text: newValue)
}
})
.disabled(true)
.onAppear {
startAnimation(text: text)
}
.onReceive(Timer.publish(every: (animationSpeed * storedSize.width) + delayTime,
on: .main,
in: .default).autoconnect()
) { _ in
offset = 0
withAnimation(.linear(duration: animationSpeed * storedSize.width).delay(delayTime)) {
func startAnimation(text: String) {
// Double the text with some spacing so that we can create a continuous loop
animatedText.append(text)
(1 ... 15).forEach { _ in
animatedText.append(" ")
}
storedSize = textSize(text: animatedText)
animatedText.append(text)
let timing: Double = (animationSpeed * storedSize.width)
withAnimation(.linear(duration: timing).delay(delayTime)) {
offset = -storedSize.width
}
}
.onChange(of: text) { newValue in
animatedText = ""
offset = 0
startAnimation(text: newValue)
func textSize(text: String) -> CGSize {
let attributes = [NSAttributedString.Key.font: font]
let size = (text as NSString).size(withAttributes: attributes)
return size
}
}
func startAnimation(text: String) {
// Double the text with some spacing so that we can create a continuous loop
animatedText.append(text)
(1 ... 15).forEach { _ in
animatedText.append(" ")
}
storedSize = textSize(text: animatedText)
animatedText.append(text)
let timing: Double = (animationSpeed * storedSize.width)
withAnimation(.linear(duration: timing).delay(delayTime)) {
offset = -storedSize.width
}
}
func textSize(text: String) -> CGSize {
let attributes = [NSAttributedString.Key.font: font]
let size = (text as NSString).size(withAttributes: attributes)
return size
}
}
// Old version:
//
// struct MarqueTextView: View {
// let font: Font
//
// @State var text: String
// @State private var intrinsicSize: CGSize = .zero
// @State private var truncatedSize: CGSize = .zero
//
// @State private var shouldAnimate: Bool = false
// @State private var animationOffset: Double = 0.0
//
// var body: some View {
// GeometryReader { geo in
// ScrollView(.horizontal, showsIndicators: false) {
// HStack(alignment: .center) {
// Spacer(minLength: 0)
// Text(text)
// .font(font)
// .lineLimit(1)
// .lineSpacing(1.25)
// .offset(x: animationOffset)
// .readSize { size in
// truncatedSize = size
// intrinsicSize = geo.size
//
// shouldAnimate = textSize().width > intrinsicSize.width
// }
// Spacer(minLength: 0)
// }
// .frame(width: max(geo.size.width, textSize().width + 10))
// }
// .frame(maxWidth: .infinity, alignment: .center)
// .disabled(true)
// .onChange(of: shouldAnimate) { _ in
//
// let baseText = text
// text.append(" ")
// let initialSize = textSize()
//
// print("starting animation, truncatedSize: ", truncatedSize, "geo width: ", geo.size)
// if shouldAnimate {
// DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
// withAnimation(.linear(duration: 0.05 * truncatedSize.width)) {
// animationOffset = -truncatedSize.width
// }
// }
// }
// }
// .onReceive(Timer.publish(every: 0.05 * truncatedSize.width + 0.5, on: .main, in: .default).autoconnect()) { _ in
// if shouldAnimate {
// animationOffset = 0
// withAnimation(.linear(duration: 0.05 * truncatedSize.width)) {
// animationOffset = -truncatedSize.width
// }
// }
// }
// }
// }
//
// func textSize() -> CGSize {
// let attributes = [NSAttributedString.Key.font: UIFont(name: "Inter-Regular", size: 16)!]
// return (text as NSString).size(withAttributes: attributes)
// }
// }
//
//// text()
//// .lineLimit(lineLimit)
//// .offset(x: animationOffset)
//// .readSize { size in
//// truncatedSize = size
//// shouldAnimate = truncatedSize != intrinsicSize
//// print("trunvatedSize: ", truncatedSize, "intrinsicSize: ", intrinsicSize)
//// }
//// .background(
//// text()
//// .fixedSize(horizontal: false, vertical: true)
//// .hidden()
//// .readSize { size in
//// intrinsicSize = size
//// shouldAnimate = truncatedSize != intrinsicSize
//// }
//// )
//// .onChange(of: shouldAnimate, perform: { _ in
//// print("starting animation")
//// DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
//// withAnimation(.linear(duration: 0.2 * intrinsicSize.width)) {
//// animationOffset = intrinsicSize.width
//// }
//// }
//// })
//// }
//// }
//
// extension View {
// func readSize(onChange: @escaping (CGSize) -> Void) -> some View {
// background(
// GeometryReader { geometryProxy in
// Color.clear
// .preference(key: SizePreferenceKey.self, value: geometryProxy.size)
// }
// )
// .onPreferenceChange(SizePreferenceKey.self, perform: onChange)
// }
// }
//
// struct SizePreferenceKey: PreferenceKey {
// static var defaultValue: CGSize = .zero
// static func reduce(value _: inout CGSize, nextValue _: () -> CGSize) {}
// }
#endif

View file

@ -99,11 +99,13 @@ struct ProfileView: View {
}
}
Section {
NavigationLink(destination: TextToSpeechView()) {
Text("Text to Speech")
#if os(iOS)
Section {
NavigationLink(destination: TextToSpeechView()) {
Text("Text to Speech")
}
}
}
#endif
Section {
NavigationLink(

View file

@ -1,47 +1,49 @@
import Models
import Services
import SwiftUI
import Views
#if os(iOS)
import Models
import Services
import SwiftUI
import Views
struct TextToSpeechLanguageView: View {
@EnvironmentObject var audioController: AudioController
struct TextToSpeechLanguageView: View {
@EnvironmentObject var audioController: AudioController
var body: some View {
Group {
#if os(iOS)
Form {
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
var body: some View {
Group {
#if os(iOS)
Form {
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
}
}
}
private var innerBody: some View {
ForEach(Voices.Languages, id: \.key.self) { language in
Button(action: {
audioController.defaultLanguage = language.key
}) {
HStack {
Text(language.name)
private var innerBody: some View {
ForEach(Voices.Languages, id: \.key.self) { language in
Button(action: {
audioController.defaultLanguage = language.key
}) {
HStack {
Text(language.name)
Spacer()
Spacer()
if audioController.defaultLanguage == language.key {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
if audioController.defaultLanguage == language.key {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
}
}
}
.contentShape(Rectangle())
}
.contentShape(Rectangle())
.buttonStyle(PlainButtonStyle())
}
.buttonStyle(PlainButtonStyle())
}
}
}
#endif

View file

@ -1,14 +1,14 @@
import Models
import Services
import SwiftUI
import Views
#if os(iOS)
import Models
import Services
import SwiftUI
import Views
struct TextToSpeechView: View {
@EnvironmentObject var audioController: AudioController
struct TextToSpeechView: View {
@EnvironmentObject var audioController: AudioController
var body: some View {
Group {
#if os(iOS)
var body: some View {
Group {
Form {
Section("Audio Settings") {
Toggle("Enable audio prefetch", isOn: $audioController.preloadEnabled)
@ -18,22 +18,17 @@ struct TextToSpeechView: View {
}
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
}
}
}
private var innerBody: some View {
Section("Voices") {
ForEach(Voices.Languages, id: \.key) { language in
NavigationLink(destination: TextToSpeechVoiceSelectionView(forLanguage: language, showLanguageChanger: false)) {
Text(language.name)
private var innerBody: some View {
Section("Voices") {
ForEach(Voices.Languages, id: \.key) { language in
NavigationLink(destination: TextToSpeechVoiceSelectionView(forLanguage: language, showLanguageChanger: false)) {
Text(language.name)
}
}
}
}
}
}
#endif

View file

@ -1,21 +1,21 @@
import Models
import Services
import SwiftUI
import Views
#if os(iOS)
import Models
import Services
import SwiftUI
import Views
struct TextToSpeechVoiceSelectionView: View {
@EnvironmentObject var audioController: AudioController
let language: VoiceLanguage
let showLanguageChanger: Bool
struct TextToSpeechVoiceSelectionView: View {
@EnvironmentObject var audioController: AudioController
let language: VoiceLanguage
let showLanguageChanger: Bool
init(forLanguage: VoiceLanguage, showLanguageChanger: Bool) {
self.language = forLanguage
self.showLanguageChanger = showLanguageChanger
}
init(forLanguage: VoiceLanguage, showLanguageChanger: Bool) {
self.language = forLanguage
self.showLanguageChanger = showLanguageChanger
}
var body: some View {
Group {
#if os(iOS)
var body: some View {
Group {
Form {
if showLanguageChanger {
Section("Language") {
@ -26,22 +26,16 @@ struct TextToSpeechVoiceSelectionView: View {
}
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
}
.navigationTitle("Choose a Voice")
}
.navigationTitle("Choose a Voice")
}
private var innerBody: some View {
ForEach(language.categories, id: \.self) { category in
Section(category.rawValue) {
ForEach(audioController.voiceList?.filter { $0.category == category } ?? [], id: \.key.self) { voice in
HStack {
// Voice samples are not working yet
private var innerBody: some View {
ForEach(language.categories, id: \.self) { category in
Section(category.rawValue) {
ForEach(audioController.voiceList?.filter { $0.category == category } ?? [], id: \.key.self) { voice in
HStack {
// Voice samples are not working yet
// Button(action: {
// audioController.playVoiceSample(voice: voice.key)
// }) {
@ -49,28 +43,29 @@ struct TextToSpeechVoiceSelectionView: View {
// }
// .buttonStyle(PlainButtonStyle())
Button(action: {
audioController.setPreferredVoice(voice.key, forLanguage: language.key)
audioController.currentVoice = voice.key
}) {
HStack {
Text(voice.name)
Spacer()
Button(action: {
audioController.setPreferredVoice(voice.key, forLanguage: language.key)
audioController.currentVoice = voice.key
}) {
HStack {
Text(voice.name)
Spacer()
if voice.selected {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
if voice.selected {
if audioController.isPlaying, audioController.isLoading {
ProgressView()
} else {
Image(systemName: "checkmark")
}
}
}
.contentShape(Rectangle())
}
.contentShape(Rectangle())
.buttonStyle(PlainButtonStyle())
}
.buttonStyle(PlainButtonStyle())
}
}
}
}
}
}
#endif

View file

@ -48,15 +48,17 @@ struct EmailAuthView: View {
Color.appBackground.edgesIgnoringSafeArea(.all)
primaryContent
.frame(maxWidth: 300)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .barTrailing) {
Button(
action: { presentationMode.wrappedValue.dismiss() },
label: { Image(systemName: "xmark").foregroundColor(.appGrayTextContrast) }
)
}
#endif
.toolbar {
ToolbarItem(placement: .barTrailing) {
Button(
action: { presentationMode.wrappedValue.dismiss() },
label: { Image(systemName: "xmark").foregroundColor(.appGrayTextContrast) }
)
}
}
}
}
}

View file

@ -52,10 +52,12 @@ struct EmailLoginFormView: View {
.font(.appFootnote)
.foregroundColor(.appGrayText)
TextField("", text: $email)
#if os(iOS)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.focused($focusedField, equals: .email)
.submitLabel(.next)
}
@ -67,8 +69,10 @@ struct EmailLoginFormView: View {
.foregroundColor(.appGrayText)
SecureField("", text: $password)
.textContentType(.password)
#if os(iOS)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.focused($focusedField, equals: .password)
.submitLabel(.done)
}

View file

@ -96,10 +96,12 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
TextField("", text: $email)
.focused($focusedField, equals: .email)
#if os(iOS)
.textContentType(.emailAddress)
.keyboardType(.emailAddress)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.submitLabel(.next)
}
.padding(.bottom, 8)
@ -111,9 +113,11 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
SecureField("", text: $password)
.focused($focusedField, equals: .password)
#if os(iOS)
.textContentType(.newPassword)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.submitLabel(.next)
}
.padding(.bottom, 8)
@ -125,9 +129,11 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
TextField("", text: $name)
.focused($focusedField, equals: .fullName)
#if os(iOS)
.textContentType(.name)
.keyboardType(.alphabet)
.disableAutocorrection(true)
#endif
.disableAutocorrection(true)
.submitLabel(.next)
}
.padding(.bottom, 8)
@ -141,10 +147,12 @@ struct EmailSignupFormView: View {
.foregroundColor(.appGrayText)
TextField("", text: $viewModel.potentialUsername)
.focused($focusedField, equals: .username)
#if os(iOS)
.textInputAutocapitalization(.never)
.textContentType(.username)
.disableAutocorrection(true)
.keyboardType(.alphabet)
#endif
.disableAutocorrection(true)
.submitLabel(.done)
}

View file

@ -51,8 +51,10 @@ struct InnerRootView: View {
.onAppear {
viewModel.triggerPushNotificationRequestIfNeeded()
}
#if os(iOS)
.miniPlayer()
.snackBar(isShowing: $viewModel.showSnackbar, message: viewModel.snackbarMessage)
#endif
.snackBar(isShowing: $viewModel.showSnackbar, message: viewModel.snackbarMessage)
// Schedule the dismissal every time we present the snackbar.
.onChange(of: viewModel.showSnackbar) { newValue in
if newValue {

View file

@ -75,47 +75,49 @@ struct WebReaderContainerView: View {
}
}
var audioNavbarItem: some View {
if audioController.isLoadingItem(itemID: item.unwrappedID) {
return AnyView(ProgressView()
#if os(iOS)
var audioNavbarItem: some View {
if audioController.isLoadingItem(itemID: item.unwrappedID) {
return AnyView(ProgressView()
.padding(.horizontal)
.scaleEffect(navBarVisibilityRatio))
} else {
return AnyView(Button(
action: {
switch audioController.state {
case .playing:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.pause()
return
}
fallthrough
case .paused:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.unpause()
return
}
fallthrough
default:
audioController.play(itemAudioProperties: item.audioProperties)
}
},
label: {
textToSpeechButtonImage
}
)
.padding(.horizontal)
.scaleEffect(navBarVisibilityRatio))
} else {
return AnyView(Button(
action: {
switch audioController.state {
case .playing:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.pause()
return
}
fallthrough
case .paused:
if audioController.itemAudioProperties?.itemID == self.item.unwrappedID {
audioController.unpause()
return
}
fallthrough
default:
audioController.play(itemAudioProperties: item.audioProperties)
}
},
label: {
textToSpeechButtonImage
}
)
.padding(.horizontal)
.scaleEffect(navBarVisibilityRatio))
}
}
}
var textToSpeechButtonImage: some View {
if audioController.state == .stopped || audioController.itemAudioProperties?.itemID != self.item.id {
return Image(systemName: "headphones").font(.appTitleThree)
var textToSpeechButtonImage: some View {
if audioController.state == .stopped || audioController.itemAudioProperties?.itemID != self.item.id {
return Image(systemName: "headphones").font(.appTitleThree)
}
let name = audioController.isPlayingItem(itemID: item.unwrappedID) ? "pause.circle" : "play.circle"
return Image(systemName: name).font(.appNavbarIcon)
}
let name = audioController.isPlayingItem(itemID: item.unwrappedID) ? "pause.circle" : "play.circle"
return Image(systemName: name).font(.appNavbarIcon)
}
#endif
var navBar: some View {
HStack(alignment: .center) {
@ -131,8 +133,8 @@ struct WebReaderContainerView: View {
)
.scaleEffect(navBarVisibilityRatio)
Spacer()
audioNavbarItem
#endif
audioNavbarItem
Button(
action: { showPreferencesPopover.toggle() },
label: {

View file

@ -0,0 +1,11 @@
#if os(macOS)
import Foundation
public final class AudioController: ObservableObject {
public init() {}
public func preload(itemIDs _: [String]) {}
public func downloadForOffline(itemID _: String) -> Bool { true }
}
#endif

View file

@ -26,11 +26,11 @@ public final class OmnivoreWebView: WKWebView {
#if os(iOS)
initNativeIOSMenus()
#endif
if #available(iOS 16.0, *) {
self.isFindInteractionEnabled = true
}
if #available(iOS 16.0, *) {
self.isFindInteractionEnabled = true
}
#endif
NotificationCenter.default.addObserver(forName: NSNotification.Name("SpeakingReaderItem"), object: nil, queue: OperationQueue.main, using: { notification in
if let pageID = notification.userInfo?["pageID"] as? String, let anchorIdx = notification.userInfo?["anchorIdx"] as? String {