diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Observer/UIDTreeObserver.m b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Observer/UIDTreeObserver.m index 168d10b3300..555bf238af8 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Observer/UIDTreeObserver.m +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Observer/UIDTreeObserver.m @@ -33,6 +33,15 @@ - (void)processNode:(id)node withContext:(UIDContext*)context { [self processNode:node withSnapshot:false withContext:context]; } +- (void)setTraversalMode:(UIDTraversalMode)traversalMode { + if (_traversalMode == traversalMode) { + return; + } + _traversalMode = traversalMode; + [UIDAllyTraversal setVoiceOverServiceEnabled:traversalMode == + UIDTraversalModeAccessibilityHierarchy]; +} + - (void)processNode:(id)node withSnapshot:(BOOL)snapshot withContext:(UIDContext*)context { diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.h b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.h index 4f97a2e791c..879f4cc9755 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.h +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.h @@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN @interface UIDAllyTraversal : NSObject ++ (void)setVoiceOverServiceEnabled:(BOOL)enabled; + @property(nonatomic, class, readonly, getter=isSupported) BOOL supported; - (instancetype)initWithDescriptorRegister: diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.m b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.m index 7e0ed379d94..a92c83895c5 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.m +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Traversal/UIDAllyTraversal.m @@ -8,6 +8,7 @@ #if FB_SONARKIT_ENABLED #import "UIDAllyTraversal.h" +#import #import "UIDDescriptorRegister.h" #import "UIDMetadataRegister.h" #import "UIDNode.h" @@ -34,6 +35,12 @@ + (BOOL)isSupported { (_accessibilityLeafDescendantsWithOptions:)]; } ++ (void)setVoiceOverServiceEnabled:(BOOL)enabled { + if (self.isSupported) { + _setVoiceOver(enabled); + } +} + - (instancetype)initWithDescriptorRegister: (UIDDescriptorRegister*)descriptorRegister { self = [super init]; @@ -114,6 +121,25 @@ static BOOL _loadAccessibilityFramework(void) { return isAccessibilityFrameworkLoaded; } +static void _setVoiceOver(BOOL enabled) { + NSString* const accessibilityUtilitiesPath = + [[NSBundle bundleForClass:UIApplication.class] + .bundleURL.URLByDeletingLastPathComponent + .URLByDeletingLastPathComponent + URLByAppendingPathComponent: + @"PrivateFrameworks/AccessibilityUtilities.framework/AccessibilityUtilities"] + .relativePath; + void* handler = dlopen( + [accessibilityUtilitiesPath cStringUsingEncoding:NSUTF8StringEncoding], + RTLD_NOW); + if (!handler) { + return; + } + void (*_AXSVoiceOverTouchSetEnabled)(BOOL) = + dlsym(handler, "_AXSVoiceOverTouchSetEnabled"); + _AXSVoiceOverTouchSetEnabled(enabled); +} + static NSString* _nameForNode(NSObject* node) { NSMutableArray* const parts = [NSMutableArray new]; if (node.accessibilityLabel.length > 0) {