Skip to content

Commit

Permalink
Refactor ExperimentalFeatures module to SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Sep 6, 2023
1 parent 3564d67 commit 9c6be68
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 92 deletions.
36 changes: 30 additions & 6 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import SwiftUI
import UIKit

struct ExperimentalFeaturesModule {

static func viewController() -> UIViewController {
ExperimentalFeaturesViewController()
let view = ExperimentalFeaturesView()

let viewController = UIHostingController(rootView: view)
viewController.title = "settings.experimental_features.title".localized

return viewController
}

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

struct ExperimentalFeaturesView: View {

var body: some View {
ScrollableThemeView {
VStack(spacing: .margin24) {
HighlightedTextView(text: "settings.experimental_features.description".localized)

ListSection {
NavigationRow(destination: {
SimpleActivateModule.bitcoinHodlingView()
}) {
Text("settings.experimental_features.bitcoin_hodling".localized).themeBody()
Image.disclosureIcon
}
}
}
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin32, trailing: .margin16))
}
.navigationBarTitle("settings.experimental_features.title".localized)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import SwiftUI
import UIKit

struct SimpleActivateModule {

static var bitcoinHodlingViewController: UIViewController {
static func bitcoinHodlingView() -> some View {
let viewModel = SimpleActivateViewModel(localStorage: App.shared.localStorage)

let view = SimpleActivateView(
return SimpleActivateView(
viewModel: viewModel,
title: "settings.bitcoin_hodling.title".localized,
toggleText: "settings.bitcoin_hodling.lock_time".localized,
description: "settings.bitcoin_hodling.description".localized(AppConfig.appName, AppConfig.appName)
)

let viewController = UIHostingController(rootView: view)
viewController.title = "settings.bitcoin_hodling.title".localized

return viewController
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
struct SimpleActivateView: View {
@ObservedObject var viewModel: SimpleActivateViewModel

let title: String
let toggleText: String
let description: String

Expand All @@ -19,6 +20,7 @@ struct SimpleActivateView: View {
}
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin32, trailing: .margin16))
}
.navigationBarTitle(title)
}

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

extension Image {

func themeIcon(color: Color = .themeGray) -> some View {
renderingMode(.template)
.foregroundColor(color)
}

static var disclosureIcon: some View {
Image("arrow_big_forward_20")
.themeIcon()
}

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

struct HighlightedTextView: View {
private let text: String
private let style: Style

init(text: String, style: Style = .warning) {
self.text = text
self.style = style
}

var body: some View {
Text(text)
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin12, trailing: .margin16))
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.themeBran)
.font(.themeSubhead2)
.background(RoundedRectangle(cornerRadius: .cornerRadius12, style: .continuous).fill(style.color.opacity(0.2)))
.overlay(
RoundedRectangle(cornerRadius: .cornerRadius12, style: .continuous).stroke(style.color, lineWidth: .heightOneDp)
)
}

}

extension HighlightedTextView {

enum Style {
case warning
case alert

var color: Color {
switch self {
case .warning: return .themeYellow
case .alert: return .themeLucian
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ struct ListRow<Content: View>: View {
content
}
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin12, trailing: .margin16))
.frame(minHeight: .heightCell48)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SwiftUI

struct NavigationRow<Content: View, Destination: View>: View {
@ViewBuilder let destination: () -> Destination
@ViewBuilder let content: Content

var body: some View {
NavigationLink(destination: destination) {
ListRow {
content
}
}
.buttonStyle(RowButton())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

struct RowButton: ButtonStyle {

func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.background(configuration.isPressed ? Color.themeLawrencePressed : Color.themeLawrence)
}

}

0 comments on commit 9c6be68

Please sign in to comment.