From 8955bfb87c13465912bf1b9b83dca7f067ddf44f Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Thu, 24 Aug 2023 14:38:26 -0700 Subject: [PATCH] Export DeviceInfoConstants type from the native module's specs (#39135) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39135 ## Changelog: [Internal] - Expose constants type from DeviceInfo native module - this makes codegen generate the corresponding data structure, making the native module implementation shorter (in C++ in particular). Reviewed By: christophpurrer Differential Revision: D48620784 fbshipit-source-id: 40ae83ebec92e0a470c20ef1ad16f8392e2bf8b0 --- .../Libraries/Utilities/NativeDeviceInfo.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js b/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js index c81d3fa0d1b..6939c03c2f1 100644 --- a/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js +++ b/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js @@ -34,6 +34,11 @@ export type DimensionsPayload = {| screenPhysicalPixels?: DisplayMetricsAndroid, |}; +export type DeviceInfoConstants = {| + +Dimensions: DimensionsPayload, + +isIPhoneX_deprecated?: boolean, +|}; + export interface Spec extends TurboModule { +getConstants: () => {| +Dimensions: DimensionsPayload, @@ -42,13 +47,10 @@ export interface Spec extends TurboModule { } const NativeModule: Spec = TurboModuleRegistry.getEnforcing('DeviceInfo'); -let constants = null; +let constants: ?DeviceInfoConstants = null; const NativeDeviceInfo = { - getConstants(): {| - +Dimensions: DimensionsPayload, - +isIPhoneX_deprecated?: boolean, - |} { + getConstants(): DeviceInfoConstants { if (constants == null) { constants = NativeModule.getConstants(); }