Skip to content

Commit

Permalink
Merge commit '02da15df6b08e054b69b815c4f0b7bcf98f3fad0' into swift-4.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	Example/Podfile.lock
  • Loading branch information
Andrey Yutkin committed May 30, 2019
2 parents 396c10c + 02da15d commit b324083
Show file tree
Hide file tree
Showing 23 changed files with 465 additions and 266 deletions.
2 changes: 2 additions & 0 deletions Example/PaparazzoExample/AppSpecificUITheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ extension PaparazzoUITheme {
theme.photoLibraryAlbumCellFont = UIFont(name: "Latoto", size: 17)!
theme.photoLibraryPlaceholderFont = UIFont(name: "Latoto", size: 17)!
theme.cameraTitleFont = UIFont(name: "LatotoSemibold", size: 17)!
theme.cameraBottomContinueButtonFont = UIFont(name: "Latoto", size: 16)!
theme.libraryBottomContinueButtonFont = UIFont(name: "Latoto", size: 16)!
return theme
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class ExamplePresenter {
maxSelectedItemsCount: 5)
{ module in
weak var weakModule = module
module.setContinueButtonPlacement(.bottom)
module.onFinish = { result in
weakModule?.dismissModule()
}
Expand Down Expand Up @@ -150,7 +151,7 @@ final class ExamplePresenter {
recognitionHandler.onRecognize = { label in
module?.showInfoMessage(label, timeout: 3)
}
}
}
)
}
}
Expand Down Expand Up @@ -214,6 +215,7 @@ final class ExamplePresenter {
}

module.setContinueButtonTitle("Done")
module.setContinueButtonPlacement(.bottom)

module.onCancel = { [weak module] in
module?.dismissModule()
Expand Down
4 changes: 4 additions & 0 deletions Paparazzo/Core/Extensions/CGRectExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ extension CGRect {
self.init(x: left, y: top, width: right - left, height: height)
}

init(left: CGFloat, right: CGFloat, bottom: CGFloat, height: CGFloat) {
self.init(x: left, y: bottom - height, width: right - left, height: height)
}

// Возвращает прямоугольник, повернутый относительно исходного на угол angle и описанный
// вокруг него (все вершины исходного прямоугольника лежат на сторонах искомого).
// Результат описан в повернутой системе координат.
Expand Down
8 changes: 8 additions & 0 deletions Paparazzo/Core/Extensions/UIDeviceExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ extension UIDevice {
let iPhonePlusHeight = CGFloat(2208)
return userInterfaceIdiom == .phone && UIScreen.main.nativeBounds.height > iPhonePlusHeight
}

var hasTopSafeAreaInset: Bool {
if #available(iOS 11.0, *) {
let top = UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0
return top > 0
}
return false
}
}
7 changes: 7 additions & 0 deletions Paparazzo/Core/PaparazzoPickerModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public enum MediaPickerContinueButtonStyle {
case spinner
}

public enum MediaPickerContinueButtonPlacement {
case topRight
case bottom
}

public struct CameraHintData {
public let title: String
public let delay: TimeInterval?
Expand All @@ -32,6 +37,7 @@ public protocol PaparazzoPickerModule: class {
func setContinueButtonEnabled(_: Bool)
func setContinueButtonVisible(_: Bool)
func setContinueButtonStyle(_: MediaPickerContinueButtonStyle)
func setContinueButtonPlacement(_: MediaPickerContinueButtonPlacement)

func setAccessDeniedTitle(_: String)
func setAccessDeniedMessage(_: String)
Expand All @@ -56,6 +62,7 @@ public protocol PaparazzoPickerModule: class {
var onCropCancel: (() -> ())? { get set }
var onContinueButtonTap: (() -> ())? { get set }

var onViewDidLoad: (() -> ())? { get set }
var onFinish: (([MediaPickerItem]) -> ())? { get set }
var onCancel: (() -> ())? { get set }
}
6 changes: 6 additions & 0 deletions Paparazzo/Core/PaparazzoUITheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public struct PaparazzoUITheme:
public var cameraSubtitleColor = UIColor(white: 1, alpha: 1)
public var cameraSubtitleFont = UIFont.systemFont(ofSize: 14)
public var cameraHintFont = UIFont.systemFont(ofSize: 17)
public var cameraBottomContinueButtonBackgroundColor = UIColor(red: 0 / 255, green: 170.0 / 255, blue: 1, alpha: 1)
public var cameraBottomContinueButtonTitleColor = UIColor.white
public var cameraBottomContinueButtonFont = UIFont.systemFont(ofSize: 16)

public var accessDeniedTitleFont = UIFont.boldSystemFont(ofSize: 17)
public var accessDeniedMessageFont = UIFont.systemFont(ofSize: 17)
Expand Down Expand Up @@ -67,6 +70,9 @@ public struct PaparazzoUITheme:
public var continueButtonTitleHighlightedColor = UIColor(red: 0, green: 152.0/255, blue: 229.0/255, alpha: 1)
public var closeIcon = PaparazzoUITheme.image(named: "bt-close")
public var continueButtonTitleFont = UIFont.systemFont(ofSize: 17)
public var libraryBottomContinueButtonBackgroundColor = UIColor(red: 0 / 255, green: 170.0 / 255, blue: 1, alpha: 1)
public var libraryBottomContinueButtonTitleColor = UIColor.white
public var libraryBottomContinueButtonFont = UIFont.systemFont(ofSize: 16)

// MARK: - ImageCroppingUITheme

Expand Down
8 changes: 5 additions & 3 deletions Paparazzo/Core/VIPER/Camera/View/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ final class CameraView: UIView, CameraViewInput, ThemeConfigurable {
override func layoutSubviews() {
super.layoutSubviews()

let labelsTargetCenterY = CGFloat(27)

accessDeniedView.bounds = bounds
accessDeniedView.center = bounds.center

cameraOutputView?.frame = bounds

titleLabel.sizeToFit()
subtitleLabel.sizeToFit()

titleLabel.centerX = bounds.centerX
let hasSubtitle = (subtitleLabel.text?.count ?? 0) > 0
titleLabel.top = hasSubtitle ? 9 : 17
titleLabel.top = floor(labelsTargetCenterY - (titleLabel.height + subtitleLabel.height) / 2)

subtitleLabel.sizeToFit()
subtitleLabel.centerX = bounds.centerX
subtitleLabel.top = titleLabel.bottom

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class ImageCroppingView: UIView, ThemeConfigurable {
override func layoutSubviews() {
super.layoutSubviews()

if UIDevice.current.isIPhoneX {
if UIDevice.current.hasTopSafeAreaInset {
layOutForIPhoneX()
} else {
layOutForDevicesExpectForIPhoneX()
Expand Down Expand Up @@ -173,7 +173,7 @@ final class ImageCroppingView: UIView, ThemeConfigurable {

switch aspectRatio {

case .portrait_3x4 where !UIDevice.current.isIPhoneX:
case .portrait_3x4 where !UIDevice.current.hasTopSafeAreaInset:

titleLabel.textColor = .white

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ final class ImageCroppingViewController: PaparazzoViewController, ImageCroppingV
forcePortraitOrientation()
navigationController?.setNavigationBarHidden(true, animated: animated)

if !UIDevice.current.isIPhoneX {
if !UIDevice.current.hasTopSafeAreaInset {
UIApplication.shared.setStatusBarHidden(true, with: .fade)
}
}

override var prefersStatusBarHidden: Bool {
return !UIDevice.current.isIPhoneX
return !UIDevice.current.hasTopSafeAreaInset
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ final class MediaPickerPresenter: MediaPickerModule {
didSet {
view?.onViewDidLoad = { [weak self] in
self?.setUpView()
DispatchQueue.main.async {
self?.onViewDidLoad?()
}
}
}
}
Expand All @@ -32,6 +35,7 @@ final class MediaPickerPresenter: MediaPickerModule {
var onCropFinish: (() -> ())?
var onCropCancel: (() -> ())?
var onContinueButtonTap: (() -> ())?
var onViewDidLoad: (() -> ())?
var onFinish: (([MediaPickerItem]) -> ())?
var onCancel: (() -> ())?

Expand All @@ -52,6 +56,11 @@ final class MediaPickerPresenter: MediaPickerModule {
view?.setContinueButtonStyle(style)
}


func setContinueButtonPlacement(_ placement: MediaPickerContinueButtonPlacement) {
view?.setContinueButtonPlacement(placement)
}

public func setCameraTitle(_ title: String) {
cameraModuleInput.setTitle(title)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ final class CameraControlsView: UIView, ThemeConfigurable {
let contentHeight = bounds.inset(by: insets).size.height
let shutterButtonDiameter = max(shutterButtonMinDiameter, min(shutterButtonMaxDiameter, contentHeight))
let shutterButtonSize = CGSize(width: shutterButtonDiameter, height: shutterButtonDiameter)
let centerY = bounds.centerY - paparazzoSafeAreaInsets.bottom / 2
let centerY = bounds.centerY

shutterButton.frame = CGRect(origin: .zero, size: shutterButtonSize)
shutterButton.center = CGPoint(x: bounds.midX, y: centerY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class PhotoControlsView: UIView, ThemeConfigurable {
button.size = CGSize.minimumTapAreaSize
button.center = CGPoint(
x: (width * (2.0 * CGFloat(index) + 1.0)) / (2.0 * CGFloat(visibleButtons.count)),
y: bounds.centerY - paparazzoSafeAreaInsets.bottom / 2
y: bounds.centerY
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import UIKit

public protocol MediaPickerRootModuleUITheme: AccessDeniedViewTheme {

var shutterButtonColor: UIColor { get }
Expand All @@ -14,6 +16,9 @@ public protocol MediaPickerRootModuleUITheme: AccessDeniedViewTheme {
var cameraSubtitleColor: UIColor { get }
var cameraSubtitleFont: UIFont { get }
var cameraHintFont: UIFont { get }
var cameraBottomContinueButtonBackgroundColor: UIColor { get }
var cameraBottomContinueButtonTitleColor: UIColor { get }
var cameraBottomContinueButtonFont: UIFont { get }

var removePhotoIcon: UIImage? { get }
var autocorrectPhotoIconInactive: UIImage? { get }
Expand Down
Loading

0 comments on commit b324083

Please sign in to comment.