Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions detox/ios/Detox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
60C1961B271F11C4000172DD /* fishhook.c in Sources */ = {isa = PBXBuildFile; fileRef = 60C19619271F11C4000172DD /* fishhook.c */; };
60E149C72759038F00519EE4 /* UIResponder+First.h in Headers */ = {isa = PBXBuildFile; fileRef = 60E149C52759038F00519EE4 /* UIResponder+First.h */; };
60E149C82759038F00519EE4 /* UIResponder+First.m in Sources */ = {isa = PBXBuildFile; fileRef = 60E149C62759038F00519EE4 /* UIResponder+First.m */; };
7D3919BE2E890DBB00D16E3A /* DetoxSwiftBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D3919BA2E890DBB00D16E3A /* DetoxSwiftBridge.h */; };
7D3919C02E890F0E00D16E3A /* DetoxSwiftBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3919BF2E890F0E00D16E3A /* DetoxSwiftBridge.m */; };
AD4781082636F7CF006774CD /* NSURL+DetoxUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = AD4781062636F7CE006774CD /* NSURL+DetoxUtils.h */; settings = {ATTRIBUTES = (Private, ); }; };
AD4781092636F7CF006774CD /* NSURL+DetoxUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = AD4781072636F7CF006774CD /* NSURL+DetoxUtils.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -346,6 +348,8 @@
60C19619271F11C4000172DD /* fishhook.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = fishhook.c; path = DetoxSync/DetoxSync/fishhook/fishhook.c; sourceTree = SOURCE_ROOT; };
60E149C52759038F00519EE4 /* UIResponder+First.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIResponder+First.h"; sourceTree = "<group>"; };
60E149C62759038F00519EE4 /* UIResponder+First.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIResponder+First.m"; sourceTree = "<group>"; };
7D3919BA2E890DBB00D16E3A /* DetoxSwiftBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DetoxSwiftBridge.h; sourceTree = "<group>"; };
7D3919BF2E890F0E00D16E3A /* DetoxSwiftBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DetoxSwiftBridge.m; sourceTree = "<group>"; };
AD4781062636F7CE006774CD /* NSURL+DetoxUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSURL+DetoxUtils.h"; sourceTree = "<group>"; };
AD4781072636F7CF006774CD /* NSURL+DetoxUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSURL+DetoxUtils.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -488,6 +492,7 @@
3980D130244C42E7004812DD /* Utilities */ = {
isa = PBXGroup;
children = (
7D3919BC2E890DBB00D16E3A /* SwiftSupport */,
397CA7982483F07D005E8A71 /* ApproximateEquality.swift */,
39E91C06247D6BB00099F8F3 /* DetoxCrashHandler.h */,
39FFD9451FD730A600C97030 /* DetoxCrashHandler.mm */,
Expand Down Expand Up @@ -724,6 +729,15 @@
name = Runtime;
sourceTree = "<group>";
};
7D3919BC2E890DBB00D16E3A /* SwiftSupport */ = {
isa = PBXGroup;
children = (
7D3919BA2E890DBB00D16E3A /* DetoxSwiftBridge.h */,
7D3919BF2E890F0E00D16E3A /* DetoxSwiftBridge.m */,
);
path = SwiftSupport;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -755,6 +769,7 @@
3980D10F2448B52C004812DD /* UIApplication+DTXAdditions.h in Headers */,
3980D1172448B52C004812DD /* DTXRunLoopSpinner.h in Headers */,
AD4781082636F7CF006774CD /* NSURL+DetoxUtils.h in Headers */,
7D3919BE2E890DBB00D16E3A /* DetoxSwiftBridge.h in Headers */,
6062B5E32720323700CBDBF0 /* NSArray+Utils.h in Headers */,
3980D135244C4373004812DD /* UIView+DetoxMatchers.h in Headers */,
3980D16D244DDCD7004812DD /* UIScrollView+DetoxActions.h in Headers */,
Expand Down Expand Up @@ -1003,6 +1018,7 @@
3990BA36245AC98C00B608C8 /* DTXAssertionHandler+Swift.swift in Sources */,
12BDDA602971652D00FDBBA8 /* UIApplication+DetoxActions.swift in Sources */,
39CA978D245B13CB00A7FC43 /* UIDevice+DetoxActions.m in Sources */,
7D3919C02E890F0E00D16E3A /* DetoxSwiftBridge.m in Sources */,
396D455225238BB90096E7FA /* UIView+Drawing.m in Sources */,
39CE25AC22197F0900D78AA1 /* DetoxInstrumentsManager.m in Sources */,
3980D1162448B52C004812DD /* DTXTouchInfo.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ReactNativeSupport.h"
#import "ReactNativeHeaders.h"
#import "DetoxSwiftBridge.h"

#include <dlfcn.h>
#include <stdatomic.h>
Expand Down Expand Up @@ -68,16 +69,21 @@ + (NSObject *) getReactHost {
NSObject<UIApplicationDelegate> *appDelegate = UIApplication.sharedApplication.delegate;

NSObject *rootViewFactory = nil;

@try {
rootViewFactory = [appDelegate valueForKey:@"rootViewFactory"];
} @catch (NSException *exception) {
@try {
NSObject *reactNativeFactory = [appDelegate valueForKey:@"reactNativeFactory"];
rootViewFactory = [reactNativeFactory valueForKey:@"rootViewFactory"];
} @catch (NSException *exception) {
[NSException raise:@"Invalid AppDelegate" format:@"Could not access rootViewFactory. Make sure your AppDelegate either: Inherits from RCTAppDelegate Or defines 'reactNativeFactory'" ];
rootViewFactory = [DetoxSwiftBridge getRootViewFactory];
if (rootViewFactory == nil) {
[NSException raise:@"Invalid AppDelegate" format:@"Could not access rootViewFactory. Make sure your AppDelegate either: Inherits from RCTAppDelegate or defines 'reactNativeFactory'" ];
}
}
}

return [rootViewFactory valueForKey:@"reactHost"];
}

Expand Down
18 changes: 18 additions & 0 deletions detox/ios/Detox/Utilities/SwiftSupport/DetoxSwiftBridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// DetoxSwiftBridge.h
// Detox
//
// Created by Mark de Vocht on 28/09/2025.
// Copyright © 2025 Wix. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface DetoxSwiftBridge : NSObject
+ (nullable NSObject *)getRootViewFactory;
+ (nullable NSObject *)getReactNativeFactory;
@end

NS_ASSUME_NONNULL_END
80 changes: 80 additions & 0 deletions detox/ios/Detox/Utilities/SwiftSupport/DetoxSwiftBridge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// DetoxSwiftBridge.m
// Detox
//
// Created by Mark de Vocht on 28/09/2025.
// Copyright © 2025 Wix. All rights reserved.
//

#import "DetoxSwiftBridge.h"
@import UIKit;
@import ObjectiveC;

DTX_CREATE_LOG(SwiftBridge);

@implementation DetoxSwiftBridge

+ (nullable NSObject *)getRootViewFactory
{
NSObject<UIApplicationDelegate> *appDelegate = UIApplication.sharedApplication.delegate;
if (!appDelegate) {
return nil;
}

NSObject *rootViewFactory = [self getPropertyFromObject:appDelegate named:@"rootViewFactory"];
if (rootViewFactory) {
return rootViewFactory;
}

NSObject *reactNativeFactory = [self getPropertyFromObject:appDelegate named:@"reactNativeFactory"];
if (reactNativeFactory) {
return [self getPropertyFromObject:reactNativeFactory named:@"rootViewFactory"];
}

return nil;
}

+ (nullable NSObject *)getReactNativeFactory
{
NSObject<UIApplicationDelegate> *appDelegate = UIApplication.sharedApplication.delegate;
if (!appDelegate) {
return nil;
}

return [self getPropertyFromObject:appDelegate named:@"reactNativeFactory"];
}

+ (nullable NSObject *)getPropertyFromObject:(NSObject *)object named:(NSString *)propertyName
{
if (!object || !propertyName) {
return nil;
}

Class objectClass = [object class];
while (objectClass) {
unsigned int ivarCount;
Ivar *ivars = class_copyIvarList(objectClass, &ivarCount);

for (unsigned int i = 0; i < ivarCount; i++) {
const char *ivarName = ivar_getName(ivars[i]);
if (ivarName) {
NSString *ivarNameString = [NSString stringWithUTF8String:ivarName];
if ([ivarNameString isEqualToString:propertyName] ||
[ivarNameString isEqualToString:[@"_" stringByAppendingString:propertyName]]) {
NSObject *value = object_getIvar(object, ivars[i]);
if (value) {
free(ivars);
return value;
}
}
}
}

free(ivars);
objectClass = class_getSuperclass(objectClass);
}

return nil;
}

@end
4 changes: 2 additions & 2 deletions detox/test/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
60A403A92D21EAE3004344C3 /* UIViewController+Shake.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60A403A82D21EADE004344C3 /* UIViewController+Shake.swift */; };
60A403AA2D21EAE3004344C3 /* UIViewController+Shake.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60A403A82D21EADE004344C3 /* UIViewController+Shake.swift */; };
60FDFD722D2E9EC400804B82 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 60FDFD6E2D2E9EC400804B82 /* AppDelegate.m */; };
60FDFD742D2E9EC400804B82 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 60FDFD6E2D2E9EC400804B82 /* AppDelegate.m */; };
60FDFD762D2E9ED500804B82 /* AppDelegate+OverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60FDFD752D2E9ED500804B82 /* AppDelegate+OverlayView.swift */; };
60FDFD772D2E9ED500804B82 /* AppDelegate+OverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60FDFD752D2E9ED500804B82 /* AppDelegate+OverlayView.swift */; };
60FDFD932D2EAF5300804B82 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 60FDFD922D2EAF5300804B82 /* main.m */; };
60FDFD942D2EAF5300804B82 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 60FDFD922D2EAF5300804B82 /* main.m */; };
7D2B472D2E8958A0002EA9EF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 60FDFD6E2D2E9EC400804B82 /* AppDelegate.m */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
90CCD0BA1322566EB1285DC2 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */; };
96E5C284421F3B8DEE84764F /* libPods-example-ci.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AB365D90AFEA3B194709EC80 /* libPods-example-ci.a */; };
Expand Down Expand Up @@ -511,10 +511,10 @@
files = (
60FDFD942D2EAF5300804B82 /* main.m in Sources */,
60A403AA2D21EAE3004344C3 /* UIViewController+Shake.swift in Sources */,
7D2B472D2E8958A0002EA9EF /* AppDelegate.m in Sources */,
6051227F2D356C5900781AE2 /* ShakeEventEmitter.m in Sources */,
608868AB2D1AA19B0070D199 /* NativeScreenManager.swift in Sources */,
608868D32D1D696E0070D199 /* OverlayMessageView.swift in Sources */,
60FDFD742D2E9EC400804B82 /* AppDelegate.m in Sources */,
60FDFD762D2E9ED500804B82 /* AppDelegate+OverlayView.swift in Sources */,
6051227C2D356C3B00781AE2 /* NativeModule.m in Sources */,
608868B22D1AA1FB0070D199 /* CustomKeyboardDelegate.swift in Sources */,
Expand Down
Loading