Skip to content

Commit

Permalink
Merge pull request #1276 from BrunoMazzo/fix-ios-16
Browse files Browse the repository at this point in the history
Fix ios 16
  • Loading branch information
Justin Martin authored Feb 26, 2023
2 parents ffa7959 + 7393c3f commit 3d0daa5
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 14 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ jobs:
- name: Validate podspec
run: pod lib lint

build:
runs-on: macos-11
build_xcode14:
runs-on: macos-12
strategy:
matrix:
run-config:
- { xcode_version: '11.7', simulator: 'name=iPhone SE (2nd generation),OS=13.7' }
- { xcode_version: '12.5.1', simulator: 'name=iPhone SE (2nd generation),OS=14.5' }
- { xcode_version: '13.0', simulator: 'name=iPad Pro (12.9-inch) (5th generation),OS=15.0' }


- { xcode_version: '14.1', simulator: 'name=iPad Pro (12.9-inch) (5th generation),OS=16.1' }
- { xcode_version: '14.1', simulator: 'name=iPhone SE (2nd generation),OS=16.1' }
steps:
- name: Checkout Project
uses: actions/checkout@v1
Expand Down Expand Up @@ -56,14 +53,13 @@ jobs:
- name: Build & Test
run: ./scripts/ci.sh "${{ matrix.run-config['simulator'] }}"

build_xcode10:
runs-on: macos-10.15
build:
runs-on: macos-11
strategy:
matrix:
run-config:
- { xcode_version: '10.3', simulator: 'name=iPad (5th generation),OS=12.4' }
- { xcode_version: '10.3', simulator: 'name=iPhone 8,OS=12.4' }

- { xcode_version: '13.0', simulator: 'name=iPhone SE (2nd generation),OS=15.0' }
- { xcode_version: '13.0', simulator: 'name=iPad Pro (12.9-inch) (5th generation),OS=15.0' }
steps:
- name: Checkout Project
uses: actions/checkout@v1
Expand Down Expand Up @@ -93,4 +89,4 @@ jobs:
run: xcrun simctl list

- name: Build & Test
run: ./scripts/ci.sh "${{ matrix.run-config['simulator'] }}"
run: ./scripts/ci.sh "${{ matrix.run-config['simulator'] }}"
41 changes: 41 additions & 0 deletions Sources/KIF/Additions/UIView-KIFAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ - (UIAccessibilityElement *)accessibilityElementMatchingBlock:(BOOL(^)(UIAccessi
// UITableViewCell is such an offender.
for (UIView *view in [self.subviews reverseObjectEnumerator]) {
UIAccessibilityElement *element = [view accessibilityElementMatchingBlock:matchBlock];

if (!element) {
UIView* fallbackView = [self tryGetiOS16KeyboardFallbackViewFromParentView:view];
element = [fallbackView accessibilityElementMatchingBlock:matchBlock];
}

if (!element) {
continue;
}
Expand Down Expand Up @@ -374,12 +380,23 @@ - (NSArray *)subviewsWithClassNamePrefix:(NSString *)prefix;
if ([NSStringFromClass([view class]) hasPrefix:prefix]) {
[result addObject:view];
}

UIView* fallbackView = [self tryGetiOS16KeyboardFallbackViewFromParentView:view];
if ([NSStringFromClass([fallbackView class]) hasPrefix:prefix]) {
[result addObject:fallbackView];
}
}

// Now traverse the subviews of the subviews, adding matches.
for (UIView *view in self.subviews) {
NSArray *matchingSubviews = [view subviewsWithClassNamePrefix:prefix];
[result addObjectsFromArray:matchingSubviews];

UIView* fallbackView = [self tryGetiOS16KeyboardFallbackViewFromParentView:view];
if (fallbackView) {
NSArray *matchingSubviews = [fallbackView subviewsWithClassNamePrefix:prefix];
[result addObjectsFromArray:matchingSubviews];
}
}

return result;
Expand All @@ -403,14 +420,30 @@ - (NSArray *)subviewsWithClassNameOrSuperClassNamePrefix:(NSString *)prefix;
// First traverse the next level of subviews, adding matches
for (UIView *view in self.subviews) {
Class klass = [view class];

while (klass) {
if ([NSStringFromClass(klass) hasPrefix:prefix]) {
[result addObject:view];
break;
}

UIView* fallbackView = [self tryGetiOS16KeyboardFallbackViewFromParentView:view];
if (fallbackView) {
Class klass = [fallbackView class];
while (klass) {
if ([NSStringFromClass(klass) hasPrefix:prefix]) {
[result addObject:fallbackView];
break;
}

klass = [klass superclass];
}
}

klass = [klass superclass];
}


}

// Now traverse the subviews of the subviews, adding matches
Expand Down Expand Up @@ -1020,5 +1053,13 @@ - (void)performBlockOnAscendentViews:(void (^)(UIView *view, BOOL *stop))block
}
}

-(UIView*)tryGetiOS16KeyboardFallbackViewFromParentView:(UIView*) parentView {
if([parentView isKindOfClass:NSClassFromString(@"_UIRemoteKeyboardPlaceholderView")]) {
UIView* fallbackView = [parentView valueForKey:@"_fallbackView"];
return fallbackView;
}

return nil;
}

@end
49 changes: 48 additions & 1 deletion Sources/KIF/Classes/KIFSystemTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,54 @@ - (void)simulateMemoryWarning

- (void)simulateDeviceRotationToOrientation:(UIDeviceOrientation)orientation
{
[[UIDevice currentDevice] setValue:@(orientation) forKey:@"orientation"];
#ifdef __IPHONE_16_0
if (@available(iOS 16.0, *)) {
NSSet<UIScene *> *scenes = [[UIApplication sharedApplication] connectedScenes];
UIWindowScene* windowScene;
for (UIScene* scene in scenes) {
if([scene isKindOfClass:[UIWindowScene class]]) {
windowScene = (UIWindowScene*) scene;
break;
}
}

if (windowScene) {
UIInterfaceOrientationMask orientationMask;
switch (orientation) {
case UIDeviceOrientationUnknown:
orientationMask = UIInterfaceOrientationMaskAll;
break;
case UIDeviceOrientationPortrait:
orientationMask = UIInterfaceOrientationMaskPortrait;
break;
case UIDeviceOrientationPortraitUpsideDown:
orientationMask = UIInterfaceOrientationMaskPortraitUpsideDown;
break;
case UIDeviceOrientationLandscapeLeft:
orientationMask = UIInterfaceOrientationMaskLandscapeLeft;
break;
case UIDeviceOrientationLandscapeRight:
orientationMask = UIInterfaceOrientationMaskLandscapeRight;
break;
case UIDeviceOrientationFaceUp:
orientationMask = UIInterfaceOrientationMaskAll;
break;
case UIDeviceOrientationFaceDown:
orientationMask = UIInterfaceOrientationMaskAll;
break;
}

UIWindowSceneGeometryPreferencesIOS* preferences = [[UIWindowSceneGeometryPreferencesIOS alloc]initWithInterfaceOrientations:orientationMask];
[windowScene requestGeometryUpdateWithPreferences:preferences errorHandler:^(NSError * _Nonnull error) {
[self failWithError:[NSError KIFErrorWithUnderlyingError:error format:@"Could not rotate the screen"] stopTest:YES];
}];
}
} else {
#endif
[[UIDevice currentDevice] setValue:@(orientation) forKey:@"orientation"];
#ifdef __IPHONE_16_0
}
#endif
}


Expand Down
5 changes: 5 additions & 0 deletions Sources/KIF/Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,16 @@ - (void)selectPickerViewRowWithTitle:(NSString *)title inComponent:(NSInteger)co
// Find all pickers in view. Either UIDatePickerView or UIPickerView
NSArray *datePickerViews = [[[UIApplication sharedApplication] datePickerWindow] subviewsWithClassNameOrSuperClassNamePrefix:@"UIPickerView"];
NSArray *pickerViews = [[[UIApplication sharedApplication] pickerViewWindow] subviewsWithClassNameOrSuperClassNamePrefix:@"UIPickerView"];

NSArray *iOS16DatePickerViews = [[[UIApplication sharedApplication] datePickerWindow] subviewsWithClassNameOrSuperClassNamePrefix:@"UIDatePicker"];

// Grab one picker and assume it is datePicker and then test our hypothesis later!
pickerView = [datePickerViews lastObject];
if ([pickerView respondsToSelector:@selector(setDate:animated:)] || [pickerView isKindOfClass:NSClassFromString(@"_UIDatePickerView")]) {
pickerType = KIFUIDatePicker;
}else if([[iOS16DatePickerViews lastObject] respondsToSelector:@selector(setDate:animated:)]) {
pickerView = [[iOS16DatePickerViews lastObject] valueForKey:@"_pickerView"];
pickerType = KIFUIDatePicker;
} else {
pickerView = [pickerViews lastObject];
pickerType = KIFUIPickerView;
Expand Down

0 comments on commit 3d0daa5

Please sign in to comment.