From 9fc3fc83acd6e04cdcaf5a992695544f8440adf2 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Tue, 9 Nov 2021 20:40:40 -0800 Subject: [PATCH] introduce RCTViewUtils Summary: Changelog: [Internal] in this diff, i convert the following method to a C function. https://www.internalfb.com/code/fbsource/[c58818169205f1e0fa816968efdb4c3fac8333e9]/xplat/js/react-native-github/React/Views/RCTView.h?lines=43 besides for testing demonstration purposes later in the stack, C functions are a superior choice to static class methods because they incur less binary size cost (see section 4.3 of https://swolchok.github.io/objcperf/ if you're curious, and https://fb.workplace.com/groups/aexpixfn/posts/1909150855887748 for the impact of a conversion) Reviewed By: RSNara Differential Revision: D31949241 fbshipit-source-id: dd40871d48f1de168d360168c4dd60015145d7e3 --- BUCK | 1 + React/Views/RCTViewUtils.h | 18 ++++++++++++++++++ React/Views/RCTViewUtils.m | 22 ++++++++++++++++++++++ packages/rn-tester/Podfile.lock | 6 +++--- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 React/Views/RCTViewUtils.h create mode 100644 React/Views/RCTViewUtils.m diff --git a/BUCK b/BUCK index 269f84020ad26f..5650357aa27962 100644 --- a/BUCK +++ b/BUCK @@ -307,6 +307,7 @@ REACT_PUBLIC_HEADERS = { "React/RCTVersion.h": RCTBASE_PATH + "RCTVersion.h", "React/RCTView.h": RCTVIEWS_PATH + "RCTView.h", "React/RCTViewManager.h": RCTVIEWS_PATH + "RCTViewManager.h", + "React/RCTViewUtils.h": RCTVIEWS_PATH + "RCTViewUtils.h", "React/RCTWeakProxy.h": RCTBASE_PATH + "RCTWeakProxy.h", "React/RCTWeakViewHolder.h": RCTVIEWS_PATH + "RCTWeakViewHolder.h", "React/RCTWrapperViewController.h": RCTVIEWS_PATH + "RCTWrapperViewController.h", diff --git a/React/Views/RCTViewUtils.h b/React/Views/RCTViewUtils.h new file mode 100644 index 00000000000000..4f056b5018026f --- /dev/null +++ b/React/Views/RCTViewUtils.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) Facebook, Inc. and its 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 + +RCT_EXTERN_C_BEGIN + +UIEdgeInsets RCTContentInsets(UIView *view); + +RCT_EXTERN_C_END + +NS_ASSUME_NONNULL_END diff --git a/React/Views/RCTViewUtils.m b/React/Views/RCTViewUtils.m new file mode 100644 index 00000000000000..a7100df597361f --- /dev/null +++ b/React/Views/RCTViewUtils.m @@ -0,0 +1,22 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTViewUtils.h" + +#import "UIView+React.h" + +UIEdgeInsets RCTContentInsets(UIView *view) +{ + while (view) { + UIViewController *controller = view.reactViewController; + if (controller) { + return controller.view.safeAreaInsets; + } + view = view.superview; + } + return UIEdgeInsetsZero; +} diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 5a9680aab1f0cc..27a26227ac4da7 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -881,7 +881,7 @@ SPEC CHECKSUMS: CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662 FBLazyVector: b81a2b70c72d8b0aefb652cea22c11e9ffd02949 - FBReactNativeSpec: c41af89a2aca37e9fe937133ffe6758301ded893 + FBReactNativeSpec: cd36c48651d54982428c1b0afd5557993b45e92c Flipper: 30e8eeeed6abdc98edaf32af0cda2f198be4b733 Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c @@ -923,10 +923,10 @@ SPEC CHECKSUMS: React-RCTTest: 12bbd7fc2e72bd9920dc7286c5b8ef96639582b6 React-RCTText: e9146b2c0550a83d1335bfe2553760070a2d75c7 React-RCTVibration: 50be9c390f2da76045ef0dfdefa18b9cf9f35cfa - React-rncore: a1249129f80f05d7e3bcba35239ceb394c1052cc + React-rncore: fb776508453c32c72c6325f421468eb8a1f3e2c4 React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3 ReactCommon: 7a2714d1128f965392b6f99a8b390e3aa38c9569 - ScreenshotManager: ec701affd6d2a5dabf8739b0cdcc937f7dbd2ac6 + ScreenshotManager: b6b23f4913712a245102024854656634fee33265 Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a