Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/eslint-plugin-react-native/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ const publicAPIMapping = {
default: 'LogBox',
types: ['ExtendedExceptionData', 'IgnorePattern', 'LogData'],
},
'Libraries/NativeModules/specs/NativeDialogManagerAndroid': {
default: 'NativeDialogManagerAndroid',
types: null,
},
'Libraries/EventEmitter/NativeEventEmitter': {
default: 'NativeEventEmitter',
types: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
*/

'use strict';
import type {HostComponent} from '../../../src/private/types/HostComponent';
import type {HostInstance} from '../../../src/private/types/HostInstance';
import type {ViewProps} from '../View/ViewPropTypes';

import StyleSheet, {type ColorValue} from '../../StyleSheet/StyleSheet';
import Platform from '../../Utilities/Platform';
import View from '../View/View';
import * as React from 'react';

export type ActivityIndicatorInstance = HostInstance;

const PlatformActivityIndicator =
Platform.OS === 'android'
? require('../ProgressBarAndroid/ProgressBarAndroid').default
Expand Down Expand Up @@ -62,7 +64,7 @@ export type ActivityIndicatorProps = Readonly<{
}>;

const ActivityIndicator: component(
ref?: React.RefSetter<HostComponent<empty>>,
ref?: React.RefSetter<ActivityIndicatorInstance>,
...props: ActivityIndicatorProps
) = ({
ref: forwardedRef,
Expand Down
12 changes: 9 additions & 3 deletions packages/react-native/Libraries/Components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,18 @@ const NativeTouchable:
| typeof TouchableOpacity =
Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;

type ButtonRef = React.ElementRef<typeof NativeTouchable>;
export type ButtonInstance = React.ElementRef<typeof NativeTouchable>;

const Button: component(
ref?: React.RefSetter<ButtonRef>,
ref?: React.RefSetter<ButtonInstance>,
...props: ButtonProps
) = ({ref, ...props}: {ref?: React.RefSetter<ButtonRef>, ...ButtonProps}) => {
) = ({
ref,
...props
}: {
ref?: React.RefSetter<ButtonInstance>,
...ButtonProps,
}) => {
const {
accessibilityLabel,
accessibilityState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,6 @@ const styles = StyleSheet.create({
},
});

export type DrawerLayoutAndroidInstance = DrawerLayoutAndroid;

export default DrawerLayoutAndroid as $FlowFixMe;
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@

import DrawerLayoutAndroidFallback from './DrawerLayoutAndroidFallback';

export type DrawerLayoutAndroidInstance = DrawerLayoutAndroidFallback;

export default DrawerLayoutAndroidFallback;
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ export interface DrawerLayoutAndroidMethods {
): void;
setNativeProps(nativeProps: Object): void;
}

export type DrawerLayoutAndroidInstance = DrawerLayoutAndroidMethods;
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,6 @@ class KeyboardAvoidingView extends React.Component<
}
}

export type KeyboardAvoidingViewInstance = KeyboardAvoidingView;

export default KeyboardAvoidingView;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @format
*/

import type {HostInstance} from '../../../src/private/types/HostInstance';
import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
import type {
GestureResponderEvent,
Expand All @@ -27,6 +28,8 @@ import useAndroidRippleForView, {
import * as React from 'react';
import {memo, useMemo, useRef, useState} from 'react';

export type PressableInstance = HostInstance;

export type {PressableAndroidRippleConfig};

export type PressableStateCallbackType = Readonly<{
Expand Down Expand Up @@ -165,8 +168,6 @@ export type PressableProps = Readonly<{
...PressableBaseProps,
}>;

type Instance = React.ElementRef<typeof View>;

/**
* Component used to build display components that should respond to whether the
* component is currently pressed or not.
Expand All @@ -175,7 +176,7 @@ function Pressable({
ref: forwardedRef,
...props
}: {
ref?: React.RefSetter<Instance>,
ref?: React.RefSetter<PressableInstance>,
...PressableProps,
}): React.Node {
const {
Expand Down Expand Up @@ -215,7 +216,7 @@ function Pressable({
...restProps
} = props;

const viewRef = useRef<Instance | null>(null);
const viewRef = useRef<PressableInstance | null>(null);
const mergedRef = useMergeRefs(forwardedRef, viewRef);

const android_rippleConfig = useAndroidRippleForView(android_ripple, viewRef);
Expand Down Expand Up @@ -354,6 +355,6 @@ const MemoedPressable = memo(Pressable);
MemoedPressable.displayName = 'Pressable';

export default MemoedPressable as component(
ref?: React.RefSetter<React.ElementRef<typeof View>>,
ref?: React.RefSetter<PressableInstance>,
...props: PressableProps
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
* @format
*/

import type {HostInstance} from '../../../src/private/types/HostInstance';
import type {ProgressBarAndroidProps} from './ProgressBarAndroidTypes';

import ProgressBarAndroidNativeComponent from './ProgressBarAndroidNativeComponent';

const React = require('react');

export type ProgressBarAndroidInstance = HostInstance;

export type {ProgressBarAndroidProps};

/**
Expand All @@ -40,9 +43,7 @@ export type {ProgressBarAndroidProps};
* ```
*/
const ProgressBarAndroid: component(
ref?: React.RefSetter<
React.ElementRef<typeof ProgressBarAndroidNativeComponent>,
>,
ref?: React.RefSetter<ProgressBarAndroidInstance>,
...props: ProgressBarAndroidProps
) = function ProgressBarAndroid({
ref: forwardedRef,
Expand All @@ -52,9 +53,7 @@ const ProgressBarAndroid: component(
animating = true,
...restProps
}: {
ref?: React.RefSetter<
React.ElementRef<typeof ProgressBarAndroidNativeComponent>,
>,
ref?: React.RefSetter<ProgressBarAndroidInstance>,
...ProgressBarAndroidProps,
}) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

'use strict';

import typeof ProgressBarAndroidNativeComponentType from './ProgressBarAndroidNativeComponent';
import type {HostInstance} from '../../../src/private/types/HostInstance';
import type {ProgressBarAndroidProps} from './ProgressBarAndroidTypes';

import Platform from '../../Utilities/Platform';

export type ProgressBarAndroidInstance = HostInstance;

export type {ProgressBarAndroidProps};

// A utility type to preserve the semantics of the union uses in the definition
Expand All @@ -30,9 +32,7 @@ type Omit<T, K> = T extends any ? Pick<T, Exclude<keyof T, K>> : T;
* @deprecated
*/
let ProgressBarAndroid: component(
ref?: React.RefSetter<
React.ElementRef<ProgressBarAndroidNativeComponentType>,
>,
ref?: React.RefSetter<ProgressBarAndroidInstance>,
...props: Omit<ProgressBarAndroidProps, empty>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,6 @@ class RefreshControl extends React.Component<RefreshControlProps> {
};
}

export type RefreshControlInstance = RefreshControl;

export default RefreshControl;
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
* @format
*/

import type {HostInstance} from '../../../src/private/types/HostInstance';
import type {ViewProps} from '../View/ViewPropTypes';

import Platform from '../../Utilities/Platform';
import View from '../View/View';
import * as React from 'react';

export type SafeAreaViewInstance = HostInstance;

/**
* Renders nested content and automatically applies paddings reflect the portion
* of the view that is not covered by navigation bars, tab bars, toolbars, and
Expand All @@ -25,7 +28,7 @@ import * as React from 'react';
* @deprecated Use `react-native-safe-area-context` instead. This component will be removed in a future release.
*/
const SafeAreaView: component(
ref?: React.RefSetter<React.ElementRef<typeof View>>,
ref?: React.RefSetter<SafeAreaViewInstance>,
...props: ViewProps
) = Platform.select({
ios: require('./RCTSafeAreaViewNativeComponent').default,
Expand Down
46 changes: 23 additions & 23 deletions packages/react-native/Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export interface ScrollViewImperativeMethods {
+getScrollableNode: () => ?number;
+getInnerViewNode: () => ?number;
+getInnerViewRef: () => InnerViewInstance | null;
+getNativeScrollRef: () => PublicScrollViewInstance | null;
+getNativeScrollRef: () => ScrollViewInstance | null;
+scrollTo: (
options?: ScrollViewScrollToOptions | number,
deprecatedX?: number,
Expand Down Expand Up @@ -167,10 +167,13 @@ export interface ScrollViewImperativeMethods {
export type DecelerationRateType = 'fast' | 'normal' | number;
export type ScrollResponderType = ScrollViewImperativeMethods;

export interface PublicScrollViewInstance
export interface ScrollViewInstance
extends HostInstance,
ScrollViewImperativeMethods {}

/** @deprecated Use ScrollViewInstance instead */
export type PublicScrollViewInstance = ScrollViewInstance;

type InnerViewInstance = React.ElementRef<typeof View>;

export type ScrollViewPropsIOS = Readonly<{
Expand Down Expand Up @@ -677,7 +680,7 @@ type ScrollViewBaseProps = Readonly<{
* all of ScrollView's public methods, in addition to native methods like
* measure, measureLayout, etc.
*/
scrollViewRef?: React.RefSetter<PublicScrollViewInstance>,
scrollViewRef?: React.RefSetter<ScrollViewInstance>,
}>;

/** @build-types emit-as-interface Nativewind compatibility */
Expand Down Expand Up @@ -874,7 +877,7 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
getNativeScrollRef: ScrollViewImperativeMethods['getNativeScrollRef'] =
() => {
// Object.assign in _scrollView's mutator augments nativeInstance in place,
// so it is already a PublicScrollViewInstance at runtime.
// so it is already a ScrollViewInstance at runtime.
// $FlowFixMe[incompatible-type]
return this._scrollView.nativeInstance;
};
Expand Down Expand Up @@ -1170,7 +1173,7 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
(instance: InnerViewInstance): InnerViewInstance => instance,
);

_scrollView: RefForwarder<HostInstance, PublicScrollViewInstance | null> =
_scrollView: RefForwarder<HostInstance, ScrollViewInstance | null> =
createRefForwarder(nativeInstance => {
// This is a hack. Ideally we would forwardRef to the underlying
// host component. However, since ScrollView has it's own methods that can be
Expand All @@ -1183,22 +1186,19 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
// $FlowFixMe[prop-missing] - Known issue with appending custom methods.
// $FlowFixMe[incompatible-type]
// $FlowFixMe[unsafe-object-assign]
const publicInstance: PublicScrollViewInstance = Object.assign(
nativeInstance,
{
getScrollResponder: this.getScrollResponder,
getScrollableNode: this.getScrollableNode,
getInnerViewNode: this.getInnerViewNode,
getInnerViewRef: this.getInnerViewRef,
getNativeScrollRef: this.getNativeScrollRef,
scrollTo: this.scrollTo,
scrollToEnd: this.scrollToEnd,
flashScrollIndicators: this.flashScrollIndicators,
scrollResponderZoomTo: this.scrollResponderZoomTo,
scrollResponderScrollNativeHandleToKeyboard:
this.scrollResponderScrollNativeHandleToKeyboard,
},
);
const publicInstance: ScrollViewInstance = Object.assign(nativeInstance, {
getScrollResponder: this.getScrollResponder,
getScrollableNode: this.getScrollableNode,
getInnerViewNode: this.getInnerViewNode,
getInnerViewRef: this.getInnerViewRef,
getNativeScrollRef: this.getNativeScrollRef,
scrollTo: this.scrollTo,
scrollToEnd: this.scrollToEnd,
flashScrollIndicators: this.flashScrollIndicators,
scrollResponderZoomTo: this.scrollResponderZoomTo,
scrollResponderScrollNativeHandleToKeyboard:
this.scrollResponderScrollNativeHandleToKeyboard,
});

return publicInstance;
});
Expand Down Expand Up @@ -1935,13 +1935,13 @@ function createRefForwarder<TNativeInstance, TPublicInstance>(
// component and we need to map `ref` to a differently named prop. This can be
// removed when `ScrollView` is a functional component.
const ScrollViewWrapper: component(
ref?: React.RefSetter<PublicScrollViewInstance>,
ref?: React.RefSetter<ScrollViewInstance>,
...props: ScrollViewProps
) = function Wrapper({
ref,
...props
}: {
ref?: React.RefSetter<PublicScrollViewInstance>,
ref?: React.RefSetter<ScrollViewInstance>,
...ScrollViewProps,
}): React.Node {
return ref == null ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,6 @@ class StatusBar extends React.Component<StatusBarProps> {
}
}

export type StatusBarInstance = StatusBar;

export default StatusBar;
15 changes: 6 additions & 9 deletions packages/react-native/Libraries/Components/Switch/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @format
*/

import type {HostInstance} from '../../../src/private/types/HostInstance';
import type {ColorValue} from '../../StyleSheet/StyleSheet';
import type {NativeSyntheticEvent} from '../../Types/CoreEventTypes';
import type {AccessibilityState} from '../View/ViewAccessibility';
Expand All @@ -25,6 +26,8 @@ import SwitchNativeComponent, {
import * as React from 'react';
import {useLayoutEffect, useRef, useState} from 'react';

export type SwitchInstance = HostInstance;

export type SwitchPropsIOS = {
/**
* Background color when the switch is turned on.
Expand Down Expand Up @@ -119,10 +122,6 @@ export type SwitchProps = Readonly<{
const returnsFalse = () => false;
const returnsTrue = () => true;

type SwitchRef = React.ElementRef<
typeof SwitchNativeComponent | typeof AndroidSwitchNativeComponent,
>;

/**
Renders a boolean input.

Expand Down Expand Up @@ -165,13 +164,13 @@ type SwitchRef = React.ElementRef<
```
*/
const Switch: component(
ref?: React.RefSetter<SwitchRef>,
ref?: React.RefSetter<SwitchInstance>,
...props: SwitchProps
) = function Switch({
ref: forwardedRef,
...props
}: {
ref?: React.RefSetter<SwitchRef>,
ref?: React.RefSetter<SwitchInstance>,
...SwitchProps,
}): React.Node {
const {
Expand All @@ -188,9 +187,7 @@ const Switch: component(
const trackColorForFalse = trackColor?.false;
const trackColorForTrue = trackColor?.true;

const nativeSwitchRef = useRef<React.ElementRef<
typeof SwitchNativeComponent | typeof AndroidSwitchNativeComponent,
> | null>(null);
const nativeSwitchRef = useRef<SwitchInstance | null>(null);

const ref = useMergeRefs(nativeSwitchRef, forwardedRef);

Expand Down
Loading
Loading