React Native transform in styled-components
Asked Answered
D

2

6

Am I able to use transform in styled-components in React Native?

I define the styled component like this:

const StyledAnimatedView = Animated.createAnimatedComponent(styled.View<
    ViewProps
  >`
    transform: translateY(-100);
`);

but it throws me an error when component mounts:

Error: Failed to parse declaration "transform: translateY(-100)"

I know it is possible in web but maybe not in React Native?

Desertion answered 4/12, 2020 at 10:32 Comment(0)
U
1
transform: translateY(-100px);
Underpinning answered 6/8, 2022 at 18:58 Comment(0)
F
0

I found that "px" is necessary in most cases when you are using react native. btw, you can use props.

styled.View<ViewProps>`
    transform: translateY(${props => props.translateY});
`);


<StyledAnimatedView translateY={'-100px'}/>
Fides answered 8/12, 2022 at 8:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.