Skip to content

Commit

Permalink
Merge pull request #7 from carousell/feature/rotation
Browse files Browse the repository at this point in the history
Merge branch 'feature/rotation'
  • Loading branch information
bcylin committed Jun 30, 2017
2 parents 082bc67 + d0bfa99 commit 7d59aa0
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* Initial release written in Swift 3.1
* Integrate with Travis CI [#1](https://github.com/carousell/pickle/pull/1)
* Support 3D touch photo preview [#3](https://github.com/carousell/pickle/pull/3)
* Support device rotation [#7](https://github.com/carousell/pickle/pull/7)
* Show the camera button in the center when the photo gallery is empty [#8](https://github.com/carousell/pickle/pull/8)
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Feedback

We'd love the feedback from you. Please create [GitHub Issues](https://github.com/carousell/pickle/issues) for feature discussions, bug reports and anything you'd like us to know. Be sure to check out the [closed issues](https://github.com/carousell/pickle/issues?q=is:closed) before you open new ones.

## Contributing

1. Fork the repo.

2. Create a local feature branch from the latest `master`, prefix it with **feature/** and use **hyphen-separated-words** to name your branch:

```sh
git checkout -b feature/your-branch
```

3. Add your changes and push it to your fork

4. Create a pull request

## Dependencies

CocoaPods is used to set up the example project. Follow the [instruction](https://guides.cocoapods.org/using/getting-started.html#installation) to install it before you set up the project by running `make bootstrap`.

**Pickle** uses Ruby 2.3.4 and [Bundler](http://bundler.io/) to manage dependencies on Travis CI. It's not required locally. However if you have Ruby environment set up, additional tools are specified in the [Gemfile](https://github.com/carousell/pickle/blob/master/Gemfile).
43 changes: 43 additions & 0 deletions Example/Pickle/CarousellImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,45 @@ internal class CarousellImagePickerController: ImagePickerController {
configuration: CarousellTheme(),
camera: UIImagePickerController.init
)

hint = {
let titleStyle = NSMutableParagraphStyle()
titleStyle.maximumLineHeight = 42
titleStyle.minimumLineHeight = 42
titleStyle.paragraphSpacing = 4
titleStyle.firstLineHeadIndent = 12
titleStyle.alignment = .left

let subtitleStyle = NSMutableParagraphStyle()
subtitleStyle.maximumLineHeight = 12
subtitleStyle.minimumLineHeight = 12
subtitleStyle.paragraphSpacing = 10
subtitleStyle.firstLineHeadIndent = 12
subtitleStyle.alignment = .left

let title = NSMutableAttributedString(
string: "What are you listing?\n",
attributes: [
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 22),
NSForegroundColorAttributeName: UIColor.black,
NSBackgroundColorAttributeName: UIColor.white,
NSParagraphStyleAttributeName: titleStyle
]
)

let subtitle = NSAttributedString(
string: "You can choose up to 4 photos for your listing.\n",
attributes: [
NSFontAttributeName: UIFont.systemFont(ofSize: 12),
NSForegroundColorAttributeName: UIColor.darkGray,
NSBackgroundColorAttributeName: UIColor.white,
NSParagraphStyleAttributeName: subtitleStyle
]
)

title.append(subtitle)
return title
}()
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -56,4 +95,8 @@ private struct CarousellTheme: ImagePickerConfigurable {
var selectedImageOverlayColor: UIColor? = nil
let allowedSelections: ImagePickerSelection? = .limit(to: 4)

// MARK: -

let hintTextMargin: UIEdgeInsets? = .zero

}
1 change: 1 addition & 0 deletions Example/Pickle/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
5 changes: 5 additions & 0 deletions Pickle/Classes/ImagePickerConfigurable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public protocol ImagePickerConfigurable {

/// Specifies the number of photo selections is allowed in ImagePickerController.
var allowedSelections: ImagePickerSelection? { get }

// MARK: -

/// The margin for the text of the hint label.
var hintTextMargin: UIEdgeInsets? { get }
}


Expand Down
7 changes: 5 additions & 2 deletions Pickle/Classes/PhotoGalleryHintLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ internal final class PhotoGalleryHintLabel: UILabel {
setUpAppearance()
}

// MARK: - Properties

internal var textMargin = UIEdgeInsets(top: 6, left: 0, bottom: 6, right: 0)

// MARK: - UIView

override var bounds: CGRect {
Expand Down Expand Up @@ -54,8 +58,7 @@ internal final class PhotoGalleryHintLabel: UILabel {
// MARK: - Private

private var contentEdgeInsets: UIEdgeInsets {
let padding: CGFloat = (text?.isEmpty ?? true) ? 0 : 6
return UIEdgeInsets(top: padding, left: 0, bottom: padding, right: 0)
return (text?.isEmpty ?? true) ? .zero : textMargin
}

private lazy var borderLayer: CALayer = {
Expand Down
36 changes: 23 additions & 13 deletions Pickle/Classes/PhotoGalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ internal final class PhotoGalleryViewController: UIViewController,
}
set {
hintLabel.attributedText = newValue
if let margin = configuration?.hintTextMargin {
hintLabel.textMargin = margin
}
if let color = newValue?.attributes?[NSBackgroundColorAttributeName] as? UIColor {
hintLabel.backgroundColor = color
}
Expand Down Expand Up @@ -81,7 +84,7 @@ internal final class PhotoGalleryViewController: UIViewController,
return PHAsset.fetchAssets(in: self.album, options: options)
}()

private lazy var hintLabel: UILabel = PhotoGalleryHintLabel()
private lazy var hintLabel: PhotoGalleryHintLabel = PhotoGalleryHintLabel()

private var _emptyView: UIView?

Expand All @@ -98,7 +101,8 @@ internal final class PhotoGalleryViewController: UIViewController,
}

internal private(set) lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: photoGalleryLayout)
let layout = self.photoGalleryLayout(for: UIScreen.main.bounds.size)
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.backgroundColor = UIColor.white
Expand All @@ -108,17 +112,6 @@ internal final class PhotoGalleryViewController: UIViewController,
return collectionView
}()

private class var photoGalleryLayout: UICollectionViewFlowLayout {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.sectionInset = UIEdgeInsets.zero
layout.minimumInteritemSpacing = 1
layout.minimumLineSpacing = 1
let itemWidth = (UIScreen.main.bounds.width - layout.minimumInteritemSpacing * 2) / 3
layout.itemSize = CGSize(width: itemWidth, height: itemWidth)
return layout
}

// MARK: - UIViewController

override func viewDidLoad() {
Expand All @@ -133,6 +126,10 @@ internal final class PhotoGalleryViewController: UIViewController,
}
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
collectionView.collectionViewLayout = photoGalleryLayout(for: size)
}

// MARK: - UICollectionViewDataSource

internal func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
Expand Down Expand Up @@ -219,6 +216,19 @@ internal final class PhotoGalleryViewController: UIViewController,

// MARK: - Private

private func photoGalleryLayout(for size: CGSize) -> UICollectionViewFlowLayout {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.sectionInset = UIEdgeInsets.zero
layout.minimumInteritemSpacing = 1
layout.minimumLineSpacing = 1
let estimatedWidth: CGFloat = 105
let numberOfColumns = max(1, floor(size.width / estimatedWidth))
let itemWidth = (size.width - layout.minimumInteritemSpacing * numberOfColumns - 1) / numberOfColumns
layout.itemSize = CGSize(width: itemWidth, height: itemWidth)
return layout
}

private func setUpSubviews() {
view.backgroundColor = UIColor.white
view.addSubview(hintLabel)
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Follow the [instructions](https://github.com/Carthage/Carthage#adding-frameworks
github "carousell/pickle" ~> 1.0.0
```

## Development
## Example

Install [CocoaPods](https://guides.cocoapods.org/using/getting-started.html#installation):

Expand All @@ -128,15 +128,19 @@ gem install cocoapods

Set up the development pods:

```shell
```sh
pod install --project-directory=Example && open Example/Pickle.xcworkspace
```

## Contributing

Thank you for being interested in contributing to this project. Check out the [CONTRIBUTING](https://github.com/carousell/pickle/blob/master/CONTRIBUTING.md) document for more info.

## About

<a href="https://github.com/carousell/" target="_blank"><img src="https://avatars2.githubusercontent.com/u/3833591" width="100px" alt="Carousell" align="right"/></a>

**Pickle** is created and maintained by [Carousell](https://carousell.com/). Help us improve this project! We'd love to hear your [feedback](https://github.com/carousell/pickle/issues).
**Pickle** is created and maintained by [Carousell](https://carousell.com/). Help us improve this project! We'd love the [feedback](https://github.com/carousell/pickle/issues) from you.

We're hiring! Find out more at <http://careers.carousell.com/>

Expand Down

0 comments on commit 7d59aa0

Please sign in to comment.