Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sample] Settings redesign #1231

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3391,8 +3391,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/WalletConnect/web3modal-swift";
requirement = {
kind = exactVersion;
version = 1.0.9;
kind = upToNextMajorVersion;
minimumVersion = 1.0.9;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
17 changes: 0 additions & 17 deletions Example/Showcase/Common/VIPER/SceneViewController.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import SwiftUI

enum NavigationBarStyle {
case translucent(UIColor)
}

protocol SceneViewModel {
var sceneTitle: String? { get }
var largeTitleDisplayMode: UINavigationItem.LargeTitleDisplayMode { get }
var leftBarButtonItem: UIBarButtonItem? { get }
var rightBarButtonItem: UIBarButtonItem? { get }
var navigationBarStyle: NavigationBarStyle { get }
var preferredStatusBarStyle: UIStatusBarStyle { get }
var isNavigationBarTranslucent: Bool { get }

Expand All @@ -28,9 +23,6 @@ extension SceneViewModel {
var rightBarButtonItem: UIBarButtonItem? {
return .none
}
var navigationBarStyle: NavigationBarStyle {
return .translucent(.w_background)
}
var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
Expand All @@ -56,7 +48,6 @@ class SceneViewController<ViewModel: SceneViewModel, Content: View>: UIHostingCo
super.viewDidLoad()
setupView()
setupNavigation()
setupNavigationBarStyle()
}

@objc required dynamic init?(coder aDecoder: NSCoder) {
Expand All @@ -79,12 +70,4 @@ private extension SceneViewController {
navigationItem.rightBarButtonItem = viewModel.rightBarButtonItem
navigationItem.leftBarButtonItem = viewModel.leftBarButtonItem
}

func setupNavigationBarStyle() {
switch viewModel.navigationBarStyle {
case .translucent(let color):
navigationController?.navigationBar.barTintColor = color
navigationController?.navigationBar.isTranslucent = true
}
}
}
31 changes: 0 additions & 31 deletions Example/WalletApp/Common/VIPER/SceneViewController.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import SwiftUI

enum NavigationBarStyle {
case solid(UIColor)
case clear
}

protocol SceneViewModel {
var sceneTitle: String? { get }
var largeTitleDisplayMode: UINavigationItem.LargeTitleDisplayMode { get }
var leftBarButtonItem: UIBarButtonItem? { get }
var rightBarButtonItem: UIBarButtonItem? { get }
var navigationBarStyle: NavigationBarStyle { get }
var preferredStatusBarStyle: UIStatusBarStyle { get }
var isNavigationBarTranslucent: Bool { get }

Expand All @@ -29,9 +23,6 @@ extension SceneViewModel {
var rightBarButtonItem: UIBarButtonItem? {
return .none
}
var navigationBarStyle: NavigationBarStyle {
return .solid(.w_background)
}
var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
Expand All @@ -58,11 +49,6 @@ class SceneViewController<ViewModel: SceneViewModel, Content: View>: UIHostingCo
setupNavigation()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupNavigationBarStyle()
}

@objc required dynamic init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand All @@ -81,21 +67,4 @@ private extension SceneViewController {
navigationItem.rightBarButtonItem = viewModel.rightBarButtonItem
navigationItem.leftBarButtonItem = viewModel.leftBarButtonItem
}

func setupNavigationBarStyle() {
switch viewModel.navigationBarStyle {
case .solid(let color):
navigationController?.navigationBar.setBackgroundImage(color.image(), for: .default)
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.backgroundColor = color
navigationController?.navigationBar.barTintColor = color
case .clear:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.backgroundColor = .clear
navigationController?.navigationBar.barTintColor = .clear
navigationController?.navigationBar.tintColor = .w_foreground
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "copy.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension BrowserPresenter: SceneViewModel {
}

var largeTitleDisplayMode: UINavigationItem.LargeTitleDisplayMode {
return .always
return .never
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct NotificationsView: View {
}

Rectangle()
.foregroundColor(.black.opacity(0.03))
.foregroundColor(Color.Foreground100.opacity(0.05))
.frame(maxWidth: .infinity)
.frame(height: 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ extension SubscriptionPresenter: SceneViewModel {
return .never
}

var navigationBarStyle: NavigationBarStyle {
return .clear
}

var rightBarButtonItem: UIBarButtonItem? {
return UIBarButtonItem(
image: UIImage(systemName: "gearshape"),
Expand Down
107 changes: 78 additions & 29 deletions Example/WalletApp/PresentationLayer/Wallet/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI
import AsyncButton
import Web3ModalUI

struct SettingsView: View {

Expand All @@ -8,37 +9,54 @@ struct SettingsView: View {
@State private var copyAlert: Bool = false

var body: some View {
List {
Section(header: Text("Account")) {
row(title: "CAIP-10", subtitle: viewModel.account)
row(title: "Private key", subtitle: viewModel.privateKey)
}
ScrollView {
VStack(spacing: 12) {
separator()

Section(header: Text("Device")) {
row(title: "Client ID", subtitle: viewModel.clientId)
row(title: "Device Token", subtitle: viewModel.deviceToken)
}
Group {
header(title: "Account")
row(title: "CAIP-10", subtitle: viewModel.account)
row(title: "Private key", subtitle: viewModel.privateKey)
}
.padding(.horizontal, 20)

separator()

Section {
Button {
viewModel.browserPressed()
} label: {
Text("Browser")
.frame(maxWidth: .infinity)
Group {
header(title: "Device")
row(title: "Client ID", subtitle: viewModel.clientId)
row(title: "Device Token", subtitle: viewModel.deviceToken)
}
}
.padding(.horizontal, 20)

separator()

Group {
Button {
viewModel.browserPressed()
} label: {
Text("Browser")
.frame(maxWidth: .infinity)
}
.frame(height: 44.0)

Section {
AsyncButton {
try await viewModel.logoutPressed()
} label: {
Text("Log out")
.foregroundColor(.red)
.frame(maxWidth: .infinity)
AsyncButton {
try await viewModel.logoutPressed()
} label: {
Text("Log out")
.foregroundColor(.red)
.frame(maxWidth: .infinity)
}
.frame(height: 44.0)
.overlay(
RoundedRectangle(cornerRadius: Radius.m)
.stroke(Color.red, lineWidth: 1)
)
.padding(.bottom, 24)
}
.padding(.horizontal, 20)
}
}
.listStyle(.insetGrouped)
.alert("Value copied to clipboard", isPresented: $copyAlert) {
Button("OK", role: .cancel) { }
}
Expand All @@ -47,22 +65,53 @@ struct SettingsView: View {
}
}

func header(title: String) -> some View {
HStack {
Text(title)
.foregroundColor(.Foreground100)
.font(.large700)
.padding(.vertical, 6)
Spacer()
}
}

func row(title: String, subtitle: String) -> some View {
return Button(action: {
UIPasteboard.general.string = subtitle
copyAlert = true
}) {
HStack(spacing: 16) {
VStack {
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 6) {
Text(title)
.multilineTextAlignment(.leading)
.foregroundColor(.Foreground100)
.font(.paragraph700)

Image("copy_small")
.foregroundColor(.Foreground100)

Spacer()
}
.padding(.vertical, 8.0)
.padding(.horizontal, 12)
.padding(.top, 16)

Text(subtitle)
.multilineTextAlignment(.trailing)
.foregroundColor(.gray)
.multilineTextAlignment(.leading)
.foregroundColor(.Foreground150)
.font(.paragraph500)
.padding(.horizontal, 12)
.padding(.bottom, 16)
}
.background(Color.Foreground100.opacity(0.05).cornerRadius(12))
}
.frame(maxWidth: .infinity)
}

func separator() -> some View {
Rectangle()
.foregroundColor(.Foreground100.opacity(0.05))
.frame(maxWidth: .infinity)
.frame(height: 1)
.padding(.top, 8)
}
}