Skip to content

Commit

Permalink
[16][6][13] Refactoring / Switchcraft integration / Support for Alerts (
Browse files Browse the repository at this point in the history
#15)

* - DebugMenuView now in NavigationView to support alerts
- Refactor PasswordEntryAlertWrapper to be used as TextFieldAlertWrapper
- General refactors
- Clean up project
- Support for Alert actions
- DebugMenuView can now surface an alert as a response
- Min version set to iOS 14
- DebugMenuAccessConfig

* - Organized files to separate folders

* - Clean up
- Switchcraft integration to example project
  • Loading branch information
AZielinsky95 authored Mar 15, 2022
1 parent afcec9b commit 553b829
Show file tree
Hide file tree
Showing 30 changed files with 537 additions and 211 deletions.
12 changes: 12 additions & 0 deletions DebugMenu/DebugMenu/Actions/DebugAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// DebugAction.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import SwiftUI

public protocol DebugAction {
var asAnyView: AnyView { get }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// DebugButtonRow.swift
// DebugButtonAction.swift
//
//
// Created by Alejandro Zielinsky on 2021-11-30.
// Created by Alejandro Zielinsky on 2022-03-10.
//

import SwiftUI
Expand All @@ -20,12 +20,3 @@ public struct DebugButtonAction: DebugAction {
self.action = action
}
}

struct DebugButtonRow: View {
let action: DebugButtonAction

var body: some View {
Button(action.title, action: action.action)
.foregroundColor(.blue)
}
}
22 changes: 22 additions & 0 deletions DebugMenu/DebugMenu/Actions/DebugHostControllerAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// DebugHostControllerAction.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import SwiftUI

public struct DebugHostControllerAction: DebugAction {
let title: String
let action: (UIHostingController<AnyView>) -> Void

public var asAnyView: AnyView {
AnyView(DebugHostControllerRow(action: self))
}

public init(title: String, action: @escaping (UIHostingController<AnyView>) -> Void) {
self.title = title
self.action = action
}
}
22 changes: 22 additions & 0 deletions DebugMenu/DebugMenu/Actions/DebugSubmenuAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// DebugSubmenuAction.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import SwiftUI

public struct DebugSubmenuAction: DebugAction {
let title: String
let dataSource: BaseDebugDataSource

public var asAnyView: AnyView {
AnyView(DebugSubmenuButtonRow(action: self))
}

public init(title: String, dataSource: BaseDebugDataSource) {
self.title = title
self.dataSource = dataSource
}
}
22 changes: 22 additions & 0 deletions DebugMenu/DebugMenu/Actions/DebugTextFieldAlertAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// DebugTextFieldAlertAction.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import SwiftUI

public struct DebugTextFieldAlertAction: DebugAction {
let title: String
let alert: DebugTextFieldAlert

public var asAnyView: AnyView {
AnyView(DebugTextFieldAlertRow(action: self))
}

public init(title: String, alert: DebugTextFieldAlert) {
self.title = title
self.alert = alert
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
//
// DebugToggleRow.swift
// DebugToggleAction.swift
//
//
// Created by Alejandro Zielinsky on 2021-11-30.
// Created by Alejandro Zielinsky on 2022-03-10.
//

import SwiftUI
import Combine

public protocol DebugAction {
var asAnyView: AnyView { get }
}

public struct DebugToggleAction: DebugAction, DebugResettable {

let displayTitle: String
Expand All @@ -32,11 +28,3 @@ public struct DebugToggleAction: DebugAction, DebugResettable {
toggle.wrappedValue = defaultValue
}
}

struct DebugToggleRow: View {
let action: DebugToggleAction

var body: some View {
Toggle(action.displayTitle, isOn: action.toggle)
}
}
2 changes: 2 additions & 0 deletions DebugMenu/DebugMenu/BaseDebugDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ open class BaseDebugDataSource: DebugMenuDataSource {
open var includeCommonOptions: Bool {
false
}

@Published public var debugAlert: DebugAlert?
}
1 change: 1 addition & 0 deletions DebugMenu/DebugMenu/DebugMenuDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public protocol DebugMenuDataSource: ObservableObject {
func addActions(_ actions: [DebugAction])
func resetToDefaults()
var includeCommonOptions: Bool { get }
var debugAlert: DebugAlert? { get set }
}

extension DebugMenuDataSource {
Expand Down
54 changes: 0 additions & 54 deletions DebugMenu/DebugMenu/DebugMenuView.swift

This file was deleted.

13 changes: 13 additions & 0 deletions DebugMenu/DebugMenu/DebugResettable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DebugResettable.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import Foundation

public protocol DebugResettable {
var defaultValue: Bool { get }
func resetToDefault()
}
31 changes: 31 additions & 0 deletions DebugMenu/DebugMenu/Models/DebugAlert.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// DebugAlert.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import Foundation

public struct DebugAlert: Identifiable {
public let id = UUID()
public let title: String
public let message: String?
public let primaryButtonTitle: String
public let secondaryButtonTitle: String
public let action: (() -> Void)?

public init(
title: String,
message: String? = nil,
primaryButtonTitle: String = "OK",
secondaryButtonTitle: String = "Cancel",
action: (() -> Void)? = nil
) {
self.title = title
self.message = message
self.primaryButtonTitle = primaryButtonTitle
self.secondaryButtonTitle = secondaryButtonTitle
self.action = action
}
}
18 changes: 18 additions & 0 deletions DebugMenu/DebugMenu/Models/DebugMenuAccessConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// DebugMenuAccessConfig.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import Foundation

public struct DebugMenuAccessConfig {
public var passwordSHA256: String
public var longPressDuration: Double

public init(passwordSHA256: String, longPressDuration: Double) {
self.passwordSHA256 = passwordSHA256
self.longPressDuration = longPressDuration
}
}
42 changes: 42 additions & 0 deletions DebugMenu/DebugMenu/Models/DebugTextFieldAlert.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// DebugTextFieldAlert.swift
//
//
// Created by Alejandro Zielinsky on 2022-03-10.
//

import Foundation
import UIKit

public struct DebugTextFieldAlert {

var title: String
var message: String?
var placeholder: String?
var accept: String
var cancel: String?
var secondaryActionTitle: String?
var keyboardType: UIKeyboardType
var action: (String?) -> Void
var secondaryAction: (() -> Void)?

public init(title: String,
message: String? = nil,
placeholder: String? = nil,
accept: String = "OK",
cancel: String? = "Cancel",
secondaryActionTitle: String? = nil,
keyboardType: UIKeyboardType = .default,
action: @escaping (String?) -> Void,
secondaryAction: (() -> Void)? = nil) {
self.title = title
self.message = message
self.placeholder = placeholder
self.accept = accept
self.cancel = cancel
self.secondaryActionTitle = secondaryActionTitle
self.keyboardType = keyboardType
self.action = action
self.secondaryAction = secondaryAction
}
}
Loading

0 comments on commit 553b829

Please sign in to comment.