Skip to content

Commit

Permalink
Notifications view components
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Oct 5, 2023
1 parent bb0a770 commit efa3c9d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
9 changes: 9 additions & 0 deletions Example/WalletApp/Common/Extensions/UIKit/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ extension UIColor {
blue: rgb & 0xFF
)
}

func image(size: CGSize = CGSize(width: 1, height: 1)) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
setFill()
UIRectFill(CGRect(origin: CGPoint.zero, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
11 changes: 6 additions & 5 deletions Example/WalletApp/Common/VIPER/SceneViewController.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

enum NavigationBarStyle {
case translucent(UIColor)
case solid(UIColor)
case clear
}

Expand Down Expand Up @@ -30,7 +30,7 @@ extension SceneViewModel {
return .none
}
var navigationBarStyle: NavigationBarStyle {
return .translucent(.w_background)
return .solid(.w_background)
}
var preferredStatusBarStyle: UIStatusBarStyle {
return .default
Expand Down Expand Up @@ -84,10 +84,11 @@ private extension SceneViewController {

func setupNavigationBarStyle() {
switch viewModel.navigationBarStyle {
case .translucent(let color):
navigationController?.navigationBar.backgroundColor = .w_background
case .solid(let color):
navigationController?.navigationBar.setBackgroundImage(color.image(), for: .default)
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.backgroundColor = color
navigationController?.navigationBar.barTintColor = color
navigationController?.navigationBar.isTranslucent = true
case .clear:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import UIKit
import Combine
import WalletConnectNotify

final class NotificationsPresenter: ObservableObject {

private let interactor: NotificationsInteractor
private let router: NotificationsRouter
private var disposeBag = Set<AnyCancellable>()

@Published var subscriptions: [SubscriptionsViewModel] = []
@Published var listings: [ListingViewModel] = []
@Published private var subscriptions: [NotifySubscription] = []
@Published private var listings: [Listing] = []

var subscriptionViewModels: [SubscriptionsViewModel] {
return subscriptions
.map { SubscriptionsViewModel(subscription: $0) }
.sorted(by: { $0.name < $1.name })
}

var listingViewModels: [ListingViewModel] {
return listings
.map { ListingViewModel(listing: $0) }
}

init(interactor: NotificationsInteractor, router: NotificationsRouter) {
defer { setupInitialState() }
Expand All @@ -19,11 +31,11 @@ final class NotificationsPresenter: ObservableObject {

@MainActor
func fetch() async throws {
self.listings = try await interactor.getListings().map { ListingViewModel(listing: $0) }
listings = try await interactor.getListings()
}

func subscription(forListing listing: ListingViewModel) -> SubscriptionsViewModel? {
return subscriptions.first(where: { $0.domain == listing.appDomain })
return subscriptionViewModels.first(where: { $0.domain == listing.appDomain })
}

func subscribe(listing: ListingViewModel) async throws {
Expand All @@ -50,7 +62,7 @@ final class NotificationsPresenter: ObservableObject {

func removeSubscribtion(at indexSet: IndexSet) async {
if let index = indexSet.first {
await interactor.removeSubscription(subscriptions[index].subscription)
await interactor.removeSubscription(subscriptionViewModels[index].subscription)
}
}
}
Expand All @@ -72,13 +84,12 @@ extension NotificationsPresenter: SceneViewModel {
private extension NotificationsPresenter {

func setupSubscriptions() {
self.subscriptions = interactor.getSubscriptions().map { SubscriptionsViewModel(subscription: $0) }
self.subscriptions = interactor.getSubscriptions()

interactor.subscriptionsPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] notifySubscriptions in
self?.subscriptions = notifySubscriptions
.map { SubscriptionsViewModel(subscription: $0) }
}
.store(in: &disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct NotificationsView: View {
.padding(.trailing, 32)
}
})
.animation(.easeInOut(duration: 0.3), value: true)
.animation(.easeInOut(duration: 0.3))
}
.listRowBackground(Color.clear)
}
Expand All @@ -50,7 +50,7 @@ struct NotificationsView: View {
}

private func discover() -> some View {
return ForEach(presenter.listings) { listing in
return ForEach(presenter.listingViewModels) { listing in
discoverListRow(listing: listing)
.listRowSeparator(.hidden)
.listRowBackground(Color.clear)
Expand Down Expand Up @@ -79,7 +79,7 @@ struct NotificationsView: View {
}

private func notifications() -> some View {
ForEach(presenter.subscriptions, id: \.id) { subscription in
ForEach(presenter.subscriptionViewModels, id: \.id) { subscription in
subscriptionRow(subscription: subscription)
.listRowSeparator(.hidden)
.listRowBackground(Color.clear)
Expand Down Expand Up @@ -114,12 +114,12 @@ struct NotificationsView: View {

VStack(alignment: .leading, spacing: 2) {
Text(subscription.name)
.foregroundColor(.grey8)
.font(.system(size: 20, weight: .semibold, design: .rounded))
.foregroundColor(.Foreground100)
.font(.system(size: 15, weight: .medium, design: .rounded))

Text(subscription.subtitle)
.foregroundColor(.grey50)
.font(.system(size: 13, weight: .medium, design: .rounded))
.foregroundColor(.Foreground150)
.font(.system(size: 14, weight: .regular, design: .rounded))
}
}
}
Expand All @@ -146,7 +146,7 @@ struct NotificationsView: View {
Spacer()

if let subscription = presenter.subscription(forListing: listing) {
AsyncButton("Unsubscribed") {
AsyncButton("Subscribed") {
try await presenter.unsubscribe(subscription: subscription)
}
.buttonStyle(W3MButtonStyle(size: .m, variant: .accent, rightIcon: .Checkmark))
Expand Down

0 comments on commit efa3c9d

Please sign in to comment.