Skip to content

Commit

Permalink
Merge pull request #12 from Raizlabs/feature/ateliercw/improve_readme
Browse files Browse the repository at this point in the history
Improved readme, minor project updates
  • Loading branch information
Michael Skiba authored Nov 30, 2016
2 parents d2a5097 + fa4284b commit 86f98e6
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 23 deletions.
109 changes: 100 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,127 @@
# RIGImageGallery
> An image gallery for iOS
[![Build Status](https://travis-ci.org/Raizlabs/RIGImageGallery.svg?branch=develop)](https://travis-ci.org/Raizlabs/RIGImageGallery)
[![Version](https://img.shields.io/cocoapods/v/RIGImageGallery.svg?style=flat)](http://cocoapods.org/pods/RIGImageGallery)
[![License](https://img.shields.io/cocoapods/l/RIGImageGallery.svg?style=flat)](http://cocoapods.org/pods/RIGImageGallery)
[![Platform](https://img.shields.io/cocoapods/p/RIGImageGallery.svg?style=flat)](http://cocoapods.org/pods/RIGImageGallery)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

RIGImageGallery is an image gallery for iOS written in Swift.
RIGImageGallery is a photo gallery meant to provide most of the functionality of the image gallery in the system Photos app, and handle asynchronous loading of images.

The goal is to offer sensible defaults that takes care of most of building an image gallery automatically, and offer easy, block-based customization.
This library is part of the Raizlabs Interface Guidelines, which are UI components that offer sensible defaults to help a project get off the ground quickly with components that feel native to the platform, and with easy to use customization options.

![RIGImageGallery](Resources/rig_demo.gif)

## Features

- [x] Swipe to advance
- [x] Pinch to zoom
- [x] Double tap to toggle 1:1 zoom
- [x] Single tap to hide the nav bar

## Requirements

- iOS 9.0+
- Xcode 8.0+

## Installation with CocoaPods

RIGImageGallery is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
#### CocoaPods
RIGImageGallery is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:

```ruby
pod 'RIGImageGallery'
```

## Installation with Carthage

RIGImageGallery is also compatible with [Carthage](https://github.com/Carthage/Carthage). To install it, simply add the following line to your Cartfile:
#### Carthage
Create a `Cartfile` that lists the framework and run `carthage update`. Follow the [instructions](https://github.com/Carthage/Carthage#if-youre-building-for-ios) to add `$(SRCROOT)/Carthage/Build/iOS/RIGImageGallery.framework` to an iOS project.

```ogdl
github "Raizlabs/RIGImageGallery"
```

## Author
#### Manually
1. Download all of the `.swift` files in `RIGImageGallery/` and drop them into your project.
2. Congratulations!

## Usage example

To see a complete example of using the gallery, take a look at the [sample project](https://github.com/Raizlabs/RIGImageGallery/blob/develop/RIGImageGalleryDemo/View%20Controller/ViewController.swift).

### Creating a Gallery from Image URLs

```swift
func createPhotoGallery() -> RIGImageGalleryViewController {

let urls: [URL] = [
"https://placehold.it/1920x1080",
"https://placehold.it/1080x1920",
"https://placehold.it/350x150",
"https://placehold.it/150x350",
].flatMap(URL.init(string:))

let rigItems = urls.map { _ in
RIGImageGalleryItem(placeholderImage: UIImage(named: "placeholder"))
}

let rigController = RIGImageGalleryViewController(images: rigItems)

Michael Skiba, mike.skiba@raizlabs.com
for (index, URL) in urls.enumerated() {
let request = imageSession.dataTask(with: URLRequest(url: URL)) { [weak rigController] data, _, error in
if let image = data.flatMap(UIImage.init), error == nil {
rigController?.images[index].image = image
}
}
request.resume()
}

return rigController
}
```

### Presenting and Customizing the View Controller
```swift
@objc func showGallery(_ sender: UIButton) {
let photoViewController = createPhotoGallery()
photoViewController.dismissHandler = dismissPhotoViewer
photoViewController.actionButtonHandler = actionButtonHandler
photoViewController.actionButton = UIBarButtonItem(barButtonSystemItem: .action, target: nil, action: nil)
photoViewController.traitCollectionChangeHandler = traitCollectionChangeHandler
photoViewController.countUpdateHandler = updateCount
let navigationController = UINavigationController(rootViewController: photoViewController)
present(navigationController, animated: true, completion: nil)
}

func dismissPhotoViewer(_ :RIGImageGalleryViewController) {
dismiss(animated: true, completion: nil)
}

func actionButtonHandler(_: RIGImageGalleryViewController, galleryItem: RIGImageGalleryItem) {
}

func updateCount(_ gallery: RIGImageGalleryViewController, position: Int, total: Int) {
gallery.countLabel.text = "\(position + 1) of \(total)"
}

func traitCollectionChangeHandler(_ photoView: RIGImageGalleryViewController) {
let isPhone = UITraitCollection(userInterfaceIdiom: .phone)
let isCompact = UITraitCollection(verticalSizeClass: .compact)
let allTraits = UITraitCollection(traitsFrom: [isPhone, isCompact])
photoView.doneButton = photoView.traitCollection.containsTraits(in: allTraits) ? nil : UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
}
```

## Contributing

Issues and pull requests are welcome! Please ensure that you have the latest [SwiftLint](https://github.com/realm/SwiftLint) installed before committing and that there are no style warnings generated when building.

Contributors are expected to abide by the [Contributor Covenant Code of Conduct](https://github.com/Raizlabs/RIGImageGallery/blob/develop/CONTRIBUTING.md).

## License

RIGImageGallery is available under the MIT license. See the LICENSE file for more info.

## Author

Michael Skiba, <mailto:mike.skiba@raizlabs.com> [@atelierclkwrk](https://twitter.com/atelierclkwrk)
4 changes: 2 additions & 2 deletions RIGImageGallery.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RIGImageGallery"
s.version = "0.2.0"
s.version = "0.2.1"
s.summary = "An image gallery view controller designed to work with the Raizlabs Interface Guidelines for iOS."

s.description = <<-DESC
Expand All @@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { "Michael Skiba" => "mike.skiba@raizlabs.com" }
s.source = { :git => "https://github.com/raizlabs/RIGImageGallery.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/ateliercw'
s.social_media_url = 'https://twitter.com/atelierclkwrk'

s.ios.deployment_target = '9.0'

Expand Down
6 changes: 3 additions & 3 deletions RIGImageGallery.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@
72A828061C68F24500B25CEE /* Frameworks */,
72A828071C68F24500B25CEE /* Resources */,
72BA263B1C6B97A500F1FE22 /* Embed Frameworks */,
7264CA1E1D3FC02E00033FC4 /* SwiftLint */,
);
buildRules = (
);
Expand All @@ -259,6 +258,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 72BA265B1C6B985A00F1FE22 /* Build configuration list for PBXNativeTarget "RIGImageGallery" */;
buildPhases = (
72D1B9C71DECB5D60049F060 /* SwiftLint */,
72BA264D1C6B985900F1FE22 /* Sources */,
72BA264E1C6B985900F1FE22 /* Frameworks */,
72BA264F1C6B985900F1FE22 /* Headers */,
Expand Down Expand Up @@ -360,7 +360,7 @@
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
7264CA1E1D3FC02E00033FC4 /* SwiftLint */ = {
72D1B9C71DECB5D60049F060 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -372,7 +372,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
shellScript = "if which swiftlint >/dev/null; then\nswiftlint || echo \"warning: SwiftLint failed with exit code $?. Is SwiftLint installed and up to date?\"\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
7 changes: 4 additions & 3 deletions RIGImageGallery/RIGImageGalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ open class RIGImageGalleryViewController: UIPageViewController {
self.images = images
}


public override init(transitionStyle style: UIPageViewControllerTransitionStyle, navigationOrientation: UIPageViewControllerNavigationOrientation, options: [String : Any]?) {
super.init(transitionStyle: style, navigationOrientation: navigationOrientation, options: options)
dataSource = self
Expand Down Expand Up @@ -305,8 +304,10 @@ private extension RIGImageGalleryViewController {
for viewController in childViewControllers {
if let index = indexOf(viewController: viewController, imagesArray: oldValue),
let childView = viewController as? RIGSingleImageViewController, index < images.count {
childView.viewerItem = images[index]
childView.scrollView.baseInsets = scrollViewInset
DispatchQueue.main.async { [unowned self] in
childView.viewerItem = self.images[index]
childView.scrollView.baseInsets = self.scrollViewInset
}
}
}
updateCountText()
Expand Down
1 change: 0 additions & 1 deletion RIGImageGalleryDemo/App Delegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down
10 changes: 5 additions & 5 deletions RIGImageGalleryDemo/View Controller/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ private extension ViewController {
private extension ViewController {

static let urls: [URL] = [
URL(string: "https://placehold.it/1920x1080"),
URL(string: "https://placehold.it/1080x1920"),
URL(string: "https://placehold.it/350x150"),
URL(string: "https://placehold.it/150x350"),
].flatMap { $0 }
"https://placehold.it/1920x1080",
"https://placehold.it/1080x1920",
"https://placehold.it/350x150",
"https://placehold.it/150x350",
].flatMap(URL.init(string:))

func loadImages() -> RIGImageGalleryViewController {

Expand Down
Binary file added Resources/rig_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 86f98e6

Please sign in to comment.