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

[TRCL-3160] Load app scheme from env.json and add scripts to update the info.plist #10

Merged
merged 4 commits into from
Nov 8, 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
112 changes: 57 additions & 55 deletions PlatformUIJedio/PlatformUIJedio/Presenters/SettingsViewPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Rui Huang on 3/21/23.
//


import Utilities
import dydxViews
import PlatformParticles
Expand All @@ -16,26 +15,28 @@ import JedioKit

open class SettingsViewPresenter: BaseSettingsViewPresenter {
private let keyValueStore: KeyValueStoreProtocol?

public init(definitionFile: String, keyValueStore: KeyValueStoreProtocol?) {
private let appScheme: String?

public init(definitionFile: String, keyValueStore: KeyValueStoreProtocol?, appScheme: String?) {
self.keyValueStore = keyValueStore
self.appScheme = appScheme
super.init(definitionFile: definitionFile)
}

override open func start() {
super.start()

loadSettings()
}

private func loadSettings() {
var sections = [SettingsViewModel.SectionViewModel]()
for fieldList in fieldLists ?? [] {
sections.append(createSection(group: fieldList))
}
viewModel?.sections = sections
}

private func createSection(group: FieldListInteractor) -> SettingsViewModel.SectionViewModel {
let listViewModel = PlatformListViewModel(firstListItemTopSeparator: true, lastListItemBottomSeparator: true)
listViewModel.width = UIScreen.main.bounds.width - 16
Expand All @@ -50,12 +51,12 @@ open class SettingsViewPresenter: BaseSettingsViewPresenter {
}
return SettingsViewModel.SectionViewModel(title: group.title, items: listViewModel)
}

private func createInput(input: FieldInput) -> PlatformViewModel? {
guard let fieldInputDefinition = input.fieldInput else {
return nil
}

if let fieldName = input.fieldName,
let value = keyValueStore?.value(forKey: fieldName) {
input.value = value
Expand All @@ -82,61 +83,61 @@ open class SettingsViewPresenter: BaseSettingsViewPresenter {
} else {
return FieldInputTextsInputViewModel(input: input, valueChanged: valueChanged)
}
// case .int:
// if hasOptions {
// return "field_input_grid_int"
// } else if fieldInput.min != nil && fieldInput.max != nil {
// return "field_input_slider_int"
// } else {
// return "field_input_textfield_int"
// }
//
// case .float:
// if fieldInput.min != nil && fieldInput.max != nil {
// return "field_input_slider_float"
// } else {
// return "field_input_textfield_float"
// }
//
// case .percent:
// return "field_input_slider_percent"
//
// case .strings:
// return "field_input_grid_strings"

// case .int:
// if hasOptions {
// return "field_input_grid_int"
// } else if fieldInput.min != nil && fieldInput.max != nil {
// return "field_input_slider_int"
// } else {
// return "field_input_textfield_int"
// }
//
// case .float:
// if fieldInput.min != nil && fieldInput.max != nil {
// return "field_input_slider_float"
// } else {
// return "field_input_textfield_float"
// }
//
// case .percent:
// return "field_input_slider_percent"
//
// case .strings:
// return "field_input_grid_strings"

case .bool:
return FieldInputSwitchViewModel(input: input, valueChanged: valueChanged)

// case .image:
// #if _iOS
// return "field_button_image"
// #else
// return "field_blank"
// #endif
//
// case .images:
// #if _iOS
// return "field_input_grid_images"
// #else
// return "field_blank"
// #endif
//
// case .signature:
// #if _iOS
// return "field_input_button_signature"
// #else
// return "field_blank"
// #endif
// case .image:
// #if _iOS
// return "field_button_image"
// #else
// return "field_blank"
// #endif
//
// case .images:
// #if _iOS
// return "field_input_grid_images"
// #else
// return "field_blank"
// #endif
//
// case .signature:
// #if _iOS
// return "field_input_button_signature"
// #else
// return "field_blank"
// #endif

default:
//assertionFailure("Not implemented")
// assertionFailure("Not implemented")
break
}
}
return nil
}

private func createOutput(output: FieldOutput) -> PlatformViewModel? {
if let xib = output.field?.xib {
// TODO: ...
Expand All @@ -148,7 +149,8 @@ open class SettingsViewPresenter: BaseSettingsViewPresenter {

open func createOutputItem(output: FieldOutput) -> FieldOutputTextViewModel {
let textViewModel = FieldOutputTextViewModel(output: output)
if let routingRequest = output.routingRequest() {
if let appScheme = appScheme, let link = output.link?.replacingOccurrences(of: "{APP_SCHEME}", with: appScheme) {
let routingRequest = RoutingRequest(url: link)
textViewModel.onTapAction = {
Router.shared?.navigate(to: routingRequest, animated: true, completion: nil)
}
Expand Down
17 changes: 13 additions & 4 deletions RoutingKit/RoutingKit/_Router/MappedRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum RoutingPresentation: Int {
case drawer
}

fileprivate struct PathTuple {
private struct PathTuple {
let path: String
let params: [String]?
}
Expand Down Expand Up @@ -123,7 +123,7 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser
public var defaults: [String: String]?
public var aliases: [String: String]?
public var maps: [String: [String: [String: RoutingMap]]]? // ["http":["www.domain.com": ["/": "Home]]]
// public var shared: [String: RoutingMap]
// public var shared: [String: RoutingMap]
public init(file: String) {
super.init()
let shared = JsonLoader.load(bundles: Bundle.particles, fileName: "routing_shared.json") as? [String: Any]
Expand All @@ -132,6 +132,15 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser
}
}

public init(jsonString: String) {
super.init()
let shared = JsonLoader.load(bundles: Bundle.particles, fileName: "routing_shared.json") as? [String: Any]
if let data = jsonString.data(using: .utf8),
let destinations = JsonLoader.load(data: data) as? [String: Any] {
parse(dictionary: destinations, shared: shared)
}
}

public func parse(dictionary: [String: Any], shared: [String: Any]?) {
if let defaultData = dictionary["defaults"] as? [String: String] {
if defaults == nil {
Expand Down Expand Up @@ -176,7 +185,7 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser
let pathTuple = parsePath(path: key)
let routing = map(destination: destination, params: pathTuple.params)
routing.parse(dictionary: dictionary)
assert(!maps.keys.contains { $0 == pathTuple.path },
assert(!maps.keys.contains { $0 == pathTuple.path },
"collision on paths \(maps.keys.filter {$0 == pathTuple.path}), remove the duplicate route in routing_swiftui.json")
maps[pathTuple.path] = routing
}
Expand Down Expand Up @@ -231,7 +240,7 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser
}

open func didSetAppState(oldValue: AppState?) {
changeObservation(from: oldValue, to: appState, keyPath: #keyPath(AppState.background)) {[weak self] observer, obj, change, animated in
changeObservation(from: oldValue, to: appState, keyPath: #keyPath(AppState.background)) {[weak self] _, _, _, _ in
self?.sendPending()
}
}
Expand Down
2 changes: 2 additions & 0 deletions Utilities/Utilities.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,8 @@
Base,
);
mainGroup = 31E65AAF216BC9C9008ABEE9;
packageReferences = (
);
productRefGroup = 31E65ABA216BC9C9008ABEE9 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down
4 changes: 4 additions & 0 deletions Utilities/Utilities/_Utils/JsonLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ import Foundation
@objc public class func load(bundled fileName: String?) -> Any? {
return load(bundle: Bundle.main, fileName: fileName)
}

@objc public class func load(data: Data) -> Any? {
return try? JSONSerialization.jsonObject(with: data, options: [])
}
}
2 changes: 1 addition & 1 deletion dydx/PodFile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ end

def util_pods
pod 'BigInt'
pod 'CryptoSwift'
pod 'CryptoSwift', '1.5.1'
pod 'libPhoneNumber-iOS'
pod 'KVOController'
pod 'SimpleKeychain', '~> 0.12.5'
Expand Down
Loading
Loading