diff --git a/packages/react-native/React/Fabric/Utils/RCTViewFinder.h b/packages/react-native/React/Fabric/Utils/RCTViewFinder.h new file mode 100644 index 00000000000..cbeac5b9fbe --- /dev/null +++ b/packages/react-native/React/Fabric/Utils/RCTViewFinder.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RCTViewFinder : NSObject + ++ (UIView *)findView:(UIView *)root withNativeId:(NSString *)nativeId; + +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/Fabric/Utils/RCTViewFinder.mm b/packages/react-native/React/Fabric/Utils/RCTViewFinder.mm new file mode 100644 index 00000000000..e6406846ce7 --- /dev/null +++ b/packages/react-native/React/Fabric/Utils/RCTViewFinder.mm @@ -0,0 +1,34 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTViewFinder.h" +#include + +@implementation RCTViewFinder + ++ (UIView *)findView:(UIView *)root withNativeId:(NSString *)nativeId +{ + if (!nativeId) { + return nil; + } + + if ([root isKindOfClass:[RCTViewComponentView class]] && + [nativeId isEqualToString:((RCTViewComponentView *)root).nativeId]) { + return root; + } + + for (UIView *subview in root.subviews) { + UIView *result = [RCTViewFinder findView:subview withNativeId:nativeId]; + if (result) { + return result; + } + } + + return nil; +} + +@end