Skip to content

Commit 69f0ab0

Browse files
committed
add nice react-navigation animations
1 parent 2a59463 commit 69f0ab0

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

hackathon/spacecraft/src/components/Image.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import React from "react";
2-
import type { ImageProps } from "expo-image";
2+
// import type { ImageProps } from "expo-image";
3+
import { Image as RNImage, ImageProps } from "react-native";
34
import { Image as ExpoImage } from "expo-image";
5+
import type { AnimateProps } from "react-native-reanimated";
6+
import Animated from "react-native-reanimated";
47

5-
export const Image = (props: ImageProps) => {
8+
const AnimatedImage = Animated.createAnimatedComponent(RNImage);
9+
10+
export const Image = (props: AnimateProps<ImageProps>) => {
611
// We should have a unique value for each image
7-
const blurhash = "L56t?txt00D*t7M{Rjxu00Rk~p-:";
12+
// const blurhash = "L56t?txt00D*t7M{Rjxu00Rk~p-:";
813

914
return (
10-
<ExpoImage
11-
placeholder={blurhash}
12-
contentFit="cover"
13-
transition={350}
15+
<AnimatedImage
16+
// placeholder={blurhash}
17+
// contentFit="cover"
18+
// transition={0}
1419
{...props}
1520
/>
1621
);

hackathon/spacecraft/src/components/StarshipCard.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export const StarshipCard = ({ ship, index }: StarshipCardProps) => {
5656

5757
const navigation = useNavigation<StarshipDetailsScreenParams>();
5858
const handleGoToDetails = () => {
59-
navigation.navigate(Routes.STARSHIP_DETAILS_SCREEN, ship);
59+
navigation.navigate(Routes.STARSHIP_DETAILS_SCREEN, {
60+
...ship,
61+
image: source,
62+
});
6063
};
6164

6265
// visibleIndex -> prop
@@ -76,6 +79,7 @@ export const StarshipCard = ({ ship, index }: StarshipCardProps) => {
7679
<Image
7780
style={{ width: "100%", height: 200, borderRadius: 12 }}
7881
source={source}
82+
sharedTransitionTag={`image-${ship.model}`}
7983
/>
8084
{/* we remplace with an Image to have the benefits of `expo-image` */}
8185
{/* <Card.Cover source={source} /> */}

hackathon/spacecraft/src/navigation/StarshipNavigator.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export const StarshipNavigator = () => {
2424
<Stack.Navigator
2525
screenOptions={{
2626
headerShown: false,
27-
presentation: "modal",
2827
}}
2928
>
3029
<Stack.Screen
@@ -34,6 +33,13 @@ export const StarshipNavigator = () => {
3433
<Stack.Screen
3534
name={Routes.STARSHIP_DETAILS_SCREEN}
3635
component={StarshipDetailsScreen}
36+
options={{
37+
presentation: "transparentModal",
38+
animation: "fade",
39+
contentStyle: {
40+
backgroundColor: "#fff",
41+
},
42+
}}
3743
/>
3844
</Stack.Navigator>
3945
);

hackathon/spacecraft/src/screens/StarshipDetailsScreen.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { Text, DataTable, List, FAB, Chip } from "react-native-paper";
1212

1313
import type { StarshipProps } from "../../api/types";
14-
import { useImage } from "../hooks/useImage";
1514

1615
import { Image } from "~/components/Image";
1716

@@ -34,9 +33,12 @@ export const StarshipDetailsScreen = ({
3433
cargo_capacity,
3534
hyperdrive_rating,
3635
max_atmosphering_speed,
36+
model,
37+
// @ts-ignore
38+
image,
3739
} = route.params;
3840

39-
const source = useImage(name);
41+
// const source = useImage(name);
4042
const navigation = useNavigation();
4143

4244
const handleClose = () => {
@@ -52,7 +54,11 @@ export const StarshipDetailsScreen = ({
5254
<ScrollView>
5355
<View style={styles.scrollContainer}>
5456
<View style={styles.imageContainer}>
55-
<Image style={{ width: "100%", height: 350 }} source={source} />
57+
<Image
58+
style={{ width: "100%", height: 350 }}
59+
source={image}
60+
sharedTransitionTag={`image-${model}`}
61+
/>
5662
<View style={[styles.closeContainer, styles.left]}>
5763
<TouchableOpacity
5864
onPress={handleClose}

0 commit comments

Comments
 (0)