From b8a814993007496142e051980544fce331c1481d Mon Sep 17 00:00:00 2001 From: Jonathan Willing Date: Tue, 8 Oct 2013 12:52:04 -0500 Subject: [PATCH 1/3] add an empty abstract reorderable layout class --- JNWCollectionView.xcodeproj/project.pbxproj | 8 +++++++ .../JNWCollectionViewReorderableLayout.h | 24 +++++++++++++++++++ .../JNWCollectionViewReorderableLayout.m | 24 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 JNWCollectionView/JNWCollectionViewReorderableLayout.h create mode 100644 JNWCollectionView/JNWCollectionViewReorderableLayout.m diff --git a/JNWCollectionView.xcodeproj/project.pbxproj b/JNWCollectionView.xcodeproj/project.pbxproj index cab8531..673599e 100644 --- a/JNWCollectionView.xcodeproj/project.pbxproj +++ b/JNWCollectionView.xcodeproj/project.pbxproj @@ -21,6 +21,8 @@ AB38E39017DF099A00D50B3C /* JNWScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = AB38E38C17DF099A00D50B3C /* JNWScrollView.h */; settings = {ATTRIBUTES = (Public, ); }; }; AB38E39117DF099A00D50B3C /* JNWScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = AB38E38D17DF099A00D50B3C /* JNWScrollView.m */; }; AB39819D1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = AB39819C1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h */; }; + AB3A2E3C18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = AB3A2E3A18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + AB3A2E3D18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = AB3A2E3B18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m */; }; AB3C71F4170CA8D3004A91DB /* JNWCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = AB3C71E8170CA8D3004A91DB /* JNWCollectionView.h */; settings = {ATTRIBUTES = (Public, ); }; }; AB3C71F5170CA8D3004A91DB /* JNWCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = AB3C71E9170CA8D3004A91DB /* JNWCollectionView.m */; }; AB3C71F7170CA8D3004A91DB /* JNWCollectionView+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = AB3C71EA170CA8D3004A91DB /* JNWCollectionView+Private.h */; }; @@ -144,6 +146,8 @@ AB38E38C17DF099A00D50B3C /* JNWScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWScrollView.h; path = external/JNWScrollView/JNWScrollView.h; sourceTree = SOURCE_ROOT; }; AB38E38D17DF099A00D50B3C /* JNWScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWScrollView.m; path = external/JNWScrollView/JNWScrollView.m; sourceTree = SOURCE_ROOT; }; AB39819C1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionViewReusableView+Private.h"; path = "JNWCollectionView/JNWCollectionViewReusableView+Private.h"; sourceTree = SOURCE_ROOT; }; + AB3A2E3A18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionViewReorderableLayout.h; path = JNWCollectionView/JNWCollectionViewReorderableLayout.h; sourceTree = SOURCE_ROOT; }; + AB3A2E3B18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionViewReorderableLayout.m; path = JNWCollectionView/JNWCollectionViewReorderableLayout.m; sourceTree = SOURCE_ROOT; }; AB3C71E8170CA8D3004A91DB /* JNWCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionView.h; path = JNWCollectionView/JNWCollectionView.h; sourceTree = SOURCE_ROOT; }; AB3C71E9170CA8D3004A91DB /* JNWCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionView.m; path = JNWCollectionView/JNWCollectionView.m; sourceTree = SOURCE_ROOT; }; AB3C71EA170CA8D3004A91DB /* JNWCollectionView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionView+Private.h"; path = "JNWCollectionView/JNWCollectionView+Private.h"; sourceTree = SOURCE_ROOT; }; @@ -243,6 +247,8 @@ AB1514731714D39600871248 /* JNWCollectionViewListLayout.m */, AB1514801715361D00871248 /* JNWCollectionViewGridLayout.h */, AB1514811715361D00871248 /* JNWCollectionViewGridLayout.m */, + AB3A2E3A18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h */, + AB3A2E3B18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m */, ); name = Layouts; sourceTree = ""; @@ -379,6 +385,7 @@ AB1514821715361E00871248 /* JNWCollectionViewGridLayout.h in Headers */, AB1514741714D39600871248 /* JNWCollectionViewListLayout.h in Headers */, AB3C7202170CA8D3004A91DB /* NSIndexPath+JNWAdditions.h in Headers */, + AB3A2E3C18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h in Headers */, AB38E38E17DF099A00D50B3C /* JNWClipView.h in Headers */, AB38E39017DF099A00D50B3C /* JNWScrollView.h in Headers */, AB3C71F7170CA8D3004A91DB /* JNWCollectionView+Private.h in Headers */, @@ -574,6 +581,7 @@ AB3C7203170CA8D3004A91DB /* NSIndexPath+JNWAdditions.m in Sources */, AB38E39117DF099A00D50B3C /* JNWScrollView.m in Sources */, AB1514701714C90800871248 /* JNWCollectionViewLayout.m in Sources */, + AB3A2E3D18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m in Sources */, AB1514751714D39600871248 /* JNWCollectionViewListLayout.m in Sources */, AB1514831715361E00871248 /* JNWCollectionViewGridLayout.m in Sources */, ABA276B3171D1C4B005C8E56 /* JNWCollectionViewDocumentView.m in Sources */, diff --git a/JNWCollectionView/JNWCollectionViewReorderableLayout.h b/JNWCollectionView/JNWCollectionViewReorderableLayout.h new file mode 100644 index 0000000..867c056 --- /dev/null +++ b/JNWCollectionView/JNWCollectionViewReorderableLayout.h @@ -0,0 +1,24 @@ +/* + Copyright (c) 2013, Jonathan Willing. All rights reserved. + Licensed under the MIT license + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + documentation files (the "Software"), to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions + of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + */ + +#import + +@interface JNWCollectionViewReorderableLayout : JNWCollectionViewLayout + +@end diff --git a/JNWCollectionView/JNWCollectionViewReorderableLayout.m b/JNWCollectionView/JNWCollectionViewReorderableLayout.m new file mode 100644 index 0000000..5c624ec --- /dev/null +++ b/JNWCollectionView/JNWCollectionViewReorderableLayout.m @@ -0,0 +1,24 @@ +/* + Copyright (c) 2013, Jonathan Willing. All rights reserved. + Licensed under the MIT license + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + documentation files (the "Software"), to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions + of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + */ + +#import "JNWCollectionViewReorderableLayout.h" + +@implementation JNWCollectionViewReorderableLayout + +@end From 154ae79079da700fd40d78052cbbedbd81bdf895 Mon Sep 17 00:00:00 2001 From: Jonathan Willing Date: Tue, 8 Oct 2013 12:53:24 -0500 Subject: [PATCH 2/3] make the grid and list layouts inherit from the reorderable layout --- JNWCollectionView/JNWCollectionViewGridLayout.h | 4 ++-- JNWCollectionView/JNWCollectionViewListLayout.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/JNWCollectionView/JNWCollectionViewGridLayout.h b/JNWCollectionView/JNWCollectionViewGridLayout.h index 377f83c..5e3df73 100644 --- a/JNWCollectionView/JNWCollectionViewGridLayout.h +++ b/JNWCollectionView/JNWCollectionViewGridLayout.h @@ -17,7 +17,7 @@ IN THE SOFTWARE. */ -#import "JNWCollectionViewLayout.h" +#import // The supplementary view kind identifiers used for the header and the footer. extern NSString * const JNWCollectionViewGridLayoutHeaderKind; @@ -43,7 +43,7 @@ extern NSString * const JNWCollectionViewGridLayoutFooterKind; // A layout subclass that displays items in an evenly spaced grid. All items // have the same size, and are evenly spaced apart from each other. -@interface JNWCollectionViewGridLayout : JNWCollectionViewLayout +@interface JNWCollectionViewGridLayout : JNWCollectionViewReorderableLayout // The delegate for the grid layout. The delegate, if needed, should be set before // the collection view is reloaded. diff --git a/JNWCollectionView/JNWCollectionViewListLayout.h b/JNWCollectionView/JNWCollectionViewListLayout.h index e839212..4c29701 100644 --- a/JNWCollectionView/JNWCollectionViewListLayout.h +++ b/JNWCollectionView/JNWCollectionViewListLayout.h @@ -17,7 +17,7 @@ IN THE SOFTWARE. */ -#import "JNWCollectionViewLayout.h" +#import // The supplementary view kind identifiers used for the header and the footer. extern NSString * const JNWCollectionViewListLayoutHeaderKind; @@ -44,7 +44,7 @@ extern NSString * const JNWCollectionViewListLayoutFooterKind; // A layout subclass that displays items in a vertical list with rows of // items, similar to a table view. -@interface JNWCollectionViewListLayout : JNWCollectionViewLayout +@interface JNWCollectionViewListLayout : JNWCollectionViewReorderableLayout // The delegate for the list layout. The delegate, if needed, should be set before // the collection view is reloaded. From ced22ff7da46032d225009c49857ae3503fbaa1e Mon Sep 17 00:00:00 2001 From: Jonathan Willing Date: Tue, 8 Oct 2013 13:26:47 -0500 Subject: [PATCH 3/3] add a bit of proposed API for the drag and drop layout --- .../JNWCollectionViewReorderableLayout.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/JNWCollectionView/JNWCollectionViewReorderableLayout.h b/JNWCollectionView/JNWCollectionViewReorderableLayout.h index 867c056..1d84db1 100644 --- a/JNWCollectionView/JNWCollectionViewReorderableLayout.h +++ b/JNWCollectionView/JNWCollectionViewReorderableLayout.h @@ -19,6 +19,36 @@ #import +typedef NS_ENUM(NSInteger, JNWReorderingType) { + JNWReorderingTypeDisplacement, + JNWReorderingTypeMarker +}; + @interface JNWCollectionViewReorderableLayout : JNWCollectionViewLayout +// Determines how the layout should handle reordering. +// +// Reordering by displacement (JNWReorderingTypeDisplacement) occurs by +// determining which cell is closest to the item that is being dragged +// within the bounds of the collection view, and swapping its position +// with that of the nearby item. +// +// Reordering by marker (JNWReorderingTypeMarker) occurs by drawing a +// marker to indicate the proposed drop position. The position of the marker +// is determined by the frame returned from -markerRect. +// +// Defaults to JNWReorderingTypeDisplacement. +@property (nonatomic, assign) JNWReorderingType reorderingType; + +// The rect in which the drop marker should be placed. This is only utilized +// if the reorderingType is JNWReorderingTypeMarker. +// +// Specified relative the scroll view, not the visible frame. +// +// Defaults to CGRectZero. +- (CGRect)markerRect; + +// The fill color of the marker. +- (NSColor *)markerColor; + @end