From c525b71f33153f178d7fdfdd1fc15119cc5704a0 Mon Sep 17 00:00:00 2001 From: Contributor Date: Thu, 3 Sep 2026 19:19:13 -0700 Subject: [PATCH] fix: detect bare `Switch` host component name The iOS native component spec codegens under the name `Switch`, but `HOST_SWITCH_NAMES` only listed the legacy `RCTSwitch` name, so `isHostSwitch` returned `false` for elements with that host name. Add `Switch` alongside `RCTSwitch`, mirroring how `HOST_TEXT_NAMES` already accepts both `Text` and `RCTText`. See: https://github.com/react/react-native/pull/58323 --- src/__tests__/host-component-names.test.tsx | 7 +++++++ src/helpers/host-component-names.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/__tests__/host-component-names.test.tsx b/src/__tests__/host-component-names.test.tsx index 3fbf5fdf2..8e2532412 100644 --- a/src/__tests__/host-component-names.test.tsx +++ b/src/__tests__/host-component-names.test.tsx @@ -38,6 +38,13 @@ test('detects host Switch component', async () => { expect(isHostSwitch(screen.root)).toBe(true); }); +// The iOS native component spec codegens under the name `Switch`, so the bare +// name has to be recognised alongside the legacy `RCTSwitch` one. +test('detects raw Switch component', async () => { + await render(React.createElement('Switch', { testID: 'switch' })); + expect(isHostSwitch(screen.root)).toBe(true); +}); + test('detects host ScrollView component', async () => { await render(); expect(isHostScrollView(screen.root)).toBe(true); diff --git a/src/helpers/host-component-names.ts b/src/helpers/host-component-names.ts index 2b7f59860..48ee21a41 100644 --- a/src/helpers/host-component-names.ts +++ b/src/helpers/host-component-names.ts @@ -3,7 +3,7 @@ import type { TestInstance } from 'test-renderer'; export const HOST_TEXT_NAMES = ['Text', 'RCTText']; const HOST_TEXT_INPUT_NAMES = ['TextInput']; const HOST_IMAGE_NAMES = ['Image']; -const HOST_SWITCH_NAMES = ['RCTSwitch']; +const HOST_SWITCH_NAMES = ['Switch', 'RCTSwitch']; const HOST_SCROLL_VIEW_NAMES = ['RCTScrollView']; const HOST_MODAL_NAMES = ['Modal'];