Skip to content
Merged
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
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ flow-typed/
packages/react-native/flow/

[options]
experimental.tslib_syntax=true
builtin_lib=core-only

emoji=true
Expand Down
59 changes: 48 additions & 11 deletions packages/react-native/Libraries/Animated/NativeAnimatedAllowlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,54 @@
* @format
*/

import type {
____TransformStyle_Internal,
ImageStyle,
NativeColorValue,
TextStyle,
} from '../StyleSheet/StyleSheetTypes';
import type {
InterpolationConfigSupportedOutputType,
InterpolationConfigType,
} from './nodes/AnimatedInterpolation';
import type {AnimatedNodeConfig} from './nodes/AnimatedNode';
import type {AnimatedPropsAllowlist} from './nodes/AnimatedProps';

import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';

type KeyAllowlist<K extends string> = Readonly<Partial<Record<K, true>>>;
type KeyOfUnion<T> = T extends unknown ? keyof T : empty;

type AnimatableStyle = Readonly<{...TextStyle, ...ImageStyle}>;
type StyleKey = keyof AnimatableStyle;
type ColorStyleKey = Values<{
[K in StyleKey]: NativeColorValue extends NonNullable<AnimatableStyle[K]>
? K
: empty,
}>;

type TransformEntry = Exclude<
NonNullable<____TransformStyle_Internal['transform']>,
string,
>[number];
type TransformKey = KeyOfUnion<NonNullable<TransformEntry>>;
type LegacyTransformStyleKey = Extract<
TransformKey,
'scaleX' | 'scaleY' | 'translateX' | 'translateY',
>;

type InterpolationParamKey = Exclude<
keyof InterpolationConfigType<InterpolationConfigSupportedOutputType>,
keyof AnimatedNodeConfig,
>;

/**
* Styles allowed by the native animated implementation.
*
* In general native animated implementation should support any numeric or color property that
* doesn't need to be updated through the shadow view hierarchy (all non-layout properties).
*/
const SUPPORTED_COLOR_STYLES: {[key: string]: true} = {
const SUPPORTED_COLOR_STYLES = {
backgroundColor: true,
borderBottomColor: true,
borderColor: true,
Expand All @@ -29,9 +66,9 @@ const SUPPORTED_COLOR_STYLES: {[key: string]: true} = {
borderTopColor: true,
color: true,
tintColor: true,
};
} as const satisfies KeyAllowlist<ColorStyleKey>;

const SUPPORTED_STYLES: {[key: string]: true} = {
const SUPPORTED_STYLES = {
...SUPPORTED_COLOR_STYLES,
borderBottomEndRadius: true,
borderBottomLeftRadius: true,
Expand Down Expand Up @@ -61,7 +98,7 @@ const SUPPORTED_STYLES: {[key: string]: true} = {
translateY: true,
// eslint-disable-next-line react-hooks/rules-of-hooks
...(ReactNativeFeatureFlags.useSharedAnimatedBackend()
? {
? ({
/* dimension */
height: true,
maxHeight: true,
Expand Down Expand Up @@ -114,11 +151,11 @@ const SUPPORTED_STYLES: {[key: string]: true} = {
gap: true,
rowGap: true,
columnGap: true,
}
} as const)
: {}),
};
} as const satisfies KeyAllowlist<StyleKey | LegacyTransformStyleKey>;

const SUPPORTED_TRANSFORMS: {[key: string]: true} = {
const SUPPORTED_TRANSFORMS = {
translateX: true,
translateY: true,
scale: true,
Expand All @@ -132,18 +169,18 @@ const SUPPORTED_TRANSFORMS: {[key: string]: true} = {
skewX: true,
skewY: true,
...(ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform()
? {matrix: true}
? ({matrix: true} as const)
: {}),
};
} as const satisfies KeyAllowlist<TransformKey>;

const SUPPORTED_INTERPOLATION_PARAMS: {[key: string]: true} = {
const SUPPORTED_INTERPOLATION_PARAMS = {
inputRange: true,
outputRange: true,
extrapolate: true,
extrapolateRight: true,
extrapolateLeft: true,
easing: true,
};
} as const satisfies KeyAllowlist<InterpolationParamKey>;

/**
* Default allowlist for component props that support native animated values.
Expand Down
10 changes: 4 additions & 6 deletions packages/react-native/Libraries/StyleSheet/splitLayoutProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

import type {ViewStyle} from './StyleSheetTypes';

type MutableViewStyle = {-readonly [K in keyof ViewStyle]: ViewStyle[K]};

export default function splitLayoutProps(props: ?ViewStyle): {
outer: ?ViewStyle,
inner: ?ViewStyle,
} {
let outer: ?ViewStyle = null;
let inner: ?ViewStyle = null;
let outer: ?MutableViewStyle = null;
let inner: ?MutableViewStyle = null;

if (props != null) {
// $FlowFixMe[incompatible-exact] Will contain a subset of keys from `props`.
outer = {};
// $FlowFixMe[incompatible-exact] Will contain a subset of keys from `props`.
inner = {};

for (const prop of Object.keys(props)) {
Expand Down Expand Up @@ -53,13 +53,11 @@ export default function splitLayoutProps(props: ?ViewStyle): {
case 'rowGap':
case 'columnGap':
case 'gap':
// $FlowFixMe[cannot-write]
// $FlowFixMe[incompatible-use]
// $FlowFixMe[prop-missing]
outer[prop] = props[prop];
break;
default:
// $FlowFixMe[cannot-write]
// $FlowFixMe[incompatible-use]
// $FlowFixMe[prop-missing]
inner[prop] = props[prop];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ type Registry<
Record<string, ReadonlyArray<UnsafeEventObject>>,
>,
> = {
[K in keyof TEventToArgsMap]: Set<Registration<TEventToArgsMap[K]>>,
-readonly [K in keyof TEventToArgsMap]?: Set<
Registration<TEventToArgsMap[K]>,
>,
};

/**
Expand Down Expand Up @@ -147,7 +149,6 @@ export default class EventEmitter<
// $FlowFixMe[incompatible-type]
this.#registry = Object.create(null);
} else {
// $FlowFixMe[cannot-write]
delete this.#registry[eventType];
}
}
Expand Down Expand Up @@ -177,7 +178,6 @@ function allocate<
registry[eventType];
if (registrations == null) {
registrations = new Set();
// $FlowFixMe[cannot-write]
registry[eventType] = registrations;
}
return registrations;
Expand Down
Loading