Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
Merge branch '0.9.x' into feature-0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
pjechris committed Oct 19, 2015
2 parents 27c607c + d696da5 commit 131999f
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Akane.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
4984BB221AC07A990095B126 /* AKNViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4984BB211AC07A990095B126 /* AKNViewHelper.m */; };
4984BB261AC080310095B126 /* UITableViewCell+AKNReusableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4984BB251AC080310095B126 /* UITableViewCell+AKNReusableView.m */; };
4984BB291AC080D10095B126 /* AKNReusableViewHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4984BB281AC080D10095B126 /* AKNReusableViewHandler.m */; };
4984D0411BD5530700C911C3 /* AKNCollectionReusableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4984D0401BD5530700C911C3 /* AKNCollectionReusableView.m */; settings = {ASSET_TAGS = (); }; };
4984D0441BD553A600C911C3 /* UICollectionReusableView+AKNReusableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4984D0431BD553A600C911C3 /* UICollectionReusableView+AKNReusableView.m */; settings = {ASSET_TAGS = (); }; };
4992F6261AB6193E00E53BE5 /* AKNTableViewAdapteriOS7.m in Sources */ = {isa = PBXBuildFile; fileRef = 4992F6251AB6193E00E53BE5 /* AKNTableViewAdapteriOS7.m */; };
49A159F51A90F04B00C2891F /* AKNViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 49A159F41A90F04B00C2891F /* AKNViewModel.m */; };
49A7FCE51AA0AA15001B4F69 /* AKNTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 49A7FCE41AA0AA15001B4F69 /* AKNTableView.m */; };
Expand Down Expand Up @@ -97,6 +99,10 @@
4984BB251AC080310095B126 /* UITableViewCell+AKNReusableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableViewCell+AKNReusableView.m"; sourceTree = "<group>"; };
4984BB271AC080D10095B126 /* AKNReusableViewHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AKNReusableViewHandler.h; sourceTree = "<group>"; };
4984BB281AC080D10095B126 /* AKNReusableViewHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AKNReusableViewHandler.m; sourceTree = "<group>"; };
4984D03F1BD5530700C911C3 /* AKNCollectionReusableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AKNCollectionReusableView.h; sourceTree = "<group>"; };
4984D0401BD5530700C911C3 /* AKNCollectionReusableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AKNCollectionReusableView.m; sourceTree = "<group>"; };
4984D0421BD553A600C911C3 /* UICollectionReusableView+AKNReusableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UICollectionReusableView+AKNReusableView.h"; sourceTree = "<group>"; };
4984D0431BD553A600C911C3 /* UICollectionReusableView+AKNReusableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UICollectionReusableView+AKNReusableView.m"; sourceTree = "<group>"; };
4992F6241AB6193E00E53BE5 /* AKNTableViewAdapteriOS7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AKNTableViewAdapteriOS7.h; sourceTree = "<group>"; };
4992F6251AB6193E00E53BE5 /* AKNTableViewAdapteriOS7.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AKNTableViewAdapteriOS7.m; sourceTree = "<group>"; };
49A159F31A90E04200C2891F /* AKNItemViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AKNItemViewModel.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -149,6 +155,8 @@
4250F3DA1AD8F9D20085B218 /* UIKit */ = {
isa = PBXGroup;
children = (
4984D0421BD553A600C911C3 /* UICollectionReusableView+AKNReusableView.h */,
4984D0431BD553A600C911C3 /* UICollectionReusableView+AKNReusableView.m */,
4250F3DB1AD8FA2F0085B218 /* UICollectionViewCell+AKNReusableView.h */,
4250F3DC1AD8FA2F0085B218 /* UICollectionViewCell+AKNReusableView.m */,
);
Expand Down Expand Up @@ -233,6 +241,8 @@
isa = PBXGroup;
children = (
49CCA7541A836EA000B0FC82 /* Adapter */,
4984D03F1BD5530700C911C3 /* AKNCollectionReusableView.h */,
4984D0401BD5530700C911C3 /* AKNCollectionReusableView.m */,
4250F3E91AD9109B0085B218 /* AKNCollectionView.h */,
4250F3EA1AD9109B0085B218 /* AKNCollectionView.m */,
4250F3EB1AD9109B0085B218 /* AKNCollectionViewCell.h */,
Expand Down Expand Up @@ -547,10 +557,12 @@
4250F3EE1AD9109B0085B218 /* AKNCollectionViewCell.m in Sources */,
4250F3E11AD8FEC80085B218 /* UICollectionView+Adapter.m in Sources */,
490ED8871AE26B9D00C2E66C /* AKNLifecycleManager.m in Sources */,
4984D0441BD553A600C911C3 /* UICollectionReusableView+AKNReusableView.m in Sources */,
4250F3DD1AD8FA2F0085B218 /* UICollectionViewCell+AKNReusableView.m in Sources */,
49717DF31A88EE760021834B /* AKNArrayDataSource.m in Sources */,
49A7FCE51AA0AA15001B4F69 /* AKNTableView.m in Sources */,
4992F6261AB6193E00E53BE5 /* AKNTableViewAdapteriOS7.m in Sources */,
4984D0411BD5530700C911C3 /* AKNCollectionReusableView.m in Sources */,
49CCA7621A839BEC00B0FC82 /* AKNTableViewAdapter.m in Sources */,
4250F3ED1AD9109B0085B218 /* AKNCollectionView.m in Sources */,
);
Expand Down
21 changes: 21 additions & 0 deletions Akane/View/AKNCollectionReusableView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// This file is part of Akane
//
// Created by Pascal Drouilly on 16/09/15.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "UICollectionReusableView+AKNReusableView.h"

@protocol AKNViewComponent;

@interface AKNCollectionReusableView : UICollectionReusableView

@property(nonatomic, strong)IBOutlet UIView<AKNViewComponent> *itemView;

+ (instancetype)reusableViewWithItemView:(UIView<AKNViewComponent> *)itemView;

@end
54 changes: 54 additions & 0 deletions Akane/View/AKNCollectionReusableView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// This file is part of Akane
//
// Created by Pascal Drouilly on 16/09/15.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code
//

#import "AKNCollectionReusableView.h"
#import "AKNViewModel.h"
#import "AKNViewComponent.h"

@implementation AKNCollectionReusableView

@synthesize itemView = _itemView;

+ (instancetype)reusableViewWithItemView:(UIView<AKNViewComponent> *)itemView {
return [[self alloc] initWithCellWithItemView:itemView];
}

- (instancetype)initWithCellWithItemView:(UIView<AKNViewComponent> *)itemView {
if (!(self = [super init])) {
return nil;
}

self.itemView = itemView;

return self;
}

- (void)setItemView:(UIView<AKNViewComponent> *)itemView {
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(itemView);

if (itemView == _itemView) {
return;
}

[_itemView removeFromSuperview];
_itemView = itemView;
itemView.translatesAutoresizingMaskIntoConstraints = NO;

[self addSubview:itemView];

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[itemView]|"
options:0
metrics:0
views:viewsDictionary]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[itemView]|"
options:0
metrics:0
views:viewsDictionary]];
}

@end
Empty file modified Akane/View/AKNCollectionView.h
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Akane/View/AKNCollectionView.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "AKNViewModel.h"
#import "UICollectionView+Adapter.h"
#import "AKNCollectionViewAdapter.h"
#import <EventListener.h>
#import <EventListener/EventListener.h>

@implementation AKNCollectionView

Expand Down
Empty file modified Akane/View/AKNCollectionViewCell.h
100755 → 100644
Empty file.
7 changes: 5 additions & 2 deletions Akane/View/AKNCollectionViewCell.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ - (void)setItemView:(UIView<AKNViewComponent> *)itemView {
itemView.translatesAutoresizingMaskIntoConstraints = NO;

[self.contentView addSubview:itemView];
// iOS7 compatibility
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[itemView]|"
options:0
metrics:0
Expand All @@ -49,6 +48,10 @@ - (void)setItemView:(UIView<AKNViewComponent> *)itemView {
options:0
metrics:0
views:viewsDictionary]];

// TODO should we wrap it in a 'if IOS 7' at minimum ? Also seems to serve no purpose when tested without it.
// iOS7 compatibility
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
}

@end
3 changes: 3 additions & 0 deletions Akane/View/AKNReusableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
@protocol AKNReusableView <NSObject>

@property(nonatomic, strong)IBOutlet UIView<AKNViewComponent> *itemView;

@optional

@property(nonatomic, strong)UIView *backgroundView;
@property(nonatomic, strong)UIView *selectedBackgroundView;

Expand Down
7 changes: 5 additions & 2 deletions Akane/View/AKNTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ - (void)setItemView:(nullable UIView<AKNViewComponent> *)itemView {
itemView.translatesAutoresizingMaskIntoConstraints = NO;

[self.contentView addSubview:itemView];
// iOS7 compatibility
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[itemView]|"
options:0
metrics:0
Expand All @@ -49,6 +48,10 @@ - (void)setItemView:(nullable UIView<AKNViewComponent> *)itemView {
options:0
metrics:0
views:viewsDictionary]];

// TODO should we wrap it in a 'if IOS 7' at minimum ? Also seems to serve no purpose when tested without it.
// iOS7 compatibility
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
- (NSString *)identifierForViewModel:(id<AKNItemViewModel>)viewModel inSection:(NSInteger)section;

- (UICollectionViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;
- (UIView<AKNViewComponent> *)dequeueReusableSectionWithIdentifier:(NSString *)identifier forSection:(NSInteger)section;

- (UICollectionReusableView *)dequeueReusableViewOfKind:(NSString *)kind withIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;

- (UIView<AKNViewComponent> *)createReusableViewWithIdentifier:(NSString *)identifier;
- (AKNReusableViewHandler *)handlerForIdentifier:(NSString *)identifier;
Expand Down
45 changes: 38 additions & 7 deletions Akane/View/Adapter/Collection/AKNCollectionViewAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#import "AKNViewCache.h"
#import "AKNItemViewModel.h"
#import "AKNCollectionViewCell.h"
#import "AKNCollectionReusableView.h"
#import "AKNViewHelper.h"
#import "AKNReusableViewHandler.h"
#import "AKNLifecycleManager.h"
#import "UICollectionReusableView+AKNReusableView.h"
#import "UICollectionViewCell+AKNReusableView.h"

@interface AKNCollectionViewAdapter () <AKNViewCache, UICollectionViewDelegate, UICollectionViewDataSource>
Expand Down Expand Up @@ -49,7 +51,6 @@ - (instancetype)initWithCollectionView:(UICollectionView *)collectionView {
return self;
}

// TODO: implement supplementary collection view views
- (id<AKNItemViewModel>)sectionModel:(NSInteger)section {
if (![self.dataSource respondsToSelector:@selector(supplementaryItemAtSection:)]) {
return nil;
Expand Down Expand Up @@ -135,6 +136,25 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
}
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
NSInteger section = indexPath.section;

id<AKNItemViewModel> viewModel = [self sectionModel:section];
NSString *identifier = [self identifierForViewModel:viewModel inSection:section];
identifier = [identifier stringByAppendingString:UICollectionElementKindSectionHeader];

if (!identifier) {
return nil;
}

UICollectionReusableView *reusableView = [self dequeueReusableViewOfKind:kind withIdentifier:identifier forIndexPath:indexPath];

[reusableView.itemView bind:viewModel];
[reusableView setNeedsLayout]; // This fix Self-sizing view labels not always sized correctly

return reusableView;
}

#pragma mark - Internal

- (NSString *)identifierForViewModel:(id<AKNItemViewModel>)viewModel inSection:(NSInteger)section {
Expand Down Expand Up @@ -162,10 +182,17 @@ - (UICollectionViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifi
return cell;
}

- (UIView<AKNViewComponent> *)dequeueReusableSectionWithIdentifier:(NSString *)identifier forSection:(NSInteger)section {
UIView<AKNViewComponent> *view = [self createReusableViewWithIdentifier:identifier];

return view;
- (UICollectionReusableView *)dequeueReusableViewOfKind:(NSString *)kind withIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView *reusableView = [self.collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:identifier forIndexPath:indexPath];

if (!reusableView.itemView) {
reusableView.itemView = [self createReusableViewWithIdentifier:identifier];
}

NSAssert([reusableView.itemView conformsToProtocol:@protocol(AKNViewComponent)],
@"reusableView.itemView for identifier %@ must conform to AKNViewComponent protocol", identifier);

return reusableView;
}

- (UIView<AKNViewComponent> *)createReusableViewWithIdentifier:(NSString *)identifier {
Expand All @@ -186,6 +213,7 @@ - (void)registerNibName:(NSString *)nibName withReuseIdentifier:(NSString *)iden

- (void)registerNibName:(NSString *)nibName withReuseIdentifier:(NSString *)identifier handle:(AKNReusableViewRegisterHandle)handle {
self.reusableViewsContent[identifier] = [UINib nibWithNibName:nibName bundle:nil];

[self.collectionView registerClass:[AKNCollectionViewCell class] forCellWithReuseIdentifier:identifier];
[self registerHandlerForReuseIdentifier:identifier onRegistered:handle];
}
Expand All @@ -196,6 +224,7 @@ - (void)registerView:(Class)viewClass withReuseIdentifier:(NSString *)identifier

- (void)registerView:(Class)viewClass withReuseIdentifier:(NSString *)identifier handle:(AKNReusableViewRegisterHandle)handle {
self.reusableViewsContent[identifier] = viewClass;

[self.collectionView registerClass:[AKNCollectionViewCell class] forCellWithReuseIdentifier:identifier];
[self registerHandlerForReuseIdentifier:identifier onRegistered:handle];
}
Expand All @@ -210,14 +239,16 @@ - (void)registerHandlerForReuseIdentifier:(NSString *)identifier onRegistered:(A

- (void)registerNibName:(NSString *)nibName supplementaryElementKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier {
identifier = [identifier stringByAppendingString:kind];

self.reusableViewsContent[identifier] = [UINib nibWithNibName:nibName bundle:nil];

[self.collectionView registerClass:[AKNCollectionReusableView class] forSupplementaryViewOfKind:kind withReuseIdentifier:identifier];
}

- (void)registerView:(Class)viewClass supplementaryElementKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier {
identifier = [identifier stringByAppendingString:kind];

self.reusableViewsContent[identifier] = viewClass;

[self.collectionView registerClass:[AKNCollectionReusableView class] forSupplementaryViewOfKind:kind withReuseIdentifier:identifier];
}

#pragma mark - Setters
Expand Down
3 changes: 3 additions & 0 deletions Akane/View/Adapter/Collection/UICollectionView+Adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
#import <UIKit/UIKit.h>
#import "AKNDataSource.h"
#import "AKNItemViewModelProvider.h"
#import "AKNCollectionViewAdapter.h"

@interface UICollectionView (Adapter)

@property(nonatomic, strong)id<AKNDataSource> adapterDataSource;

@property(nonatomic, strong)id<AKNItemViewModelProvider> adapterItemProvider;

@property(nonatomic, strong)AKNCollectionViewAdapter *adapter;

@end
4 changes: 4 additions & 0 deletions Akane/View/Adapter/Collection/UICollectionView+Adapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ - (AKNCollectionViewAdapter *)adapter {
return adapter;
}

- (void)setAdapter:(AKNCollectionViewAdapter *)adapter {
objc_setAssociatedObject(self, &UICollectionViewAdapter, adapter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)setAdapterDataSource:(id<AKNDataSource>)adapterDataSource {
[self adapter].dataSource = adapterDataSource;
}
Expand Down
6 changes: 4 additions & 2 deletions Akane/View/Adapter/Table/AKNTableViewAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

@interface AKNTableViewAdapter () <AKNViewCache>
@property(nonatomic, strong)NSMapTable *itemViewModels;
@property(nonatomic, strong)NSMapTable *sectionViewModels;
@property(nonatomic, strong)NSMutableDictionary *reusableViewsContent;
@property(nonatomic, strong)NSMutableDictionary *reusableViewsHandler;
@property(nonatomic, weak)UITableView *tableView;
Expand All @@ -35,6 +36,7 @@ - (instancetype)initCluster {
}

self.itemViewModels = [NSMapTable weakToStrongObjectsMapTable];
self.sectionViewModels = [NSMapTable weakToStrongObjectsMapTable];
self.reusableViewsContent = [NSMutableDictionary new];
self.reusableViewsHandler = [NSMutableDictionary new];

Expand Down Expand Up @@ -68,13 +70,13 @@ - (instancetype)initWithTableView:(UITableView *)tableView {
}

id item = [self.dataSource supplementaryItemAtSection:section];
id<AKNItemViewModel> model = [self.itemViewModels objectForKey:item];
id<AKNItemViewModel> model = [self.sectionViewModels objectForKey:item];

if (!model) {
model = [self.itemViewModelProvider supplementaryItemViewModel:item];

if (model) {
[self.itemViewModels setObject:model forKey:item];
[self.sectionViewModels setObject:model forKey:item];
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// This file is part of Akane
//
// Created by Pascal Drouilly on 16/09/15.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AKNReusableView.h"

@interface UICollectionReusableView (AKNReusableView) <AKNReusableView>

@end
Loading

0 comments on commit 131999f

Please sign in to comment.