mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Align AnimateProps to match TS types (#50214)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50214 This diff is a second step toward the TS AnimatedProps alignment. In this change the rest of the extended types and recursions in `WithAnimatedValue` are applied. Changelog: [Internal] - Aligned AnimateProps to match TS types. Reviewed By: huntie Differential Revision: D71623036 fbshipit-source-id: d4777e25c3bf3119608938ee4cd246cdc4c4f7ee
This commit is contained in:
1 parent
eb2d9c1ac0
commit
9c5cf4e9c4
9 files changed
+90
-15
No files matched your search
@@ -46,11 +46,12 @@ const AnimatedScrollView: AnimatedComponentType<Props, Instance> =
|
||||
props.style != null
|
||||
) {
|
||||
return (
|
||||
// $FlowFixMe[prop-missing]
|
||||
// $FlowFixMe - It should return an Animated ScrollView but it returns a ScrollView with Animated props applied.
|
||||
<AnimatedScrollViewWithInvertedRefreshControl
|
||||
scrollEventThrottle={0.0001}
|
||||
{...props}
|
||||
ref={forwardedRef}
|
||||
// $FlowFixMe[incompatible-type]
|
||||
refreshControl={props.refreshControl}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -8,7 +8,16 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type AnimatedAddition from './nodes/AnimatedAddition';
|
||||
import type AnimatedDiffClamp from './nodes/AnimatedDiffClamp';
|
||||
import type AnimatedDivision from './nodes/AnimatedDivision';
|
||||
import type AnimatedInterpolation from './nodes/AnimatedInterpolation';
|
||||
import type AnimatedModulo from './nodes/AnimatedModulo';
|
||||
import type AnimatedMultiplication from './nodes/AnimatedMultiplication';
|
||||
import type AnimatedNode from './nodes/AnimatedNode';
|
||||
import type {AnimatedPropsAllowlist} from './nodes/AnimatedProps';
|
||||
import type AnimatedSubtraction from './nodes/AnimatedSubtraction';
|
||||
import type AnimatedValue from './nodes/AnimatedValue';
|
||||
|
||||
import createAnimatedPropsHook from '../../src/private/animated/createAnimatedPropsHook';
|
||||
import composeStyles from '../../src/private/styles/composeStyles';
|
||||
@@ -18,16 +27,44 @@ import * as React from 'react';
|
||||
import {useMemo} from 'react';
|
||||
|
||||
type Nullable = void | null;
|
||||
type Primitive = string | number | boolean | symbol | void;
|
||||
type Builtin = (...$ReadOnlyArray<empty>) => mixed | Date | Error | RegExp;
|
||||
|
||||
export type WithAnimatedValue<+T> = T extends Builtin | Nullable ? T : any;
|
||||
export type WithAnimatedValue<+T> = T extends Builtin | Nullable
|
||||
? T
|
||||
: T extends Primitive
|
||||
?
|
||||
| T
|
||||
| AnimatedNode
|
||||
| AnimatedAddition
|
||||
| AnimatedSubtraction
|
||||
| AnimatedDivision
|
||||
| AnimatedMultiplication
|
||||
| AnimatedModulo
|
||||
| AnimatedDiffClamp
|
||||
| AnimatedValue
|
||||
| AnimatedInterpolation<number | string>
|
||||
| AnimatedInterpolation<number>
|
||||
| AnimatedInterpolation<string>
|
||||
: T extends $ReadOnlyArray<infer P>
|
||||
? $ReadOnlyArray<WithAnimatedValue<P>>
|
||||
: T extends {...}
|
||||
? {+[K in keyof T]: WithAnimatedValue<T[K]>}
|
||||
: T;
|
||||
|
||||
export type AnimatedProps<Props: {...}> = {
|
||||
+[K in keyof Props]: WithAnimatedValue<Props[K]>,
|
||||
} & {
|
||||
type NonAnimatedProps = 'ref' | 'innerViewRef' | 'scrollViewRef';
|
||||
type PassThroughProps = $ReadOnly<{
|
||||
passthroughAnimatedPropExplicitValues?: React.ElementConfig<
|
||||
typeof View,
|
||||
> | null,
|
||||
}>;
|
||||
|
||||
export type AnimatedProps<Props: {...}> = {
|
||||
[K in keyof (Props & PassThroughProps)]: K extends $Keys<PassThroughProps>
|
||||
? PassThroughProps[K]
|
||||
: K extends NonAnimatedProps
|
||||
? Props[K]
|
||||
: WithAnimatedValue<Props[K]>,
|
||||
};
|
||||
|
||||
// We could use a mapped type here to introduce acceptable Animated variants
|
||||
|
||||
@@ -214,7 +214,9 @@ export default class AnimatedValueXY extends AnimatedWithChildren {
|
||||
*
|
||||
* See https://reactnative.dev/docs/animatedvaluexy#gettranslatetransform
|
||||
*/
|
||||
getTranslateTransform(): Array<{[key: string]: AnimatedValue, ...}> {
|
||||
getTranslateTransform(): Array<
|
||||
{translateX: AnimatedValue} | {translateY: AnimatedValue},
|
||||
> {
|
||||
return [{translateX: this.x}, {translateY: this.y}];
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,8 @@ class TouchableBounce extends React.Component<Props, State> {
|
||||
importantForAccessibility={
|
||||
this.props['aria-hidden'] === true
|
||||
? 'no-hide-descendants'
|
||||
: this.props.importantForAccessibility
|
||||
: // $FlowFixMe[incompatible-type] - AnimatedProps types were made more strict and need refining at this call site
|
||||
this.props.importantForAccessibility
|
||||
}
|
||||
accessibilityViewIsModal={
|
||||
this.props['aria-modal'] ?? this.props.accessibilityViewIsModal
|
||||
|
||||
@@ -308,7 +308,8 @@ class TouchableOpacity extends React.Component<TouchableOpacityProps, State> {
|
||||
importantForAccessibility={
|
||||
this.props['aria-hidden'] === true
|
||||
? 'no-hide-descendants'
|
||||
: this.props.importantForAccessibility
|
||||
: // $FlowFixMe[incompatible-type] - AnimatedProps types were made more strict and need refining at this call site
|
||||
this.props.importantForAccessibility
|
||||
}
|
||||
accessibilityViewIsModal={
|
||||
this.props['aria-modal'] ?? this.props.accessibilityViewIsModal
|
||||
|
||||
@@ -53,7 +53,8 @@ export type AccessibilityRole =
|
||||
| 'webview'
|
||||
| 'drawerlayout'
|
||||
| 'slidingdrawer'
|
||||
| 'iconmenu';
|
||||
| 'iconmenu'
|
||||
| string;
|
||||
|
||||
// Role types for web
|
||||
export type Role =
|
||||
|
||||
@@ -645,14 +645,41 @@ exports[`public API should not change unintentionally Libraries/Animated/compone
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Animated/createAnimatedComponent.js 1`] = `
|
||||
"type Nullable = void | null;
|
||||
type Primitive = string | number | boolean | symbol | void;
|
||||
type Builtin = (...$ReadOnlyArray<empty>) => mixed | Date | Error | RegExp;
|
||||
export type WithAnimatedValue<+T> = T extends Builtin | Nullable ? T : any;
|
||||
export type AnimatedProps<Props: { ... }> = {
|
||||
+[K in keyof Props]: WithAnimatedValue<Props[K]>,
|
||||
} & {
|
||||
export type WithAnimatedValue<+T> = T extends Builtin | Nullable
|
||||
? T
|
||||
: T extends Primitive
|
||||
?
|
||||
| T
|
||||
| AnimatedNode
|
||||
| AnimatedAddition
|
||||
| AnimatedSubtraction
|
||||
| AnimatedDivision
|
||||
| AnimatedMultiplication
|
||||
| AnimatedModulo
|
||||
| AnimatedDiffClamp
|
||||
| AnimatedValue
|
||||
| AnimatedInterpolation<number | string>
|
||||
| AnimatedInterpolation<number>
|
||||
| AnimatedInterpolation<string>
|
||||
: T extends $ReadOnlyArray<infer P>
|
||||
? $ReadOnlyArray<WithAnimatedValue<P>>
|
||||
: T extends { ... }
|
||||
? { +[K in keyof T]: WithAnimatedValue<T[K]> }
|
||||
: T;
|
||||
type NonAnimatedProps = \\"ref\\" | \\"innerViewRef\\" | \\"scrollViewRef\\";
|
||||
type PassThroughProps = $ReadOnly<{
|
||||
passthroughAnimatedPropExplicitValues?: React.ElementConfig<
|
||||
typeof View,
|
||||
> | null,
|
||||
}>;
|
||||
export type AnimatedProps<Props: { ... }> = {
|
||||
[K in keyof (Props & PassThroughProps)]: K extends $Keys<PassThroughProps>
|
||||
? PassThroughProps[K]
|
||||
: K extends NonAnimatedProps
|
||||
? Props[K]
|
||||
: WithAnimatedValue<Props[K]>,
|
||||
};
|
||||
export type StrictAnimatedProps<Props: { ... }> = $ReadOnly<{
|
||||
...$Exact<Props>,
|
||||
@@ -998,7 +1025,9 @@ declare export default class AnimatedValueXY extends AnimatedWithChildren {
|
||||
removeListener(id: string): void;
|
||||
removeAllListeners(): void;
|
||||
getLayout(): { [key: string]: AnimatedValue, ... };
|
||||
getTranslateTransform(): Array<{ [key: string]: AnimatedValue, ... }>;
|
||||
getTranslateTransform(): Array<
|
||||
{ translateX: AnimatedValue } | { translateY: AnimatedValue },
|
||||
>;
|
||||
}
|
||||
"
|
||||
`;
|
||||
@@ -3800,7 +3829,8 @@ exports[`public API should not change unintentionally Libraries/Components/View/
|
||||
| \\"webview\\"
|
||||
| \\"drawerlayout\\"
|
||||
| \\"slidingdrawer\\"
|
||||
| \\"iconmenu\\";
|
||||
| \\"iconmenu\\"
|
||||
| string;
|
||||
export type Role =
|
||||
| \\"alert\\"
|
||||
| \\"alertdialog\\"
|
||||
|
||||
@@ -70,6 +70,7 @@ function AnimatedView({
|
||||
Apply Selected Transforms
|
||||
</RNTesterButton>
|
||||
<Animated.View
|
||||
// $FlowFixMe[incompatible-type] - properties are not exact
|
||||
style={[styles.animatedView, {transform: transformStyles}]}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -318,6 +318,7 @@ export function SectionList_scrollable(Props: {...}): React.MixedElement {
|
||||
)
|
||||
}
|
||||
onEndReachedThreshold={0}
|
||||
// $FlowFixMe[incompatible-type] - incompatible redenerItem type
|
||||
sections={filteredSectionData}
|
||||
style={styles.list}
|
||||
viewabilityConfig={VIEWABILITY_CONFIG}
|
||||
|
||||
Reference in new issue
Block a user