1. José Manuel Sánchez Peñarroja
  2. BMF

Commits

José Manuel Sánchez Peñarroja  committed aa75bbc

Added tableviewpintoheader behavior. Added index path to item tapped in item tap behaviors. Made magical record save when going to background by default

  • Participants
  • Parent commits a8ad24e
  • Branches master

Comments (0)

Files changed (18)

File Example/Example.xcworkspace/contents.xcworkspacedata

View file
  • Ignore whitespace
 <Workspace
    version = "1.0">
    <FileRef
-      location = "group:../bmf/shared/base/BMFRegistrableProtocol.h">
-   </FileRef>
-   <FileRef
       location = "group:Example/Example.xcodeproj">
    </FileRef>
    <FileRef

File Example/Example.xcworkspace/xcuserdata/josanchez.xcuserdatad/UserInterfaceState.xcuserstate

  • Ignore whitespace
Binary file modified.

File Example/Example/Example.xcodeproj/project.pbxproj

View file
  • Ignore whitespace
 				);
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				USER_HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../bmf/**";
+				WARNING_CFLAGS = "-Weverything";
 				WRAPPER_EXTENSION = app;
 			};
 			name = Debug;
 				);
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				USER_HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../bmf/**";
+				WARNING_CFLAGS = "-Weverything";
 				WRAPPER_EXTENSION = app;
 			};
 			name = Release;

File Example/Example/Example/BMFExampleTestConfigurator.m

View file
  • Ignore whitespace
 	return [NSString class];
 }
 
-+ (void) configure:(UITableViewCell *) cell kind:(BMFViewKind)kind withItem:(id)item inView:(UIView *)containerView atIndexPath:(NSIndexPath *)indexPath controller:(id)controller {
++ (void) configure:(UITableViewCell *)cell kind:(BMFViewKind)kind withItem:(id)item inView:(UIView *)containerView atIndexPath:(NSIndexPath *)indexPath controller:(id)controller {
 	cell.textLabel.text = item;
 }
 

File Example/Example/Example/Example-Prefix.pch

View file
  • Ignore whitespace
 //  The contents of this file are implicitly included at the beginning of every source file.
 //
 
-#import <Availability.h>
+@import Darwin.Availability;
 
 #ifndef __IPHONE_5_0
 #warning "This project uses features only available in iOS SDK 5.0 and later."
 #endif
 
 #ifdef __OBJC__
-	#import <UIKit/UIKit.h>
-	#import <Foundation/Foundation.h>
+	@import UIKit;
+	@import Foundation;
 
 	#import <BMF/BMFBase.h>
 #endif

File Example/Example/Example/ExampleHeaderView.h

View file
  • Ignore whitespace
 //  Copyright (c) 2014 José Manuel Sánchez. All rights reserved.
 //
 
-#import <UIKit/UIKit.h>
+@import UIKit;
 
 #import "BMFView.h"
 #import "BMFTableViewHeaderFooterView.h"

File Example/Example/Example/ExampleHomeScreenItemConfigurator.m

View file
  • Ignore whitespace
 	return [BMFHomeScreenItemCell class];
 }
 
-+ (void) configure:(BMFHomeScreenItemCell *)view kind:(BMFViewKind)kind withItem:(id)item inView:(UIView *)containerView atIndexPath:(NSIndexPath *)indexPath controller:(id)controller {
-	view.item.textLabel.text = item;
++ (void) configure:(id)view kind:(BMFViewKind)kind withItem:(id)item inView:(UIView *)containerView atIndexPath:(NSIndexPath *)indexPath controller:(id)controller {
+	BMFHomeScreenItemCell *cell = view;
+	cell.item.textLabel.text = item;
 }
 
 @end

File Example/Example/Example/ExampleTestViewController.h

View file
  • Ignore whitespace
 #import "BMFTableViewController.h"
 
 @interface ExampleTestViewController : BMFTableViewController
+
 @property (weak, nonatomic) IBOutlet UILabel *label;
 
 @end

File Example/Example/Example/ExampleTestViewController.m

View file
  • Ignore whitespace
 
 @implementation ExampleTestViewController
 
+@synthesize label;
 
 - (void) viewDidLoad {
 	[super viewDidLoad];
 	BMFScrollHidesNavigationBarBehavior *behavior = [[BMFScrollHidesNavigationBarBehavior alloc] initWithView:self.tableView];
 	[self addBehavior:behavior];
 
-	BMFItemTapBlockBehavior *tapBehavior = [[BMFItemTapBlockBehavior alloc] initWithTapBlock:^(id sender) {
+	BMFItemTapBlockBehavior *tapBehavior = [[BMFItemTapBlockBehavior alloc] initWithTapBlock:^(id sender,NSIndexPath *indexPath) {
 		[self performSegueWithIdentifier:@"collection" sender:sender];
 	}];
 	[self addBehavior:tapBehavior];

File bmf/ios/behaviors/BMFItemTapPresentsViewControllerBehavior.m

View file
  • Ignore whitespace
     return self;
 }
 
-- (void) itemTapped:(id) item {
+- (void) itemTapped:(id) item atIndexPath:(NSIndexPath *)indexPath {
 
 	BMFAssertReturn(self.object);
 

File bmf/ios/behaviors/BMFScrollViewViewControllerBehavior.m

View file
  • Ignore whitespace
 	BMFInvalidInit(initWithView:);
 }
 
+- (void) setScrollView:(UIScrollView *)scrollView {
+	BMFAssertReturn(scrollView);
+	
+	_scrollView = scrollView;
+}
+
 @end

File bmf/ios/behaviors/BMFTableViewPinToHeaderBehavior.h

View file
  • Ignore whitespace
+//
+//  BMFTableViewPinToHeaderBehavior.h
+//  Pods
+//
+//  Created by Jose Manuel Sánchez Peñarroja on 20/06/14.
+//
+//
+
+#import "BMFViewControllerBehavior.h"
+
+@interface BMFTableViewPinToHeaderBehavior : BMFViewControllerBehavior <UIScrollViewDelegate>
+
+@property (nonatomic, weak) UITableView *tableView;
+
+- (instancetype) initWithView:(UITableView *) tableView;
+
+@end

File bmf/ios/behaviors/BMFTableViewPinToHeaderBehavior.m

View file
  • Ignore whitespace
+//
+//  BMFTableViewPinToHeaderBehavior.m
+//  Pods
+//
+//  Created by Jose Manuel Sánchez Peñarroja on 20/06/14.
+//
+//
+
+#import "BMFTableViewPinToHeaderBehavior.h"
+
+#import "BMF.h"
+
+@implementation BMFTableViewPinToHeaderBehavior
+
+- (instancetype) initWithView:(UITableView *)tableView {
+	BMFAssertReturnNil(tableView);
+	
+    self = [super init];
+    if (self) {
+		_tableView = tableView;
+	}
+    return self;
+}
+
+- (instancetype)init {
+	BMFInvalidInit(initWithView:);
+}
+
+- (void) setTableView:(UITableView *)tableView {
+	BMFAssertReturn(tableView);
+	
+	_tableView = tableView;
+}
+
+- (void) scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
+	BMFAssertReturn(self.tableView.tableHeaderView);
+	
+//	CGFloat computedTargetOffset = scrollView.contentOffset.y*velocity.y+self.tableView.contentInset.top;
+	CGFloat computedTargetOffset = scrollView.contentOffset.y+self.tableView.contentInset.top;
+	
+	//CGFloat time = fabsf(targetContentOffset->y-scrollView.contentOffset.y)/fabsf(velocity.y);
+	CGFloat time = 0.2;
+	
+//	if (computedTargetOffset>self.tableView.tableHeaderView.bounds.size.height) return;
+	DDLogInfo(@"Animation time: %f",time);
+	
+	[UIView animateWithDuration:time delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
+//	[UIView animateWithDuration:time animations:^{
+		UIEdgeInsets oldInsets = self.tableView.contentInset;
+		
+		if (computedTargetOffset<(self.tableView.tableHeaderView.bounds.size.height/3.0)) {
+			*targetContentOffset = CGPointMake(targetContentOffset->x, 0);
+			self.tableView.contentInset = UIEdgeInsetsZero;
+			
+			//		CGPoint offset = self.tableView.contentOffset;
+			//		offset.y += oldInsets.top;
+			//		self.tableView.contentOffset = offset;
+		}
+		else {
+			if (computedTargetOffset<(self.tableView.tableHeaderView.bounds.size.height)) {
+				*targetContentOffset = CGPointMake(targetContentOffset->x, self.tableView.tableHeaderView.bounds.size.height);
+			}
+			
+			self.tableView.contentInset = UIEdgeInsetsMake(-self.tableView.tableHeaderView.bounds.size.height, 0, 0, 0);
+		}
+	} completion:nil];
+	
+	
+//	CGPoint offset = self.tableView.contentOffset;
+//	offset.y += (self.tableView.contentInset.top-oldInsets.top);
+//	self.tableView.contentOffset = offset;
+
+}
+
+
+@end

File bmf/ios/factories/BMFIOSDefaultFactory.h

View file
  • Ignore whitespace
 
 #pragma mark Collection view
 
+- (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellIdentifier:(NSString *)cellIdentifier sender:(id) sender;
 - (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellRegister:(id<BMFCellRegisterProtocol>)cellRegister sender:(id) sender;
 - (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellClassOrNib:(id) classOrNib sender:(id) sender;
 - (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellRegisterBlock:(BMFCellRegisterCellsBlock) registerBlock cellIdBlock:(BMFCellIdBlock)cellIdBlock sender:(id) sender;

File bmf/ios/factories/BMFIOSDefaultFactory.m

View file
  • Ignore whitespace
 
 #pragma mark Collection view
 
+- (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellIdentifier:(NSString *)cellIdentifier sender:(id) sender {
+	id<BMFCellRegisterProtocol> cellRegister = [[BMFSingleCellRegister alloc] initWithId:cellIdentifier classOrUINib:nil];
+	return [self collectionViewDataSourceWithStore:store cellRegister:cellRegister sender:sender];
+}
+
 - (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellRegister:(id<BMFCellRegisterProtocol>)cellRegister sender:(id) sender {
 	BMFCollectionViewDataSource *dataSource = [[BMFCollectionViewDataSource alloc] initWithDataStore:store];
 	

File bmf/ios/factories/BMFUIFactoryProtocol.h

View file
  • Ignore whitespace
 
 #pragma mark Collection view
 
+- (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellIdentifier:(NSString *)cellIdentifier sender:(id) sender;
 - (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellRegister:(id<BMFCellRegisterProtocol>)cellRegister sender:(id) sender;
 - (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellClassOrNib:(id) classOrNib sender:(id) sender;
 - (id) collectionViewDataSourceWithStore:(id<BMFDataReadProtocol>) store cellRegisterBlock:(BMFCellRegisterCellsBlock) registerBlock cellIdBlock:(BMFCellIdBlock)cellIdBlock sender:(id) sender;

File bmf/shared/data/data stores/BMFComplexDataStore.m

View file
  • Ignore whitespace
 - (NSInteger) numberOfRowsInSection:(NSUInteger) section { return 0; }
 - (NSString *) titleForSection:(NSUInteger) section kind:(BMFViewKind)kind { return nil; }
 - (id) itemAt:(NSInteger) section row:(NSInteger) row { return nil; }
-- (id) itemAt:(NSIndexPath *) indexPath  { return nil; }
+- (id) itemAt:(NSIndexPath *) indexPath  { return [self itemAt:indexPath.BMF_section row:indexPath.BMF_row]; }
 
 - (NSIndexPath *) indexOfItem:(id) item { return nil; }
 

File bmf/shared/subspecs/coredata/BMFMagicalRecordConfigurationModule.m

View file
  • Ignore whitespace
 
 @implementation BMFMagicalRecordConfigurationModule
 
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        _automaticSaving = YES;
+    }
+    return self;
+}
+
 - (BOOL) setup {
 	
 	[MagicalRecord setupAutoMigratingCoreDataStack];