Skip to content

Commit

Permalink
Add CustomStringItem example (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschob authored May 22, 2021
1 parent 24ff34a commit a821bbc
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 34 deletions.
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 @@ -20,6 +20,7 @@
A2A40885254EE33200ACA56B /* QAMenuUtils.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A2A40881254EE33200ACA56B /* QAMenuUtils.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
A2BEC150257C23A80005EFDF /* CustomPaneRepresentableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2BEC14F257C23A80005EFDF /* CustomPaneRepresentableViewController.swift */; };
A2BEC152257C248E0005EFDF /* CustomPaneRepresentableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A2BEC151257C248E0005EFDF /* CustomPaneRepresentableViewController.xib */; };
A2D87CB1264D69B70074A3A8 /* CustomItemsAdvancedExamplesFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2D87CB0264D69B70074A3A8 /* CustomItemsAdvancedExamplesFactory.swift */; };
A2DE479B24FBB60B00CE7F7A /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2DE478524FBB60B00CE7F7A /* ExampleViewController.swift */; };
A2DE479C24FBB60B00CE7F7A /* ShowcaseItemsFactory+DetailedItemExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2DE478724FBB60B00CE7F7A /* ShowcaseItemsFactory+DetailedItemExamples.swift */; };
A2DE479D24FBB60B00CE7F7A /* BoolItemAdvancedExamplesFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2DE478924FBB60B00CE7F7A /* BoolItemAdvancedExamplesFactory.swift */; };
Expand Down Expand Up @@ -70,6 +71,7 @@
A2A40881254EE33200ACA56B /* QAMenuUtils.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = QAMenuUtils.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A2BEC14F257C23A80005EFDF /* CustomPaneRepresentableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomPaneRepresentableViewController.swift; sourceTree = "<group>"; };
A2BEC151257C248E0005EFDF /* CustomPaneRepresentableViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomPaneRepresentableViewController.xib; sourceTree = "<group>"; };
A2D87CB0264D69B70074A3A8 /* CustomItemsAdvancedExamplesFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomItemsAdvancedExamplesFactory.swift; sourceTree = "<group>"; };
A2DE478524FBB60B00CE7F7A /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
A2DE478724FBB60B00CE7F7A /* ShowcaseItemsFactory+DetailedItemExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ShowcaseItemsFactory+DetailedItemExamples.swift"; sourceTree = "<group>"; };
A2DE478924FBB60B00CE7F7A /* BoolItemAdvancedExamplesFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoolItemAdvancedExamplesFactory.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +171,7 @@
children = (
A2DE478924FBB60B00CE7F7A /* BoolItemAdvancedExamplesFactory.swift */,
A2DE478B24FBB60B00CE7F7A /* ButtonItemAdvancedExamplesFactory.swift */,
A2D87CB0264D69B70074A3A8 /* CustomItemsAdvancedExamplesFactory.swift */,
A200F19F25D83BF100B309F4 /* EditableStringItemAdvancedExamplesFactory.swift */,
A2E6596625E456100013DEE0 /* ItemGroupAdvancedExamplesFactory.swift */,
A249DE3D258E472D002AEC41 /* PickerGroupAdvancedExamplesFactory.swift */,
Expand Down Expand Up @@ -303,6 +306,7 @@
A289795425E1A11200EB7326 /* MultipleAsyncPickerGroups.swift in Sources */,
A2DE479C24FBB60B00CE7F7A /* ShowcaseItemsFactory+DetailedItemExamples.swift in Sources */,
A200F1A025D83BF100B309F4 /* EditableStringItemAdvancedExamplesFactory.swift in Sources */,
A2D87CB1264D69B70074A3A8 /* CustomItemsAdvancedExamplesFactory.swift in Sources */,
A249DE3E258E472D002AEC41 /* PickerGroupAdvancedExamplesFactory.swift in Sources */,
A2DE47AC24FBB7D300CE7F7A /* SceneDelegate.swift in Sources */,
A2DE47A424FBB60B00CE7F7A /* ShowcaseItemsFactory.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Examples/Example-iOS/Sources/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class ExampleViewController: UITableViewController {
)
if let presenter = self.showcaseQAMenu?.presenter as? QAMenuUIKitPresenter {
presenter.ui.register(CustomPaneViewController.self, for: CustomPane.self)
presenter.ui.register(CustomStringItemView.self, for: CustomStringItem.self)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// CustomItemsAdvancedExamplesFactory.swift
//
// Created by Hans Seiffert on 13.05.21.
//
// ---
// MIT License
//
// Copyright © 2021 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 UIKit
import QAMenu

class CustomItemsAdvancedExamplesFactory {

func makePane() -> Pane {
let pane = Pane(
title: .static("Custom Items"),
groups: [
[
ShowcaseItemsFactory.DetailedItemExamples.ChildPane.customStringView,
ShowcaseItemsFactory.DetailedItemExamples.ChildPane.customScreen
]
.asItemGroup()
]
)
return pane
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ import UIKit
import QAMenu
import QAMenuUIKit

// MARK: - CustomStringItem

class CustomStringItem: StringItem {

override var isSharingEnabled: Bool {
return false
}
}

// MARK: - CustomStringItemView

class CustomStringItemView: NibView, ItemUIRepresentable {

// MARK: - Properties (Internal)
Expand All @@ -39,6 +50,10 @@ class CustomStringItemView: NibView, ItemUIRepresentable {
return "CustomStringItemView"
}

override var nib: UINib {
return UINib(nibName: Self.nibName, bundle: Bundle.main)
}

weak var delegate: ItemUIRepresentableDelegate?

var footerText: Dynamic<String?>? {
Expand All @@ -65,7 +80,7 @@ class CustomStringItemView: NibView, ItemUIRepresentable {
// MARK: -

func setItem(_ item: Item) {
guard let item = item as? StringItem else { return }
guard let item = item as? CustomStringItem else { return }
self.item = item
self.item?.onInvalidation
.observe { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CustomStringItemView" customModule="Example_iOS" customModuleProvider="target">
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CustomItemView" customModule="Example_iOS" customModuleProvider="target">
<connections>
<outlet property="stackView" destination="rQ8-Be-LmF" id="HSQ-TC-ySL"/>
<outlet property="titleLabel" destination="suP-sd-BSz" id="pST-P8-z3L"/>
Expand All @@ -21,30 +23,53 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" spacing="15" translatesAutoresizingMaskIntoConstraints="NO" id="rQ8-Be-LmF">
<rect key="frame" x="0.0" y="0.0" width="414" height="100"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="qzJ-ZW-enx">
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="qzJ-ZW-enx">
<rect key="frame" x="0.0" y="0.0" width="414" height="100"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="suP-sd-BSz">
<rect key="frame" x="0.0" y="0.0" width="134.5" height="100"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qep-lR-URx">
<rect key="frame" x="139.5" y="0.0" width="135" height="100"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Lorem Ipsum Dolores" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AU6-Fc-hkI">
<rect key="frame" x="279.5" y="0.0" width="134.5" height="100"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XG8-iB-o7q">
<rect key="frame" x="0.0" y="0.0" width="414" height="34.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="suP-sd-BSz">
<rect key="frame" x="186.5" y="0.0" width="41.5" height="34.5"/>
<color key="backgroundColor" systemColor="systemYellowColor"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="suP-sd-BSz" secondAttribute="trailing" id="1HH-uo-UoB"/>
<constraint firstItem="suP-sd-BSz" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="XG8-iB-o7q" secondAttribute="leading" id="Hvk-B5-4qK"/>
<constraint firstAttribute="bottom" secondItem="suP-sd-BSz" secondAttribute="bottom" id="bZU-WU-znU"/>
<constraint firstItem="suP-sd-BSz" firstAttribute="top" secondItem="XG8-iB-o7q" secondAttribute="top" id="ltq-xp-Nih"/>
<constraint firstItem="suP-sd-BSz" firstAttribute="centerX" secondItem="XG8-iB-o7q" secondAttribute="centerX" id="wD5-B2-fUZ"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="RSx-Hf-qws">
<rect key="frame" x="0.0" y="39.5" width="414" height="60.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Lorem Ipsum Dolores" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AU6-Fc-hkI">
<rect key="frame" x="126.5" y="0.0" width="161.5" height="60.5"/>
<color key="backgroundColor" systemColor="systemIndigoColor"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="AU6-Fc-hkI" firstAttribute="centerX" secondItem="RSx-Hf-qws" secondAttribute="centerX" id="0Bn-60-QaH"/>
<constraint firstAttribute="bottom" secondItem="AU6-Fc-hkI" secondAttribute="bottom" id="3gz-N7-fpC"/>
<constraint firstItem="AU6-Fc-hkI" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="RSx-Hf-qws" secondAttribute="leading" id="87X-RK-eq8"/>
<constraint firstItem="AU6-Fc-hkI" firstAttribute="top" secondItem="RSx-Hf-qws" secondAttribute="top" id="JEX-Ns-oks"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="AU6-Fc-hkI" secondAttribute="trailing" id="veg-8z-SyC"/>
</constraints>
</view>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</stackView>
</subviews>
<constraints>
Expand All @@ -59,4 +84,12 @@
<point key="canvasLocation" x="834.78260869565224" y="322.76785714285711"/>
</view>
</objects>
<resources>
<systemColor name="systemIndigoColor">
<color red="0.34509803921568627" green="0.33725490196078434" blue="0.83921568627450982" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemYellowColor">
<color red="1" green="0.80000000000000004" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ extension ShowcaseItemsFactory {
})
}

static var customStringView: CustomStringItem {
return CustomStringItem(
title: .static("Your own"),
value: .static("custom view")
)
}

static var customScreen: ChildPaneItem {
return ChildPaneItem(pane: {
CustomPane(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class ShowcaseItemsFactory {
}),
ChildPaneItem(pane: { ProgressItemAdvancedExamplesFactory.makePane() }),
ChildPaneItem(pane: { ItemGroupAdvancedExamplesFactory().makePane() }),
ChildPaneItem(pane: { PickerGroupAdvancedExamplesFactory().makePane() })
ChildPaneItem(pane: { PickerGroupAdvancedExamplesFactory().makePane() }),
ChildPaneItem(pane: { CustomItemsAdvancedExamplesFactory().makePane() })
])
)

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

import Foundation

open class StringItem: Item, FooterSupport {
open class StringItem: Item, FooterSupport, Shareable {

// MARK: - Properties (Public)

Expand Down Expand Up @@ -93,11 +93,6 @@ open class StringItem: Item, FooterSupport {
self.valueTextAttributes = textAttributes
return self
}
}

// MARK: - StringItem + Shareable

extension StringItem: Shareable {

open var isSharingEnabled: Bool {
guard let shareContent = self.shareContent, !shareContent.isEmpty else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/QAMenuUIKit/Internal/UI/PaneViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ extension PaneViewController: UITableViewDelegate {
tableView.deselectRow(at: indexPath, animated: true)

guard let item = self.item(at: indexPath) as? Selectable else {
Logger.verbose("UITableView row at index \(indexPath) was selectable but the the cell is not \(Selectable.self)")
Logger.verbose("UITableView row at index \(indexPath) was selected but the the cell is not \(Selectable.self)")
return
}

Expand Down
Loading

0 comments on commit a821bbc

Please sign in to comment.