Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0e0bb94

Browse filesBrowse files
committed
Chapter 26
1 parent 671962e commit 0e0bb94
Copy full SHA for 0e0bb94
Expand file treeCollapse file tree

25 files changed

+27459
-0
lines changed

‎Chapter26/animate-styling/.gitignore

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
2+
3+
# dependencies
4+
node_modules/
5+
6+
# Expo
7+
.expo/
8+
dist/
9+
web-build/
10+
11+
# Native
12+
*.orig.*
13+
*.jks
14+
*.p8
15+
*.p12
16+
*.key
17+
*.mobileprovision
18+
19+
# Metro
20+
.metro-health-check*
21+
22+
# debug
23+
npm-debug.*
24+
yarn-debug.*
25+
yarn-error.*
26+
27+
# macOS
28+
.DS_Store
29+
*.pem
30+
31+
# local env files
32+
.env*.local
33+
34+
# typescript
35+
*.tsbuildinfo

‎Chapter26/animate-styling/App.tsx

Copy file name to clipboard
+66Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from "react";
2+
import { Text, View, Pressable } from "react-native";
3+
import Animated, {
4+
interpolateColor,
5+
useAnimatedStyle,
6+
useSharedValue,
7+
withSpring,
8+
} from "react-native-reanimated";
9+
import styles from "./styles";
10+
11+
const App = () => {
12+
const radius = useSharedValue(30);
13+
const opacity = useSharedValue(1);
14+
const scale = useSharedValue(1);
15+
const color = useSharedValue(0);
16+
17+
const animatedStyles = useAnimatedStyle(() => {
18+
const backgroundColor = interpolateColor(
19+
color.value,
20+
[0, 1],
21+
["orange", "red"]
22+
);
23+
24+
return {
25+
opacity: opacity.value,
26+
borderRadius: radius.value,
27+
transform: [{ scale: scale.value }],
28+
backgroundColor: backgroundColor,
29+
};
30+
}, []);
31+
32+
const onPressIn = () => {
33+
radius.value = withSpring(20);
34+
opacity.value = withSpring(0.7);
35+
scale.value = withSpring(0.9);
36+
};
37+
38+
const onLongPress = () => {
39+
scale.value = withSpring(0.8);
40+
color.value = withSpring(1);
41+
};
42+
43+
const onPressOut = () => {
44+
radius.value = withSpring(30);
45+
opacity.value = withSpring(1);
46+
scale.value = withSpring(1, { damping: 50 });
47+
color.value = withSpring(0);
48+
};
49+
50+
return (
51+
<View style={styles.container}>
52+
<Animated.View style={[styles.buttonContainer, animatedStyles]}>
53+
<Pressable
54+
onPressIn={onPressIn}
55+
onPressOut={onPressOut}
56+
onLongPress={onLongPress}
57+
style={styles.button}
58+
>
59+
<Text style={styles.buttonText}>Press me</Text>
60+
</Pressable>
61+
</Animated.View>
62+
</View>
63+
);
64+
};
65+
66+
export default App;

‎Chapter26/animate-styling/app.json

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"expo": {
3+
"name": "animate-styling",
4+
"slug": "animate-styling",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"userInterfaceStyle": "light",
9+
"splash": {
10+
"image": "./assets/splash.png",
11+
"resizeMode": "contain",
12+
"backgroundColor": "#ffffff"
13+
},
14+
"assetBundlePatterns": [
15+
"**/*"
16+
],
17+
"ios": {
18+
"supportsTablet": true
19+
},
20+
"android": {
21+
"adaptiveIcon": {
22+
"foregroundImage": "./assets/adaptive-icon.png",
23+
"backgroundColor": "#ffffff"
24+
}
25+
},
26+
"web": {
27+
"favicon": "./assets/favicon.png"
28+
}
29+
}
30+
}
Loading
1.43 KB
Loading
21.9 KB
Loading
46.2 KB
Loading
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function (api) {
2+
api.cache(true);
3+
return {
4+
presets: ["babel-preset-expo"],
5+
plugins: ["react-native-reanimated/plugin"],
6+
};
7+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.