Skip to content

Commit 8accd13

Browse files
committed
Fix: hook _updateInteractionIsEnabled on iOS ≤15 and don't hook it on iPadOS
1 parent 905ca38 commit 8accd13

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Natives/UIKit+hook.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern NSNotificationName UIPresentationControllerPresentationTransitionWillBegi
4848

4949
@interface UIPointerInteraction(private)
5050
- (NSArray <id<_UIPointerInteractionDriver>> *)drivers;
51+
- (id<_UIPointerInteractionDriver>)driver;
5152
@end
5253

5354
/*

Natives/UIKit+hook.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void swizzleUIImageMethod(SEL originalAction, SEL swizzledAction) {
3131
void init_hookUIKitConstructor(void) {
3232
swizzle(UIDevice.class, @selector(userInterfaceIdiom), @selector(hook_userInterfaceIdiom));
3333
swizzle(UIImageView.class, @selector(setImage:), @selector(hook_setImage:));
34-
swizzle(UIPointerInteraction.class, @selector(_updateInteractionIsEnabled), @selector(hook__updateInteractionIsEnabled));
34+
if(UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
35+
swizzle(UIPointerInteraction.class, @selector(_updateInteractionIsEnabled), @selector(hook__updateInteractionIsEnabled));
36+
}
3537

3638
// Add this line to swizzle the _imageWithSize: method
3739
swizzleUIImageMethod(NSSelectorFromString(@"_imageWithSize:"), @selector(hook_imageWithSize:));
@@ -211,8 +213,12 @@ @implementation UIPointerInteraction(hook)
211213
- (void)hook__updateInteractionIsEnabled {
212214
UIView *view = self.view;
213215
BOOL enabled = self.enabled; // && view.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad
214-
for(id<_UIPointerInteractionDriver> driver in self.drivers) {
215-
driver.view = enabled ? view : nil;
216+
if([self respondsToSelector:@selector(drivers)]) {
217+
for(id<_UIPointerInteractionDriver> driver in self.drivers) {
218+
driver.view = enabled ? view : nil;
219+
}
220+
} else {
221+
self.driver.view = enabled ? view : nil;
216222
}
217223
// to keep it fast, ivar offset is cached for later direct access
218224
static ptrdiff_t ivarOff = 0;

0 commit comments

Comments
 (0)