From 34b7cf3ed55f9d44f1237f83d9687d66cc4ac5f0 Mon Sep 17 00:00:00 2001 From: Igor Kulman Date: Wed, 7 Feb 2024 15:11:49 +0100 Subject: [PATCH] Add previews for all the view controllers --- .../ViewControllers/AboutViewController.swift | 9 ++++++++ .../LibrariesViewController.swift | 9 ++++++++ .../DetailViewController.swift | 9 ++++++++ .../ViewControllers/FeedViewController.swift | 22 +++++++++++++++++++ .../CustomSourceViewController.swift | 9 ++++++++ .../SourceSelectionViewController.swift | 9 ++++++++ 6 files changed, 67 insertions(+) diff --git a/Sources/iOSSampleApp/Scenarios/About/ViewControllers/AboutViewController.swift b/Sources/iOSSampleApp/Scenarios/About/ViewControllers/AboutViewController.swift index 2072b53..dfcebdc 100644 --- a/Sources/iOSSampleApp/Scenarios/About/ViewControllers/AboutViewController.swift +++ b/Sources/iOSSampleApp/Scenarios/About/ViewControllers/AboutViewController.swift @@ -126,3 +126,12 @@ final class AboutViewController: UITableViewController { return headerView } } + +#if canImport(SwiftUI) && DEBUG +import SwiftUI +struct AboutViewControllerPreview: PreviewProvider { + static var previews: some View { + UINavigationController(rootViewController: AboutViewController(viewModel: AboutViewModel())).asPreview() + } +} +#endif diff --git a/Sources/iOSSampleApp/Scenarios/About/ViewControllers/LibrariesViewController.swift b/Sources/iOSSampleApp/Scenarios/About/ViewControllers/LibrariesViewController.swift index 4e2fcb5..548fd8e 100644 --- a/Sources/iOSSampleApp/Scenarios/About/ViewControllers/LibrariesViewController.swift +++ b/Sources/iOSSampleApp/Scenarios/About/ViewControllers/LibrariesViewController.swift @@ -52,3 +52,12 @@ final class LibrariesViewController: UITableViewController { }.disposed(by: disposeBag) } } + +#if canImport(SwiftUI) && DEBUG +import SwiftUI +struct LibrariesViewControllerPreview: PreviewProvider { + static var previews: some View { + UINavigationController(rootViewController: LibrariesViewController(viewModel: LibrariesViewModel())).asPreview() + } +} +#endif diff --git a/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/DetailViewController.swift b/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/DetailViewController.swift index a1a79ee..1dc46b1 100644 --- a/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/DetailViewController.swift +++ b/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/DetailViewController.swift @@ -180,3 +180,12 @@ final class DetailViewController: UIViewController { } } } + +#if canImport(SwiftUI) && DEBUG +import SwiftUI +struct DetailViewControllerPreview: PreviewProvider { + static var previews: some View { + UINavigationController(rootViewController: DetailViewController(item: RssItem(title: "New post", description: "Some description", link: "http://www.github.com/igorkulman/iOSSampleApp", pubDate: Date()))).asPreview() + } +} +#endif diff --git a/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/FeedViewController.swift b/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/FeedViewController.swift index 42218fc..dd83710 100644 --- a/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/FeedViewController.swift +++ b/Sources/iOSSampleApp/Scenarios/Feed/ViewControllers/FeedViewController.swift @@ -130,3 +130,25 @@ final class FeedViewController: UIViewController, ToastCapable { .disposed(by: disposeBag) } } + +#if canImport(SwiftUI) && DEBUG +import SwiftUI +final class PreviewDataService: DataService { + func getFeed(source: RssSource, onCompletion: @escaping (RssResult) -> Void) { + onCompletion(.success([ + RssItem(title: "Post 1", description: "Description", link: "", pubDate: Date()), + RssItem(title: "Post 2", description: "Description", link: "", pubDate: Date()), + RssItem(title: "Post 3", description: "Description", link: "", pubDate: Date()) + ])) + } +} +final class PreviewSettingsService: SettingsService { + var selectedSource: RssSource? = RssSource(title: "Website", url: "", rss: "", icon: "") +} + +struct FeedViewControllerPreview: PreviewProvider { + static var previews: some View { + UINavigationController(rootViewController: FeedViewController(viewModel: FeedViewModel(dataService: PreviewDataService(), settingsService: PreviewSettingsService()))).asPreview() + } +} +#endif diff --git a/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/CustomSourceViewController.swift b/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/CustomSourceViewController.swift index 16e3406..bdde81f 100644 --- a/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/CustomSourceViewController.swift +++ b/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/CustomSourceViewController.swift @@ -113,3 +113,12 @@ final class CustomSourceViewController: UIViewController { doneButton.rx.tap.withLatestFrom(viewModel.source.flatMap(ignoreNil)).withUnretained(self).bind { owner, source in owner.delegate?.userDidAddCustomSource(source: source) }.disposed(by: disposeBag) } } + +#if canImport(SwiftUI) && DEBUG +import SwiftUI +struct CustomSourceViewControllerPreview: PreviewProvider { + static var previews: some View { + UINavigationController(rootViewController: CustomSourceViewController(viewModel: CustomSourceViewModel())).asPreview() + } +} +#endif diff --git a/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/SourceSelectionViewController.swift b/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/SourceSelectionViewController.swift index 82206e6..9714b95 100644 --- a/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/SourceSelectionViewController.swift +++ b/Sources/iOSSampleApp/Scenarios/Setup/ViewControllers/SourceSelectionViewController.swift @@ -123,3 +123,12 @@ final class SourceSelectionViewController: UIViewController { .disposed(by: disposeBag) } } + +#if canImport(SwiftUI) && DEBUG +import SwiftUI +struct SourceSelectionViewControllerPreview: PreviewProvider { + static var previews: some View { + UINavigationController(rootViewController: SourceSelectionViewController(viewModel: SourceSelectionViewModel(settingsService: UserDefaultsSettingsService()))).asPreview() + } +} +#endif