Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support dark mode #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ public class FMPhotoPickerViewController: UIViewController {

public override func loadView() {
view = UIView()
view.backgroundColor = .white
// view.backgroundColor = .white
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
self.view.backgroundColor = .black
} else {
self.view.backgroundColor = .white
}
} else {
self.view.backgroundColor = .white
}
initializeViews()
setupView()
}
Expand Down Expand Up @@ -360,6 +369,15 @@ private extension FMPhotoPickerViewController {
func initializeViews() {
let headerView = UIView()
headerView.backgroundColor = .white
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
headerView.backgroundColor = .black
} else {
headerView.backgroundColor = .white
}
} else {
headerView.backgroundColor = .white
}

headerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(headerView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ public class FMImageEditorViewController: UIViewController {
public override func loadView() {
view = UIView()
view.backgroundColor = .white
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
self.view.backgroundColor = .black
} else {
self.view.backgroundColor = .white
}
} else {
self.view.backgroundColor = .white
}
setupView()
}

Expand All @@ -181,6 +190,7 @@ public class FMImageEditorViewController: UIViewController {
appliedCrop: fmPhotoAsset.getAppliedCrop(),
appliedCropArea: fmPhotoAsset.getAppliedCropArea())
cropView.foregroundView.eclipsePreviewEnabled = config.eclipsePreviewEnabled
cropView.backgroundColor = .red

view.addSubview(cropView)
view.sendSubviewToBack(cropView)
Expand Down Expand Up @@ -501,7 +511,16 @@ private extension FMImageEditorViewController {
func setupView() {
let headerView = UIView()
self.headerView = headerView
headerView.backgroundColor = .white

if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
headerView.backgroundColor = .black
} else {
headerView.backgroundColor = .white
}
} else {
headerView.backgroundColor = .white
}

headerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(headerView)
Expand Down Expand Up @@ -564,7 +583,16 @@ private extension FMImageEditorViewController {

let bottomViewContainer = UIView()
self.bottomViewContainer = bottomViewContainer
bottomViewContainer.backgroundColor = .white

if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
bottomViewContainer.backgroundColor = .black
} else {
bottomViewContainer.backgroundColor = .white
}
} else {
bottomViewContainer.backgroundColor = .white
}

bottomViewContainer.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bottomViewContainer)
Expand Down Expand Up @@ -608,12 +636,21 @@ private extension FMImageEditorViewController {
bottomMenuContainer.addArrangedSubview(filterMenuButton)
} else {
bottomMenuContainer.addArrangedSubview(filterMenuButton)
bottomMenuContainer.addArrangedSubview(cropMenuButton)
bottomMenuContainer.addArrangedSubview(cropMenuButton)
}

let subMenuContainer = UIView()
self.subMenuContainer = subMenuContainer
subMenuContainer.backgroundColor = .white

if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
subMenuContainer.backgroundColor = .black
} else {
subMenuContainer.backgroundColor = .white
}
} else {
subMenuContainer.backgroundColor = .white
}

subMenuContainer.translatesAutoresizingMaskIntoConstraints = false
bottomViewContainer.addSubview(subMenuContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,17 @@ class FMCropView: UIView {
cropBoxView = FMCropCropBoxView(cropRatio: nil)

foregroundView = FMCropForegroundView(image: image)
translucencyView = FMCropTranslucencyView(effect: UIBlurEffect(style: .light))


if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
translucencyView = FMCropTranslucencyView(effect: UIBlurEffect(style: .dark))
} else {
translucencyView = FMCropTranslucencyView(effect: UIBlurEffect(style: .light))
}
} else {
translucencyView = FMCropTranslucencyView(effect: UIBlurEffect(style: .light))
}

cornersView = FMCropCropBoxCornersView()

Expand Down Expand Up @@ -126,6 +136,9 @@ class FMCropView: UIView {
translucencyView.insert(toView: self)
translucencyView.isUserInteractionEnabled = false


foregroundView.backgroundColor = .blue

addSubview(whiteBackgroundView)
addSubview(foregroundView)
addSubview(cropBoxView)
Expand Down Expand Up @@ -205,7 +218,7 @@ class FMCropView: UIView {
}

//The scale we need to scale up the crop box to fit full screen
let cropBoxScale = min(contentFrame.width / cropFrame.width, contentFrame.height / cropFrame.height)
let cropBoxScale = min(contentFrame.width / cropFrame.width, contentFrame.height / cropFrame.height)

// calculate new cropFrame that is translated to center of contentBound
cropFrame.size.width = cropFrame.size.width * cropBoxScale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ class FMPhotoPresenterViewController: UIViewController {

override func loadView() {
view = UIView()
view.backgroundColor = .white
// view.backgroundColor = .white
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
self.view.backgroundColor = .black
} else {
self.view.backgroundColor = .white
}
} else {
self.view.backgroundColor = .white
}
setupView()
}

Expand Down Expand Up @@ -318,7 +327,15 @@ private extension FMPhotoPresenterViewController {
// private weak var unsafeAreaBottomView: UIView!

let headerView = UIView()
headerView.backgroundColor = .white
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
headerView.backgroundColor = .black
} else {
headerView.backgroundColor = .white
}
} else {
headerView.backgroundColor = .white
}

headerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(headerView)
Expand Down Expand Up @@ -484,6 +501,16 @@ private extension FMPhotoPresenterViewController {
let bottomViewContainer = UIView()
self.bottomViewContainer = bottomViewContainer
bottomViewContainer.backgroundColor = .white
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
bottomViewContainer.backgroundColor = .black
} else {
bottomViewContainer.backgroundColor = .white
}
} else {
bottomViewContainer.backgroundColor = .white
}


bottomViewContainer.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bottomViewContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ class FMPresenterEditMenuView: UIView {
editButton.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
// editButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 80).isActive = true
editButton.heightAnchor.constraint(greaterThanOrEqualToConstant: 40).isActive = true
editButton.setTitleColor(.black, for: .normal)
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
editButton.setTitleColor(.white, for: .normal)
} else {
editButton.setTitleColor(.black, for: .normal)
}
} else {
editButton.setTitleColor(.black, for: .normal)
}

editButton.setTitle(config.strings["present_button_edit_image"], for: .normal)
editButton.titleLabel?.font = UIFont.systemFont(ofSize: config.titleFontSize, weight: .bold)

Expand Down
63 changes: 59 additions & 4 deletions FMPhotoPicker/FMPhotoPicker/source/Utilities/Const.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,65 @@ internal let kKeyframeAnimationDuration: Double = 2.0

internal let kRedColor = UIColor(red: 1, green: 81/255, blue: 81/255, alpha: 1)
internal let kGrayColor = UIColor(red: 114/255, green: 114/255, blue: 114/255, alpha: 1)
internal let kBlackColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
internal let kBackgroundColor = UIColor(red: 242/255, green: 242/255, blue: 242/255, alpha: 1)
internal let kTransparentBackgroundColor = UIColor(white: 1, alpha: 0.9)
internal let kBorderColor = UIColor(red: 221/255, green: 221/255, blue: 221/255, alpha: 1)
internal var kBlackColor: UIColor = {
if #available(iOS 13, *) {
return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
if UITraitCollection.userInterfaceStyle == .dark {
return UIColor.white
} else {
return UIColor(red: 0, green: 0, blue: 0, alpha: 1)
}
}
} else {
return UIColor(red: 0, green: 0, blue: 0, alpha: 1)
}
}()

internal var kBackgroundColor: UIColor = {
if #available(iOS 13, *) {
return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
if UITraitCollection.userInterfaceStyle == .dark {
return UIColor.black
} else {
return UIColor(red: 242/255, green: 242/255, blue: 242/255, alpha: 1)

}
}
} else {
return UIColor(red: 242/255, green: 242/255, blue: 242/255, alpha: 1)

}
}()

internal var kTransparentBackgroundColor: UIColor = {
if #available(iOS 13, *) {
return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
if UITraitCollection.userInterfaceStyle == .dark {
return UIColor.black
} else {
return UIColor(white: 1, alpha: 0.9)

}
}
} else {
return UIColor(white: 1, alpha: 0.9)

}
}()

internal var kBorderColor: UIColor = {
if #available(iOS 13, *) {
return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
if UITraitCollection.userInterfaceStyle == .dark {
return UIColor(red: 221/255, green: 221/255, blue: 221/255, alpha: 1)
} else {
return UIColor(red: 221/255, green: 221/255, blue: 221/255, alpha: 1)
}
}
} else {
return UIColor(red: 221/255, green: 221/255, blue: 221/255, alpha: 1)
}
}()

internal let kDefaultFilter = FMFilter.None
internal let kDefaultCrop = FMCrop.ratioCustom
Expand Down