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

Feature - Change date menu from protocol to concrete class #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- Instabug (5.2.4)
- Yoshi/Core (2.2.2)
- Yoshi/QAKit (2.2.2):
- Yoshi/Core (3.0.0-beta.1)
- Yoshi/QAKit (3.0.0-beta.1):
- Yoshi/Core

DEPENDENCIES:
Expand All @@ -14,7 +14,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Instabug: 6fa40a5e2a4620f0589dfc8e4e01b1018c8c42b1
Yoshi: 032a56c87369104a3a1ee80a247e551d91bddc99
Yoshi: 53a4349a09f1efbc7ee40774251843a5e86e7187

PODFILE CHECKSUM: 3e1269998b54f9d27d611d2231c251556652c10a

Expand Down
4 changes: 0 additions & 4 deletions Example/YoshiExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
276BCED91C29F060002138C7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 276BCED71C29F060002138C7 /* LaunchScreen.storyboard */; };
32CF65FF1F7B052F001A712A /* YoshiBaseEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32CF65FE1F7B0515001A712A /* YoshiBaseEnvironment.swift */; };
6A80770C715FF7079F982454 /* Pods_YoshiExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38AED69D51CB2462EC94055C /* Pods_YoshiExample.framework */; };
94E2C9C11F081DDE00811CE9 /* DateSelectorMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94E2C9C01F081DDE00811CE9 /* DateSelectorMenu.swift */; };
94E2C9C91F081F5900811CE9 /* CustomCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 94E2C9C71F081F5900811CE9 /* CustomCell.xib */; };
94E2C9CA1F081F5900811CE9 /* CustomUIMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94E2C9C81F081F5900811CE9 /* CustomUIMenu.swift */; };
/* End PBXBuildFile section */
Expand All @@ -32,7 +31,6 @@
38AED69D51CB2462EC94055C /* Pods_YoshiExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_YoshiExample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4B69EFE97A45841AA3569F78 /* Pods-YoshiExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YoshiExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-YoshiExample/Pods-YoshiExample.release.xcconfig"; sourceTree = "<group>"; };
611645F651489CBB0C351E8B /* Pods-YoshiExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YoshiExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-YoshiExample/Pods-YoshiExample.debug.xcconfig"; sourceTree = "<group>"; };
94E2C9C01F081DDE00811CE9 /* DateSelectorMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateSelectorMenu.swift; sourceTree = "<group>"; };
94E2C9C71F081F5900811CE9 /* CustomCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomCell.xib; sourceTree = "<group>"; };
94E2C9C81F081F5900811CE9 /* CustomUIMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomUIMenu.swift; sourceTree = "<group>"; };
9E459C63EB9049F862020412 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -95,7 +93,6 @@
94E2C9B91F080A0E00811CE9 /* Custom Menus */ = {
isa = PBXGroup;
children = (
94E2C9C01F081DDE00811CE9 /* DateSelectorMenu.swift */,
94E2C9C61F081F5900811CE9 /* CustomUIMenu */,
);
path = "Custom Menus";
Expand Down Expand Up @@ -256,7 +253,6 @@
276BCED11C29F060002138C7 /* ViewController.swift in Sources */,
94E2C9CA1F081F5900811CE9 /* CustomUIMenu.swift in Sources */,
276BCECF1C29F060002138C7 /* AppDelegate.swift in Sources */,
94E2C9C11F081DDE00811CE9 /* DateSelectorMenu.swift in Sources */,
32CF65FF1F7B052F001A712A /* YoshiBaseEnvironment.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
8 changes: 4 additions & 4 deletions Example/YoshiExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

private func dateSelectorMenu() -> YoshiDateSelectorMenu {
return DateSelectorMenu(title: "Environment Date",
subtitle: nil,
didUpdateDate: { (dateSelected) in
NotificationCenter.default.post(name:
return YoshiDateSelectorMenu(title: "Environment Date",
subtitle: nil,
didUpdateDate: { (dateSelected) in
NotificationCenter.default.post(name:
NSNotification.Name(rawValue: Notifications.EnvironmentDateUpdatedNotification),
object: dateSelected)
})
Expand Down
28 changes: 0 additions & 28 deletions Example/YoshiExample/Custom Menus/DateSelectorMenu.swift

This file was deleted.

70 changes: 46 additions & 24 deletions Yoshi/Yoshi/Menus/YoshiDateSelectorMenu/YoshiDateSelectorMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,54 @@
//

/**
Protocol for defining a menu option for choosing a date.
A date menu used to display and select from date picker.
*/
public protocol YoshiDateSelectorMenu: class, YoshiMenu {

/// The selected date.
var selectedDate: Date { get set }

/// Function to handle the date selection.
var didUpdateDate: (_ dateSelected: Date) -> Void { get }

}

public extension YoshiDateSelectorMenu {

/// Data source for the date selector style cell
var cellSource: YoshiReusableCellDataSource {
return YoshiDateSelectorMenuCellDataSource(title: title, date: selectedDate)
open class YoshiDateSelectorMenu: YoshiMenu {

public var title: String
public var subtitle: String?

/// Selected Date of the menu.
public var selectedDate: Date

/// The callback when date is selected.
public var didUpdateDate: (_ dateSelected: Date) -> Void

private let dateFormatter: DateFormatter

open static var defaultDateFormatter: DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .short

return dateFormatter
}

/**
Function to execute when the menu item is seleted.

- returns: A result for handling the selected menu item.
*/
func execute() -> YoshiActionResult {

/// Intialize a YoshiDateSelectorMenu
///
/// - Parameters:
/// - title: Main title for the cell.
/// - subtitle: Subtitle for the cell.
/// - selectedDate: Selected Date.
/// - dateFormatter: date formatter of the date picker. default to medium date style and short time style.
/// - didUpdateDate: Callback when the date is selected.
public init(title: String,
subtitle: String? = nil,
selectedDate: Date = Date(),
dateFormatter: DateFormatter = defaultDateFormatter,
didUpdateDate: @escaping (Date) -> Void) {
self.title = title
self.subtitle = subtitle
self.selectedDate = selectedDate
self.didUpdateDate = didUpdateDate
self.dateFormatter = dateFormatter
}

public var cellSource: YoshiReusableCellDataSource {
return YoshiDateSelectorMenuCellDataSource(title: title, date: selectedDate, dateFormatter: dateFormatter)
}

public func execute() -> YoshiActionResult {
let bundle = Bundle(for: YoshiConfigurationManager.self)
let datePickerViewController =
DebugDatePickerViewController(nibName: String(describing: DebugDatePickerViewController.self),
Expand All @@ -41,5 +64,4 @@ public extension YoshiDateSelectorMenu {

return .push(datePickerViewController)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ internal struct YoshiDateSelectorMenuCellDataSource: YoshiReusableCellDataSource
private let title: String

private let date: Date

private var dateFormatter: DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .short

return dateFormatter
}

private let dateFormatter: DateFormatter

/// Intialize the YoshiDateSelectorMenuCellDataSource instance
///
/// - Parameters:
/// - title: Main title for the cell
/// - date: Selected Date
init(title: String, date: Date) {
/// - dateFormatter: DateFormatter for the date picker, default to medium dateStyle and short timeStyle
init(title: String,
date: Date,
dateFormatter: DateFormatter) {
self.title = title
self.date = date
self.dateFormatter = dateFormatter
}

func cellFor(tableView: UITableView) -> UITableViewCell {
Expand Down