Skip to content

Commit d2cbc0e

Browse files
artus9033meta-codesync[bot]
authored andcommitted
Refresh DeviceInfo constants on each read (#57715)
Summary: Pull Request resolved: #57715 Update `NativeDeviceInfo.getConstants()` to read directly from the native module instead of retaining a stale JS-side cache. Changelog: [General][Fixed] - Refresh `DeviceInfo` constants on each read Test Plan: - `yarn build-types --validate` - `arc lint xplat/js/react-native-github/packages/react-native/ReactNativeApi.d.ts` - Verify Dimensions updates after resizing the RNTester window. Reviewed By: javache Differential Revision: D113758830 Pulled By: cipolleschi
1 parent bd99abd commit d2cbc0e

2 files changed

Lines changed: 9 additions & 18 deletions

File tree

packages/react-native/ReactNativeApi.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<4406ddb15814262a7ccc2b56e9625d67>>
7+
* @generated SignedSource<<dba1cff53d9df1a0770d079056259d8b>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -76,7 +76,7 @@ declare const $$index: {
7676
get VirtualizedListContextResetter(): VirtualizedListContextResetterT
7777
get VirtualizedSectionList(): AnyVirtualizedSectionList
7878
}
79-
declare const $$NativeDeviceInfo: typeof NativeDeviceInfo_default
79+
declare const $$NativeDeviceInfo: typeof NativeModule_default
8080
declare const $$ReactFabric: typeof ReactFabric_default
8181
declare const $$ScrollViewContext: typeof ScrollViewContext_default
8282
declare const absoluteFill: AbsoluteFillStyle
@@ -288,9 +288,7 @@ declare const multiplyImpl: (
288288
b: AnimatedNode_default | number,
289289
) => AnimatedMultiplication_default
290290
declare const NativeAppEventEmitter: typeof RCTNativeAppEventEmitter_default
291-
declare const NativeDeviceInfo_default: {
292-
getConstants(): DeviceInfoConstants
293-
}
291+
declare const NativeModule_default: Spec
294292
declare const NativeModules: typeof NativeModules_default
295293
declare let NativeModules_default: {
296294
[moduleName: string]: any
@@ -4514,6 +4512,9 @@ declare type ShareOptions = {
45144512
tintColor?: ColorValue
45154513
}
45164514
declare interface Spec extends TurboModule {
4515+
readonly getConstants: () => DeviceInfoConstants
4516+
}
4517+
declare interface Spec_2 extends TurboModule {
45174518
readonly blur?: (reactTag: number) => void
45184519
readonly focus?: (reactTag: number) => void
45194520
readonly getConstantsForViewManager?: (
@@ -5361,7 +5362,7 @@ declare type TVViewPropsIOS = {
53615362
readonly tvParallaxTiltAngle?: number
53625363
}
53635364
declare type UIManager = typeof UIManager
5364-
declare interface UIManagerJSInterface extends Spec {
5365+
declare interface UIManagerJSInterface extends Spec_2 {
53655366
readonly getViewManagerConfig: (viewManagerName: string) => Object
53665367
readonly hasViewManagerConfig: (viewManagerName: string) => boolean
53675368
}
@@ -5752,7 +5753,7 @@ export {
57525753
DevMenu, // 21b8b7a9
57535754
DevSettings, // e55b91dc
57545755
DeviceEventEmitter, // bdbdd014
5755-
DeviceInfo, // 521bfb71
5756+
DeviceInfo, // 0f5a517b
57565757
DeviceInfoConstants, // 279e7858
57575758
DimensionValue, // b163a381
57585759
Dimensions, // 980ef68c

packages/react-native/src/private/specs_DEPRECATED/modules/NativeDeviceInfo.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,5 @@ export interface Spec extends TurboModule {
4545
}
4646

4747
const NativeModule: Spec = TurboModuleRegistry.getEnforcing<Spec>('DeviceInfo');
48-
let constants: ?DeviceInfoConstants = null;
49-
50-
const NativeDeviceInfo = {
51-
getConstants(): DeviceInfoConstants {
52-
if (constants == null) {
53-
constants = NativeModule.getConstants();
54-
}
55-
return constants;
56-
},
57-
};
5848

59-
export default NativeDeviceInfo;
49+
export default NativeModule;

0 commit comments

Comments
 (0)