Skip to content

Commit

Permalink
[ios-sdk] Fix bug in paging laoder.
Browse files Browse the repository at this point in the history
Summary:
FBGraphObjectPagingLoader had a race condition where the data source has graph objects but
the table has not yet been refreshed. It was trying to reference a row that didn't exist. Fixed
it to do nothing in the case where the table does not contain rows.

Fixed Scrumptious resource bundle reference.

Test Plan:
- Ran PlacePickerSample, typed "fairm" quickly in text box, did not see crash, whereas it crashed previously
- Ran Scrumptious

Revert Plan:

Reviewers: jacl, mmarucheck, gregschechte, ayden

Reviewed By: jacl

CC: msdkexp@, platform-diffs@lists

Differential Revision: https://phabricator.fb.com/D539281
  • Loading branch information
Chris Lang committed Aug 3, 2012
1 parent 4a4f8ca commit b1bd32e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
10 changes: 5 additions & 5 deletions samples/Scrumptious/Scrumptious.xcodeproj/project.pbxproj
Expand Up @@ -13,7 +13,7 @@
846809C4158F85A100F2DBB9 /* action-photo.png in Resources */ = {isa = PBXBuildFile; fileRef = 846809C0158F85A100F2DBB9 /* action-photo.png */; };
84A5DA9615A68A3D00FE54AF /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A5DA9515A68A3D00FE54AF /* Accounts.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
8527EC6815C9DB3800660673 /* Scrumptious.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8527EC6A15C9DB3800660673 /* Scrumptious.strings */; };
8527EC5915C9D73700660673 /* FBUserSettingsViewResources.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8527EC5815C9D73700660673 /* FBUserSettingsViewResources.bundle */; };
8534B4DF15CC657900348ED2 /* FBUserSettingsViewResources.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8534B4DE15CC657900348ED2 /* FBUserSettingsViewResources.bundle */; };
856DC21A1577F105001FA6A6 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 856DC2171577F105001FA6A6 /* Icon-72.png */; };
856DC21B1577F105001FA6A6 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 856DC2181577F105001FA6A6 /* Icon.png */; };
856DC21C1577F105001FA6A6 /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 856DC2191577F105001FA6A6 /* Icon@2x.png */; };
Expand Down Expand Up @@ -45,8 +45,8 @@
846809C0158F85A100F2DBB9 /* action-photo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "action-photo.png"; path = "scrumptious/images/action-photo.png"; sourceTree = SOURCE_ROOT; };
84A5DA9515A68A3D00FE54AF /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
8527EC6915C9DB3800660673 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Scrumptious.strings; sourceTree = "<group>"; };
8527EC6B15C9DB4A00660673 /* he */ = {isa = PBXFileReference; name = he; path = he.lproj/Scrumptious.strings; sourceTree = "<group>"; };
8527EC5815C9D73700660673 /* FBUserSettingsViewResources.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = FBUserSettingsViewResources.bundle; path = ../../src/FBUserSettingsViewResources.bundle; sourceTree = "<group>"; };
8527EC6B15C9DB4A00660673 /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Scrumptious.strings; sourceTree = "<group>"; };
8534B4DE15CC657900348ED2 /* FBUserSettingsViewResources.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = FBUserSettingsViewResources.bundle; path = ../../build/FacebookSDK.framework/Versions/A/Resources/FBUserSettingsViewResources.bundle; sourceTree = "<group>"; };
856DC2171577F105001FA6A6 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72.png"; path = "../Icon-72.png"; sourceTree = "<group>"; };
856DC2181577F105001FA6A6 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon.png; path = ../Icon.png; sourceTree = "<group>"; };
856DC2191577F105001FA6A6 /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon@2x.png"; path = "../Icon@2x.png"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -118,7 +118,7 @@
B9CD0A72150EA4DD00560A93 /* Frameworks */ = {
isa = PBXGroup;
children = (
8527EC5815C9D73700660673 /* FBUserSettingsViewResources.bundle */,
8534B4DE15CC657900348ED2 /* FBUserSettingsViewResources.bundle */,
DD55EAB015ABA246000A64B8 /* FacebookSDKResources.bundle */,
DD55EAAE15AB9EDF000A64B8 /* FacebookSDK.framework */,
84A5DA9515A68A3D00FE54AF /* Accounts.framework */,
Expand Down Expand Up @@ -248,7 +248,7 @@
DDBF24B81590050600BAAB8F /* SCPhotoViewController.xib in Resources */,
DD55EAB115ABA246000A64B8 /* FacebookSDKResources.bundle in Resources */,
8527EC6815C9DB3800660673 /* Scrumptious.strings in Resources */,
8527EC5915C9D73700660673 /* FBUserSettingsViewResources.bundle in Resources */,
8534B4DF15CC657900348ED2 /* FBUserSettingsViewResources.bundle in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
42 changes: 22 additions & 20 deletions src/FBGraphObjectPagingLoader.m
Expand Up @@ -145,26 +145,28 @@ - (void)addResultsAndUpdateView:(NSDictionary*)results {
// (If possible, we choose the second row, to give context above and below and avoid
// cases where the first row is only barely visible, thus providing little context.)
NSArray *visibleRowIndexPaths = [self.tableView indexPathsForVisibleRows];
int anchorRowIndex = (visibleRowIndexPaths.count > 1) ? 1 : 0;
NSIndexPath *anchorIndexPath = [visibleRowIndexPaths objectAtIndex:anchorRowIndex];
id anchorObject = [self.dataSource itemAtIndexPath:anchorIndexPath];

// What is its rect, and what is the overall contentOffset of the table?
CGRect anchorRowRectBefore = [self.tableView rectForRowAtIndexPath:anchorIndexPath];
CGPoint contentOffset = self.tableView.contentOffset;

// Update with new data and reload the table.
[self.dataSource appendGraphObjects:data];
[self updateView];

// Where is the anchor object now?
anchorIndexPath = [self.dataSource indexPathForItem:anchorObject];
CGRect anchorRowRectAfter = [self.tableView rectForRowAtIndexPath:anchorIndexPath];

// Keep the content offset the same relative to the rect of the row (so if it was
// 1/4 scrolled off the top before, it still will be, etc.)
contentOffset.y += anchorRowRectAfter.origin.y - anchorRowRectBefore.origin.y;
self.tableView.contentOffset = contentOffset;
if (visibleRowIndexPaths.count > 0) {
int anchorRowIndex = (visibleRowIndexPaths.count > 1) ? 1 : 0;
NSIndexPath *anchorIndexPath = [visibleRowIndexPaths objectAtIndex:anchorRowIndex];
id anchorObject = [self.dataSource itemAtIndexPath:anchorIndexPath];

// What is its rect, and what is the overall contentOffset of the table?
CGRect anchorRowRectBefore = [self.tableView rectForRowAtIndexPath:anchorIndexPath];
CGPoint contentOffset = self.tableView.contentOffset;

// Update with new data and reload the table.
[self.dataSource appendGraphObjects:data];
[self updateView];

// Where is the anchor object now?
anchorIndexPath = [self.dataSource indexPathForItem:anchorObject];
CGRect anchorRowRectAfter = [self.tableView rectForRowAtIndexPath:anchorIndexPath];

// Keep the content offset the same relative to the rect of the row (so if it was
// 1/4 scrolled off the top before, it still will be, etc.)
contentOffset.y += anchorRowRectAfter.origin.y - anchorRowRectBefore.origin.y;
self.tableView.contentOffset = contentOffset;
}
}

if ([self.delegate respondsToSelector:@selector(pagingLoader:didLoadData:)]) {
Expand Down

0 comments on commit b1bd32e

Please sign in to comment.