-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
226 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...Presenters/dydxPresenters/_v4/Profile/Components/dydxProfileTopButtonsViewPresenter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// dydxProfileTopButtonsViewPresenter.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 14/01/2025. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
import dydxStateManager | ||
import dydxFormatter | ||
import Combine | ||
|
||
protocol dydxProfileTopButtonsViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxProfileTopButtonsViewModel? { get } | ||
} | ||
|
||
class dydxProfileTopButtonsViewPresenter: HostedViewPresenter<dydxProfileTopButtonsViewModel>, dydxProfileTopButtonsViewPresenterProtocol { | ||
override init() { | ||
super.init() | ||
|
||
viewModel = dydxProfileTopButtonsViewModel() | ||
|
||
viewModel?.settingsAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/settings"), animated: true, completion: nil) | ||
} | ||
|
||
viewModel?.modeAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/settings/app_mode"), animated: true, completion: nil) | ||
} | ||
|
||
viewModel?.alertsAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/alerts"), animated: true, completion: nil) | ||
} | ||
} | ||
|
||
override func start() { | ||
super.start() | ||
|
||
Publishers | ||
.CombineLatest( | ||
AbacusStateManager.shared.state.onboarded, | ||
AbacusStateManager.shared.state.alerts) | ||
.sink { [weak self] onboarded, alerts in | ||
self?.viewModel?.hasNewAlerts = alerts.count > 0 && onboarded | ||
} | ||
.store(in: &self.subscriptions) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
dydx/dydxViews/dydxViews/_v4/Profile/Components/dydxProfileTopButtonsView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// | ||
// dydxProfileTopButtonsView.swift | ||
// dydxUI | ||
// | ||
// Created by Rui Huang on 14/01/2025. | ||
// Copyright © 2025 dYdX Trading Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import PlatformUI | ||
import Utilities | ||
|
||
public class dydxProfileTopButtonsViewModel: PlatformViewModel { | ||
@Published public var settingsAction: (() -> Void)? | ||
@Published public var alertsAction: (() -> Void)? | ||
@Published public var modeAction: (() -> Void)? | ||
@Published public var hasNewAlerts: Bool = false | ||
|
||
public lazy var toggleBinding = Binding<Bool> { | ||
return true | ||
} set: { _ in | ||
self.modeAction?() | ||
} | ||
|
||
public init() { } | ||
|
||
public static var previewValue: dydxProfileTopButtonsViewModel { | ||
let vm = dydxProfileTopButtonsViewModel() | ||
vm.hasNewAlerts = true | ||
return vm | ||
} | ||
|
||
public override func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformView { | ||
PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] style in | ||
guard let self = self else { return AnyView(PlatformView.nilView) } | ||
|
||
let view = HStack(spacing: 16) { | ||
HStack(spacing: 16) { | ||
self.createButton(style: style, | ||
imageName: "icon_settings", | ||
badge: false, | ||
action: self.settingsAction) | ||
.frame(maxWidth: .infinity) | ||
|
||
self.createButton(style: style, | ||
imageName: "icon_alerts", | ||
badge: self.hasNewAlerts, | ||
action: self.alertsAction) | ||
.frame(maxWidth: .infinity) | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
|
||
self.createModeButton(style: style) | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
} | ||
.frame(minHeight: 68) | ||
|
||
return AnyView(view) | ||
} | ||
} | ||
|
||
private func createModeButton(style: ThemeStyle) -> some View { | ||
HStack(alignment: .center) { | ||
VStack(alignment: .leading) { | ||
Text("dYdX " + DataLocalizer.localize(path: "APP.TRADE.MODE.PRO")) | ||
.themeFont(fontSize: .medium) | ||
.themeColor(foreground: .textSecondary) | ||
|
||
Text(DataLocalizer.localize(path: "APP.TRADE.MODE.FULLY_FEATURED")) | ||
.themeFont(fontSize: .small) | ||
.themeColor(foreground: .textTertiary) | ||
} | ||
Toggle("", isOn: toggleBinding) | ||
.tint(ThemeColor.SemanticColor.colorPurple.color) | ||
} | ||
.padding(.horizontal, 16) | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.themeColor(background: .layer3) | ||
.cornerRadius(12, corners: .allCorners) | ||
} | ||
|
||
private func createButton(style: ThemeStyle, imageName: String, badge: Bool, action: (() -> Void)?) -> some View { | ||
let content = ZStack { | ||
PlatformIconViewModel(type: .asset(name: imageName, bundle: Bundle.dydxView), | ||
clip: .noClip, | ||
size: CGSize(width: 24, height: 24), | ||
templateColor: .textTertiary) | ||
.createView(parentStyle: style) | ||
.padding(.horizontal, 16) | ||
|
||
if badge { | ||
Circle() | ||
.fill(ThemeColor.SemanticColor.colorPurple.color) | ||
.frame(width: 10, height: 10) | ||
.padding(12) | ||
.rightAligned() | ||
.topAligned() | ||
} | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.themeColor(background: .layer3) | ||
.cornerRadius(12, corners: .allCorners) | ||
|
||
return PlatformButtonViewModel(content: content.wrappedViewModel, | ||
type: .iconType) { | ||
action?() | ||
} | ||
.createView(parentStyle: style) | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct dydxProfileTopButtonsView_Previews_Dark: PreviewProvider { | ||
@StateObject static var themeSettings = ThemeSettings.shared | ||
|
||
static var previews: some View { | ||
ThemeSettings.applyDarkTheme() | ||
ThemeSettings.applyStyles() | ||
return dydxProfileTopButtonsViewModel.previewValue | ||
.createView() | ||
.themeColor(background: .layer0) | ||
.environmentObject(themeSettings) | ||
// .edgesIgnoringSafeArea(.bottom) | ||
.previewLayout(.sizeThatFits) | ||
} | ||
} | ||
|
||
struct dydxProfileTopButtonsView_Previews_Light: PreviewProvider { | ||
@StateObject static var themeSettings = ThemeSettings.shared | ||
|
||
static var previews: some View { | ||
ThemeSettings.applyLightTheme() | ||
ThemeSettings.applyStyles() | ||
return dydxProfileTopButtonsViewModel.previewValue | ||
.createView() | ||
.themeColor(background: .layer0) | ||
.environmentObject(themeSettings) | ||
// .edgesIgnoringSafeArea(.bottom) | ||
.previewLayout(.sizeThatFits) | ||
} | ||
} | ||
#endif |
Oops, something went wrong.