Skip to content

Commit

Permalink
Separate search view
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Jan 15, 2025
1 parent dd1871b commit 6306f6f
Show file tree
Hide file tree
Showing 17 changed files with 446 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private class DismissAction: NSObject, NavigableProtocol {
viewController?.navigationController?.viewControllers.count ?? 0 > 1 {
viewController?.navigationController?.popViewController(animated: animated)
} else if viewController?.presentingViewController !== nil {
viewController?.dismiss(animated: true, completion: {
viewController?.dismiss(animated: animated, completion: {
completion?(nil, true)
})
} else if viewController?.floatingParent !== nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ open class MappedUIKitRouter: MappedRouter {
if completed {
completion?(object, true)
} else {
self?.route(xib: map, request: request, completion: completion)
self?.route(xib: map, request: request, animated: animated, completion: completion)
}
}
}
Expand Down Expand Up @@ -458,12 +458,12 @@ open class MappedUIKitRouter: MappedRouter {
}
}

private func route(xib map: RoutingMap, request: RoutingRequest, completion: RoutingCompletionBlock?) {
private func route(xib map: RoutingMap, request: RoutingRequest, animated: Bool, completion: RoutingCompletionBlock?) {
loadAction(from: map) { [weak self] action in
if let action = action {
self?.actions.append(action)
weak var actionReference = action
action.navigate(to: request, animated: true) { data, success in
action.navigate(to: request, animated: animated) { data, success in
self?.actions.removeAll(where: { (actionInList) -> Bool in
actionReference === actionInList
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,22 @@ public extension View {
}
}

public func dragIndicator(topPadding: CGFloat = 18) -> some View {
Rectangle()
.themeColor(background: .layer1)
.frame(width: 36, height: 4)
.clipShape(Capsule())
.padding(.top, topPadding)
}

private struct SheetViewModifier: ViewModifier {
let topPadding: CGFloat = 18
let sheetStyle: MakeSheetStyle

@EnvironmentObject var themeSettings: ThemeSettings

func body(content: Content) -> some View {
let dragIndicator = Rectangle()
.themeColor(background: .layer1)
.frame(width: 36, height: 4)
.clipShape(Capsule())
.padding(.top, topPadding)
let dragIndicator = dragIndicator(topPadding: topPadding)

switch sheetStyle {
case .fullScreen:
Expand Down
16 changes: 12 additions & 4 deletions dydx/dydxPresenters/dydxPresenters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
02048AFC2D35837F00394CBE /* dydxSwitchAppModeActionBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02048AEE2D35837000394CBE /* dydxSwitchAppModeActionBuilder.swift */; };
02048B122D35E3DF00394CBE /* dydxSimpleUIPositionListViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02048B112D35E3DE00394CBE /* dydxSimpleUIPositionListViewPresenter.swift */; };
02048BBD2D372AAE00394CBE /* dydxProfileTopButtonsViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02048BBC2D372AAD00394CBE /* dydxProfileTopButtonsViewPresenter.swift */; };
02048BC32D382B9500394CBE /* dydxSimpleUIMarketSearchViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02048BC22D382B9300394CBE /* dydxSimpleUIMarketSearchViewBuilder.swift */; };
0207FC9D2D269C00004C2C9F /* dydxSimpleUITradeInputValidationViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0207FC8F2D269BFF004C2C9F /* dydxSimpleUITradeInputValidationViewPresenter.swift */; };
0207FC9F2D27BA6B004C2C9F /* dydxSimpleUITradeInputCtaButtonViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0207FC9E2D27BA62004C2C9F /* dydxSimpleUITradeInputCtaButtonViewPresenter.swift */; };
0207FCA32D2A181D004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0207FCA22D2A181C004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift */; };
Expand Down Expand Up @@ -95,7 +96,6 @@
0280B3A629CB63E10017D64A /* dydxOnboardWelcomeViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0280B3A529CB63E10017D64A /* dydxOnboardWelcomeViewBuilder.swift */; };
0284202F29AD727200C0E7CC /* dydxViews.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0284201F29AD725000C0E7CC /* dydxViews.framework */; };
02860A9F29C15E760079E644 /* dydxOnboardScanViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02860A9329C15E760079E644 /* dydxOnboardScanViewBuilder.swift */; };
028CF14F2D1489E900476930 /* dydxSimpleUIMarketSearchViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028CF1412D1489E800476930 /* dydxSimpleUIMarketSearchViewPresenter.swift */; };
028DB3402A05893D0090BE58 /* dydxProfileHeaderViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028DB33F2A05893D0090BE58 /* dydxProfileHeaderViewPresenter.swift */; };
028FB3EC2AD642B30013136C /* dydxTokenConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028FB3EB2AD642B30013136C /* dydxTokenConstants.swift */; };
0295392329FB256E009026E3 /* dydxThemeViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0295392229FB256E009026E3 /* dydxThemeViewBuilder.swift */; };
Expand Down Expand Up @@ -427,6 +427,7 @@
02048AEE2D35837000394CBE /* dydxSwitchAppModeActionBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSwitchAppModeActionBuilder.swift; sourceTree = "<group>"; };
02048B112D35E3DE00394CBE /* dydxSimpleUIPositionListViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUIPositionListViewPresenter.swift; sourceTree = "<group>"; };
02048BBC2D372AAD00394CBE /* dydxProfileTopButtonsViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxProfileTopButtonsViewPresenter.swift; sourceTree = "<group>"; };
02048BC22D382B9300394CBE /* dydxSimpleUIMarketSearchViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUIMarketSearchViewBuilder.swift; sourceTree = "<group>"; };
0207FC8F2D269BFF004C2C9F /* dydxSimpleUITradeInputValidationViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUITradeInputValidationViewPresenter.swift; sourceTree = "<group>"; };
0207FC9E2D27BA62004C2C9F /* dydxSimpleUITradeInputCtaButtonViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUITradeInputCtaButtonViewPresenter.swift; sourceTree = "<group>"; };
0207FCA22D2A181C004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUIMarketsHeaderViewPresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -511,7 +512,6 @@
0280B3A529CB63E10017D64A /* dydxOnboardWelcomeViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxOnboardWelcomeViewBuilder.swift; sourceTree = "<group>"; };
0284201929AD725000C0E7CC /* dydxViews.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = dydxViews.xcodeproj; path = ../dydxViews/dydxViews.xcodeproj; sourceTree = "<group>"; };
02860A9329C15E760079E644 /* dydxOnboardScanViewBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxOnboardScanViewBuilder.swift; sourceTree = "<group>"; };
028CF1412D1489E800476930 /* dydxSimpleUIMarketSearchViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSimpleUIMarketSearchViewPresenter.swift; sourceTree = "<group>"; };
028DB33F2A05893D0090BE58 /* dydxProfileHeaderViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxProfileHeaderViewPresenter.swift; sourceTree = "<group>"; };
028FB3EB2AD642B30013136C /* dydxTokenConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTokenConstants.swift; sourceTree = "<group>"; };
0295392229FB256E009026E3 /* dydxThemeViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxThemeViewBuilder.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -686,6 +686,14 @@
path = Orderbook;
sourceTree = "<group>";
};
02048BC12D382B8A00394CBE /* Search */ = {
isa = PBXGroup;
children = (
02048BC22D382B9300394CBE /* dydxSimpleUIMarketSearchViewBuilder.swift */,
);
path = Search;
sourceTree = "<group>";
};
02084B1B297FC2B400CF9522 /* Components */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1357,6 +1365,7 @@
02D6DAEA2D1234A3008AAEA1 /* SimpleUI */ = {
isa = PBXGroup;
children = (
02048BC12D382B8A00394CBE /* Search */,
027886012D1F4BC300366321 /* Trade */,
027885E22D1DD62600366321 /* MarketInfo */,
02D6DAF82D1234A8008AAEA1 /* Markets */,
Expand Down Expand Up @@ -1386,7 +1395,6 @@
children = (
0207FCA22D2A181C004C2C9F /* dydxSimpleUIMarketsHeaderViewPresenter.swift */,
027885DA2D1A34EA00366321 /* dydxSimpleUIPortfolioViewPresenter.swift */,
028CF1412D1489E800476930 /* dydxSimpleUIMarketSearchViewPresenter.swift */,
02D6DBB82D134BE8008AAEA1 /* dydxSimpleUIMarketListViewPresenter.swift */,
02048B112D35E3DE00394CBE /* dydxSimpleUIPositionListViewPresenter.swift */,
);
Expand Down Expand Up @@ -2199,7 +2207,6 @@
0238FC4C296DA55A002E1C1A /* dydxOrderDetailsViewBuilder.swift in Sources */,
02F95A7E2A1D314400828F9A /* dydxPortfolioSelectorViewPresenter.swift in Sources */,
020EB697299D36AD00E8026B /* dydxApiStatusWorker.swift in Sources */,
028CF14F2D1489E900476930 /* dydxSimpleUIMarketSearchViewPresenter.swift in Sources */,
02A5C85E297FBCD700FFE1F9 /* dydxTransferViewBuilder.swift in Sources */,
023848C22A9E637C00B1A673 /* SettingsLandingViewPresenter.swift in Sources */,
0258BA23299294BF0098E1BE /* dydxProfileViewBuilder.swift in Sources */,
Expand All @@ -2213,6 +2220,7 @@
026FC3E42AFACA3300C52F20 /* dydxPresentersBundleClass.swift in Sources */,
02F95A8E2A1D6AAD00828F9A /* dydxProfileHistoryViewPresenter.swift in Sources */,
02E90C5A29D62719004E2311 /* dydxFeatureFlagsViewBuilder.swift in Sources */,
02048BC32D382B9500394CBE /* dydxSimpleUIMarketSearchViewBuilder.swift in Sources */,
6453AB26299D98110041A0C4 /* dydxClosePositionInputEditPresenter.swift in Sources */,
0243A76129BE572C00A083FE /* dydxCancelOrderActionBuilder.swift in Sources */,
0279DE482BEBE76900F9ECF8 /* dydxTargetLeverageCtaButtonViewPresenter.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
},
"/markets/search":{
"destination":"dydxPresenters.dydxMarketsSearchViewBuilder",
"presentation":"half"
"presentation":"prompt"
},
"/market/:market":{
"destination":"dydxPresenters.dydxMarketInfoViewBuilder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ private var cachedPresenter: dydxMarketsSearchViewPresenter?

public class dydxMarketsSearchViewBuilder: NSObject, ObjectBuilderProtocol {
public func build<T>() -> T? {
let presenter = cachedPresenter ?? dydxMarketsSearchViewPresenter()
cachedPresenter = presenter
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView()
let configuration = HostingViewControllerConfiguration(fixedHeight: UIScreen.main.bounds.height)
return dydxMarketsSearchViewController(presenter: presenter, view: view, configuration: configuration) as? T
if dydxBoolFeatureFlag.simple_ui.isEnabled, AppMode.current == .simple {
let viewController: dydxSimpleUIMarketSearchViewController? = dydxSimpleUIMarketSearchViewBuilder().build()
return viewController as? T
} else {
let presenter = cachedPresenter ?? dydxMarketsSearchViewPresenter()
cachedPresenter = presenter
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView()
let configuration = HostingViewControllerConfiguration(fixedHeight: UIScreen.main.bounds.height)
return dydxMarketsSearchViewController(presenter: presenter, view: view, configuration: configuration) as? T
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ private class dydxSimpleUIMarketInfoViewPresenter: HostedViewPresenter<dydxSimpl
attachChildren(workers: childPresenters)
}

override func start() {
super.start()

floatTradeInput()
}

private func floatTradeInput() {
if shouldDisplayFullTradeInputOnAppear {
Router.shared?.navigate(to: RoutingRequest(path: "/trade/input", params: ["full": "true", "market": marketId ?? ""]), animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ protocol dydxSimpleUIMarketListViewPresenterProtocol: HostedViewPresenterProtoco

class dydxSimpleUIMarketListViewPresenter: HostedViewPresenter<dydxSimpleUIMarketListViewModel>, dydxSimpleUIMarketListViewPresenterProtocol {

private let excludePositions: Bool

@Published var searchText: String = ""

override init() {
var onMarketSelected: ((String) -> Void)?

init(excludePositions: Bool = true) {
self.excludePositions = excludePositions
super.init()

viewModel = dydxSimpleUIMarketListViewModel()
Expand Down Expand Up @@ -65,10 +70,12 @@ class dydxSimpleUIMarketListViewPresenter: HostedViewPresenter<dydxSimpleUIMarke
let position = positions.first { position in
position.id == market.id
}
if position != nil {
if excludePositions && position != nil {
return nil
}
return dydxSimpleUIMarketViewModel.createFrom(market: market, asset: asset, position: position)
return dydxSimpleUIMarketViewModel.createFrom(displayType: .market, market: market, asset: asset, position: position) { [weak self] in
self?.onMarketSelected?(market.id)
}
}
.sorted { lhs, rhs in
let lhsLeverage = lhs.leverage ?? 0
Expand All @@ -86,7 +93,11 @@ class dydxSimpleUIMarketListViewPresenter: HostedViewPresenter<dydxSimpleUIMarke
}

extension dydxSimpleUIMarketViewModel {
static func createFrom(market: PerpetualMarket, asset: Asset?, position: SubaccountPosition?) -> dydxSimpleUIMarketViewModel {
static func createFrom(displayType: dydxSimpleUIMarketViewModel.DisplayType,
market: PerpetualMarket,
asset: Asset?,
position: SubaccountPosition?,
onMarketsSelected: (() -> Void)?) -> dydxSimpleUIMarketViewModel {
let price = dydxFormatter.shared.dollar(number: market.oraclePrice?.doubleValue, digits: market.configs?.displayTickSizeDecimals?.intValue ?? 2)
let change = SignedAmountViewModel(amount: market.priceChange24HPercent?.doubleValue,
displayType: .percent,
Expand All @@ -102,7 +113,8 @@ extension dydxSimpleUIMarketViewModel {

let positionSize = dydxFormatter.shared.localFormatted(number: position?.size.current?.doubleValue, digits: market.configs?.displayStepSizeDecimals?.intValue ?? 1)

return dydxSimpleUIMarketViewModel(marketId: market.id,
return dydxSimpleUIMarketViewModel(displayType: displayType,
marketId: market.id,
assetName: asset?.displayableAssetId ?? market.assetId,
iconUrl: asset?.resources?.imageUrl,
price: price,
Expand All @@ -112,8 +124,6 @@ extension dydxSimpleUIMarketViewModel {
volumn: market.perpetual?.volume24H?.doubleValue,
positionTotal: position?.valueTotal.current?.doubleValue,
positionSize: positionSize,
onMarketSelected: {
Router.shared?.navigate(to: RoutingRequest(path: "/market", params: ["market": market.id]), animated: true, completion: nil)
})
onMarketSelected: onMarketsSelected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class dydxSimpleUIPositionListViewPresenter: HostedViewPresenter<dydxSimpleUIPos
if position == nil {
return nil
}
return dydxSimpleUIMarketViewModel.createFrom(market: market, asset: asset, position: position)
return dydxSimpleUIMarketViewModel.createFrom(displayType: .position, market: market, asset: asset, position: position) {
Router.shared?.navigate(to: RoutingRequest(path: "/market", params: ["market": market.id]), animated: true, completion: nil)
}
}
.sorted { lhs, rhs in
return (lhs.positionTotal ?? 0) > (rhs.positionTotal ?? 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ public protocol dydxSimpleUIMarketsViewPresenterProtocol: HostedViewPresenterPro

public class dydxSimpleUIMarketsViewPresenter: HostedViewPresenter<dydxSimpleUIMarketsViewModel>, dydxSimpleUIMarketsViewPresenterProtocol {

private let marketListPresenter = dydxSimpleUIMarketListViewPresenter()
private let marketListPresenter = dydxSimpleUIMarketListViewPresenter(excludePositions: true)
private let positionListPresenter = dydxSimpleUIPositionListViewPresenter()
private let marketSearchPresenter = dydxSimpleUIMarketSearchViewPresenter()
private let portfolioPresenter = dydxSimpleUIPortfolioViewPresenter()
private let headerPresenter = dydxSimpleUIMarketsHeaderViewPresenter()

private lazy var childPresenters: [HostedViewPresenterProtocol] = [
marketListPresenter,
positionListPresenter,
marketSearchPresenter,
portfolioPresenter,
headerPresenter
]
Expand All @@ -56,16 +54,23 @@ public class dydxSimpleUIMarketsViewPresenter: HostedViewPresenter<dydxSimpleUIM

marketListPresenter.$viewModel.assign(to: &viewModel.$marketList)
positionListPresenter.$viewModel.assign(to: &viewModel.$positionList)
marketSearchPresenter.$viewModel.assign(to: &viewModel.$marketSearch)
portfolioPresenter.$viewModel.assign(to: &viewModel.$portfolio)
marketSearchPresenter.viewModel?.$searchText.assign(to: &marketListPresenter.$searchText)
marketSearchPresenter.viewModel?.$focused.assign(to: &viewModel.$keyboardUp)
headerPresenter.$viewModel.assign(to: &viewModel.$header)

super.init()

self.viewModel = viewModel

viewModel.searchAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/markets/search"),
animated: true,
completion: nil)
}

marketListPresenter.onMarketSelected = { marketId in
Router.shared?.navigate(to: RoutingRequest(path: "/market", params: ["market": marketId]), animated: true, completion: nil)
}

attachChildren(workers: childPresenters)
}

Expand Down
Loading

0 comments on commit 6306f6f

Please sign in to comment.