Skip to content

Commit

Permalink
Merge pull request #43 from reloni/develop
Browse files Browse the repository at this point in the history
Swipe actions
  • Loading branch information
reloni authored Oct 7, 2017
2 parents a40492c + dcb8338 commit 0102856
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Aika.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1004,7 +1004,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down Expand Up @@ -1132,7 +1132,7 @@
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.AntonEfimenko.Aika.NotificationServiceExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1153,7 +1153,7 @@
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.AntonEfimenko.Aika.NotificationServiceExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
1 change: 1 addition & 0 deletions Aika/Controllers/Tasks/TaskRepeatModeController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import RxSwift
import RxDataSources

final class TaskRepeatModeController: UIViewController {

let viewModel: TaskRepeatModeViewModel
let bag = DisposeBag()
let tableViewDelegate = TaskRepeatModeTableViewDelegate()
Expand Down
49 changes: 41 additions & 8 deletions Aika/Controllers/Tasks/TasksController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class TasksController : UIViewController {

configureDataSource()
bind()

viewModel.synchronize()
}

Expand Down Expand Up @@ -127,6 +127,7 @@ final class TasksController : UIViewController {
cell.layoutMargins = .zero
cell.contentView.layoutMargins = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
cell.selectionStyle = .none
cell.isUserInteractionEnabled = true
cell.isExpanded = false
cell.taskDescription.text = "\(item.description)"
cell.targetDate.attributedText = item.targetDate?.toAttributedString(withSpelling: true)
Expand All @@ -151,7 +152,7 @@ final class TasksController : UIViewController {
dataSource.canEditRowAtIndexPath = { _, _ in
return true
}

dataSource.canMoveRowAtIndexPath = { _, _ in
return true
}
Expand Down Expand Up @@ -188,26 +189,58 @@ final class TasksController : UIViewController {
}

final class TasksTableViewDelegate : NSObject, UITableViewDelegate {
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.delete
@available(iOS 11.0, *)
static func createAction(title: String, backgroundColor: UIColor, image: UIImage?, completionHandler: @escaping () -> Bool) -> UIContextualAction {
let action = UIContextualAction(style: .normal,
title: title,
handler: { _, _, completion in completion(completionHandler()) })
action.backgroundColor = backgroundColor
action.image = image
return action
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) as? TaskCell else { return }

cell.isExpanded = !cell.isExpanded
animateCellExpansion(tableView: tableView)
}

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) as? TaskCell else { return }

cell.isExpanded = false
}

func animateCellExpansion(tableView: UITableView) {
tableView.beginUpdates()
tableView.endUpdates()
tableView.scrollToNearestSelectedRow(at: .none, animated: true)
}

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let cell = tableView.cellForRow(at: indexPath) as? TaskCell else { return nil }

let deleteAction = TasksTableViewDelegate.createAction(title: "Delete",
backgroundColor: Theme.Colors.upsdelRed,
image: Theme.Images.delete.tint(with: .white)!.resize(toWidth: 22),
completionHandler: { [weak cell] in cell?.deleteTapped?(); return true })
let editAction = TasksTableViewDelegate.createAction(title: "Edit",
backgroundColor: Theme.Colors.blueberry,
image: Theme.Images.edit.tint(with: .white)!.resize(toWidth: 22),
completionHandler: { [weak cell] in cell?.editTapped?(); return true })
return UISwipeActionsConfiguration(actions: [deleteAction, editAction])
}

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let cell = tableView.cellForRow(at: indexPath) as? TaskCell else { return nil }

let completeAction = TasksTableViewDelegate.createAction(title: "Complete",
backgroundColor: Theme.Colors.darkSpringGreen,
image: Theme.Images.checked.tint(with: .white)!.resize(toWidth: 22),
completionHandler: { [weak cell] in cell?.completeTapped?(); return true })
return UISwipeActionsConfiguration(actions: [completeAction])
}
}

0 comments on commit 0102856

Please sign in to comment.