Skip to content

Instantly share code, notes, and snippets.

cell.completedClosure = { listItem in
self.decorateReadyToMove(for: cell, andAngle: 0.0)
cell.leadingConstraint.constant = 0
cell.trailingConstraint.constant = 0
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .curveLinear, animations: {
cell.layoutIfNeeded()
}, completion: { (_) in
if(listItem.isCompleted) {
cell.trailingConstraint.constant = cell.frame.width - self.markerWidth
} else {
func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
let item = listItemDataset.item(at: indexPath.row)
return !item.isCompleted
}
func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
listItemDataset.moveItem(from: sourceIndexPath.row, to: destinationIndexPath.row)
}
func handleLongGesture(gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
//-----
case .ended:
if let cell = self.movingCell {
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .curveEaseIn, animations: {
self.decorateResting(for: cell)
}, completion: { (_) in
})
func handleLongGesture(gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
//---
case .changed:
let changedTo: CGPoint = gesture.location(in: collectionView)
if let hitIndexpath = self.collectionView.indexPathForItem(at: changedTo) {
let item = listItemDataset.item(at: hitIndexpath.row)
if !item.isCompleted {
collectionView.updateInteractiveMovementTargetPosition(changedTo)
if let cell = movingCell {
func handleLongGesture(gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
case .began:
movementStartLocation = gesture.location(in: collectionView)
if let indexPath = self.collectionView.indexPathForItem(at: movementStartLocation!) {
let cell = self.collectionView.cellForItem(at: indexPath) as! ListItemCell
if let item = cell.listItem {
if !item.isCompleted {
let canBegin = collectionView.beginInteractiveMovementForItem(at: indexPath)
if canBegin {
package is.uncommon.playbook.android.motion;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.graphics.Outline;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View android:id="@+id/fab" android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|right"
package is.uncommon.playbook.android.motion;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.support.v7.app.AppCompatActivity;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="is.uncommon.playbook.android.motion.MainActivity">
package is.uncommon.playbook.android.motion;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;