Skip to content

Commit

Permalink
[MODIFY] make crop item title configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
c-nguyen committed Apr 10, 2018
1 parent 9100e0d commit d785a4e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
27 changes: 21 additions & 6 deletions FMPhotoPicker/FMPhotoPicker/source/ImageEditor/Crop/FMCrop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import UIKit
public struct FMCropRatio {
let width: CGFloat
let height: CGFloat

public init(width: CGFloat, height: CGFloat) {
self.width = width
self.height = height
}
}

public enum FMCrop: FMCroppable {
Expand All @@ -33,13 +38,13 @@ public enum FMCrop: FMCroppable {
}
}

public func name() -> String {
public func name(strings: [String: String]) -> String? {
switch self {
case .ratio4x3: return "4:3"
case .ratio16x9: return "16:9"
case .ratioCustom: return "Custom"
case .ratioOrigin: return "Origin"
case .ratioSquare: return "Square"
case .ratio4x3: return strings["editor_crop_ratio4x3"]
case .ratio16x9: return strings["editor_crop_ratio16x9"]
case .ratioCustom: return strings["editor_crop_ratioCustom"]
case .ratioOrigin: return strings["editor_crop_ratioOrigin"]
case .ratioSquare: return strings["editor_crop_ratioSquare"]
}
}

Expand All @@ -62,4 +67,14 @@ public enum FMCrop: FMCroppable {
}
return UIImage()
}

public func identifier() -> String {
switch self {
case .ratio4x3: return "ratio4x3"
case .ratio16x9: return "ratio16x9"
case .ratioCustom: return "ratioCustom"
case .ratioOrigin: return "ratioOrigin"
case .ratioSquare: return "ratioSquare"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import UIKit

public protocol FMCroppable {
func crop(image: UIImage, toRect rect: CGRect) -> UIImage
func name() -> String
func name(strings: [String: String]) -> String?
func icon() -> UIImage
func ratio() -> FMCropRatio?
func identifier() -> String
}

extension FMCroppable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ struct FMImageEditor {
}

public func isEdited() -> Bool {
return filter.filterName() != initFilter.filterName() || crop.name() != initCrop.name() || !cropArea.isApproximatelyEqual(to: initCropArea)
return filter.filterName() != initFilter.filterName() || crop.identifier() != initCrop.identifier() || !cropArea.isApproximatelyEqual(to: initCropArea)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ extension FMCropMenuView: UICollectionViewDataSource {
} else if indexPath.section == 1 {
// crop items
let cropItem = cropItems[indexPath.row]
cell.name.text = cropItem.name()
cell.name.text = cropItem.name(strings: config.strings)
cell.imageView.image = cropItem.icon()

if selectedCrop?.name() == cropItem.name() {
if selectedCrop?.identifier() == cropItem.identifier() {
cell.setSelected()
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ extension FMCropMenuView: UICollectionViewDelegate {
cell.setSelected()

if let prevCropItem = prevCropItem,
let prevRow = cropItems.index(where: { $0.name() == prevCropItem.name() }) {
let prevRow = cropItems.index(where: { $0.identifier() == prevCropItem.identifier() }) {
collectionView.reloadItems(at: [IndexPath(row: prevRow, section: 1)])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public struct FMPhotoPickerConfig {
"editor_menu_crop": "Crop",
"editor_menu_crop_button_reset": "Reset",
"editor_menu_crop_button_rotate": "Rotate",

"editor_crop_ratio4x3": "4:3",
"editor_crop_ratio16x9": "16:9",
"editor_crop_ratioCustom": "Custom",
"editor_crop_ratioOrigin": "Origin",
"editor_crop_ratioSquare": "Square",
]

public init() {
Expand Down

0 comments on commit d785a4e

Please sign in to comment.