Skip to content

Commit

Permalink
Switch About module to SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Oct 6, 2023
1 parent 2fcb1d7 commit fb5aa55
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 400 deletions.
30 changes: 12 additions & 18 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import RxSwift
import RxRelay
import Combine
import HsExtensions
import StorageKit

class TermsManager {
private let keyTermsAccepted = "key_terms_accepted"
private let storage: StorageKit.ILocalStorage

private let termsAcceptedRelay = PublishRelay<Bool>()
@DistinctPublished var termsAccepted: Bool

init(storage: StorageKit.ILocalStorage) {
self.storage = storage
}

termsAccepted = storage.value(for: keyTermsAccepted) ?? false
}
}

extension TermsManager {

var termsAccepted: Bool {
storage.value(for: keyTermsAccepted) ?? false
}

var termsAcceptedObservable: Observable<Bool> {
termsAcceptedRelay.asObservable()
}

func setTermsAccepted() {
storage.set(value: true, for: keyTermsAccepted)
termsAcceptedRelay.accept(true)
termsAccepted = true
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit
import SafariServices
import SwiftUI
import UIKit

class UrlManager {
private let inApp: Bool
Expand Down Expand Up @@ -51,5 +52,16 @@ class UrlManager {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}

struct SFSafariView: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController

let url: URL

func makeUIViewController(context _: Context) -> UIViewController {
SFSafariViewController(url: url, configuration: SFSafariViewController.Configuration())
}

func updateUIViewController(_: UIViewController, context _: Context) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ class MainBadgeService {
}
.store(in: &cancellables)

termsManager.termsAcceptedObservable
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background))
.observeOn(ConcurrentDispatchQueueScheduler(qos: .background))
.subscribe(onNext: { [weak self] _ in
termsManager.$termsAccepted
.sink { [weak self] _ in
self?.syncSettingsBadge()
})
.disposed(by: disposeBag)
}
.store(in: &cancellables)

walletConnectSessionManager.activePendingRequestsObservable
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI
import UIKit

struct MarkdownModule {

static func viewController(url: URL, handleRelativeUrl: Bool = true) -> UIViewController {
let provider = MarkdownPlainContentProvider(url: url, networkManager: App.shared.networkManager)
let service = MarkdownService(provider: provider)
Expand All @@ -11,7 +11,7 @@ struct MarkdownModule {
return MarkdownViewController(viewModel: viewModel, handleRelativeUrl: handleRelativeUrl)
}

static func gitReleaseNotesMarkdownViewController(url: URL, presented: Bool, closeHandler: (() -> ())? = nil) -> UIViewController {
static func gitReleaseNotesMarkdownViewController(url: URL, presented: Bool, closeHandler: (() -> Void)? = nil) -> UIViewController {
let provider = MarkdownGitReleaseContentProvider(url: url, networkManager: App.shared.networkManager)
let service = MarkdownService(provider: provider)
let parser = MarkdownParser()
Expand All @@ -20,6 +20,9 @@ struct MarkdownModule {
return ReleaseNotesViewController(viewModel: viewModel, handleRelativeUrl: false, urlManager: UrlManager(inApp: false), presented: presented, closeHandler: closeHandler)
}

static func gitReleaseNotesMarkdownView(url: URL, presented: Bool) -> some View {
ReleaseNotesView(url: url, presented: presented)
}
}

enum MarkdownBlockViewItem {
Expand All @@ -36,3 +39,16 @@ enum MarkdownImageType {
case portrait
case square
}

struct ReleaseNotesView: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController

let url: URL
let presented: Bool

func makeUIViewController(context _: Context) -> UIViewController {
MarkdownModule.gitReleaseNotesMarkdownViewController(url: url, presented: presented)
}

func updateUIViewController(_: UIViewController, context _: Context) {}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import UIKit
import SwiftUI

struct AboutModule {
static func viewController() -> UIViewController {
let service = AboutService(
termsManager: App.shared.termsManager,
systemInfoManager: App.shared.systemInfoManager
)
static func view() -> some View {
let releaseNotesService = ReleaseNotesService(appVersionManager: App.shared.appVersionManager)

let viewModel = AboutViewModel(service: service, releaseNotesService: releaseNotesService)
let viewModel = AboutViewModel(
termsManager: App.shared.termsManager,
systemInfoManager: App.shared.systemInfoManager,
releaseNotesService: releaseNotesService
)

return AboutViewController(viewModel: viewModel, urlManager: UrlManager(inApp: true))
return AboutView(viewModel: viewModel)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import SwiftUI

struct AboutView: View {
@ObservedObject var viewModel: AboutViewModel

@State private var termsPresented = false
@State private var linkUrl: URL?

var body: some View {
ScrollableThemeView {
VStack(spacing: .margin24) {
HStack(spacing: .margin16) {
Image(uiImage: UIImage(named: AppIcon.main.imageName) ?? UIImage())
.resizable()
.scaledToFit()
.clipShape(RoundedRectangle(cornerRadius: .cornerRadius16, style: .continuous))
.frame(width: 72, height: 72)

VStack(spacing: .margin8) {
Text("settings.about_app.app_name".localized(AppConfig.appName)).themeHeadline1()
Text("version".localized(viewModel.appVersion)).themeSubhead2()
}
}
.padding(.horizontal, .margin24)

Text("settings.about_app.description".localized(AppConfig.appName, AppConfig.appName))
.font(.themeBody)
.foregroundColor(.themeBran)
.padding(.horizontal, .margin32)
.padding(.vertical, .margin12)

VStack(spacing: .margin32) {
if let releaseNotesUrl = viewModel.releaseNotesUrl {
ListSection {
NavigationRow(destination: {
MarkdownModule.gitReleaseNotesMarkdownView(url: releaseNotesUrl, presented: false)
.ignoresSafeArea()
}) {
Image("circle_information_24").themeIcon()
Text("settings.about_app.whats_new".localized).themeBody()
Image.disclosureIcon
}
}
}

ListSection {
NavigationRow(destination: {
AppStatusModule.view()
}) {
Image("app_status_24").themeIcon()
Text("app_status.title".localized).themeBody()
Image.disclosureIcon
}

ClickableRow(action: {
termsPresented = true
}) {
Image("unordered_24").themeIcon()
Text("terms.title".localized).themeBody()

if viewModel.termsAlert {
Image("warning_2_20").themeIcon(color: .themeLucian).padding(.trailing, -.margin8)
}

Image.disclosureIcon
}

NavigationRow(destination: {
PrivacyPolicyView(config: .privacy)
.navigationTitle(PrivacyPolicyViewController.Config.privacy.title)
.ignoresSafeArea()
}) {
Image("user_24").themeIcon()
Text("settings.privacy".localized).themeBody()
Image.disclosureIcon
}
}

ListSection {
ClickableRow(action: {
linkUrl = URL(string: "https://github.com/\(AppConfig.appGitHubAccount)/\(AppConfig.appGitHubRepository)")
}) {
Image("github_24").themeIcon()
Text("GitHub").themeBody()
Image.disclosureIcon
}

ClickableRow(action: {
let account = AppConfig.appTwitterAccount

if let appUrl = URL(string: "twitter://user?screen_name=\(account)"), UIApplication.shared.canOpenURL(appUrl) {
UIApplication.shared.open(appUrl)
} else {
linkUrl = URL(string: "https://twitter.com/\(account)")
}
}) {
Image("twitter_24").themeIcon()
Text("Twitter").themeBody()
Image.disclosureIcon
}

ClickableRow(action: {
linkUrl = URL(string: AppConfig.appWebPageLink)
}) {
Image("globe_24").themeIcon()
Text("settings.about_app.website".localized).themeBody()
Image.disclosureIcon
}
}
}
.padding(.horizontal, .margin16)
}
.padding(EdgeInsets(top: .margin24, leading: 0, bottom: .margin32, trailing: 0))
.sheet(isPresented: $termsPresented) {
TermsModule.view()
.ignoresSafeArea()
}
.sheet(item: $linkUrl) { url in
SFSafariView(url: url)
.ignoresSafeArea()
}
}
.navigationTitle("settings.about_app.title".localized)
}
}
Loading

0 comments on commit fb5aa55

Please sign in to comment.