Skip to content

Commit 5585fb2

Browse files
feat: exclude opacity and transform from style type
EaseViewStyle omits opacity and transform from ViewStyle so TypeScript catches misuse at compile time instead of only warning at runtime.
1 parent 5b067d2 commit 5585fb2

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src/EaseView.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { StyleSheet, type ViewProps } from 'react-native';
1+
import { StyleSheet, type ViewProps, type ViewStyle } from 'react-native';
22
import NativeEaseView from './EaseViewNativeComponent';
33
import type { AnimateProps, Transition } from './types';
44

5+
export type EaseViewStyle = Omit<ViewStyle, 'opacity' | 'transform'>;
6+
57
const IDENTITY: Required<AnimateProps> = {
68
opacity: 1,
79
translateX: 0,
@@ -10,10 +12,11 @@ const IDENTITY: Required<AnimateProps> = {
1012
rotate: 0,
1113
};
1214

13-
export type EaseViewProps = ViewProps & {
15+
export type EaseViewProps = Omit<ViewProps, 'style'> & {
1416
animate?: AnimateProps;
1517
initialAnimate?: AnimateProps;
1618
transition?: Transition;
19+
style?: EaseViewStyle | EaseViewStyle[];
1720
};
1821

1922
export function EaseView({
@@ -26,19 +29,17 @@ export function EaseView({
2629
const resolved = { ...IDENTITY, ...animate };
2730
const resolvedInitial = { ...IDENTITY, ...(initialAnimate ?? animate) };
2831

29-
// Strip animated properties from style
32+
// Strip animated properties from style at runtime as a safety net
3033
let cleanStyle = style;
31-
if (style) {
32-
const flat = StyleSheet.flatten(style);
33-
if (flat) {
34-
const { opacity, transform, ...remaining } = flat;
35-
if (__DEV__ && (opacity !== undefined || transform !== undefined)) {
36-
console.warn(
37-
'react-native-ease: Set opacity/transforms in the animate prop, not style. ' +
38-
'Animated properties in style will be ignored.'
39-
);
40-
}
41-
cleanStyle = remaining;
34+
if (__DEV__ && style) {
35+
const flat = StyleSheet.flatten(style as ViewStyle) as Record<string, unknown>;
36+
if (flat && ('opacity' in flat || 'transform' in flat)) {
37+
console.warn(
38+
'react-native-ease: Set opacity/transforms in the animate prop, not style. ' +
39+
'Animated properties in style will be ignored.'
40+
);
41+
const { opacity: _o, transform: _t, ...remaining } = flat;
42+
cleanStyle = remaining as EaseViewStyle;
4243
}
4344
}
4445

0 commit comments

Comments
 (0)