Skip to content

Commit

Permalink
Export DeviceInfoConstants type from the native module's specs (faceb…
Browse files Browse the repository at this point in the history
…ook#39135)

Summary:
Pull Request resolved: facebook#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: bb700b8d75313ccdc82f0b2c94fd98468ad3c563
  • Loading branch information
rshest authored and facebook-github-bot committed Aug 24, 2023
1 parent 3c6bf7b commit f23be82
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/react-native/Libraries/Utilities/NativeDeviceInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,13 +47,10 @@ export interface Spec extends TurboModule {
}

const NativeModule: Spec = TurboModuleRegistry.getEnforcing<Spec>('DeviceInfo');
let constants = null;
let constants: ?DeviceInfoConstants = null;

const NativeDeviceInfo = {
getConstants(): {|
+Dimensions: DimensionsPayload,
+isIPhoneX_deprecated?: boolean,
|} {
getConstants(): DeviceInfoConstants {
if (constants == null) {
constants = NativeModule.getConstants();
}
Expand Down

0 comments on commit f23be82

Please sign in to comment.