Skip to content

Commit 3b313ff

Browse files
committed
24-zoom-react-native
1 parent 8c17f51 commit 3b313ff

File tree

11 files changed

+16920
-0
lines changed

11 files changed

+16920
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
3+
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
4+
}

24-zoom-react-native/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/
2+
.expo/
3+
dist/
4+
npm-debug.*
5+
*.jks
6+
*.p8
7+
*.p12
8+
*.key
9+
*.mobileprovision
10+
*.orig.*
11+
web-build/
12+
13+
# macOS
14+
.DS_Store

24-zoom-react-native/App.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { StyleSheet, SafeAreaView, Dimensions } from "react-native";
2+
import {
3+
Gesture,
4+
GestureDetector,
5+
GestureHandlerRootView,
6+
} from "react-native-gesture-handler";
7+
import Animated, {
8+
useSharedValue,
9+
useAnimatedStyle,
10+
withTiming,
11+
} from "react-native-reanimated";
12+
13+
export default function App() {
14+
const width = Dimensions.get("window").width;
15+
const ANCHO_IMAGEN = width;
16+
const ALTO_IMAGEN = width;
17+
18+
const escalaImg = useSharedValue(1);
19+
const focoX = useSharedValue(0);
20+
const focoY = useSharedValue(0);
21+
22+
const pinchazoPantalla = Gesture.Pinch()
23+
.onStart((e) => {
24+
focoX.value = e.focalX;
25+
focoY.value = e.focalY;
26+
})
27+
.onUpdate((e) => {
28+
escalaImg.value = e.scale;
29+
})
30+
.onEnd(() => {
31+
escalaImg.value = withTiming(1, { duration: 500 });
32+
});
33+
34+
const centroImagen = {
35+
x: ANCHO_IMAGEN / 2,
36+
y: ALTO_IMAGEN / 2,
37+
};
38+
39+
const styles = StyleSheet.create({
40+
container: {
41+
flex: 1,
42+
backgroundColor: "#fff",
43+
alignItems: "center",
44+
justifyContent: "center",
45+
},
46+
img: {
47+
width: ANCHO_IMAGEN,
48+
height: ALTO_IMAGEN,
49+
},
50+
});
51+
52+
const estiloAnimado = useAnimatedStyle(() => ({
53+
transform: [
54+
{ translateX: focoX.value },
55+
{ translateY: focoY.value },
56+
{ translateX: -centroImagen.x },
57+
{ translateY: -centroImagen.y },
58+
{ scale: escalaImg.value },
59+
{ translateX: -focoX.value },
60+
{ translateY: -focoY.value },
61+
{ translateX: centroImagen.x },
62+
{ translateY: centroImagen.y },
63+
],
64+
}));
65+
66+
return (
67+
<SafeAreaView style={styles.container}>
68+
<GestureHandlerRootView>
69+
<GestureDetector gesture={pinchazoPantalla}>
70+
<Animated.Image
71+
style={[styles.img, estiloAnimado]}
72+
source={{
73+
uri: "https://images.unsplash.com/photo-1642880384912-2cd8371979b1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1064&q=80",
74+
}}
75+
/>
76+
</GestureDetector>
77+
</GestureHandlerRootView>
78+
</SafeAreaView>
79+
);
80+
}

24-zoom-react-native/app.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"expo": {
3+
"name": "zoom-react-native",
4+
"slug": "zoom-react-native",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"splash": {
9+
"image": "./assets/splash.png",
10+
"resizeMode": "contain",
11+
"backgroundColor": "#ffffff"
12+
},
13+
"updates": {
14+
"fallbackToCacheTimeout": 0
15+
},
16+
"assetBundlePatterns": [
17+
"**/*"
18+
],
19+
"ios": {
20+
"supportsTablet": true
21+
},
22+
"android": {
23+
"adaptiveIcon": {
24+
"foregroundImage": "./assets/adaptive-icon.png",
25+
"backgroundColor": "#FFFFFF"
26+
}
27+
},
28+
"web": {
29+
"favicon": "./assets/favicon.png"
30+
}
31+
}
32+
}
17.1 KB
Loading
1.43 KB
Loading

24-zoom-react-native/assets/icon.png

21.9 KB
Loading
46.2 KB
Loading

24-zoom-react-native/babel.config.js

Lines 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)