{"id":16482786,"url":"https://github.com/shaps80/snaply","last_synced_at":"2025-08-02T13:43:02.907Z","repository":{"id":62455709,"uuid":"65079147","full_name":"shaps80/Snaply","owner":"shaps80","description":"Drop-in snapping behaviour for any scroll/collection/table/view using arbitrary points!","archived":false,"fork":false,"pushed_at":"2017-11-21T16:12:33.000Z","size":530,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T07:23:12.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaps80.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-06T11:15:58.000Z","updated_at":"2023-05-04T14:49:18.000Z","dependencies_parsed_at":"2022-11-01T23:46:35.994Z","dependency_job_id":null,"html_url":"https://github.com/shaps80/Snaply","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FSnaply","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FSnaply/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FSnaply/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FSnaply/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaps80","download_url":"https://codeload.github.com/shaps80/Snaply/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238535885,"owners_count":19488613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T13:12:01.783Z","updated_at":"2025-02-12T19:31:10.039Z","avatar_url":"https://github.com/shaps80.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snap\n\n[![Version](https://img.shields.io/cocoapods/v/Snaply.svg?style=flat)](http://cocoapods.org/pods/Snaply)\n[![License](https://img.shields.io/cocoapods/l/Snaply.svg?style=flat)](http://cocoapods.org/pods/Snaply)\n[![Language](https://img.shields.io/badge/language-swift_2.2-ff69b4.svg)](http://cocoadocs.org/docsets/Snaply)\n[![Platform](https://img.shields.io/cocoapods/p/Snaply.svg?style=flat)](http://cocoapods.org/pods/Snaply)\n\n## Usage\n\nThe example project includes an example of a UICollectionViewFlowLayout including support for sections and spacing. It also includes support for snapping to the left, middle and right edges.\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth width=\"30%\"\u003eLets add snapping support to our UICollectionView\u003c/th\u003e\n\u003cth width=\"30%\"\u003eSnaply In Action\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eThe following code is all that's required to setup the top preview on the right.\u003c/td\u003e\n\u003cth rowspan=\"9\"\u003e\u003cimg src=\"snap.gif\"\u003e\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\u003cdiv class=\"highlight highlight-source-swift\"\u003e\u003cpre\u003e\n\nlet collectionView = UICollectionView(frame: view.bounds, \ncollectionViewLayout: UICollectionViewFlowLayout())\n\n// The delegate will automatically forward all events \n// to you existing delegate so it won't break your code :)\nlet snap = Snap(scrollView: collectionView, edge: .Min, \ndirection: .Horizontal, delegate: self)\n\nvar locations = [CGFloat]()\nvar widths = [CGFloat]()\n\nfor i in 0..\u003c20 {\n  widths.append(itemWidth)\n  let offset = layout.headerReferenceSize.width + \n  layout.sectionInset.left\n  let size = widths.reduce(offset, \n  combine: { $0 + $1 + layout.minimumInteritemSpacing })\n  locations.append(size - offset)\n}\n\nsnap.setSnapLocations(locations, realignImmediately: true)\n\n\u003c/pre\u003e\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n## How does it work\n\nIf we take a look at the following image, the red lines represent points we want our scrollView to snap to, along a given edge. So you just need to specify these points and Snaply will handle the snapping behaviour for you. Including things like finding the closest point and ensuring overscroll doens't occur.\n\n\u003cimg src=\"layout.jpg\" width=375 /\u003e\n\nTo get started, you just need a single line in your project:\n\n`snap = Snap(scrollView: collectionView, edge: .Min, direction: .Horizontal, delegate: self)`\n\nThis adds snapping to the specified collectionView, using the left edge as the snap point since we're using a horizontal layout. \n\nYou may notice we also pass along the original delegate (if any). This allows Snaply to automatically forward all events back to the original delegate to ensure no existing behaviour is effected by dropping in Snaply :)\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\nSnaply requires iOS 8+\nThe current version requires Swift 2.2\n\n## Installation\n\nSnap is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"Snaply\"\n```\n\n## Author\n\n[@shaps](http://twitter.com/shaps) on Twitter\n\n## License\n\nSnap is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fsnaply","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaps80%2Fsnaply","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fsnaply/lists"}