Skip to content

Commit

Permalink
Export DeviceInfoConstants type from the native module's specs (#39135)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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: 8e1fd40806c897261e156154ecd79fcc1fdce2f1
  • Loading branch information
rshest authored and facebook-github-bot committed Aug 24, 2023
1 parent cc39a80 commit f903fd7
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 f903fd7

Please sign in to comment.