From 37e0973bb3f47803cd166d6a532031f53f146ab6 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 9 Oct 2024 12:55:12 -0700 Subject: [PATCH] Replace React.AbstractComponent with `component` type in Switch (#46911) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46911 Prepare for the ref-as-prop typing change in flow. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D64103195 fbshipit-source-id: e0ff745c70df910dcb84ed3a824d67883bbfc44d --- .../Libraries/Components/Switch/Switch.js | 14 ++++++++------ .../__snapshots__/public-api-test.js.snap | 11 ++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/react-native/Libraries/Components/Switch/Switch.js b/packages/react-native/Libraries/Components/Switch/Switch.js index eb0f18521e4..b1aa2383def 100644 --- a/packages/react-native/Libraries/Components/Switch/Switch.js +++ b/packages/react-native/Libraries/Components/Switch/Switch.js @@ -130,12 +130,14 @@ const returnsTrue = () => true; ``` */ -const SwitchWithForwardedRef: React.AbstractComponent< - Props, - React.ElementRef< - typeof SwitchNativeComponent | typeof AndroidSwitchNativeComponent, - >, -> = React.forwardRef(function Switch(props, forwardedRef): React.Node { +type SwitchRef = React.ElementRef< + typeof SwitchNativeComponent | typeof AndroidSwitchNativeComponent, +>; + +const SwitchWithForwardedRef: component( + ref: React.RefSetter, + ...props: Props +) = React.forwardRef(function Switch(props, forwardedRef): React.Node { const { disabled, ios_backgroundColor, diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 2e1295aa8ee..c0b72bd8038 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -2529,12 +2529,13 @@ export type Props = $ReadOnly<{| onChange?: ?(event: SwitchChangeEvent) => Promise | void, onValueChange?: ?(value: boolean) => Promise | void, |}>; -declare const SwitchWithForwardedRef: React.AbstractComponent< - Props, - React.ElementRef< - typeof SwitchNativeComponent | typeof AndroidSwitchNativeComponent, - >, +type SwitchRef = React.ElementRef< + typeof SwitchNativeComponent | typeof AndroidSwitchNativeComponent, >; +declare const SwitchWithForwardedRef: component( + ref: React.RefSetter, + ...props: Props +); declare export default typeof SwitchWithForwardedRef; " `;