diff --git a/PlatformRouting/PlatformRouting/Resources/_UIKit/routing_shared.json b/PlatformRouting/PlatformRouting/Resources/_UIKit/routing_shared.json index 5474cba66..3884785fa 100644 --- a/PlatformRouting/PlatformRouting/Resources/_UIKit/routing_shared.json +++ b/PlatformRouting/PlatformRouting/Resources/_UIKit/routing_shared.json @@ -32,7 +32,7 @@ "destination":"Refresh.xib" }, "/action/share":{ - "destination":"Share.xib" + "destination":"PlatformRouting.ShareActionBuilder" }, "/action/wallet":{ "destination":"Wallet.xib" diff --git a/PlatformRouting/PlatformRouting/_Actions/ShareAction.swift b/PlatformRouting/PlatformRouting/_Actions/ShareAction.swift index bd8631d1d..86d4465d1 100644 --- a/PlatformRouting/PlatformRouting/_Actions/ShareAction.swift +++ b/PlatformRouting/PlatformRouting/_Actions/ShareAction.swift @@ -7,8 +7,16 @@ // import RoutingKit +import Utilities import UIToolkits +public class ShareActionBuilder: NSObject, ObjectBuilderProtocol { + public func build() -> T? { + let action = ShareAction() + return action as? T + } +} + open class ShareAction: NSObject, NavigableProtocol { private var completion: RoutingCompletionBlock? open func navigate(to request: RoutingRequest?, animated: Bool, completion: RoutingCompletionBlock?) { @@ -25,6 +33,14 @@ open class ShareAction: NSObject, NavigableProtocol { activityVC.popoverPresentationController?.sourceView = UserInteraction.shared.sender as? UIView activityVC.popoverPresentationController?.barButtonItem = UserInteraction.shared.sender as? UIBarButtonItem UIViewController.topmost()?.present(activityVC, animated: true, completion: nil) + + let data: [String: String]? + if let shareSource = request?.params?["share_source"] as? String { + data = ["share_source": shareSource] + } else { + data = nil + } + Tracking.shared?.log(event: "ShareDialogDisplayed", data: data) completion?(nil, true) } else { completion?(nil, false) diff --git a/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json b/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json index e2fc9185a..a220fe73e 100644 --- a/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json +++ b/dydx/dydxPresenters/dydxPresenters/_Features/routing_swiftui.json @@ -64,7 +64,7 @@ "destination":"dydxPresenters.dydxCancelOrderActionBuilder" }, "/action/share": { - "destination":"ShareAction.xib" + "destination":"PlatformRouting.ShareActionBuilder" }, "/action/wallet/connect": { "destination":"dydxPresenters.WalletActionBuilder" diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/dydxProfileViewBuilder.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/dydxProfileViewBuilder.swift index 5f4825fba..e490f889e 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/dydxProfileViewBuilder.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/dydxProfileViewBuilder.swift @@ -11,6 +11,7 @@ import PlatformParticles import RoutingKit import ParticlesKit import PlatformUI +import dydxStateManager public class dydxProfileViewBuilder: NSObject, ObjectBuilderProtocol { public func build() -> T? { @@ -72,5 +73,13 @@ private class dydxProfileViewPresenter: HostedViewPresenter Void)? + + private let shareCta: AttributedString = { + let localizedString = DataLocalizer.shared?.localize(path: "APP.GENERAL.SHARE_DYDX", params: nil) ?? "" + let unhighlightedString = DataLocalizer.shared?.localize(path: "APP.GENERAL.SHARE", params: nil) ?? "" + + var attributedString = AttributedString(localizedString) + .themeFont(fontType: .text, fontSize: .medium) + + attributedString = attributedString.themeColor(foreground: .textSecondary) + if let unhighlightedStringRange = attributedString.range(of: unhighlightedString) { + attributedString = attributedString.themeColor(foreground: .textTertiary, to: unhighlightedStringRange) + } + + return attributedString + }() + + public static var previewValue: dydxInlineShareViewModel = { + let vm = dydxInlineShareViewModel() + 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) } + + return AnyView( + HStack(alignment: .center, spacing: 6) { + Text(self.shareCta) + PlatformIconViewModel(type: .asset(name: "icon_share", bundle: .dydxView), + clip: .noClip, + size: CGSize(width: 20, height: 20), + templateColor: .textSecondary) + .createView(parentStyle: style) + } + .onTapGesture { [weak self] in + self?.shareAction?() + } + ) + } + } +} + +#Preview { + Group { + dydxInlineShareViewModel.previewValue + .createView() + .environmentObject(ThemeSettings.shared) + .previewLayout(.sizeThatFits) + } +} diff --git a/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift b/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift index e5307cbb3..f27f8b1f8 100644 --- a/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift +++ b/dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift @@ -19,6 +19,7 @@ public class dydxProfileViewModel: PlatformViewModel { @Published public var fees: dydxProfileFeesViewModel? = dydxProfileFeesViewModel() @Published public var balances: dydxProfileBalancesViewModel? = dydxProfileBalancesViewModel() @Published public var rewards: dydxProfileRewardsViewModel? = dydxProfileRewardsViewModel() + @Published public var share: dydxInlineShareViewModel? = dydxInlineShareViewModel() public init() { } @@ -58,7 +59,10 @@ public class dydxProfileViewModel: PlatformViewModel { self.history? .createView(parentStyle: style) - Spacer(minLength: 100) + self.share? + .createView(parentStyle: style) + + Spacer(minLength: 136) } } .padding(.horizontal)