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

Conform to DialogTrigger in all Items and Groups (#23) #23

Merged
merged 2 commits into from
Feb 12, 2022
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#### Enhancements

* None
* Conform to `DialogTrigger` in all Items and Groups (PR #23)

#### Bug Fixes

Expand Down
4 changes: 4 additions & 0 deletions Examples/Example-iOS/Example-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
A2E6596525E453880013DEE0 /* MultipleAsyncItemGroups.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2E6596425E453880013DEE0 /* MultipleAsyncItemGroups.swift */; };
A2E6596725E456100013DEE0 /* ItemGroupAdvancedExamplesFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2E6596625E456100013DEE0 /* ItemGroupAdvancedExamplesFactory.swift */; };
A2E6645D25E563B20013DEE0 /* ProgressItemAdvancedExamplesFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2E6645C25E563B20013DEE0 /* ProgressItemAdvancedExamplesFactory.swift */; };
A2FC196027B7C1BC001FC161 /* ShowcaseItemsFactory+CapabilitiesExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2FC195F27B7C1BC001FC161 /* ShowcaseItemsFactory+CapabilitiesExamples.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -100,6 +101,7 @@
A2E6596425E453880013DEE0 /* MultipleAsyncItemGroups.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipleAsyncItemGroups.swift; sourceTree = "<group>"; };
A2E6596625E456100013DEE0 /* ItemGroupAdvancedExamplesFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemGroupAdvancedExamplesFactory.swift; sourceTree = "<group>"; };
A2E6645C25E563B20013DEE0 /* ProgressItemAdvancedExamplesFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressItemAdvancedExamplesFactory.swift; sourceTree = "<group>"; };
A2FC195F27B7C1BC001FC161 /* ShowcaseItemsFactory+CapabilitiesExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ShowcaseItemsFactory+CapabilitiesExamples.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -190,6 +192,7 @@
isa = PBXGroup;
children = (
A2DE479124FBB60B00CE7F7A /* ShowcaseItemsFactory.swift */,
A2FC195F27B7C1BC001FC161 /* ShowcaseItemsFactory+CapabilitiesExamples.swift */,
A2DE478724FBB60B00CE7F7A /* ShowcaseItemsFactory+DetailedItemExamples.swift */,
A2DE478824FBB60B00CE7F7A /* AdvancedExamples */,
A2DE478C24FBB60B00CE7F7A /* CustomViews */,
Expand Down Expand Up @@ -343,6 +346,7 @@
A2DE47A424FBB60B00CE7F7A /* ShowcaseItemsFactory.swift in Sources */,
A2BB6F5D26593B68007B900F /* SwiftUIViewContainerView.swift in Sources */,
A2DE489624FC009C00CE7F7A /* CustomPane.swift in Sources */,
A2FC196027B7C1BC001FC161 /* ShowcaseItemsFactory+CapabilitiesExamples.swift in Sources */,
A2DE47A824FBB60B00CE7F7A /* AppDelegate.swift in Sources */,
A2DE47A024FBB60B00CE7F7A /* CustomPaneViewController.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
//
// ShowcaseItemsFactory+CapabilitiesExamples.swift
//
// Created by Hans Seiffert on 12.02.22.
//
// ---
// MIT License
//
// Copyright © 2022 Hans Seiffert
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//

import Foundation
import QAMenu

extension ShowcaseItemsFactory {

struct CapabilitiesExamples {

static var group: ItemGroup {
return ItemGroup(
title: .static("Capabilities Examples"),
items: .static([
DialogTriggers.pane.asChildPaneItem()
])
)
}

struct DialogTriggers {

static var pane: Pane {
return Pane(title: .static("DialogTrigger"), groups: [
self.wrapItemInGroup(self.boolItem),
self.wrapItemInGroup(self.buttonItem),
self.wrapItemInGroup(self.progressItem),
self.wrapItemInGroup(self.childPaneItem),
self.wrapItemInGroup(self.editableStringItem),
self.pickerChildPaneItemGroup,
self.wrapItemInGroup(self.stringItemGroup)
])
}

private static func makeDialogContent(withSource sourceName: String) -> DialogContent {
return DialogContent(
title: "Dialog",
message: "This dialog was triggered using the \(sourceName) instance.",
closeButtonTitle: "Great"
)
}

private static func makeDialogTriggerButton(withSource source: DialogTrigger, title: String) -> ButtonItem {
return ButtonItem(
title: .static(title),
action: { _, _ in
source.onPresentDialog.fire(with: self.makeDialogContent(withSource: "\(source.self)"))
}
)
}

private static func wrapItemInGroup(_ item: Item, dialogTitle: String = "Trigger dialog") -> ItemGroup {
return ItemGroup(
title: .static("\(item.self)"),
items: .static([item, self.makeDialogTriggerButton(withSource: item, title: dialogTitle)])
)
}

private static var boolItem: BoolItem {
return BoolItem(
title: .static("BoolItem"),
value: .static(true),
onValueChange: { _, _, result in
result(.success)
}
)
}

private static var buttonItem: ButtonItem {
return ButtonItem(
title: .static("ButtonItem"),
action: { _, _ in
// Nothing
}
)
}

private static var progressItem: ProgressItem {
return ProgressItem(state: .progress("ProgressItem"))
}

private static var childPaneItem: ChildPaneItem {
return ChildPaneItem(pane: { Pane(title: .static("ChildPaneItem"), items: []) })
}

static var editableStringValue = "Value"
private static var editableStringItem: EditableStringItem {
return EditableStringItem(
title: .static(""),
value: .computed({
editableStringValue
}),
onValueChange: { newValue, _, result in
editableStringValue = newValue
result(.success)
}
)
}

static var isPickableItemSelected = true
private static var pickerChildPaneItemGroup: ItemGroup {
let item = PickableStringItem(
identifier: .static("a"),
title: .static("PickableStringItem"),
isSelected: .computed({
return isPickableItemSelected
})
)
let pickerGroup = PickerGroup(
title: .static("PickerGroup"),
options: .init([item]),
onPickedOption: { _, result in
self.isPickableItemSelected.toggle()
result(.success(shouldDismiss: false))
}
)
let groups: [Group] = [
pickerGroup,
ItemGroup(
title: .static("\(item.self)"),
items: .static([
self.makeDialogTriggerButton(withSource: item, title: "Trigger dialog on PicableStringItem"),
self.makeDialogTriggerButton(withSource: pickerGroup, title: "Trigger dialog on PickerGroup")
])
)
]
return ChildPaneItem(
pane: {
return Pane(
title: .static("Picker"),
groups: groups
)
},
footerText: .static("PickerGroup, PickableStringItem")
).asItemGroup(title: .static("Picker"))
}

private static var stringItemGroup: StringItem {
return StringItem(title: .static("StringItem"), value: nil)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DetailedItemExamples.swift
// ShowcaseItemsFactory+DetailedItemExamples.swift
//
// Created by Hans Seiffert on 11.07.20.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ class ShowcaseItemsFactory {
])
)

return [simpleCatalogGroup, detailedCatalogGroup, advancedExamples]
return [
simpleCatalogGroup,
detailedCatalogGroup,
CapabilitiesExamples.group,
advancedExamples
]
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Capabilities:
- [ ] Edit strings (multiline)
- [x] Async loading operation (Items)
- [ ] Async loading operation (Groups)
- [x] Interface to trigger dialogs on Items and Groups

See [DataStructure](Docs/DataStructure.md) for more details.

Expand Down
2 changes: 1 addition & 1 deletion Sources/QAMenu/Public/Data Structure/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import Foundation

public protocol Group: Invalidatable, FooterSupport {
public protocol Group: Invalidatable, DialogTrigger, FooterSupport {

// MARK: - Properties (Public)

Expand Down
4 changes: 3 additions & 1 deletion Sources/QAMenu/Public/Data Structure/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import Foundation

open class Item: Invalidatable, Searchable {
open class Item: Invalidatable, DialogTrigger, Searchable {

// MARK: - Properties (Public)

Expand All @@ -38,6 +38,8 @@ open class Item: Invalidatable, Searchable {

public let onInvalidation = InvalidationEvent()

public let onPresentDialog = ObservableEvent<DialogContent>()

open weak var parentGroup: Group?

// MARK: - Properties (Internal)
Expand Down
2 changes: 2 additions & 0 deletions Sources/QAMenu/Public/Data Structure/ItemGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ open class ItemGroup: Group, Searchable {

public let onInvalidation = InvalidationEvent()

public let onPresentDialog = ObservableEvent<DialogContent>()

// MARK: - Properties (Private / Internal)

private var disposeBag = DisposeBag()
Expand Down
4 changes: 1 addition & 3 deletions Sources/QAMenu/Public/Data Structure/Items/BoolItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import Foundation

open class BoolItem: Item, FooterSupport, DialogTrigger {
open class BoolItem: Item, FooterSupport {

// MARK: - Properties (Public)

Expand All @@ -42,8 +42,6 @@ open class BoolItem: Item, FooterSupport, DialogTrigger {
public let footerText: Dynamic<String?>?
public let onValueChange: (_ newValue: Bool, _ item: BoolItem, _ result: @escaping (ValueChangeResult) -> Void) -> Void?

public let onPresentDialog = ObservableEvent<DialogContent>()

override open var searchableContent: [String?] {
return [
self.title(),
Expand Down
4 changes: 2 additions & 2 deletions Sources/QAMenu/Public/Data Structure/PickerGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ open class PickerGroup: Group, DialogTrigger, NavigationTrigger {
open private(set) var footerText: Dynamic<String?>?
open private(set) var onPickedOption: ((_ item: PickableItem, _ result: @escaping (PickResult) -> Void) -> Void?)?

open var onPresentDialog = ObservableEvent<DialogContent>()

open var onNavigateBack = ObservableEvent<(() -> Void)>()

open var searchableContent: [String?] {
Expand All @@ -63,6 +61,8 @@ open class PickerGroup: Group, DialogTrigger, NavigationTrigger {

public let onInvalidation = InvalidationEvent()

public let onPresentDialog = ObservableEvent<DialogContent>()

// MARK: - Properties (Private / Internal)

private var disposeBag = DisposeBag()
Expand Down
4 changes: 2 additions & 2 deletions Sources/QAMenuUIKit/Internal/UI/PaneViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ internal class PaneViewController: UIViewController {
) {
pane.groups.forEach { group in
self.observeInvalidatable(group)
self.observeDialogTriggerable(group as? DialogTrigger)
self.observeDialogTriggerable(group)
group.items.unboxed.forEach { item in
self.observeDialogTriggerable(item as? DialogTrigger)
self.observeDialogTriggerable(item)
self.observeNavigationTrigger(item as? NavigationTrigger)
}
}
Expand Down