Skip to content

Commit 962d579

Browse files
authored
Merge pull request #1319 from kif-framework/markj/collection_view_changes_iOS_18
Change the collection view changes to iOS 18
2 parents 1c7a174 + 87d9002 commit 962d579

3 files changed

Lines changed: 64 additions & 28 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
strategy:
2020
matrix:
2121
run-config:
22-
- { xcode_version: '15.4', simulator: 'name=iPad Air (5th generation),OS=17.5', run_extra_validations: 'false' }
22+
- { xcode_version: '15.4', simulator: 'name=iPad (10th generation),OS=17.5', run_extra_validations: 'false' }
2323
- { xcode_version: '15.4', simulator: 'name=iPhone 15,OS=17.5', run_extra_validations: 'false' }
24-
- { xcode_version: '16.1', simulator: 'name=iPad Air (5th generation),OS=18.1', run_extra_validations: 'false' }
24+
- { xcode_version: '16.1', simulator: 'name=iPad (10th generation),OS=18.1', run_extra_validations: 'false' }
2525
- { xcode_version: '16.1', simulator: 'name=iPhone 16,OS=18.1', run_extra_validations: 'true' }
2626
steps:
2727
- name: Checkout Project

Scripts/ci.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515
rm -rf ${PWD}/build
1616

1717
# Run KIF Tests
18-
env NSUnbufferedIO=YES xcodebuild test -project KIF.xcodeproj -scheme KIF -derivedDataPath=${PWD}/build/KIF -destination "platform=iOS Simulator,${SIMULATOR}" | xcpretty -c
18+
env NSUnbufferedIO=YES xcodebuild test -project KIF.xcodeproj -scheme KIF -derivedDataPath=${PWD}/build/KIF -destination "platform=iOS Simulator,${SIMULATOR}" CODE_SIGNING_ALLOWED=NO | xcbeautify
1919

2020
if [ $RUN_EXTRA_VALIDATIONS != "true" ]; then
2121
exit 0
@@ -25,14 +25,14 @@ fi
2525
swift build -Xcc "-isysroot" -Xcc "$(xcrun --sdk iphonesimulator --show-sdk-path)" -Xcc "-target" -Xcc "x86_64-apple-ios$(xcrun --sdk iphonesimulator --show-sdk-version)-simulator"
2626

2727
# Consume KIF via Swift Package Manager in an Xcode project
28-
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/SPMIntegration/SPMIntegration.xcodeproj" -scheme "SPMIntegration" -derivedDataPath=${PWD}/build/SPMIntegration -destination "platform=iOS Simulator,${SIMULATOR}" | xcpretty -c
28+
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/SPMIntegration/SPMIntegration.xcodeproj" -scheme "SPMIntegration" -derivedDataPath=${PWD}/build/SPMIntegration -destination "platform=iOS Simulator,${SIMULATOR}" CODE_SIGNING_ALLOWED=NO | xcbeautify
2929

3030
# Test the "Testable" example project
31-
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/Testable/Testable.xcodeproj" -scheme Testable -derivedDataPath=${PWD}/build/Testable -destination "platform=iOS Simulator,${SIMULATOR}" | xcpretty -c
31+
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/Testable/Testable.xcodeproj" -scheme Testable -derivedDataPath=${PWD}/build/Testable -destination "platform=iOS Simulator,${SIMULATOR}" CODE_SIGNING_ALLOWED=NO | xcbeautify
3232

3333
# Test the "TestableSwift" example project
34-
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/TestableSwift/TestableSwift.xcodeproj" -scheme "TestableSwift" -derivedDataPath=${PWD}/build/TestableSwift -destination "platform=iOS Simulator,${SIMULATOR}" | xcpretty -c
34+
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/TestableSwift/TestableSwift.xcodeproj" -scheme "TestableSwift" -derivedDataPath=${PWD}/build/TestableSwift -destination "platform=iOS Simulator,${SIMULATOR}" CODE_SIGNING_ALLOWED=NO | xcbeautify
3535

3636
# Test the "Calculator" example project
37-
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/Calculator/Calculator.xcodeproj" -scheme "Calculator" -derivedDataPath=${PWD}/build/Calculator -destination "platform=iOS Simulator,${SIMULATOR}" | xcpretty -c
37+
env NSUnbufferedIO=YES xcodebuild test -project "Documentation/Examples/Calculator/Calculator.xcodeproj" -scheme "Calculator" -derivedDataPath=${PWD}/build/Calculator -destination "platform=iOS Simulator,${SIMULATOR}" CODE_SIGNING_ALLOWED=NO | xcbeautify
3838

Sources/KIF/Additions/UIView-KIFAdditions.m

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -375,31 +375,67 @@ - (UIAccessibilityElement *)accessibilityElementMatchingBlock:(BOOL(^)(UIAccessi
375375
continue;
376376
}
377377

378-
@autoreleasepool {
379-
CGRect visibleRect = [collectionView layoutAttributesForItemAtIndexPath:indexPath].frame;
380-
[collectionView scrollRectToVisible:visibleRect animated:NO];
381-
[collectionView layoutIfNeeded];
382-
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
383-
if (cell == nil) {
384-
[collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
378+
if (@available(iOS 18, *)) {
379+
@autoreleasepool {
380+
CGRect visibleRect = [collectionView layoutAttributesForItemAtIndexPath:indexPath].frame;
381+
[collectionView scrollRectToVisible:visibleRect animated:NO];
385382
[collectionView layoutIfNeeded];
386-
cell = [collectionView cellForItemAtIndexPath:indexPath];
383+
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
384+
for (NSUInteger attempts = 0; attempts < 10 && !cell && collectionView.window; attempts++) {
385+
CFRunLoopRunInMode(UIApplicationCurrentRunMode, 0.01, false);
386+
cell = [collectionView cellForItemAtIndexPath:indexPath];
387+
}
388+
if (cell == nil) {
389+
[collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
390+
[collectionView layoutIfNeeded];
391+
cell = [collectionView cellForItemAtIndexPath:indexPath];
392+
}
393+
// Skip this cell if it can't be found
394+
if (!cell) {
395+
continue;
396+
}
397+
UIAccessibilityElement *element = [cell accessibilityElementMatchingBlock:matchBlock notHidden:NO disableScroll:NO];
398+
399+
// Skip this cell if it isn't the one we're looking for
400+
if (!element) {
401+
continue;
402+
}
387403
}
388-
// Skip this cell if it can't be found
389-
if (!cell) {
390-
continue;
391-
}
392-
UIAccessibilityElement *element = [cell accessibilityElementMatchingBlock:matchBlock notHidden:NO disableScroll:NO];
393-
394-
// Skip this cell if it isn't the one we're looking for
395-
if (!element) {
396-
continue;
404+
405+
// Note: using KIFRunLoopRunInModeRelativeToAnimationSpeed here may cause tests to stall
406+
CFRunLoopRunInMode(UIApplicationCurrentRunMode, CELL_SCROLL_DELAY_STABILIZATION, false);
407+
return [self accessibilityElementMatchingBlock:matchBlock disableScroll:NO];
408+
} else {
409+
@autoreleasepool {
410+
// Get the cell directly from the dataSource because UICollectionView will only vend visible cells
411+
UICollectionViewCell *cell = [collectionView.dataSource collectionView:collectionView cellForItemAtIndexPath:indexPath];
412+
413+
// The cell contents might change just prior to being displayed, so we simulate the cell appearing onscreen
414+
if ([collectionView.delegate respondsToSelector:@selector(collectionView:willDisplayCell:forItemAtIndexPath:)]) {
415+
[collectionView.delegate collectionView:collectionView willDisplayCell:cell forItemAtIndexPath:indexPath];
416+
}
417+
418+
UIAccessibilityElement *element = [cell accessibilityElementMatchingBlock:matchBlock notHidden:NO disableScroll:NO];
419+
420+
// Remove the cell from the collection view so that it doesn't stick around
421+
[cell removeFromSuperview];
422+
423+
// Skip this cell if it isn't the one we're looking for
424+
// Sometimes we get cells with no size here which can cause an endless loop, so we ignore those
425+
if (!element || CGSizeEqualToSize(cell.frame.size, CGSizeZero)) {
426+
continue;
427+
}
397428
}
429+
430+
// Scroll to the cell and wait for the animation to complete
431+
CGRect frame = [collectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:indexPath].frame;
432+
[collectionView scrollRectToVisible:frame animated:YES];
433+
// Note: using KIFRunLoopRunInModeRelativeToAnimationSpeed here may cause tests to stall
434+
CFRunLoopRunInMode(UIApplicationCurrentRunMode, 0.5, false);
435+
436+
// Now try finding the element again
437+
return [self accessibilityElementMatchingBlock:matchBlock];
398438
}
399-
400-
// Note: using KIFRunLoopRunInModeRelativeToAnimationSpeed here may cause tests to stall
401-
CFRunLoopRunInMode(UIApplicationCurrentRunMode, CELL_SCROLL_DELAY_STABILIZATION, false);
402-
return [self accessibilityElementMatchingBlock:matchBlock disableScroll:NO];
403439
}
404440
}
405441

0 commit comments

Comments
 (0)