Skip to content

Commit

Permalink
ColorPicker: メインカラーをデフォルトに戻すオプションを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
YuigaWada committed May 1, 2020
1 parent afa3e75 commit 997ab2c
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions MissCat/View/Settings/Cell/ColorPickerCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import ChromaColorPicker
import Eureka
import RxCocoa
import RxSwift
import UIKit

Expand Down Expand Up @@ -56,10 +57,14 @@ public class ColorPickerCell: Cell<String>, CellType {

private func setupTapGesture() {
setTapGesture(disposeBag, closure: {
let picker = self.prepareColorPicker()
UIView.animate(withDuration: 0.15, delay: 0, options: .curveEaseInOut, animations: {
picker?.alpha = 1
})
self.showMenu()
})
}

private func showColorPicker() {
let picker = prepareColorPicker()
UIView.animate(withDuration: 0.15, delay: 0, options: .curveEaseInOut, animations: {
picker?.alpha = 1
})
}

Expand All @@ -77,6 +82,30 @@ public class ColorPickerCell: Cell<String>, CellType {

return picker
}

private func showMenu() {
guard let parent = parentViewController else { return }
let panelMenu = PanelMenuViewController()
let menuItems: [PanelMenuViewController.MenuItem] = [.init(title: "デフォルトに戻す", awesomeIcon: "", order: 0),
.init(title: "カスタムカラーを設定", awesomeIcon: "", order: 1)]

panelMenu.setupMenu(items: menuItems)
panelMenu.tapTrigger.asDriver(onErrorDriveWith: Driver.empty()).drive(onNext: { order in // どのメニューがタップされたのか
guard order >= 0 else { return }
panelMenu.dismiss(animated: true, completion: nil)

switch order {
case 0: // Default
self.setColor(.systemBlue)
case 1: // Custom
self.showColorPicker()
default:
break
}
}).disposed(by: disposeBag)

parent.present(panelMenu, animated: true, completion: nil)
}
}

public final class ColorPickerRow: Row<ColorPickerCell>, RowType {
Expand Down

0 comments on commit 997ab2c

Please sign in to comment.