Skip to content

Commit 1d63a8c

Browse files
author
Gianmarco
committed
Fix: Transfer leadingScreensForBatching from pending state on node load
and add tests
1 parent e696302 commit 1d63a8c

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

Source/ASCollectionNode.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ - (void)didLoad
345345
[view setContentOffset:contentOffset animated:pendingState.animatesContentOffset];
346346
}
347347

348+
if (pendingState.leadingScreensForBatching != 0) {
349+
view.leadingScreensForBatching = pendingState.leadingScreensForBatching;
350+
}
351+
348352
const auto tuningParametersVector = pendingState->_tuningParameters;
349353
const auto tuningParametersVectorSize = tuningParametersVector.size();
350354
for (NSInteger rangeMode = 0; rangeMode < tuningParametersVectorSize; rangeMode++) {

Source/ASTableNode.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ - (void)didLoad
176176
if (!CGPointEqualToPoint(contentOffset, CGPointZero)) {
177177
[view setContentOffset:contentOffset animated:pendingState.animatesContentOffset];
178178
}
179+
180+
if (pendingState.leadingScreensForBatching != 0) {
181+
view.leadingScreensForBatching = pendingState.leadingScreensForBatching;
182+
}
179183

180184
const auto tuningParametersVector = pendingState->_tuningParameters;
181185
const auto tuningParametersVectorSize = tuningParametersVector.size();

Tests/ASCollectionViewTests.mm

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,4 +1299,63 @@ - (void)DISABLED_testThatAutomaticallyManagedSubnodesGetPreloadCallBeforeDisplay
12991299

13001300
}
13011301

1302+
- (void)testAllPendingStatePropertiesTransferredToView {
1303+
// Create node without loading view
1304+
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
1305+
ASCollectionNode *node = [[ASCollectionNode alloc] initWithFrame:CGRectZero
1306+
collectionViewLayout:layout];
1307+
1308+
XCTAssertFalse(node.isNodeLoaded, @"View should not be loaded before setting properties");
1309+
1310+
// Set pending state properties before view loads
1311+
node.leadingScreensForBatching = 3.6;
1312+
node.inverted = YES;
1313+
node.allowsMultipleSelection = YES;
1314+
node.alwaysBounceVertical = YES;
1315+
node.alwaysBounceHorizontal = YES;
1316+
node.pagingEnabled = YES;
1317+
node.showsVerticalScrollIndicator = NO;
1318+
node.showsHorizontalScrollIndicator = NO;
1319+
UIEdgeInsets testInsets = UIEdgeInsetsMake(10, 20, 30, 40);
1320+
node.contentInset = testInsets;
1321+
CGPoint testOffset = CGPointMake(50, 60);
1322+
node.contentOffset = testOffset;
1323+
ASCollectionViewTestDelegate *delegate = [[ASCollectionViewTestDelegate alloc] initWithNumberOfSections:10 numberOfItemsInSection:10];
1324+
node.delegate = delegate;
1325+
ASCollectionViewTestDelegate *dataSource = [[ASCollectionViewTestDelegate alloc] initWithNumberOfSections:20 numberOfItemsInSection:20];
1326+
node.dataSource = dataSource;
1327+
1328+
1329+
// Load the view (triggers pending state transfer)
1330+
ASCollectionView *view = node.view;
1331+
1332+
XCTAssertTrue(node.isNodeLoaded, @"View should be loaded after accessing node.view");
1333+
1334+
// Verify properties were transferred correctly
1335+
XCTAssertEqual(view.leadingScreensForBatching, 3.6,
1336+
@"leadingScreensForBatching should transfer from pending state");
1337+
XCTAssertEqual(view.inverted, YES,
1338+
@"inverted should transfer from pending state");
1339+
XCTAssertEqual(view.allowsMultipleSelection, YES,
1340+
@"allowsMultipleSelection should transfer from pending state");
1341+
XCTAssertEqual(view.alwaysBounceVertical, YES,
1342+
@"alwaysBounceVertical should transfer from pending state");
1343+
XCTAssertEqual(view.alwaysBounceHorizontal, YES,
1344+
@"alwaysBounceHorizontal should transfer from pending state");
1345+
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(view.contentInset, testInsets),
1346+
@"contentInset should transfer from pending state");
1347+
XCTAssertTrue(CGPointEqualToPoint(view.contentOffset, testOffset),
1348+
@"contentOffset should transfer from pending state");
1349+
XCTAssertEqual(view.showsVerticalScrollIndicator, NO,
1350+
@"showsVerticalScrollIndicator should transfer from pending state");
1351+
XCTAssertEqual(view.showsHorizontalScrollIndicator, NO,
1352+
@"showsHorizontalScrollIndicator should transfer from pending state");
1353+
XCTAssertEqual(view.pagingEnabled, YES,
1354+
@"pagingEnabled should transfer from pending state");
1355+
XCTAssertEqual(view.asyncDelegate, delegate,
1356+
@"delegate should transfer from pending state");
1357+
XCTAssertEqual(view.asyncDataSource, dataSource,
1358+
@"dataSource should transfer from pending state");
1359+
}
1360+
13021361
@end

Tests/ASTableViewTests.mm

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,4 +1049,57 @@ - (void)testTintColorIsPropagatedToTableViewCell
10491049
XCTAssertTrue(areColorsEqual);
10501050
}
10511051

1052+
- (void)testAllPendingStatePropertiesTransferredToView {
1053+
// Create node without loading view
1054+
ASTableNode *node = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain];
1055+
1056+
XCTAssertFalse(node.isNodeLoaded, @"View should not be loaded before setting properties");
1057+
1058+
// Set pending state properties before view loads
1059+
node.leadingScreensForBatching = 3.6;
1060+
node.inverted = YES;
1061+
node.allowsSelectionDuringEditing = YES;
1062+
node.allowsMultipleSelection = YES;
1063+
node.allowsMultipleSelectionDuringEditing = YES;
1064+
node.pagingEnabled = YES;
1065+
node.automaticallyAdjustsContentOffset = NO;
1066+
UIEdgeInsets testInsets = UIEdgeInsetsMake(10, 20, 30, 40);
1067+
node.contentInset = testInsets;
1068+
CGPoint testOffset = CGPointMake(50, 60);
1069+
node.contentOffset = testOffset;
1070+
ASTableViewFilledDelegate *delegate = [ASTableViewFilledDelegate new];
1071+
node.delegate = delegate;
1072+
ASTableViewFilledDataSource *dataSource = [ASTableViewFilledDataSource new];
1073+
node.dataSource = dataSource;
1074+
1075+
// Load the view (triggers pending state transfer)
1076+
ASTableView *view = node.view;
1077+
1078+
XCTAssertTrue(node.isNodeLoaded, @"View should be loaded after accessing node.view");
1079+
1080+
// Verify properties were transferred correctly
1081+
XCTAssertEqual(view.leadingScreensForBatching, 3.6,
1082+
@"leadingScreensForBatching should transfer from pending state");
1083+
XCTAssertEqual(view.inverted, YES,
1084+
@"inverted should transfer from pending state");
1085+
XCTAssertEqual(view.allowsSelectionDuringEditing, YES,
1086+
@"allowsSelectionDuringEditing should transfer from pending state");
1087+
XCTAssertEqual(view.allowsMultipleSelection, YES,
1088+
@"allowsMultipleSelection should transfer from pending state");
1089+
XCTAssertEqual(view.allowsMultipleSelectionDuringEditing, YES,
1090+
@"allowsMultipleSelectionDuringEditing should transfer from pending state");
1091+
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(view.contentInset, testInsets),
1092+
@"contentInset should transfer from pending state");
1093+
XCTAssertTrue(CGPointEqualToPoint(view.contentOffset, testOffset),
1094+
@"contentOffset should transfer from pending state");
1095+
XCTAssertEqual(view.automaticallyAdjustsContentOffset, NO,
1096+
@"automaticallyAdjustsContentOffset should transfer from pending state");
1097+
XCTAssertEqual(view.pagingEnabled, YES,
1098+
@"pagingEnabled should transfer from pending state");
1099+
XCTAssertEqual(view.asyncDelegate, delegate,
1100+
@"delegate should transfer from pending state");
1101+
XCTAssertEqual(view.asyncDataSource, dataSource,
1102+
@"dataSource should transfer from pending state");
1103+
}
1104+
10521105
@end

0 commit comments

Comments
 (0)