Skip to content

Commit

Permalink
Eliminate 2 more remaining React.AbstractComponent<...> in react na…
Browse files Browse the repository at this point in the history
…tive

Summary:
In order to adopt react 19's ref-as-prop model, we need to eliminate all the places where they are treated differently. `React.AbstractComponent` is the worst example of this, and we need to eliminate it.

This diff replaces 2 more remaining ones in react-native. Now the only remaining one is the one synced from react repo.

Changelog: [Internal]

Reviewed By: alexmckenley

Differential Revision: D64722899

fbshipit-source-id: 2b2484c385fc5d6c173253f9bee66dfc736368a5
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Oct 22, 2024
1 parent 71e9039 commit 036e4f6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ export type StrictAnimatedProps<Props: {...}> = $ReadOnly<{
passthroughAnimatedPropExplicitValues?: ?Props,
}>;

export type AnimatedComponentType<
Props: {...},
+Instance = mixed,
> = React.AbstractComponent<AnimatedProps<Props>, Instance>;
export type AnimatedComponentType<Props: {...}, +Instance = mixed> = component(
ref: React.RefSetter<Instance>,
...AnimatedProps<Props>
);

export type StrictAnimatedComponentType<
Props: {...},
+Instance = mixed,
> = React.AbstractComponent<StrictAnimatedProps<Props>, Instance>;
> = component(ref: React.RefSetter<Instance>, ...StrictAnimatedProps<Props>);

export default function createAnimatedComponent<TProps: {...}, TInstance>(
Component: React.AbstractComponent<TProps, TInstance>,
Component: component(ref: React.RefSetter<TInstance>, ...TProps),
): AnimatedComponentType<TProps, TInstance> {
return unstable_createAnimatedComponentWithAllowlist(Component, null);
}
Expand All @@ -55,7 +55,7 @@ export function unstable_createAnimatedComponentWithAllowlist<
TProps: {...},
TInstance,
>(
Component: React.AbstractComponent<TProps, TInstance>,
Component: component(ref: React.RefSetter<TInstance>, ...TProps),
allowlist: ?AnimatedPropsAllowlist,
): StrictAnimatedComponentType<TProps, TInstance> {
const AnimatedComponent = React.forwardRef<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ const ScrollViewStickyHeaderWithForwardedRef: component(
: null;

return (
/* $FlowFixMe[prop-missing] passthroughAnimatedPropExplicitValues isn't properly
included in the Animated.View flow type. */
<Animated.View
collapsable={false}
nativeID={props.nativeID}
onLayout={_onLayout}
/* $FlowFixMe[prop-missing] passthroughAnimatedPropExplicitValues isn't properly
included in the Animated.View flow type. */
ref={ref}
style={[
child.props.style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class TouchableBounce extends React.Component<Props, State> {
this.props.onPress !== undefined &&
!this.props.disabled
}
// $FlowFixMe[prop-missing]
ref={this.props.hostRef}
{...eventHandlersWithoutBlurAndFocus}>
{this.props.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class TouchableOpacity extends React.Component<Props, State> {
this.props.onPress !== undefined &&
!this.props.disabled
}
// $FlowFixMe[prop-missing]
ref={this.props.hostRef}
{...eventHandlersWithoutBlurAndFocus}>
{this.props.children}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Lists/SectionListModern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
SectionBase as _SectionBase,
VirtualizedSectionListProps,
} from '@react-native/virtualized-lists';
import type {AbstractComponent, ElementRef} from 'react';
import type {ElementRef} from 'react';

import Platform from '../Utilities/Platform';
import {VirtualizedSectionList} from '@react-native/virtualized-lists';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,22 +744,22 @@ export type StrictAnimatedProps<Props: { ... }> = $ReadOnly<{
export type AnimatedComponentType<
Props: { ... },
+Instance = mixed,
> = React.AbstractComponent<AnimatedProps<Props>, Instance>;
> = component(ref: React.RefSetter<Instance>, ...AnimatedProps<Props>);
export type StrictAnimatedComponentType<
Props: { ... },
+Instance = mixed,
> = React.AbstractComponent<StrictAnimatedProps<Props>, Instance>;
> = component(ref: React.RefSetter<Instance>, ...StrictAnimatedProps<Props>);
declare export default function createAnimatedComponent<
TProps: { ... },
TInstance,
>(
Component: React.AbstractComponent<TProps, TInstance>
Component: component(ref: React.RefSetter<TInstance>, ...TProps)
): AnimatedComponentType<TProps, TInstance>;
declare export function unstable_createAnimatedComponentWithAllowlist<
TProps: { ... },
TInstance,
>(
Component: React.AbstractComponent<TProps, TInstance>,
Component: component(ref: React.RefSetter<TInstance>, ...TProps),
allowlist: ?AnimatedPropsAllowlist
): StrictAnimatedComponentType<TProps, TInstance>;
"
Expand Down

0 comments on commit 036e4f6

Please sign in to comment.