Skip to content

Commit

Permalink
Merge pull request #97 from jwilling/deprecate-layout-initializer
Browse files Browse the repository at this point in the history
Deprecate layout initializer
  • Loading branch information
jwilling committed Jan 25, 2014
2 parents bd11cb4 + 09027fd commit 4bdb151
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 15 deletions.
4 changes: 4 additions & 0 deletions JNWCollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
8467C6D7171E587F00A1F343 /* JNWCollectionViewReusableViewSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8467C6D6171E587F00A1F343 /* JNWCollectionViewReusableViewSpec.m */; };
8467C6FA171E58F700A1F343 /* libExpecta.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8467C6E0171E589200A1F343 /* libExpecta.a */; };
8467C6FB171E58F700A1F343 /* libSpecta.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8467C6EF171E589500A1F343 /* libSpecta.a */; };
AB0EA369189472A400E28525 /* JNWCollectionViewLayout+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = AB0EA368189472A400E28525 /* JNWCollectionViewLayout+Private.h */; };
AB15146F1714C90800871248 /* JNWCollectionViewLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = AB15146D1714C90800871248 /* JNWCollectionViewLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
AB1514701714C90800871248 /* JNWCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = AB15146E1714C90800871248 /* JNWCollectionViewLayout.m */; };
AB1514741714D39600871248 /* JNWCollectionViewListLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = AB1514721714D39600871248 /* JNWCollectionViewListLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -134,6 +135,7 @@
8467C6D8171E589200A1F343 /* Expecta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Expecta.xcodeproj; path = external/Expecta/Expecta.xcodeproj; sourceTree = SOURCE_ROOT; };
8467C6E7171E589500A1F343 /* Specta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Specta.xcodeproj; path = external/Specta/Specta.xcodeproj; sourceTree = SOURCE_ROOT; };
8467C704171E5C9B00A1F343 /* JNWCollectionViewTests-Tests.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionViewTests-Tests.pch"; path = "JNWCollectionViewTests/JNWCollectionViewTests-Tests.pch"; sourceTree = SOURCE_ROOT; };
AB0EA368189472A400E28525 /* JNWCollectionViewLayout+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionViewLayout+Private.h"; path = "JNWCollectionView/JNWCollectionViewLayout+Private.h"; sourceTree = SOURCE_ROOT; };
AB15146D1714C90800871248 /* JNWCollectionViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionViewLayout.h; path = JNWCollectionView/JNWCollectionViewLayout.h; sourceTree = SOURCE_ROOT; };
AB15146E1714C90800871248 /* JNWCollectionViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionViewLayout.m; path = JNWCollectionView/JNWCollectionViewLayout.m; sourceTree = SOURCE_ROOT; };
AB1514721714D39600871248 /* JNWCollectionViewListLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionViewListLayout.h; path = JNWCollectionView/JNWCollectionViewListLayout.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -255,6 +257,7 @@
AB3C71EA170CA8D3004A91DB /* JNWCollectionView+Private.h */,
AB3C71ED170CA8D3004A91DB /* JNWCollectionViewCell+Private.h */,
AB39819C1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h */,
AB0EA368189472A400E28525 /* JNWCollectionViewLayout+Private.h */,
);
name = Private;
sourceTree = "<group>";
Expand Down Expand Up @@ -384,6 +387,7 @@
AB3C7202170CA8D3004A91DB /* NSIndexPath+JNWAdditions.h in Headers */,
AB38E38E17DF099A00D50B3C /* JNWClipView.h in Headers */,
AB38E39017DF099A00D50B3C /* JNWScrollView.h in Headers */,
AB0EA369189472A400E28525 /* JNWCollectionViewLayout+Private.h in Headers */,
ABC05C691807808E00CAED48 /* JNWCollectionView.h in Headers */,
AB3C71F7170CA8D3004A91DB /* JNWCollectionView+Private.h in Headers */,
AB3C71FB170CA8D3004A91DB /* JNWCollectionViewCell+Private.h in Headers */,
Expand Down
3 changes: 3 additions & 0 deletions JNWCollectionView/JNWCollectionViewFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) {
///
/// A valid layout must be set before calling -reloadData, otherwise an exception will be thrown.
///
/// Layouts must not be reused between separate collection view instances. A single layout can be
/// associated with only one collection view at any given time.
///
/// Defaults to nil.
@property (nonatomic, strong) JNWCollectionViewLayout *collectionViewLayout;

Expand Down
4 changes: 4 additions & 0 deletions JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#import "JNWCollectionViewListLayout.h"
#import "JNWCollectionViewDocumentView.h"
#import "JNWCollectionViewLayout.h"
#import "JNWCollectionViewLayout+Private.h"

typedef NS_ENUM(NSInteger, JNWCollectionViewSelectionType) {
JNWCollectionViewSelectionTypeSingle,
Expand Down Expand Up @@ -268,7 +269,10 @@ - (void)setCollectionViewLayout:(JNWCollectionViewLayout *)collectionViewLayout
if (self.collectionViewLayout == collectionViewLayout)
return;

NSAssert(collectionViewLayout.collectionView == nil, @"Collection view layouts should not be reused between separate collection view instances.");

_collectionViewLayout = collectionViewLayout;
_collectionViewLayout.collectionView = self;

// Don't reload the data until we've performed an initial reload.
if (_collectionViewFlags.wantsLayout) {
Expand Down
25 changes: 25 additions & 0 deletions JNWCollectionView/JNWCollectionViewLayout+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2014, Jonathan Willing. All rights reserved.
Licensed under the MIT license <http://opensource.org/licenses/MIT>
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 "JNWCollectionViewLayout.h"

@class JNWCollectionView;
@interface JNWCollectionViewLayout ()
@property (nonatomic, weak, readwrite) JNWCollectionView *collectionView;
@end
9 changes: 4 additions & 5 deletions JNWCollectionView/JNWCollectionViewLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewDirection) {

@property (nonatomic, weak, readonly) JNWCollectionView *collectionView;


/// Dedicated initializer. Subclasses should override this method for their custom
/// initializers.
- (instancetype)initWithCollectionView:(JNWCollectionView *)collectionView;

/// This method is provided as a way to inform the layout that it will
/// need to invalidate the current layout and recalculate data.
///
Expand Down Expand Up @@ -138,3 +133,7 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewDirection) {
- (NSIndexPath *)indexPathForNextSelectableItemBeforeIndexPath:(NSIndexPath *)indexPath;

@end

@interface JNWCollectionViewLayout(Deprecated)
- (instancetype)initWithCollectionView:(JNWCollectionView *)collectionView __attribute__((deprecated("use -init instead.")));
@end
10 changes: 2 additions & 8 deletions JNWCollectionView/JNWCollectionViewLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

#import "JNWCollectionViewLayout.h"
#import "JNWCollectionView+Private.h"

@interface JNWCollectionViewLayout()
@property (nonatomic, weak, readwrite) JNWCollectionView *collectionView;
@end
#import "JNWCollectionViewLayout+Private.h"

@implementation JNWCollectionViewLayoutAttributes

Expand All @@ -40,10 +37,7 @@ - (void)prepareLayout {
}

- (instancetype)initWithCollectionView:(JNWCollectionView *)collectionView {
self = [super init];
if (self == nil) return nil;
self.collectionView = collectionView;
return self;
return [super init];
}

- (JNWCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
Expand Down
2 changes: 1 addition & 1 deletion demo/JNWCollectionViewDemo/GridDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (id)init {
- (void)awakeFromNib {
[self generateImages];

JNWCollectionViewGridLayout *gridLayout = [[JNWCollectionViewGridLayout alloc] initWithCollectionView:self.collectionView];
JNWCollectionViewGridLayout *gridLayout = [[JNWCollectionViewGridLayout alloc] init];
gridLayout.delegate = self;
self.collectionView.collectionViewLayout = gridLayout;
self.collectionView.dataSource = self;
Expand Down
2 changes: 1 addition & 1 deletion demo/JNWCollectionViewDemo/ListDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (void)loadView {
self.collectionView.dataSource = self;
[self.view addSubview:self.collectionView];

JNWCollectionViewListLayout *layout = [[JNWCollectionViewListLayout alloc] initWithCollectionView:self.collectionView];
JNWCollectionViewListLayout *layout = [[JNWCollectionViewListLayout alloc] init];
layout.rowHeight = 44.f;
layout.delegate = self;
self.collectionView.collectionViewLayout = layout;
Expand Down

0 comments on commit 4bdb151

Please sign in to comment.