Skip to content

Commit

Permalink
feat: IssueCoordinator에 pushImagePickerView기능 구현(#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
dahun-lee-daji committed Jun 17, 2021
1 parent 013637d commit fd89324
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
8 changes: 7 additions & 1 deletion iOS/issue-tracker/IssueList/IssueCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ class IssueCoordinator: NSObject, Coordinator {
func pushEditView() {
let issueEditVC = UIStoryboard(name: StoryBoardName.IssueEdit.description, bundle: nil)
.instantiateViewController(withIdentifier: IssueEditViewController.reuseIdentifier) as! IssueEditViewController

issueEditVC.coordinator = self
navigationController.pushViewController(issueEditVC, animated: true)
}

func pushImagePickerView() {
let imagePickerDelegate = ImagePickerDelegate()
let imagePicker = ImagePicker.init(presentationController: self.navigationController, delegate: imagePickerDelegate)
self.navigationController.present(imagePicker.pickerController, animated: true, completion: nil)
}
}
7 changes: 5 additions & 2 deletions iOS/issue-tracker/IssueList/IssueListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import UIKit

class IssueListViewController: UIViewController, ReuseIdentity {

weak var coordinator: IssueCoordinator?
weak var coordinator: Coordinator?

@IBAction func pushToEditView(_ sender: Any) {
coordinator?.pushEditView()
guard let issueCoordinator = coordinator as? IssueCoordinator else {
return
}
issueCoordinator.pushEditView()
}

override func viewDidLoad() {
Expand Down
13 changes: 4 additions & 9 deletions iOS/issue-tracker/NewIssue/IssueEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class IssueEditViewController: UIViewController, ReuseIdentity {
private var tableDelegate = AdditionalTableDelegate()
private var tableDataSource = AdditionalTableViewDataSource()

private lazy var photoPicker = ImagePicker(presentationController: self, delegate: self)

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -42,7 +40,10 @@ class IssueEditViewController: UIViewController, ReuseIdentity {

@objc
func insertPhoto() {
self.photoPicker.present()
guard let issueCoordinator = coordinator as? IssueCoordinator else {
return
}
issueCoordinator.pushImagePickerView()
}

}
Expand All @@ -54,9 +55,3 @@ extension IssueEditViewController: UITextViewDelegate {
}
}

extension IssueEditViewController: ImagePickerDelegate {

func didSelect(image: UIImage?) {

}
}
22 changes: 11 additions & 11 deletions iOS/issue-tracker/Photo/ImagePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,30 @@

import UIKit

public protocol ImagePickerDelegate: AnyObject {
public protocol ImagePickerDelegatable: AnyObject {
func didSelect(image: UIImage?)
}

class ImagePicker: NSObject {

private let pickerController: UIImagePickerController
private weak var presentationController: UIViewController?
private weak var delegate: ImagePickerDelegate?
let pickerController: UIImagePickerController
private weak var delegate: ImagePickerDelegatable?

public init(presentationController: UIViewController, delegate: ImagePickerDelegate) {
public init(presentationController: UIViewController, delegate: ImagePickerDelegatable) {
self.pickerController = UIImagePickerController()

super.init()
self.presentationController = presentationController
self.delegate = delegate

self.pickerController.delegate = self
self.pickerController.allowsEditing = true
self.pickerController.mediaTypes = ["public.image"]

}

private func pickerController(_ controller: UIImagePickerController, didSelect image: UIImage?) {
controller.dismiss(animated: true, completion: nil)
self.delegate?.didSelect(image: image)
}

func present() {
self.presentationController?.present(pickerController, animated: true)
}
}

extension ImagePicker: UIImagePickerControllerDelegate {
Expand All @@ -57,3 +51,9 @@ extension ImagePicker: UIImagePickerControllerDelegate {
extension ImagePicker: UINavigationControllerDelegate {

}

class ImagePickerDelegate: ImagePickerDelegatable {
func didSelect(image: UIImage?) {

}
}

0 comments on commit fd89324

Please sign in to comment.