Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35169

This reorganizes typing structure a bit.

`Utilities.d.ts` was originally added for utilitiy types but I ended up leaving it a grab bag of types that didn't belong to any individual bit of code. Out of what is in it right now, `Insets` was actually public, and seems to have been imported.

We also run into files around the renderer which are [currently overwritten](e286da25fc/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts) by the React sync script.

Finally, all of the top-level imports of `Utilities` were auto-generated by VS Code, but fail in real apps. I think this is because our tsconfig sets a `baseUrl` to allow resolution from the types folder, so the tooling in the RN repo will use that, but it breaks in real apps that don't have that mapping.

This splits all these up into a couple separate directories that are hopefully easier to reason about, and removes `Omit` which has been a builtin type for quite some time (we were actually already using built-in `Omit`).

Changelog:
[General][Fixed] - Fixup TS Organization

Reviewed By: cipolleschi

Differential Revision: D40932319

fbshipit-source-id: 0b6e3e3eda603885b4dc01dcb9f5233aa546d128
This commit is contained in:
Nick Gerleman 2022-11-02 14:58:37 -07:00 коммит произвёл Facebook GitHub Bot
Родитель b5405b2954
Коммит 5d26ceaa23
41 изменённых файлов: 581 добавлений и 273 удалений

Просмотреть файл

@ -8,7 +8,7 @@
*/
import type * as React from 'react';
import {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import {HostComponent} from '../../../types/public/ReactNativeTypes';
import {EmitterSubscription} from '../../vendor/emitter/EventEmitter';
type AccessibilityChangeEventName =

Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {LayoutChangeEvent} from '../../Types/CoreEventTypes';

Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ViewProps} from '../View/ViewPropTypes';
export interface DatePickerIOSProps extends ViewProps {

Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue} from '../../StyleSheet/StyleSheet';
import {
NativeSyntheticEvent,

Просмотреть файл

@ -8,7 +8,8 @@
*/
import type * as React from 'react';
import {Constructor, TimerMixin} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {TimerMixin} from '../../../types/private/TimerMixin';
import {StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {ViewProps} from '../View/ViewPropTypes';

Просмотреть файл

@ -8,7 +8,7 @@
*/
import type * as React from 'react';
import {Insets} from 'Utilities';
import {Insets} from '../../../types/public/Insets';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {

Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue} from '../../StyleSheet/StyleSheet';
import {ViewProps} from '../View/ViewPropTypes';

Просмотреть файл

@ -8,9 +8,9 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {ImageURISource} from '../../Image/ImageSource';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue} from '../../StyleSheet/StyleSheet';
import {ViewProps} from '../View/ViewPropTypes';

Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue} from '../../StyleSheet/StyleSheet';
import {ViewProps} from '../View/ViewPropTypes';

Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ViewProps} from '../View/ViewPropTypes';
/**

Просмотреть файл

@ -8,7 +8,8 @@
*/
import type * as React from 'react';
import {Constructor, Insets} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {Insets} from '../../../types/public/Insets';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {

4
Libraries/Components/Slider/Slider.d.ts поставляемый
Просмотреть файл

@ -8,9 +8,9 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {ImageURISource} from '../../Image/ImageSource';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {ViewProps} from '../View/ViewPropTypes';

4
Libraries/Components/Switch/Switch.d.ts поставляемый
Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {ViewProps} from '../View/ViewPropTypes';

Просмотреть файл

@ -8,11 +8,12 @@
*/
import type * as React from 'react';
import {Constructor, TimerMixin} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {TimerMixin} from '../../../types/private/TimerMixin';
import {
HostComponent,
NativeMethods,
} from '../../Renderer/shims/ReactNativeTypes';
} from '../../../types/public/ReactNativeTypes';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {TextStyle} from '../../StyleSheet/StyleSheetTypes';
import {

Просмотреть файл

@ -8,7 +8,7 @@
*/
import type * as React from 'react';
import {Insets} from 'Utilities';
import {Insets} from '../../../types/public/Insets';
import {GestureResponderEvent} from '../../Types/CoreEventTypes';
/**

Просмотреть файл

@ -8,8 +8,9 @@
*/
import type * as React from 'react';
import {Constructor, TimerMixin} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {TimerMixin} from '../../../types/private/TimerMixin';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {TouchableMixin} from './Touchable';

Просмотреть файл

@ -8,7 +8,7 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {ColorValue} from '../../StyleSheet/StyleSheet';
import {TouchableMixin} from './Touchable';

Просмотреть файл

@ -8,8 +8,9 @@
*/
import type * as React from 'react';
import {Constructor, TimerMixin} from 'Utilities';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {Constructor} from '../../../types/private/Utilities';
import {TimerMixin} from '../../../types/private/TimerMixin';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {TVParallaxProperties} from '../View/ViewPropTypes';
import {TouchableMixin} from './Touchable';
import {TouchableWithoutFeedbackProps} from './TouchableWithoutFeedback';

Просмотреть файл

@ -8,7 +8,9 @@
*/
import type * as React from 'react';
import {Constructor, Insets, TimerMixin} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {TimerMixin} from '../../../types/private/TimerMixin';
import {Insets} from '../../../types/public/Insets';
import {StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {

4
Libraries/Components/View/View.d.ts поставляемый
Просмотреть файл

@ -8,9 +8,9 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {Constructor} from '../../../types/private/Utilities';
import {ViewProps} from './ViewPropTypes';
import {NativeMethods} from '../../Renderer/shims/ReactNativeTypes';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
/**
* The most fundamental component for building UI, View is a container that supports layout with flexbox, style, some touch handling,

Просмотреть файл

@ -8,8 +8,8 @@
*/
import type * as React from 'react';
import {Insets} from '../../../types/Utilities';
import {GestureResponderHandlers} from '../../Renderer/implementations/ReactNativeRenderer';
import {Insets} from '../../../types/public/Insets';
import {GestureResponderHandlers} from '../../../types/public/ReactNativeRenderer';
import {StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {LayoutChangeEvent, PointerEvents} from '../../Types/CoreEventTypes';

5
Libraries/Image/Image.d.ts поставляемый
Просмотреть файл

@ -8,9 +8,10 @@
*/
import * as React from 'react';
import {Constructor, Insets} from 'Utilities';
import {Constructor} from '../../types/private/Utilities';
import {AccessibilityProps} from '../Components/View/ViewAccessibility';
import {NativeMethods} from '../Renderer/shims/ReactNativeTypes';
import {Insets} from '../../types/public/Insets';
import {NativeMethods} from '../../types/public/ReactNativeTypes';
import {StyleProp} from '../StyleSheet/StyleSheet';
import {ImageStyle, ViewStyle} from '../StyleSheet/StyleSheetTypes';
import {LayoutChangeEvent, NativeSyntheticEvent} from '../Types/CoreEventTypes';

2
Libraries/Interaction/PanResponder.d.ts поставляемый
Просмотреть файл

@ -7,7 +7,7 @@
* @format
*/
import {GestureResponderHandlers} from '../Renderer/implementations/ReactNativeRenderer';
import {GestureResponderHandlers} from '../../types/public/ReactNativeRenderer';
import {GestureResponderEvent} from '../Types/CoreEventTypes';
export interface PanResponderGestureState {

2
Libraries/ReactNative/UIManager.d.ts поставляемый
Просмотреть файл

@ -12,7 +12,7 @@ import {
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
} from '../Renderer/shims/ReactNativeTypes';
} from '../../types/public/ReactNativeTypes';
export interface UIManagerStatic {
/**

Просмотреть файл

@ -7,7 +7,7 @@
* @format
*/
import {HostComponent} from '../Renderer/shims/ReactNativeTypes';
import {HostComponent} from '../../types/public//ReactNativeTypes';
/**
* Creates values that can be used like React components which represent native

4
Libraries/Text/Text.d.ts поставляемый
Просмотреть файл

@ -8,9 +8,9 @@
*/
import type * as React from 'react';
import {Constructor} from 'Utilities';
import {Constructor} from '../../types/private/Utilities';
import {AccessibilityProps} from '../Components/View/ViewAccessibility';
import {NativeMethods} from '../Renderer/shims/ReactNativeTypes';
import {NativeMethods} from '../../types/public/ReactNativeTypes';
import {ColorValue, StyleProp} from '../StyleSheet/StyleSheet';
import {TextStyle} from '../StyleSheet/StyleSheetTypes';
import {

2
Libraries/Types/CoreEventTypes.d.ts поставляемый
Просмотреть файл

@ -9,7 +9,7 @@
import type * as React from 'react';
import {NodeHandle} from '../ReactNative/RendererProxy';
import {HostComponent} from '../Renderer/shims/ReactNativeTypes';
import {HostComponent} from '../../types/public/ReactNativeTypes';
export interface LayoutRectangle {
x: number;

18
types/index.d.ts поставляемый
Просмотреть файл

@ -65,12 +65,11 @@
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <reference path="globals.d.ts" />
/// <reference path="legacy-properties.d.ts" />
/// <reference path="BatchedBridge.d.ts" />
/// <reference path="Codegen.d.ts" />
/// <reference path="Devtools.d.ts" />
/// <reference path="LaunchScreen.d.ts" />
/// <reference path="modules/BatchedBridge.d.ts" />
/// <reference path="modules/Codegen.d.ts" />
/// <reference path="modules/Devtools.d.ts" />
/// <reference path="modules/globals.d.ts" />
/// <reference path="modules/LaunchScreen.d.ts" />
export * from '../Libraries/ActionSheetIOS/ActionSheetIOS';
export * from '../Libraries/Alert/Alert';
@ -131,8 +130,6 @@ export * from '../Libraries/ReactNative/I18nManager';
export * from '../Libraries/ReactNative/RendererProxy';
export * from '../Libraries/ReactNative/UIManager';
export * from '../Libraries/ReactNative/requireNativeComponent';
export * from '../Libraries/Renderer/implementations/ReactNativeRenderer';
export * from '../Libraries/Renderer/shims/ReactNativeTypes';
export * from '../Libraries/Settings/Settings';
export * from '../Libraries/Share/Share';
export * from '../Libraries/StyleSheet/PlatformColorValueTypesIOS';
@ -155,6 +152,11 @@ export * from '../Libraries/YellowBox/YellowBoxDeprecated';
export * from '../Libraries/vendor/core/ErrorUtils';
export * from '../Libraries/vendor/emitter/EventEmitter';
export * from './public/DeprecatedPropertiesAlias';
export * from './public/Insets';
export * from './public/ReactNativeRenderer';
export * from './public/ReactNativeTypes';
import type {ErrorUtils} from '../Libraries/vendor/core/ErrorUtils';
declare global {

208
types/legacy-properties.d.ts поставляемый
Просмотреть файл

@ -1,208 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {
TextProps,
TextPropsIOS,
TextPropsAndroid,
AccessibilityProps,
AccessibilityPropsIOS,
AccessibilityPropsAndroid,
TextInputProps,
TextInputIOSProps,
TextInputAndroidProps,
ViewProps,
ViewPropsIOS,
ViewPropsAndroid,
ScrollViewProps,
ScrollViewPropsIOS,
ScrollViewPropsAndroid,
InputAccessoryViewProps,
ActivityIndicatorProps,
ActivityIndicatorIOSProps,
DatePickerIOSProps,
DrawerLayoutAndroidProps,
ProgressBarAndroidProps,
ProgressViewIOSProps,
RefreshControlProps,
RefreshControlPropsIOS,
RefreshControlPropsAndroid,
SliderProps,
SliderPropsIOS,
SliderPropsAndroid,
ImageSourcePropType,
ImageProps,
ImagePropsIOS,
ImagePropsAndroid,
ImageBackgroundProps,
FlatListProps,
VirtualizedListProps,
SectionListProps,
ModalProps,
TouchableWithoutFeedbackProps,
TouchableHighlightProps,
TouchableOpacityProps,
TouchableNativeFeedbackProps,
ButtonProps,
StatusBarProps,
StatusBarPropsIOS,
StatusBarPropsAndroid,
SwitchProps,
SwitchPropsIOS,
} from 'react-native';
declare module 'react-native' {
/*
* Previously, props interfaces where named *Properties
* They have been renamed to *Props to match React Native documentation
* The following lines ensure compatibility with *Properties and should be removed in the future
*/
/** @deprecated Use TextProps */
export type TextProperties = TextProps;
/** @deprecated Use TextPropsIOS */
export type TextPropertiesIOS = TextPropsIOS;
/** @deprecated Use TextPropsAndroid */
export type TextPropertiesAndroid = TextPropsAndroid;
/** @deprecated Use AccessibilityProps */
export type AccessibilityProperties = AccessibilityProps;
/** @deprecated Use AccessibilityPropsIOS */
export type AccessibilityPropertiesIOS = AccessibilityPropsIOS;
/** @deprecated Use AccessibilityPropsAndroid */
export type AccessibilityPropertiesAndroid = AccessibilityPropsAndroid;
/** @deprecated Use TextInputProps */
export type TextInputProperties = TextInputProps;
/** @deprecated Use TextInputIOSProps */
export type TextInputIOSProperties = TextInputIOSProps;
/** @deprecated Use TextInputAndroidProps */
export type TextInputAndroidProperties = TextInputAndroidProps;
/** @deprecated Use ViewProps */
export type ViewProperties = ViewProps;
/** @deprecated Use ViewPropsIOS */
export type ViewPropertiesIOS = ViewPropsIOS;
/** @deprecated Use ViewPropsAndroid */
export type ViewPropertiesAndroid = ViewPropsAndroid;
/** @deprecated Use ScrollViewProps */
export type ScrollViewProperties = ScrollViewProps;
/** @deprecated Use ScrollViewPropsIOS */
export type ScrollViewPropertiesIOS = ScrollViewPropsIOS;
/** @deprecated Use ScrollViewPropsAndroid */
export type ScrollViewPropertiesAndroid = ScrollViewPropsAndroid;
/** @deprecated Use InputAccessoryViewProps */
export type InputAccessoryViewProperties = InputAccessoryViewProps;
/** @deprecated Use ActivityIndicatorProps */
export type ActivityIndicatorProperties = ActivityIndicatorProps;
/** @deprecated Use ActivityIndicatorIOSProps */
export type ActivityIndicatorIOSProperties = ActivityIndicatorIOSProps;
/** @deprecated Use DatePickerIOSProps */
export type DatePickerIOSProperties = DatePickerIOSProps;
/** @deprecated Use DrawerLayoutAndroidProps */
export type DrawerLayoutAndroidProperties = DrawerLayoutAndroidProps;
/** @deprecated Use ProgressBarAndroidProps */
export type ProgressBarAndroidProperties = ProgressBarAndroidProps;
/** @deprecated Use ProgressViewIOSProps */
export type ProgressViewIOSProperties = ProgressViewIOSProps;
/** @deprecated Use RefreshControlProps */
export type RefreshControlProperties = RefreshControlProps;
/** @deprecated Use RefreshControlPropsIOS */
export type RefreshControlPropertiesIOS = RefreshControlPropsIOS;
/** @deprecated Use RefreshControlPropsAndroid */
export type RefreshControlPropertiesAndroid = RefreshControlPropsAndroid;
/** @deprecated Use SliderProps */
export type SliderProperties = SliderProps;
/** @deprecated Use SliderPropsIOS */
export type SliderPropertiesIOS = SliderPropsIOS;
/** @deprecated Use SliderPropsAndroid */
export type SliderPropertiesAndroid = SliderPropsAndroid;
/** @deprecated Use ImageSourcePropType */
export type ImagePropertiesSourceOptions = ImageSourcePropType;
/** @deprecated Use ImageProps */
export type ImageProperties = ImageProps;
/** @deprecated Use ImagePropsIOS */
export type ImagePropertiesIOS = ImagePropsIOS;
/** @deprecated Use ImagePropsAndroid */
export type ImagePropertiesAndroid = ImagePropsAndroid;
/** @deprecated Use ImageBackgroundProps */
export type ImageBackgroundProperties = ImageBackgroundProps;
/** @deprecated Use FlatListProps */
export type FlatListProperties<ItemT> = FlatListProps<ItemT>;
/** @deprecated Use VirtualizedListProps */
export type VirtualizedListProperties<ItemT> = VirtualizedListProps<ItemT>;
/** @deprecated Use SectionListProps */
export type SectionListProperties<ItemT> = SectionListProps<ItemT>;
/** @deprecated Use ModalProps */
export type ModalProperties = ModalProps;
/** @deprecated Use TouchableWithoutFeedbackProps */
export type TouchableWithoutFeedbackProperties =
TouchableWithoutFeedbackProps;
/** @deprecated Use TouchableHighlightProps */
export type TouchableHighlightProperties = TouchableHighlightProps;
/** @deprecated Use TouchableOpacityProps */
export type TouchableOpacityProperties = TouchableOpacityProps;
/** @deprecated Use TouchableNativeFeedbackProps */
export type TouchableNativeFeedbackProperties = TouchableNativeFeedbackProps;
/** @deprecated Use ButtonProps */
export type ButtonProperties = ButtonProps;
/** @deprecated Use StatusBarProps */
export type StatusBarProperties = StatusBarProps;
/** @deprecated Use StatusBarPropsIOS */
export type StatusBarPropertiesIOS = StatusBarPropsIOS;
/** @deprecated Use StatusBarPropsAndroid */
export type StatusBarPropertiesAndroid = StatusBarPropsAndroid;
/** @deprecated Use SwitchProps */
export type SwitchProperties = SwitchProps;
/** @deprecated Use SwitchPropsIOS */
export type SwitchPropertiesIOS = SwitchPropsIOS;
}

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -7,9 +7,6 @@
* @format
*/
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type Constructor<T> = new (...args: any[]) => T;
export interface TimerMixin {
setTimeout: typeof setTimeout;
clearTimeout: typeof clearTimeout;
@ -20,10 +17,3 @@ export interface TimerMixin {
requestAnimationFrame: typeof requestAnimationFrame;
cancelAnimationFrame: typeof cancelAnimationFrame;
}
export interface Insets {
top?: number | undefined;
left?: number | undefined;
bottom?: number | undefined;
right?: number | undefined;
}

10
types/private/Utilities.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
export type Constructor<T> = new (...args: any[]) => T;

205
types/public/DeprecatedPropertiesAlias.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,205 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {
TextProps,
TextPropsIOS,
TextPropsAndroid,
AccessibilityProps,
AccessibilityPropsIOS,
AccessibilityPropsAndroid,
TextInputProps,
TextInputIOSProps,
TextInputAndroidProps,
ViewProps,
ViewPropsIOS,
ViewPropsAndroid,
ScrollViewProps,
ScrollViewPropsIOS,
ScrollViewPropsAndroid,
InputAccessoryViewProps,
ActivityIndicatorProps,
ActivityIndicatorIOSProps,
DatePickerIOSProps,
DrawerLayoutAndroidProps,
ProgressBarAndroidProps,
ProgressViewIOSProps,
RefreshControlProps,
RefreshControlPropsIOS,
RefreshControlPropsAndroid,
SliderProps,
SliderPropsIOS,
SliderPropsAndroid,
ImageSourcePropType,
ImageProps,
ImagePropsIOS,
ImagePropsAndroid,
ImageBackgroundProps,
FlatListProps,
VirtualizedListProps,
SectionListProps,
ModalProps,
TouchableWithoutFeedbackProps,
TouchableHighlightProps,
TouchableOpacityProps,
TouchableNativeFeedbackProps,
ButtonProps,
StatusBarProps,
StatusBarPropsIOS,
StatusBarPropsAndroid,
SwitchProps,
SwitchPropsIOS,
} from 'react-native';
/*
* Previously, props interfaces where named *Properties
* They have been renamed to *Props to match React Native documentation
* The following lines ensure compatibility with *Properties and should be removed in the future
*/
/** @deprecated Use TextProps */
export type TextProperties = TextProps;
/** @deprecated Use TextPropsIOS */
export type TextPropertiesIOS = TextPropsIOS;
/** @deprecated Use TextPropsAndroid */
export type TextPropertiesAndroid = TextPropsAndroid;
/** @deprecated Use AccessibilityProps */
export type AccessibilityProperties = AccessibilityProps;
/** @deprecated Use AccessibilityPropsIOS */
export type AccessibilityPropertiesIOS = AccessibilityPropsIOS;
/** @deprecated Use AccessibilityPropsAndroid */
export type AccessibilityPropertiesAndroid = AccessibilityPropsAndroid;
/** @deprecated Use TextInputProps */
export type TextInputProperties = TextInputProps;
/** @deprecated Use TextInputIOSProps */
export type TextInputIOSProperties = TextInputIOSProps;
/** @deprecated Use TextInputAndroidProps */
export type TextInputAndroidProperties = TextInputAndroidProps;
/** @deprecated Use ViewProps */
export type ViewProperties = ViewProps;
/** @deprecated Use ViewPropsIOS */
export type ViewPropertiesIOS = ViewPropsIOS;
/** @deprecated Use ViewPropsAndroid */
export type ViewPropertiesAndroid = ViewPropsAndroid;
/** @deprecated Use ScrollViewProps */
export type ScrollViewProperties = ScrollViewProps;
/** @deprecated Use ScrollViewPropsIOS */
export type ScrollViewPropertiesIOS = ScrollViewPropsIOS;
/** @deprecated Use ScrollViewPropsAndroid */
export type ScrollViewPropertiesAndroid = ScrollViewPropsAndroid;
/** @deprecated Use InputAccessoryViewProps */
export type InputAccessoryViewProperties = InputAccessoryViewProps;
/** @deprecated Use ActivityIndicatorProps */
export type ActivityIndicatorProperties = ActivityIndicatorProps;
/** @deprecated Use ActivityIndicatorIOSProps */
export type ActivityIndicatorIOSProperties = ActivityIndicatorIOSProps;
/** @deprecated Use DatePickerIOSProps */
export type DatePickerIOSProperties = DatePickerIOSProps;
/** @deprecated Use DrawerLayoutAndroidProps */
export type DrawerLayoutAndroidProperties = DrawerLayoutAndroidProps;
/** @deprecated Use ProgressBarAndroidProps */
export type ProgressBarAndroidProperties = ProgressBarAndroidProps;
/** @deprecated Use ProgressViewIOSProps */
export type ProgressViewIOSProperties = ProgressViewIOSProps;
/** @deprecated Use RefreshControlProps */
export type RefreshControlProperties = RefreshControlProps;
/** @deprecated Use RefreshControlPropsIOS */
export type RefreshControlPropertiesIOS = RefreshControlPropsIOS;
/** @deprecated Use RefreshControlPropsAndroid */
export type RefreshControlPropertiesAndroid = RefreshControlPropsAndroid;
/** @deprecated Use SliderProps */
export type SliderProperties = SliderProps;
/** @deprecated Use SliderPropsIOS */
export type SliderPropertiesIOS = SliderPropsIOS;
/** @deprecated Use SliderPropsAndroid */
export type SliderPropertiesAndroid = SliderPropsAndroid;
/** @deprecated Use ImageSourcePropType */
export type ImagePropertiesSourceOptions = ImageSourcePropType;
/** @deprecated Use ImageProps */
export type ImageProperties = ImageProps;
/** @deprecated Use ImagePropsIOS */
export type ImagePropertiesIOS = ImagePropsIOS;
/** @deprecated Use ImagePropsAndroid */
export type ImagePropertiesAndroid = ImagePropsAndroid;
/** @deprecated Use ImageBackgroundProps */
export type ImageBackgroundProperties = ImageBackgroundProps;
/** @deprecated Use FlatListProps */
export type FlatListProperties<ItemT> = FlatListProps<ItemT>;
/** @deprecated Use VirtualizedListProps */
export type VirtualizedListProperties<ItemT> = VirtualizedListProps<ItemT>;
/** @deprecated Use SectionListProps */
export type SectionListProperties<ItemT> = SectionListProps<ItemT>;
/** @deprecated Use ModalProps */
export type ModalProperties = ModalProps;
/** @deprecated Use TouchableWithoutFeedbackProps */
export type TouchableWithoutFeedbackProperties = TouchableWithoutFeedbackProps;
/** @deprecated Use TouchableHighlightProps */
export type TouchableHighlightProperties = TouchableHighlightProps;
/** @deprecated Use TouchableOpacityProps */
export type TouchableOpacityProperties = TouchableOpacityProps;
/** @deprecated Use TouchableNativeFeedbackProps */
export type TouchableNativeFeedbackProperties = TouchableNativeFeedbackProps;
/** @deprecated Use ButtonProps */
export type ButtonProperties = ButtonProps;
/** @deprecated Use StatusBarProps */
export type StatusBarProperties = StatusBarProps;
/** @deprecated Use StatusBarPropsIOS */
export type StatusBarPropertiesIOS = StatusBarPropsIOS;
/** @deprecated Use StatusBarPropsAndroid */
export type StatusBarPropertiesAndroid = StatusBarPropsAndroid;
/** @deprecated Use SwitchProps */
export type SwitchProperties = SwitchProps;
/** @deprecated Use SwitchPropsIOS */
export type SwitchPropertiesIOS = SwitchPropsIOS;

15
types/public/Insets.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,15 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
export interface Insets {
top?: number | undefined;
left?: number | undefined;
bottom?: number | undefined;
right?: number | undefined;
}

149
types/public/ReactNativeRenderer.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,149 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {GestureResponderEvent} from '../../Libraries/Types/CoreEventTypes';
/**
* Gesture recognition on mobile devices is much more complicated than web.
* A touch can go through several phases as the app determines what the user's intention is.
* For example, the app needs to determine if the touch is scrolling, sliding on a widget, or tapping.
* This can even change during the duration of a touch. There can also be multiple simultaneous touches.
*
* The touch responder system is needed to allow components to negotiate these touch interactions
* without any additional knowledge about their parent or child components.
* This system is implemented in ResponderEventPlugin.js, which contains further details and documentation.
*
* Best Practices
* Users can feel huge differences in the usability of web apps vs. native, and this is one of the big causes.
* Every action should have the following attributes:
* Feedback/highlighting- show the user what is handling their touch, and what will happen when they release the gesture
* Cancel-ability- when making an action, the user should be able to abort it mid-touch by dragging their finger away
*
* These features make users more comfortable while using an app,
* because it allows people to experiment and interact without fear of making mistakes.
*
* TouchableHighlight and Touchable*
* The responder system can be complicated to use.
* So we have provided an abstract Touchable implementation for things that should be "tappable".
* This uses the responder system and allows you to easily configure tap interactions declaratively.
* Use TouchableHighlight anywhere where you would use a button or link on web.
*/
export interface GestureResponderHandlers {
/**
* A view can become the touch responder by implementing the correct negotiation methods.
* There are two methods to ask the view if it wants to become responder:
*/
/**
* Does this view want to become responder on the start of a touch?
*/
onStartShouldSetResponder?:
| ((event: GestureResponderEvent) => boolean)
| undefined;
/**
* Called for every touch move on the View when it is not the responder: does this view want to "claim" touch responsiveness?
*/
onMoveShouldSetResponder?:
| ((event: GestureResponderEvent) => boolean)
| undefined;
/**
* If the View returns true and attempts to become the responder, one of the following will happen:
*/
onResponderEnd?: ((event: GestureResponderEvent) => void) | undefined;
/**
* The View is now responding for touch events.
* This is the time to highlight and show the user what is happening
*/
onResponderGrant?: ((event: GestureResponderEvent) => void) | undefined;
/**
* Something else is the responder right now and will not release it
*/
onResponderReject?: ((event: GestureResponderEvent) => void) | undefined;
/**
* If the view is responding, the following handlers can be called:
*/
/**
* The user is moving their finger
*/
onResponderMove?: ((event: GestureResponderEvent) => void) | undefined;
/**
* Fired at the end of the touch, ie "touchUp"
*/
onResponderRelease?: ((event: GestureResponderEvent) => void) | undefined;
onResponderStart?: ((event: GestureResponderEvent) => void) | undefined;
/**
* Something else wants to become responder.
* Should this view release the responder? Returning true allows release
*/
onResponderTerminationRequest?:
| ((event: GestureResponderEvent) => boolean)
| undefined;
/**
* The responder has been taken from the View.
* Might be taken by other views after a call to onResponderTerminationRequest,
* or might be taken by the OS without asking (happens with control center/ notification center on iOS)
*/
onResponderTerminate?: ((event: GestureResponderEvent) => void) | undefined;
/**
* onStartShouldSetResponder and onMoveShouldSetResponder are called with a bubbling pattern,
* where the deepest node is called first.
* That means that the deepest component will become responder when multiple Views return true for *ShouldSetResponder handlers.
* This is desirable in most cases, because it makes sure all controls and buttons are usable.
*
* However, sometimes a parent will want to make sure that it becomes responder.
* This can be handled by using the capture phase.
* Before the responder system bubbles up from the deepest component,
* it will do a capture phase, firing on*ShouldSetResponderCapture.
* So if a parent View wants to prevent the child from becoming responder on a touch start,
* it should have a onStartShouldSetResponderCapture handler which returns true.
*/
onStartShouldSetResponderCapture?:
| ((event: GestureResponderEvent) => boolean)
| undefined;
/**
* onStartShouldSetResponder and onMoveShouldSetResponder are called with a bubbling pattern,
* where the deepest node is called first.
* That means that the deepest component will become responder when multiple Views return true for *ShouldSetResponder handlers.
* This is desirable in most cases, because it makes sure all controls and buttons are usable.
*
* However, sometimes a parent will want to make sure that it becomes responder.
* This can be handled by using the capture phase.
* Before the responder system bubbles up from the deepest component,
* it will do a capture phase, firing on*ShouldSetResponderCapture.
* So if a parent View wants to prevent the child from becoming responder on a touch start,
* it should have a onStartShouldSetResponderCapture handler which returns true.
*/
onMoveShouldSetResponderCapture?:
| ((event: GestureResponderEvent) => boolean)
| undefined;
}
/**
* React Native also implements unstable_batchedUpdates
*/
export function unstable_batchedUpdates<A, B>(
callback: (a: A, b: B) => any,
a: A,
b: B,
): void;
export function unstable_batchedUpdates<A>(callback: (a: A) => any, a: A): void;
export function unstable_batchedUpdates(callback: () => any): void;

141
types/public/ReactNativeTypes.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,141 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import type * as React from 'react';
export type MeasureOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number,
pageX: number,
pageY: number,
) => void;
export type MeasureInWindowOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number,
) => void;
export type MeasureLayoutOnSuccessCallback = (
left: number,
top: number,
width: number,
height: number,
) => void;
/**
* NativeMethods provides methods to access the underlying native component directly.
* This can be useful in cases when you want to focus a view or measure its on-screen dimensions,
* for example.
* The methods described here are available on most of the default components provided by React Native.
* Note, however, that they are not available on composite components that aren't directly backed by a
* native view. This will generally include most components that you define in your own app.
* For more information, see [Direct Manipulation](https://reactnative.dev/docs/direct-manipulation).
* @see https://github.com/facebook/react-native/blob/master/Libraries/Renderer/shims/ReactNativeTypes.js#L87
*/
export interface NativeMethods {
/**
* Determines the location on screen, width, and height of the given view and
* returns the values via an async callback. If successful, the callback will
* be called with the following arguments:
*
* - x
* - y
* - width
* - height
* - pageX
* - pageY
*
* Note that these measurements are not available until after the rendering
* has been completed in native. If you need the measurements as soon as
* possible, consider using the [`onLayout`
* prop](docs/view.html#onlayout) instead.
*/
measure(callback: MeasureOnSuccessCallback): void;
/**
* Determines the location of the given view in the window and returns the
* values via an async callback. If the React root view is embedded in
* another native view, this will give you the absolute coordinates. If
* successful, the callback will be called with the following
* arguments:
*
* - x
* - y
* - width
* - height
*
* Note that these measurements are not available until after the rendering
* has been completed in native.
*/
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
/**
* Like [`measure()`](#measure), but measures the view relative an ancestor,
* specified as `relativeToNativeComponentRef`. This means that the returned x, y
* are relative to the origin x, y of the ancestor view.
* _Can also be called with a relativeNativeNodeHandle but is deprecated._
*/
measureLayout(
relativeToNativeComponentRef: HostComponent<unknown> | number,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail: () => void /* currently unused */,
): void;
/**
* This function sends props straight to native. They will not participate in
* future diff process - this means that if you do not include them in the
* next render, they will remain active (see [Direct
* Manipulation](https://reactnative.dev/docs/direct-manipulation)).
*/
setNativeProps(nativeProps: object): void;
/**
* Requests focus for the given input or view. The exact behavior triggered
* will depend on the platform and type of view.
*/
focus(): void;
/**
* Removes focus from an input or view. This is the opposite of `focus()`.
*/
blur(): void;
refs: {
[key: string]: React.Component<any, any>;
};
}
/**
* @deprecated Use NativeMethods instead.
*/
export type NativeMethodsMixin = NativeMethods;
/**
* @deprecated Use NativeMethods instead.
*/
export type NativeMethodsMixinType = NativeMethods;
/**
* Represents a native component, such as those returned from `requireNativeComponent`.
*
* @see https://github.com/facebook/react-native/blob/v0.62.0-rc.5/Libraries/Renderer/shims/ReactNativeTypes.js
*
* @todo This should eventually be defined as an AbstractComponent, but that
* should first be introduced in the React typings.
*/
export interface HostComponent<P>
extends Pick<
React.ComponentClass<P>,
Exclude<keyof React.ComponentClass<P>, 'new'>
> {
new (props: P, context?: any): React.Component<P> & Readonly<NativeMethods>;
}

Просмотреть файл

@ -10,10 +10,6 @@
"jsx": "react",
"noEmit": true,
"forceConsistentCasingInFileNames": true,
// If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index".
// If the library is global (cannot be imported via `import` or `require`), leave this out.
"baseUrl": ".",
"paths": {"react-native": ["."]}
}
}