Skip to content

Commit

Permalink
Merge pull request #9 from carousell/feature/photo-albums-layout
Browse files Browse the repository at this point in the history
Photo Albums Layout
  • Loading branch information
bcylin authored Jul 17, 2017
2 parents bc84776 + 48f90fb commit c37e53b
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 210 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ cache:
directories:
- vendor/bundle
- Example/Pods/SwiftLint
before_install:
- xcrun instruments -s devices
- xcrun instruments -w "iPhone 7 (10.3.1) [" || true
install:
- bundle install --jobs=3 --retry=3 --deployment
- bundle exec pod install --project-directory=Example
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## Next Release

* Add a configuration for the photo albums navigation bar shadow color [#9](https://github.com/carousell/pickle/pull/9)
* Fix the photo albums layout after device rotation [#9](https://github.com/carousell/pickle/pull/9)

## v1.0.0

* Initial release written in Swift 3.1
Expand Down
3 changes: 1 addition & 2 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ end

# Review duty
members = ENV["IOS_TEAM"] ? github.api.team_members(ENV["IOS_TEAM"]).map(&:login) : []
contributors = github.api.contributors(repo).map(&:login)
reviewer = (contributors & members - [github.pr_author]).sample
reviewer = (members - [github.pr_author]).sample
assigned = github.api.issue_comments(repo, pr_number).map(&:body).any? { |m| m.end_with? "can you review this pull request?" }

if reviewer && !assigned
Expand Down
1 change: 1 addition & 0 deletions Example/Pickle/CarousellImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private struct CarousellTheme: ImagePickerConfigurable {
let navigationBarTranslucent: Bool? = false
let navigationBarTintColor: UIColor? = .white
let navigationBarBackgroundColor: UIColor? = UIColor(red: 0xD2 / 255.0, green: 0x23 / 255.0, blue: 0x2A / 255.0, alpha: 1)
let photoAlbumsNavigationBarShadowColor: UIColor? = .clear

// MARK: - Navigation Bar Title View

Expand Down
410 changes: 207 additions & 203 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build:
set -o pipefail && xcodebuild -workspace Example/Pickle.xcworkspace -scheme Pickle clean build | bundle exec xcpretty -c

test:
set -o pipefail && xcodebuild -workspace Example/Pickle.xcworkspace -scheme Pickle-Example -sdk iphonesimulator -destination 'name=iPhone SE,OS=10.3.1' clean test | bundle exec xcpretty -c
set -o pipefail && xcodebuild -workspace Example/Pickle.xcworkspace -scheme Pickle-Example -sdk iphonesimulator -destination 'name=iPhone 7,OS=10.3.1' clean test | bundle exec xcpretty -c

bump:
ifeq (,$(strip $(version)))
Expand Down
3 changes: 3 additions & 0 deletions Pickle/Classes/ImagePickerConfigurable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public protocol ImagePickerConfigurable {
/// The navigation bar background color (barTintColor).
var navigationBarBackgroundColor: UIColor? { get }

/// The color of navigation bar 1px shadow when the album list is presented.
var photoAlbumsNavigationBarShadowColor: UIColor? { get }

// MARK: - Navigation Bar Title View

/// The font for the navigation title view.
Expand Down
55 changes: 55 additions & 0 deletions Pickle/Classes/PhotoAlbumsTableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// This source file is part of the carousell/pickle open source project
//
// Copyright © 2017 Carousell and the project authors
// Licensed under Apache License v2.0
//
// See https://github.com/carousell/pickle/blob/master/LICENSE for license information
// See https://github.com/carousell/pickle/graphs/contributors for the list of project authors
//

import UIKit

internal final class PhotoAlbumsTableView: UITableView {

// MARK: - Initialization

convenience init(configuration: ImagePickerConfigurable? = nil) {
self.init(frame: .zero, style: .plain)

let color = configuration?.photoAlbumsNavigationBarShadowColor
guard color != .clear else {
return
}

layer.addSublayer(shadawLayer)
shadawLayer.borderColor = color?.cgColor ?? UIColor.Palette.magnesium.cgColor
}

// MARK: - Properties

private var _shadawLayer: CALayer?

private var shadawLayer: CALayer {
if let instantiated = _shadawLayer {
return instantiated
}

let layer = CALayer()
layer.borderWidth = 1 / UIScreen.main.scale
layer.rasterizationScale = UIScreen.main.scale
layer.shouldRasterize = true

_shadawLayer = layer
return layer
}

// MARK: - UIView

override var frame: CGRect {
didSet {
_shadawLayer?.frame = bounds.insetBy(dx: -1, dy: -1).offsetBy(dx: 0, dy: 1)
}
}

}
2 changes: 1 addition & 1 deletion Pickle/Classes/PhotoAlbumsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal final class PhotoAlbumsViewController: UIViewController, UITableViewDat
private let configuration: ImagePickerConfigurable?

private(set) lazy var tableView: UITableView = {
let tableView = UITableView(frame: CGRect.zero, style: .plain)
let tableView = PhotoAlbumsTableView(configuration: self.configuration)
tableView.dataSource = self
tableView.delegate = self
return tableView
Expand Down
26 changes: 23 additions & 3 deletions Pickle/Classes/SlideUpPresentationController.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
//
// Copyright © 2017 Carousell. All rights reserved.
// This source file is part of the carousell/pickle open source project
//
// Copyright © 2017 Carousell and the project authors
// Licensed under Apache License v2.0
//
// See https://github.com/carousell/pickle/blob/master/LICENSE for license information
// See https://github.com/carousell/pickle/graphs/contributors for the list of project authors
//

import UIKit

internal final class SlideUpPresentationController: UIPresentationController {

override func presentationTransitionWillBegin() {
adjustContainerFrame()
}

// MARK: - UITraitEnvironment

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
if previousTraitCollection != nil {
// Update the frame for the container view after device rotation.
adjustContainerFrame()
}
}

// MARK: - Private

private func adjustContainerFrame() {
// Calculate the presented frame that doesn't cover the navigation bar.
let targetFrame: CGRect
let shadow = 1 / UIScreen.main.scale

if let navigationBar = presentingViewController.view.subviews.filter({ $0 is UINavigationBar }).first {
targetFrame = presentingViewController.view.frame.divided(atDistance: navigationBar.frame.maxY + shadow, from: .minYEdge).remainder
targetFrame = presentingViewController.view.frame.divided(atDistance: navigationBar.frame.maxY, from: .minYEdge).remainder
} else {
targetFrame = presentingViewController.view.frame
}
Expand Down
1 change: 1 addition & 0 deletions Pickle/Classes/UIColor+Palette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal extension UIColor {
static let lightGray = UIColor(hex: 0x8F939C)
static let gray = UIColor(hex: 0x8F939C)
static let darkGray = UIColor(hex: 0x8F939C)
static let magnesium = UIColor(hex: 0xB2B2B2)
}

internal convenience init(hex: Int) {
Expand Down

0 comments on commit c37e53b

Please sign in to comment.