Use type aliases for native module getConstants where applicable

Summary:
## Changelog:
[Internal] -

This replaces object literal return types in `getConstants()` for core RN native modules with type aliases.

This is a valid change from the point of view of binary compatibility between native/JS, and provides a couple of benefits, such as clearer code in general, but also ability to employ C++ codegen for the corresponding types and their marshalling.

bypass-github-export-checks

Reviewed By: christophpurrer

Differential Revision: D48685992

fbshipit-source-id: f21358b12448d30a7b5e25e81f62ef77964d1fcd
This commit is contained in:
Ruslan Shestopalyuk
2023-08-29 14:49:09 -07:00
committed by Facebook GitHub Bot
parent 268d9edad6
commit ff4e7fac6c
6 changed files with 57 additions and 56 deletions
+5 -3
View File
@@ -12,10 +12,12 @@ import type {TurboModule} from '../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
export type AppStateConstants = {|
initialAppState: string,
|};
export interface Spec extends TurboModule {
+getConstants: () => {|
initialAppState: string,
|};
+getConstants: () => AppStateConstants;
+getCurrentAppState: (
success: (appState: {|app_state: string|}) => void,
error: (error: Object) => void,
+5 -11
View File
@@ -8,15 +8,13 @@
* @format
*/
import type {I18nManagerConstants} from './NativeI18nManager';
import NativeI18nManager from './NativeI18nManager';
const i18nConstants: {|
doLeftAndRightSwapInRTL: boolean,
isRTL: boolean,
localeIdentifier?: ?string,
|} = getI18nManagerConstants();
const i18nConstants: I18nManagerConstants = getI18nManagerConstants();
function getI18nManagerConstants() {
function getI18nManagerConstants(): I18nManagerConstants {
if (NativeI18nManager) {
const {isRTL, doLeftAndRightSwapInRTL, localeIdentifier} =
NativeI18nManager.getConstants();
@@ -30,11 +28,7 @@ function getI18nManagerConstants() {
}
module.exports = {
getConstants: (): {|
doLeftAndRightSwapInRTL: boolean,
isRTL: boolean,
localeIdentifier: ?string,
|} => {
getConstants: (): I18nManagerConstants => {
return i18nConstants;
},
@@ -12,12 +12,14 @@ import type {TurboModule} from '../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
export type I18nManagerConstants = {|
doLeftAndRightSwapInRTL: boolean,
isRTL: boolean,
localeIdentifier?: ?string,
|};
export interface Spec extends TurboModule {
+getConstants: () => {|
isRTL: boolean,
doLeftAndRightSwapInRTL: boolean,
localeIdentifier: ?string,
|};
+getConstants: () => I18nManagerConstants;
allowRTL: (allowRTL: boolean) => void;
forceRTL: (forceRTL: boolean) => void;
swapLeftAndRightInRTL: (flipStyles: boolean) => void;
@@ -40,10 +40,7 @@ export type DeviceInfoConstants = {|
|};
export interface Spec extends TurboModule {
+getConstants: () => {|
+Dimensions: DimensionsPayload,
+isIPhoneX_deprecated?: boolean,
|};
+getConstants: () => DeviceInfoConstants;
}
const NativeModule: Spec = TurboModuleRegistry.getEnforcing<Spec>('DeviceInfo');
@@ -12,26 +12,30 @@ import type {TurboModule} from '../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
export type ReactNativeVersionAndroid = {|
major: number,
minor: number,
patch: number,
prerelease: ?number,
|};
export type PlatformConstantsAndroid = {|
isTesting: boolean,
isDisableAnimations?: boolean,
reactNativeVersion: ReactNativeVersionAndroid,
Version: number,
Release: string,
Serial: string,
Fingerprint: string,
Model: string,
ServerHost?: string,
uiMode: string,
Brand: string,
Manufacturer: string,
|};
export interface Spec extends TurboModule {
+getConstants: () => {|
isTesting: boolean,
isDisableAnimations?: boolean,
reactNativeVersion: {|
major: number,
minor: number,
patch: number,
prerelease: ?number,
|},
Version: number,
Release: string,
Serial: string,
Fingerprint: string,
Model: string,
ServerHost?: string,
uiMode: string,
Brand: string,
Manufacturer: string,
|};
+getConstants: () => PlatformConstantsAndroid;
+getAndroidID: () => string;
}
@@ -12,21 +12,23 @@ import type {TurboModule} from '../TurboModule/RCTExport';
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
export type PlatformConstantsIOS = {|
isTesting: boolean,
isDisableAnimations?: boolean,
reactNativeVersion: {|
major: number,
minor: number,
patch: number,
prerelease: ?number,
|},
forceTouchAvailable: boolean,
osVersion: string,
systemName: string,
interfaceIdiom: string,
|};
export interface Spec extends TurboModule {
+getConstants: () => {|
isTesting: boolean,
isDisableAnimations?: boolean,
reactNativeVersion: {|
major: number,
minor: number,
patch: number,
prerelease: ?number,
|},
forceTouchAvailable: boolean,
osVersion: string,
systemName: string,
interfaceIdiom: string,
|};
+getConstants: () => PlatformConstantsIOS;
}
export default (TurboModuleRegistry.getEnforcing<Spec>(