Skip to content

Commit

Permalink
[pagingscrollview] Misc bug fixes.
Browse files Browse the repository at this point in the history
- Moved all subclassing methods out to a separate header "NIPagingScrollView+Subclassing.h"
- The offset is not modified if the user is dragging the paging scroll view while the data is reloaded.
- We now safely handle end-of-animation notifications. No longer using a sketchy timer.
- Added more support for modifying the behavior of the paging scroll view.
  • Loading branch information
jverkoey committed Nov 14, 2012
1 parent bc116ce commit 9fee412
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 84 deletions.
2 changes: 2 additions & 0 deletions examples/catalog/NimbusCatalog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
66BB4FCD15959B5000020EE8 /* RestoringLauncherViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RestoringLauncherViewController.m; sourceTree = "<group>"; };
66CB01A215ACA85E0048E189 /* BlockCellsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockCellsViewController.h; sourceTree = "<group>"; };
66CB01A315ACA85E0048E189 /* BlockCellsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BlockCellsViewController.m; sourceTree = "<group>"; };
66CB9A1E1654306E00FFB4BF /* NIPagingScrollView+Subclassing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NIPagingScrollView+Subclassing.h"; path = "../../src/pagingscrollview/src/NIPagingScrollView+Subclassing.h"; sourceTree = "<group>"; };
66D2E54815D9613700281511 /* NIMutableTableViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NIMutableTableViewModel.h; path = ../../src/models/src/NIMutableTableViewModel.h; sourceTree = "<group>"; };
66D2E54915D9613800281511 /* NIMutableTableViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NIMutableTableViewModel.m; path = ../../src/models/src/NIMutableTableViewModel.m; sourceTree = "<group>"; };
66D2E54A15D9613800281511 /* NIMutableTableViewModel+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NIMutableTableViewModel+Private.h"; path = "../../src/models/src/NIMutableTableViewModel+Private.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -753,6 +754,7 @@
66A29F9815951C0000F6EA64 /* NIPageView.m */,
66A29F9915951C0000F6EA64 /* NIPagingScrollView.h */,
66A29F9A15951C0000F6EA64 /* NIPagingScrollView.m */,
66CB9A1E1654306E00FFB4BF /* NIPagingScrollView+Subclassing.h */,
66A29F9B15951C0000F6EA64 /* NIPagingScrollViewDataSource.h */,
66A29F9C15951C0000F6EA64 /* NIPagingScrollViewDelegate.h */,
66A29F9D15951C0000F6EA64 /* NIPagingScrollViewPage.h */,
Expand Down
4 changes: 4 additions & 0 deletions src/Nimbus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
66C3A6AF143D61140048542F /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66A03C1A13E6E85E00B514F3 /* SenTestingKit.framework */; };
66C3A6B1143D61140048542F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66A03C0C13E6E85E00B514F3 /* Foundation.framework */; };
66C3A6B4143D61140048542F /* libNimbusCss.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 66C3A6A1143D61130048542F /* libNimbusCss.a */; };
66CB9A211654307A00FFB4BF /* NIPagingScrollView+Subclassing.h in Headers */ = {isa = PBXBuildFile; fileRef = 66CB9A201654307A00FFB4BF /* NIPagingScrollView+Subclassing.h */; };
66D2E53F15D9432000281511 /* NIMutableTableViewModel.h in Headers */ = {isa = PBXBuildFile; fileRef = 66D2E53D15D9432000281511 /* NIMutableTableViewModel.h */; };
66D2E54015D9432000281511 /* NIMutableTableViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 66D2E53E15D9432000281511 /* NIMutableTableViewModel.m */; };
66D2E54315D9438D00281511 /* NIMutableTableViewModel+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 66D2E54115D9438D00281511 /* NIMutableTableViewModel+Private.h */; };
Expand Down Expand Up @@ -906,6 +907,7 @@
66C1153F1486ACDD003C9AC6 /* NIOperations+Subclassing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NIOperations+Subclassing.h"; sourceTree = "<group>"; };
66C3A6A1143D61130048542F /* libNimbusCss.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libNimbusCss.a; sourceTree = BUILT_PRODUCTS_DIR; };
66C3A6AE143D61140048542F /* NimbusCssTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NimbusCssTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
66CB9A201654307A00FFB4BF /* NIPagingScrollView+Subclassing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NIPagingScrollView+Subclassing.h"; sourceTree = "<group>"; };
66D2E53D15D9432000281511 /* NIMutableTableViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NIMutableTableViewModel.h; sourceTree = "<group>"; };
66D2E53E15D9432000281511 /* NIMutableTableViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NIMutableTableViewModel.m; sourceTree = "<group>"; };
66D2E54115D9438D00281511 /* NIMutableTableViewModel+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NIMutableTableViewModel+Private.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1293,6 +1295,7 @@
666F73B014BBFF6300D1A32F /* NimbusPagingScrollView+Namespace.h */,
663B52681445070100CC26DF /* NIPagingScrollView.h */,
663B52691445070100CC26DF /* NIPagingScrollView.m */,
66CB9A201654307A00FFB4BF /* NIPagingScrollView+Subclassing.h */,
663B527014450CC100CC26DF /* NIPagingScrollViewPage.h */,
663B527214450CEF00CC26DF /* NIPagingScrollViewDelegate.h */,
663B527414450D1C00CC26DF /* NIPagingScrollViewDataSource.h */,
Expand Down Expand Up @@ -2086,6 +2089,7 @@
663B527514450D1C00CC26DF /* NIPagingScrollViewDataSource.h in Headers */,
66F27D55145B7A5F00AFCA08 /* NIPageView.h in Headers */,
666F73B114BBFF6300D1A32F /* NimbusPagingScrollView+Namespace.h in Headers */,
66CB9A211654307A00FFB4BF /* NIPagingScrollView+Subclassing.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
113 changes: 113 additions & 0 deletions src/pagingscrollview/src/NIPagingScrollView+Subclassing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//
// Copyright 2011-2012 Jeff Verkoeyen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "NIPagingScrollView.h"

@interface NIPagingScrollView (Subclassing)

// Meant to be subclassed. Default implementations are stubs.
- (void)willDisplayPage:(UIView<NIPagingScrollViewPage> *)pageView;
- (void)didRecyclePage:(UIView<NIPagingScrollViewPage> *)pageView;
- (void)didReloadNumberOfPages;
- (void)didChangeCenterPageIndexFrom:(NSInteger)from to:(NSInteger)to;

// Meant to be subclassed.
- (UIView<NIPagingScrollViewPage>* )loadPageAtIndex:(NSInteger)pageIndex;

// Not meant to be subclassed.
- (void)setCenterPageIndexIvar:(NSInteger)centerPageIndex;
- (void)recyclePageAtIndex:(NSInteger)pageIndex;
- (void)displayPageAtIndex:(NSInteger)pageIndex;
- (CGFloat)pageScrollableDimension;
- (void)layoutVisiblePages;

@end

/**
* Called before the page is about to be shown and after its frame has been set.
*
* Meant to be subclassed. By default this method does nothing.
*
* @fn NIPagingScrollView::willDisplayPage:
*/

/**
* Called immediately after the page is removed from the paging scroll view.
*
* Meant to be subclassed. By default this method does nothing.
*
* @fn NIPagingScrollView::didRecyclePage:
*/

/**
* Called immediately after the data source has been queried for its number of
* pages.
*
* Meant to be subclassed. By default this method does nothing.
*
* @fn NIPagingScrollView::didReloadNumberOfPages
*/

/**
* Called when the visible page has changed.
*
* Meant to be subclassed. By default this method does nothing.
*
* @fn NIPagingScrollView::didChangeCenterPageIndexFrom:to:
*/

/**
* Called when a page needs to be loaded before it is displayed.
*
* By default this method asks the data source for the page at the given index.
* A subclass may chose to modify the page index using a transformation method
* before calling super.
*
* @fn NIPagingScrollView::loadPageAtIndex:
*/

/**
* Sets the centerPageIndex ivar without side effects.
*
* @fn NIPagingScrollView::setCenterPageIndexIvar:
*/

/**
* Recycles the page at the given index.
*
* @fn NIPagingScrollView::recyclePageAtIndex:
*/

/**
* Displays the page at the given index.
*
* @fn NIPagingScrollView::displayPageAtIndex:
*/

/**
* Returns the page's scrollable dimension.
*
* This is the width of the paging scroll view for horizontal scroll views, or
* the height of the paging scroll view for vertical scroll views.
*
* @fn NIPagingScrollView::pageScrollableDimension
*/

/**
* Updates the frames of all visible pages based on their page indices.
*
* @fn NIPagingScrollView::layoutVisiblePages
*/
19 changes: 0 additions & 19 deletions src/pagingscrollview/src/NIPagingScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ typedef enum {
@property (nonatomic, readonly, NI_STRONG) UIScrollView* pagingScrollView;
@property (nonatomic, readonly, copy) NSMutableSet* visiblePages; // Set of UIView<NIPagingScrollViewPage>*

- (void)willDisplayPage:(UIView<NIPagingScrollViewPage> *)pageView;
- (void)didRecyclePage:(UIView<NIPagingScrollViewPage> *)pageView;

@end

/** @name Data Source */
Expand Down Expand Up @@ -271,19 +268,3 @@ typedef enum {
*
* @fn NIPagingScrollView::visiblePages
*/

/**
* Called before the page is about to be shown and after its frame has been set.
*
* Meant to be subclassed. By default this method does nothing.
*
* @fn NIPagingScrollView::willDisplayPage:
*/

/**
* Called immediately after the page is removed from the paging scroll view.
*
* Meant to be subclassed. By default this method does nothing.
*
* @fn NIPagingScrollView::didRecyclePage:
*/
Loading

0 comments on commit 9fee412

Please sign in to comment.