Skip to content

Commit

Permalink
Set animation speed for all windows (#1279)
Browse files Browse the repository at this point in the history
* Set animation speed for all windows

* remove nslog

* rename

* rename

* Swizzle init

* change testing code back

* set project level
  • Loading branch information
steve-sun-me authored Apr 3, 2023
1 parent fafb26b commit 4081d3f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 1 deletion.
24 changes: 24 additions & 0 deletions KIF.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,16 @@
85DB94741C5A5FE10025F83E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 85DB94711C5A5D430025F83E /* QuartzCore.framework */; };
85DB94751C5A5FEA0025F83E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 85DB94711C5A5D430025F83E /* QuartzCore.framework */; };
8E654FC429D79BD8007F7811 /* OffscreenTests_ViewTestActor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E654FC329D79BD8007F7811 /* OffscreenTests_ViewTestActor.m */; };
8E654FCE29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E654FCC29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h */; };
8E654FCF29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E654FCC29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h */; };
8E654FD029DA2FE7007F7811 /* UIWindow+KIFSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E654FCD29DA2FE7007F7811 /* UIWindow+KIFSwizzle.m */; };
8E654FD129DA2FE8007F7811 /* UIWindow+KIFSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E654FCD29DA2FE7007F7811 /* UIWindow+KIFSwizzle.m */; };
8EAA1EE229D3AF7A008F6029 /* OffscreenViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EAA1EE129D3AF7A008F6029 /* OffscreenViewController.m */; };
8EAA1EE429D3B1F5008F6029 /* OffscreenTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EAA1EE329D3B1F5008F6029 /* OffscreenTests.m */; };
8EC2CB1F29DB3D3B001BE493 /* NSObject+KIFSwizzle.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC2CB1D29DB3D3B001BE493 /* NSObject+KIFSwizzle.h */; };
8EC2CB2029DB3D3B001BE493 /* NSObject+KIFSwizzle.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC2CB1D29DB3D3B001BE493 /* NSObject+KIFSwizzle.h */; };
8EC2CB2129DB3D3B001BE493 /* NSObject+KIFSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC2CB1E29DB3D3B001BE493 /* NSObject+KIFSwizzle.m */; };
8EC2CB2229DB3D3B001BE493 /* NSObject+KIFSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC2CB1E29DB3D3B001BE493 /* NSObject+KIFSwizzle.m */; };
97E8A5CF1B0A62F700124E3B /* BackgroundViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 97E8A5CE1B0A62F700124E3B /* BackgroundViewController.m */; };
97E8A5D11B0A63D100124E3B /* BackgroundTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 97E8A5D01B0A63D100124E3B /* BackgroundTests.m */; };
9CC881A91AD4CE39002CD34C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAB072B413971AEA008AF393 /* UIKit.framework */; };
Expand Down Expand Up @@ -405,8 +413,12 @@
84D293B71A2C8DF700C10944 /* AddressBookUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBookUI.framework; path = System/Library/Frameworks/AddressBookUI.framework; sourceTree = SDKROOT; };
85DB94711C5A5D430025F83E /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
8E654FC329D79BD8007F7811 /* OffscreenTests_ViewTestActor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OffscreenTests_ViewTestActor.m; sourceTree = "<group>"; };
8E654FCC29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIWindow+KIFSwizzle.h"; sourceTree = "<group>"; };
8E654FCD29DA2FE7007F7811 /* UIWindow+KIFSwizzle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIWindow+KIFSwizzle.m"; sourceTree = "<group>"; };
8EAA1EE129D3AF7A008F6029 /* OffscreenViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OffscreenViewController.m; sourceTree = "<group>"; };
8EAA1EE329D3B1F5008F6029 /* OffscreenTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OffscreenTests.m; sourceTree = "<group>"; };
8EC2CB1D29DB3D3B001BE493 /* NSObject+KIFSwizzle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+KIFSwizzle.h"; sourceTree = "<group>"; };
8EC2CB1E29DB3D3B001BE493 /* NSObject+KIFSwizzle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+KIFSwizzle.m"; sourceTree = "<group>"; };
97E8A5CE1B0A62F700124E3B /* BackgroundViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BackgroundViewController.m; sourceTree = "<group>"; };
97E8A5D01B0A63D100124E3B /* BackgroundTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BackgroundTests.m; sourceTree = "<group>"; };
9CC881A21AD4CAAC002CD34C /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -651,6 +663,10 @@
2229D54E25BEF47D0093296C /* UIWindow-KIFAdditions.m */,
2229D56E25BEF47D0093296C /* XCTestCase-KIFAdditions.h */,
2229D55C25BEF47D0093296C /* XCTestCase-KIFAdditions.m */,
8E654FCC29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h */,
8E654FCD29DA2FE7007F7811 /* UIWindow+KIFSwizzle.m */,
8EC2CB1D29DB3D3B001BE493 /* NSObject+KIFSwizzle.h */,
8EC2CB1E29DB3D3B001BE493 /* NSObject+KIFSwizzle.m */,
);
name = Additions;
path = Sources/KIF/Additions;
Expand Down Expand Up @@ -972,6 +988,7 @@
22B1376C25D6E32700D88061 /* KIFTestCase.h in Headers */,
22B1373225D6E32700D88061 /* KIFUITestActor_Private.h in Headers */,
22B1375725D6E32700D88061 /* KIFUIObject.h in Headers */,
8E654FCF29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h in Headers */,
22B1375525D6E32700D88061 /* KIFUIViewTestActor.h in Headers */,
22B1375B25D6E32700D88061 /* CAAnimation+KIFAdditions.h in Headers */,
22B1375225D6E32700D88061 /* NSPredicate+KIFAdditions.h in Headers */,
Expand All @@ -980,6 +997,7 @@
22B1376225D6E32700D88061 /* UITableView-KIFAdditions.h in Headers */,
9CC967401AD4B1B600576D13 /* KIF.h in Headers */,
22B1373525D6E32700D88061 /* UIDatePicker+KIFAdditions.h in Headers */,
8EC2CB2029DB3D3B001BE493 /* NSObject+KIFSwizzle.h in Headers */,
22B1376F25D6E32700D88061 /* KIFTestActor_Private.h in Headers */,
22B1375025D6E32700D88061 /* KIFTouchVisualizerView.h in Headers */,
22B1377925D6E32700D88061 /* KIFSystemTestActor.h in Headers */,
Expand Down Expand Up @@ -1015,6 +1033,7 @@
2229D5DE25BEF47D0093296C /* KIF.h in Headers */,
2229D5CE25BEF47D0093296C /* KIFTypist.h in Headers */,
2229D5A725BEF47D0093296C /* UITableView-KIFAdditions.h in Headers */,
8EC2CB1F29DB3D3B001BE493 /* NSObject+KIFSwizzle.h in Headers */,
2229D5AB25BEF47D0093296C /* NSError-KIFAdditions.h in Headers */,
2229D5B825BEF47D0093296C /* UIScreen+KIFAdditions.h in Headers */,
2229D5AA25BEF47D0093296C /* UIView-KIFAdditions.h in Headers */,
Expand All @@ -1029,6 +1048,7 @@
2229D5B625BEF47D0093296C /* NSString+KIFAdditions.h in Headers */,
2229D5BC25BEF47D0093296C /* CAAnimation+KIFAdditions.h in Headers */,
2229D59525BEF47D0093296C /* KIFUITestActor-IdentifierTests.h in Headers */,
8E654FCE29DA2FE7007F7811 /* UIWindow+KIFSwizzle.h in Headers */,
2229D59925BEF47D0093296C /* KIFTouchVisualizerView.h in Headers */,
2229D5C525BEF47D0093296C /* NSBundle-KIFAdditions.h in Headers */,
2229D59B25BEF47D0093296C /* KIFTouchVisualizerViewCoordinator.h in Headers */,
Expand Down Expand Up @@ -1276,6 +1296,7 @@
22B1375F25D6E32700D88061 /* KIFTextInputTraitsOverrides.m in Sources */,
22B1375925D6E32700D88061 /* NSError-KIFAdditions.m in Sources */,
22B1377025D6E32700D88061 /* CAAnimation+KIFAdditions.m in Sources */,
8E654FD129DA2FE8007F7811 /* UIWindow+KIFSwizzle.m in Sources */,
22B1373325D6E32700D88061 /* NSPredicate+KIFAdditions.m in Sources */,
22B1376E25D6E32700D88061 /* IOHIDEvent+KIF.m in Sources */,
22B1375D25D6E32700D88061 /* UITableView-KIFAdditions.m in Sources */,
Expand Down Expand Up @@ -1304,6 +1325,7 @@
22B1373A25D6E32700D88061 /* KIFUIObject.m in Sources */,
22B1377425D6E32700D88061 /* KIFTestActor.m in Sources */,
22B1374C25D6E32700D88061 /* UIApplication-KIFAdditions.m in Sources */,
8EC2CB2229DB3D3B001BE493 /* NSObject+KIFSwizzle.m in Sources */,
22B1375C25D6E32700D88061 /* KIFUITestActor-ConditionalTests.m in Sources */,
22B1376525D6E32700D88061 /* KIFTypist.m in Sources */,
);
Expand All @@ -1321,6 +1343,7 @@
2229D59725BEF47D0093296C /* KIFTouchVisualizerViewCoordinator.m in Sources */,
2229D5B125BEF47D0093296C /* XCTestCase-KIFAdditions.m in Sources */,
2229D5A225BEF47D0093296C /* CGGeometry-KIFAdditions.m in Sources */,
8E654FD029DA2FE7007F7811 /* UIWindow+KIFSwizzle.m in Sources */,
2229D5BE25BEF47D0093296C /* UITableView-KIFAdditions.m in Sources */,
2229D5AF25BEF47D0093296C /* NSBundle-KIFAdditions.m in Sources */,
2229D59C25BEF47D0093296C /* KIFTouchVisualizerView.m in Sources */,
Expand Down Expand Up @@ -1349,6 +1372,7 @@
2229D5D925BEF47D0093296C /* KIFTestStepValidation.m in Sources */,
2229D5A525BEF47D0093296C /* UIView-Debugging.m in Sources */,
2229D5C125BEF47D0093296C /* NSError-KIFAdditions.m in Sources */,
8EC2CB2129DB3D3B001BE493 /* NSObject+KIFSwizzle.m in Sources */,
2229D5B525BEF47D0093296C /* UIApplication-KIFAdditions.m in Sources */,
2229D5C025BEF47D0093296C /* UIEvent+KIFAdditions.m in Sources */,
);
Expand Down
14 changes: 14 additions & 0 deletions Sources/KIF/Additions/NSObject+KIFSwizzle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NSObject+KIFSwizzle.h
// KIF
//
// Created by Steve Sun on 2023-04-03.
//

#import <Foundation/Foundation.h>

@interface NSObject (KIFSwizzle)

+ (void)swizzleSEL:(SEL)originalSEL withSEL:(SEL)swizzledSEL;

@end
23 changes: 23 additions & 0 deletions Sources/KIF/Additions/NSObject+KIFSwizzle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// NSObject+KIFSwizzle.m
// KIF
//
// Created by Steve Sun on 2023-04-03.
//

#import "NSObject+KIFSwizzle.h"
#import <objc/runtime.h>

@implementation NSObject (KIFSwizzle)

+ (void)swizzleSEL:(SEL)originalSEL withSEL:(SEL)swizzledSEL
{
Class class = [self class];

Method originalMethod = class_getInstanceMethod(class, originalSEL);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSEL);

method_exchangeImplementations(originalMethod, swizzledMethod);
}

@end
4 changes: 3 additions & 1 deletion Sources/KIF/Additions/UIApplication-KIFAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ - (float)animationSpeed

- (void)setAnimationSpeed:(float)animationSpeed
{
self.keyWindow.layer.speed = animationSpeed;
for (UIWindow *window in self.windows) {
window.layer.speed = animationSpeed;
}
}

#pragma mark - Screenshotting
Expand Down
12 changes: 12 additions & 0 deletions Sources/KIF/Additions/UIWindow+KIFSwizzle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// UIWindow+KIFAdditions.h
// KIF
//
// Created by Steve Sun on 2023-04-02.
//

#import <UIKit/UIKit.h>

@interface UIWindow (KIFSwizzle)

@end
48 changes: 48 additions & 0 deletions Sources/KIF/Additions/UIWindow+KIFSwizzle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// UIWindow+KIFAdditions.m
// KIF
//
// Created by Steve Sun on 2023-04-02.
//

#import "UIWindow+KIFSwizzle.h"
#import "UIApplication-KIFAdditions.h"
#import "NSObject+KIFSwizzle.h"

@implementation UIWindow (KIFSwizzle)

+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self swizzleSEL:@selector(init) withSEL:@selector(swizzle_init)];
[self swizzleSEL:@selector(becomeKeyWindow) withSEL:@selector(swizzle_becomeKeyWindow)];
if (@available(iOS 13.0, *)) {
[self swizzleSEL:@selector(initWithWindowScene:) withSEL:@selector(swizzle_initWithWindowScene:)];
}
});
}

- (instancetype)swizzle_initWithWindowScene:(UIWindowScene *)scene API_AVAILABLE(ios(13))
{
UIWindow *window = [self swizzle_initWithWindowScene:scene];
window.layer.speed = [UIApplication sharedApplication].animationSpeed;

return window;
}

- (instancetype)swizzle_init
{
UIWindow *window = [self swizzle_init];
window.layer.speed = [UIApplication sharedApplication].animationSpeed;

return window;
}

- (void)swizzle_becomeKeyWindow
{
[self swizzle_becomeKeyWindow];
self.layer.speed = [UIApplication sharedApplication].animationSpeed;
}

@end

0 comments on commit 4081d3f

Please sign in to comment.