Skip to content

Commit 74eac59

Browse files
committed
feat: version 1 🚀
1 parent 792844e commit 74eac59

6 files changed

Lines changed: 100 additions & 37 deletions

File tree

example/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import ProfileHeader from "react-native-profile-header";
1111
import IGStoryCircle from "react-native-instagram-story-circle";
1212
import { AppleCard, AppOfTheDayCard } from "react-native-apple-card-views";
13-
import RNBounceable from "@freakycoder/react-native-bounceable";
13+
import RNBounceable from "./lib/RNBounceable";
1414

1515
const coloredNotification = require("./assets/notification-colored.png");
1616
const notification = require("./assets/notification.png");

example/lib/RNBounceable.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import * as React from "react";
2+
import {
3+
Animated,
4+
ViewStyle,
5+
StyleProp,
6+
Pressable,
7+
PressableProps,
8+
} from "react-native";
9+
const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
10+
11+
type CustomStyleProp = StyleProp<ViewStyle> | Array<StyleProp<ViewStyle>>;
12+
export interface IRNBounceableProps extends PressableProps {
13+
onPress?: () => void;
14+
bounceEffectIn?: number;
15+
bounceEffectOut?: number;
16+
bounceVelocityIn?: number;
17+
bounceVelocityOut?: number;
18+
bouncinessIn?: number;
19+
bouncinessOut?: number;
20+
useNativeDriver?: boolean;
21+
children?: React.ReactNode;
22+
style?: CustomStyleProp;
23+
}
24+
25+
interface IState {
26+
bounceValue: any;
27+
}
28+
29+
export default class RNBounceable extends React.Component<
30+
IRNBounceableProps,
31+
IState
32+
> {
33+
constructor(props: IRNBounceableProps) {
34+
super(props);
35+
this.state = {
36+
bounceValue: new Animated.Value(1),
37+
};
38+
}
39+
40+
bounceAnimation = (value: number, velocity: number, bounciness: number) => {
41+
const { useNativeDriver = true } = this.props;
42+
Animated.spring(this.state.bounceValue, {
43+
toValue: value,
44+
velocity,
45+
bounciness,
46+
useNativeDriver,
47+
}).start();
48+
};
49+
50+
render() {
51+
const {
52+
bounceEffectIn = 0.93,
53+
bounceEffectOut = 1,
54+
bounceVelocityIn = 0.1,
55+
bounceVelocityOut = 0.4,
56+
bouncinessIn = 0,
57+
bouncinessOut = 0,
58+
children,
59+
style,
60+
onPress,
61+
} = this.props;
62+
return (
63+
<AnimatedPressable
64+
{...this.props}
65+
style={[{ transform: [{ scale: this.state.bounceValue }] }, style]}
66+
onPressIn={() => {
67+
this.bounceAnimation(bounceEffectIn, bounceVelocityIn, bouncinessIn);
68+
}}
69+
onPressOut={() => {
70+
this.bounceAnimation(
71+
bounceEffectOut,
72+
bounceVelocityOut,
73+
bouncinessOut,
74+
);
75+
}}
76+
onPress={onPress}
77+
>
78+
{children}
79+
</AnimatedPressable>
80+
);
81+
}
82+
}

example/package-lock.json

Lines changed: 7 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/yarn.lock

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,10 @@
781781
"minimatch" "^3.0.4"
782782
"strip-json-comments" "^3.1.1"
783783

784-
"@freakycoder/react-native-bounceable@>= 0.1.1":
785-
"integrity" "sha512-J8WBOYxbm/um7SqXYneduZ08T5Kin9z+ixsS3wOLtpeNvKscuqmDEgsgefTYydeSIoI5dOfWmklnRRgu5i/8nA=="
786-
"resolved" "https://registry.npmjs.org/@freakycoder/react-native-bounceable/-/react-native-bounceable-0.2.5.tgz"
787-
"version" "0.2.5"
784+
"@freakycoder/react-native-bounceable@^1.0.1", "@freakycoder/react-native-bounceable@>= 0.1.1":
785+
"integrity" "sha512-1fAC9Sbi40mp1YOl5eBSMzetPJVwlpZxSE1AAVtHnEujfKxuulTM8uG3NmJ3BHc3KVk2fwF6TrS32d56DdXZZQ=="
786+
"resolved" "https://registry.npmjs.org/@freakycoder/react-native-bounceable/-/react-native-bounceable-1.0.1.tgz"
787+
"version" "1.0.1"
788788

789789
"@hapi/hoek@^9.0.0":
790790
"integrity" "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ=="
@@ -5756,11 +5756,6 @@
57565756
"resolved" "https://registry.npmjs.org/react-native-apple-header/-/react-native-apple-header-0.1.1.tgz"
57575757
"version" "0.1.1"
57585758

5759-
"react-native-bounceable@^0.2.1":
5760-
"integrity" "sha512-3voGBf7e7z3i06PXSD8ahpzpuKVYURkFOvcxX3ZTBMsJN1hPjnj7B8J6P9PZlSojFMFvqUeGwE7/S2bOzCb1pg=="
5761-
"resolved" "https://registry.npmjs.org/react-native-bounceable/-/react-native-bounceable-0.2.1.tgz"
5762-
"version" "0.2.1"
5763-
57645759
"react-native-codegen@^0.69.1":
57655760
"integrity" "sha512-TOZEqBarczcyYN3iZE3VpKkooOevaAzBq9n7lU0h9mQUvtRhLVyolc+a5K6cWI0e4v4K69I0MqzjPcPeFKo32Q=="
57665761
"resolved" "https://registry.npmjs.org/react-native-codegen/-/react-native-codegen-0.69.1.tgz"

lib/RNBounceable.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Pressable,
77
PressableProps,
88
} from "react-native";
9+
const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
910

1011
type CustomStyleProp = StyleProp<ViewStyle> | Array<StyleProp<ViewStyle>>;
1112
export interface IRNBounceableProps extends PressableProps {
@@ -59,8 +60,9 @@ export default class RNBounceable extends React.Component<
5960
onPress,
6061
} = this.props;
6162
return (
62-
<Pressable
63+
<AnimatedPressable
6364
{...this.props}
65+
style={[{ transform: [{ scale: this.state.bounceValue }] }, style]}
6466
onPressIn={() => {
6567
this.bounceAnimation(bounceEffectIn, bounceVelocityIn, bouncinessIn);
6668
}}
@@ -73,12 +75,8 @@ export default class RNBounceable extends React.Component<
7375
}}
7476
onPress={onPress}
7577
>
76-
<Animated.View
77-
style={[{ transform: [{ scale: this.state.bounceValue }] }, style]}
78-
>
79-
{children}
80-
</Animated.View>
81-
</Pressable>
78+
{children}
79+
</AnimatedPressable>
8280
);
8381
}
8482
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@freakycoder/react-native-bounceable",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Animate and bounce any component with RNBounceable for React Native",
55
"main": "./build/dist/RNBounceable.js",
66
"repository": "git@github.com:WrathChaos/react-native-bounceable.git",

0 commit comments

Comments
 (0)