Skip to content

Commit 6a45079

Browse files
feat: add alternative api
1 parent e311fff commit 6a45079

File tree

2 files changed

+76
-16
lines changed

2 files changed

+76
-16
lines changed

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ Add `spin` style object to an `Animated` component add a linear spinning animati
2020

2121
<img src="https://github.com/user-attachments/assets/d3a87650-83f4-476b-bf85-832a3a2d0fea" alt="Spin animation demo" align="right" width="275" />
2222

23-
```typescript
23+
```jsx
2424
import { spin } from 'react-native-css-animations';
2525
import Animated from 'react-native-reanimated';
2626

2727
function App() {
28-
return (
29-
<Animated.View style={[styles.spinner, spin]}/>
30-
)
28+
return <Animated.View style={[styles.spinner, spin]} />;
3129
}
3230
```
3331

@@ -37,14 +35,12 @@ Add `ping` style object to an `Animated` component to make the element scale and
3735

3836
<img src="https://github.com/user-attachments/assets/51c604b4-621b-4821-ab9a-f289f15e07ae" alt="Ping animation demo" align="right" width="275" />
3937

40-
```typescript
38+
```jsx
4139
import { ping } from 'react-native-css-animations';
4240
import Animated from 'react-native-reanimated';
4341

4442
function App() {
45-
return (
46-
<Animated.View style={[styles.notification, ping]}/>
47-
)
43+
return <Animated.View style={[styles.notification, ping]} />;
4844
}
4945
```
5046

@@ -54,14 +50,12 @@ Add `pulse` style object to an `Animated` component to make it fade in and out.
5450

5551
<img src="https://github.com/user-attachments/assets/d36924b1-f4f8-4bd4-b3dd-a298d3b2f4b6" alt="Pulse animation demo" align="right" width="275"/>
5652

57-
```typescript
53+
```jsx
5854
import { pulse } from 'react-native-css-animations';
5955
import Animated from 'react-native-reanimated';
6056

6157
function App() {
62-
return (
63-
<Animated.View style={[styles.skeleton, pulse]}/>
64-
)
58+
return <Animated.View style={[styles.skeleton, pulse]} />;
6559
}
6660
```
6761

@@ -71,14 +65,28 @@ Add `bounce` style object to an `Animated` component to make it bounce up and do
7165

7266
<img src="https://github.com/user-attachments/assets/81e75ed0-b7ec-4f56-a06a-c593a626cb39" alt="Bounce animation demo" align="right" width="275" />
7367

74-
```typescript
68+
```jsx
7569
import { bounce } from 'react-native-css-animations';
7670
import Animated from 'react-native-reanimated';
7771

72+
function App() {
73+
return <Animated.View style={[styles.arrow, bounce]} />;
74+
}
75+
```
76+
77+
## Alternative API
78+
79+
The following animations are also available in a form of React Native components.
80+
81+
```jsx
82+
import { Spin, Ping, Pulse, Bounce } from 'react-native-css-animations';
83+
7884
function App() {
7985
return (
80-
<Animated.View style={[styles.arrow, bounce]}/>
81-
)
86+
<Bounce>
87+
<ArrowIcon />
88+
</Bounce>
89+
);
8290
}
8391
```
8492

src/index.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
import { cubicBezier } from 'react-native-reanimated';
23+
import Animated, { cubicBezier } from 'react-native-reanimated';
2424
import type { CSSStyleDeclaration } from 'react-native-reanimated/lib/typescript/css/types';
2525

26+
interface CSSAnimationProps {
27+
style?: CSSStyleDeclaration;
28+
}
29+
2630
export const spin: CSSStyleDeclaration = {
2731
animationName: {
2832
to: {
@@ -34,6 +38,18 @@ export const spin: CSSStyleDeclaration = {
3438
animationIterationCount: 'infinite',
3539
};
3640

41+
export function Spin({
42+
style,
43+
children,
44+
...rest
45+
}: React.PropsWithChildren<CSSAnimationProps>): JSX.Element {
46+
return (
47+
<Animated.View style={[spin, style]} {...rest}>
48+
{children}
49+
</Animated.View>
50+
);
51+
}
52+
3753
export const ping: CSSStyleDeclaration = {
3854
animationName: {
3955
'75%, 100%': {
@@ -46,6 +62,18 @@ export const ping: CSSStyleDeclaration = {
4662
animationIterationCount: 'infinite',
4763
};
4864

65+
export function Ping({
66+
style,
67+
children,
68+
...rest
69+
}: React.PropsWithChildren<CSSAnimationProps>): JSX.Element {
70+
return (
71+
<Animated.View style={[ping, style]} {...rest}>
72+
{children}
73+
</Animated.View>
74+
);
75+
}
76+
4977
export const pulse: CSSStyleDeclaration = {
5078
animationName: {
5179
'50%': {
@@ -57,6 +85,18 @@ export const pulse: CSSStyleDeclaration = {
5785
animationIterationCount: 'infinite',
5886
};
5987

88+
export function Pulse({
89+
style,
90+
children,
91+
...rest
92+
}: React.PropsWithChildren<CSSAnimationProps>): JSX.Element {
93+
return (
94+
<Animated.View style={[pulse, style]} {...rest}>
95+
{children}
96+
</Animated.View>
97+
);
98+
}
99+
60100
export const bounce: CSSStyleDeclaration = {
61101
animationName: {
62102
'0%, 100%': {
@@ -71,3 +111,15 @@ export const bounce: CSSStyleDeclaration = {
71111
animationDuration: '1s',
72112
animationIterationCount: 'infinite',
73113
};
114+
115+
export function Bounce({
116+
style,
117+
children,
118+
...rest
119+
}: React.PropsWithChildren<CSSAnimationProps>): JSX.Element {
120+
return (
121+
<Animated.View style={[bounce, style]} {...rest}>
122+
{children}
123+
</Animated.View>
124+
);
125+
}

0 commit comments

Comments
 (0)