[ADD] News, Browse and Settings views ported to SwiftUI

This commit contains WIP SwiftUI versions of most of the views in SideStore.
This commit is contained in:
Fabian Thies
2022-11-23 22:34:02 +01:00
parent ed2270ff46
commit 16a8bce102
30 changed files with 2047 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
//
// PillButtonProgressViewStyle.swift
// SideStore
//
// Created by Fabian Thies on 22.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
struct PillButtonProgressViewStyle: ProgressViewStyle {
let tint: Color
func makeBody(configuration: Configuration) -> some View {
ZStack(alignment: .leading) {
Capsule(style: .continuous)
.foregroundColor(tint.opacity(0.15))
GeometryReader { proxy in
Capsule(style: .continuous)
// .frame(width: proxy.size.width * (configuration.fractionCompleted ?? 0.0))
.foregroundColor(tint)
.offset(x: -proxy.size.width * (1 - (configuration.fractionCompleted ?? 1)))
}
}
.animation(.easeInOut(duration: 0.2))
}
}

View File

@@ -0,0 +1,46 @@
//
// PillButtonStyle.swift
// SideStore
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
struct PillButtonStyle: ButtonStyle {
let tintColor: UIColor
var progress: Progress?
func makeBody(configuration: Configuration) -> some View {
ZStack {
if progress == nil {
configuration.label
.opacity(configuration.isPressed ? 0.4 : 1.0)
} else {
ProgressView()
.progressViewStyle(DefaultProgressViewStyle())
}
}
.frame(minWidth: 40)
.padding(.horizontal, 16)
.padding(.vertical, 8)
.background(background)
.foregroundColor(self.progress == nil ? .white : Color(tintColor))
.clipShape(Capsule())
}
var background: some View {
ZStack {
if let progress {
Color(tintColor).opacity(0.15)
ProgressView(progress)
.progressViewStyle(PillButtonProgressViewStyle(tint: Color(tintColor)))
} else {
Color(tintColor)
}
}
}
}

View File

@@ -0,0 +1,20 @@
//
// SafariView.swift
// SideStore
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import SafariServices
struct SafariView: UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: Context) -> some UIViewController {
SFSafariViewController(url: url)
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
}

View File

@@ -0,0 +1,52 @@
//
// SiriShortcutSetupView.swift
// SideStore
//
// Created by Fabian Thies on 21.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import UIKit
import Intents
import IntentsUI
struct SiriShortcutSetupView: UIViewControllerRepresentable {
let shortcut: INShortcut
func makeUIViewController(context: Context) -> some UIViewController {
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
viewController.delegate = context.coordinator
viewController.modalPresentationStyle = .formSheet
return viewController
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
func makeCoordinator() -> Coordinator {
Coordinator(shortcut: shortcut)
}
class Coordinator: NSObject {
let shortcut: INShortcut
init(shortcut: INShortcut) {
self.shortcut = shortcut
}
}
}
extension SiriShortcutSetupView.Coordinator: INUIAddVoiceShortcutViewControllerDelegate {
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
// TODO: Handle errors
controller.dismiss(animated: true)
}
func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
controller.dismiss(animated: true)
}
}