From 5261acd0a3f940c70e291a9228a1d4c0f2babcf2 Mon Sep 17 00:00:00 2001 From: Fabrizio Duroni Date: Mon, 9 Mar 2026 21:16:07 +0100 Subject: [PATCH 1/2] fix: isDarkerSystemColorsEnabled unresolved (never ending) promise --- .../AccessibilityInfo/AccessibilityInfo.js | 12 ++-- .../__tests__/AccessibilityInfo-test.js | 59 +++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js b/packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js index 910ad6518f32..098f7e303e7c 100644 --- a/packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +++ b/packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js @@ -237,10 +237,10 @@ const AccessibilityInfo = { * The result is `true` when dark system colors is enabled and `false` otherwise. */ isDarkerSystemColorsEnabled(): Promise { - return new Promise((resolve, reject) => { - if (Platform.OS === 'android') { - return Promise.resolve(false); - } else { + if (Platform.OS === 'android') { + return Promise.resolve(false); + } else { + return new Promise((resolve, reject) => { if ( NativeAccessibilityManagerIOS?.getCurrentDarkerSystemColorsState != null @@ -256,8 +256,8 @@ const AccessibilityInfo = { ), ); } - } - }); + }); + } }, /** diff --git a/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js b/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js index 0b37087dd525..761e81673867 100644 --- a/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js +++ b/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js @@ -13,6 +13,9 @@ jest.unmock('../AccessibilityInfo'); const mockGetCurrentPrefersCrossFadeTransitionsState = jest.fn( (onSuccess, onError) => onSuccess(true), ); +const mockGetCurrentDarkerSystemColorsState = jest.fn((onSuccess, onError) => + onSuccess(true), +); const mockNativeAccessibilityManagerDefault: { getCurrentPrefersCrossFadeTransitionsState: JestMockFn< [ @@ -21,9 +24,17 @@ const mockNativeAccessibilityManagerDefault: { ], void, > | null, + getCurrentDarkerSystemColorsState: JestMockFn< + [ + onSuccess: (isDarkerSystemColorsEnabled: boolean) => void, + onError: (error: Error) => void, + ], + void, + > | null, } = { getCurrentPrefersCrossFadeTransitionsState: mockGetCurrentPrefersCrossFadeTransitionsState, + getCurrentDarkerSystemColorsState: mockGetCurrentDarkerSystemColorsState, }; jest.mock('../NativeAccessibilityManager', () => ({ @@ -91,9 +102,57 @@ describe('AccessibilityInfo', () => { }); }); + describe('isDarkerSystemColorsEnabled', () => { + describe('Android', () => { + it('should return immediately', async () => { + /* $FlowFixMe[incompatible-type] */ + Platform.OS = 'android'; + + const isDarkerSystemColorsEnabled = + await AccessibilityInfo.isDarkerSystemColorsEnabled(); + + expect(isDarkerSystemColorsEnabled).toBe(false); + }); + }); + + describe('iOS', () => { + it('should call getCurrentDarkerSystemColorsState if available', async () => { + /* $FlowFixMe[incompatible-type] */ + Platform.OS = 'ios'; + + const isDarkerSystemColorsEnabled = + await AccessibilityInfo.isDarkerSystemColorsEnabled(); + + expect(mockGetCurrentDarkerSystemColorsState).toHaveBeenCalled(); + expect(isDarkerSystemColorsEnabled).toBe(true); + }); + + it('should throw error if getCurrentDarkerSystemColorsState is not available', async () => { + /* $FlowFixMe[incompatible-type] */ + Platform.OS = 'ios'; + + mockNativeAccessibilityManagerDefault.getCurrentDarkerSystemColorsState = + null; + + const result: mixed = + await AccessibilityInfo.isDarkerSystemColorsEnabled().catch(e => e); + + invariant( + result instanceof Error, + 'Expected isDarkerSystemColorsEnabled to reject', + ); + expect(result.message).toEqual( + 'NativeAccessibilityManagerIOS.getCurrentDarkerSystemColorsState is not available', + ); + }); + }); + }); + afterEach(() => { mockNativeAccessibilityManagerDefault.getCurrentPrefersCrossFadeTransitionsState = mockGetCurrentPrefersCrossFadeTransitionsState; + mockNativeAccessibilityManagerDefault.getCurrentDarkerSystemColorsState = + mockGetCurrentDarkerSystemColorsState; /* $FlowFixMe[incompatible-type] */ Platform.OS = originalPlatform; }); From 595e893e2bf5183fa44201dbff8d3fa863b7e4fe Mon Sep 17 00:00:00 2001 From: Fabrizio Duroni Date: Tue, 10 Mar 2026 20:41:57 +0100 Subject: [PATCH 2/2] fix: added mock reset for mockGetCurrentDarkerSystemColorsState --- .../AccessibilityInfo/__tests__/AccessibilityInfo-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js b/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js index 761e81673867..5240b9251039 100644 --- a/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js +++ b/packages/react-native/Libraries/Components/AccessibilityInfo/__tests__/AccessibilityInfo-test.js @@ -52,6 +52,7 @@ describe('AccessibilityInfo', () => { beforeEach(() => { originalPlatform = Platform.OS; mockGetCurrentPrefersCrossFadeTransitionsState.mockClear(); + mockGetCurrentDarkerSystemColorsState.mockClear(); }); describe('prefersCrossFadeTransitions', () => {