diff --git a/React/Views/RCTShadowView+Hierarchy.h b/React/Views/RCTShadowView+Hierarchy.h new file mode 100644 index 000000000..be644c953 --- /dev/null +++ b/React/Views/RCTShadowView+Hierarchy.h @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import +#import + +@interface RCTShadowView (Hierarchy) + +@property (nonatomic, readonly) RCTRootShadowView *rootView; + +@end diff --git a/React/Views/RCTShadowView+Hierarchy.m b/React/Views/RCTShadowView+Hierarchy.m new file mode 100644 index 000000000..d0b05c8a9 --- /dev/null +++ b/React/Views/RCTShadowView+Hierarchy.m @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import "RCTShadowView+Hierarchy.h" + +@implementation RCTShadowView (Hierarchy) + +- (nullable RCTRootShadowView *)rootView +{ + RCTShadowView *view = self; + while (view != nil && ![view isKindOfClass:[RCTRootShadowView class]]) { + view = view.superview; + } + + return (RCTRootShadowView *)view; +} + +@end