Skip to content

Commit c041b56

Browse files
committed
fix animation
1 parent 9eb2033 commit c041b56

File tree

12 files changed

+59
-35
lines changed

12 files changed

+59
-35
lines changed

hackathon/spacecraft/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@react-navigation/native": "^6.1.1",
3434
"@react-navigation/native-stack": "^6.9.7",
3535
"@tanstack/react-query": "^5.17.19",
36+
"@types/react-currency-format": "^1.0.4",
3637
"babel-core": "^7.0.0-bridge.0",
3738
"babel-jest": "^29.5.0",
3839
"deepmerge": "^4.3.1",
@@ -46,6 +47,7 @@
4647
"expo-updates": "~0.24.12",
4748
"expo-web-browser": "~12.8.2",
4849
"react": "18.2.0",
50+
"react-currency-format": "^1.1.0",
4951
"react-dom": "^18.2.0",
5052
"react-native": "0.73.6",
5153
"react-native-gesture-handler": "~2.14.1",

hackathon/spacecraft/src/components/Image.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from "react";
22
// import type { ImageProps } from "expo-image";
3-
import { Image as RNImage, ImageProps } from "react-native";
3+
import type { ImageProps } from "react-native";
4+
import { Image as RNImage } from "react-native";
45
import { Image as ExpoImage } from "expo-image";
5-
import type { AnimateProps } from "react-native-reanimated";
6+
import type { AnimatedProps } from "react-native-reanimated";
67
import Animated from "react-native-reanimated";
78

89
const AnimatedImage = Animated.createAnimatedComponent(RNImage);
910

10-
export const Image = (props: AnimateProps<ImageProps>) => {
11+
export const Image = (props: AnimatedProps<ImageProps>) => {
1112
// We should have a unique value for each image
1213
// const blurhash = "L56t?txt00D*t7M{Rjxu00Rk~p-:";
1314

hackathon/spacecraft/src/components/StarshipCard.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1+
import CurrencyFormat from "react-currency-format";
12
import { useNavigation } from "@react-navigation/native";
23
import * as React from "react";
34
import { Alert, StyleSheet } from "react-native";
45
import { Button, Card, Text } from "react-native-paper";
5-
import Animated, {
6-
AnimateProps,
7-
FadeIn,
8-
FadeOut,
9-
FadeInDown,
10-
} from "react-native-reanimated";
6+
import { FadeOut, FadeInDown } from "react-native-reanimated";
117

128
import type { StarshipProps } from "../../api/types";
139
import { useImage } from "../hooks/useImage";
@@ -64,15 +60,24 @@ export const StarshipCard = ({ ship, index }: StarshipCardProps) => {
6460
<Image
6561
style={{ width: "100%", height: 200, borderRadius: 12 }}
6662
source={source}
67-
sharedTransitionTag={`image-${ship.model}`}
63+
// sharedTransitionTag={`image-${ship.model}`}
6864
/>
6965
{/* we remplace with an Image to have the benefits of `expo-image` */}
7066
{/* <Card.Cover source={source} /> */}
7167
<Card.Title title={title} subtitle={manufacturer} />
7268

73-
<Card.Content>
74-
<Text variant="titleLarge">{price} credits</Text>
75-
</Card.Content>
69+
{price !== "unknown" && (
70+
<Card.Content>
71+
<CurrencyFormat
72+
value={price}
73+
displayType="text"
74+
thousandSeparator={true}
75+
renderText={(value: string) => (
76+
<Text variant="titleLarge">{value} credits</Text>
77+
)}
78+
/>
79+
</Card.Content>
80+
)}
7681
<Card.Actions>
7782
{price === "unknown" ? (
7883
<Button disabled>Not for sale</Button>

hackathon/spacecraft/src/navigation/BottomTabNavigator.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FontAwesome5, Ionicons } from "@expo/vector-icons";
55
import { useTheme } from "react-native-paper";
66
import { getFocusedRouteNameFromRoute } from "@react-navigation/native";
77

8-
import { ExploreNavigator } from "~/navigation/ExploreNavigator";
8+
import { PlanetNavigator } from "~/navigation/PlanetNavigator";
99
import { Routes } from "~/navigation/Routes";
1010
import { PilotNavigator } from "~/navigation/PilotNavigator";
1111
import { StarshipNavigator } from "~/navigation/StarshipNavigator";
@@ -46,8 +46,8 @@ export const BottomTabNavigator = () => {
4646
}}
4747
/>
4848
<Tab.Screen
49-
name={Routes.EXPLORE_SCREEN}
50-
component={ExploreNavigator}
49+
name={Routes.PLANETS}
50+
component={PlanetNavigator}
5151
options={{
5252
tabBarLabel: "Explore",
5353
tabBarIcon: ({ color }) => (

hackathon/spacecraft/src/navigation/ExploreNavigator.tsx renamed to hackathon/spacecraft/src/navigation/PlanetNavigator.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { createNativeStackNavigator } from "@react-navigation/native-stack";
22

33
import { Routes } from "./Routes";
44

5-
import { ExploreScreen } from "~/screens/ExploreScreen";
5+
import { PlanetsScreen } from "~/screens/PlanetsScreen";
66
import { PlanetDetailsScreen } from "~/screens/PlanetDetailsScreen";
77

88
const Stack = createNativeStackNavigator();
99

10-
export const ExploreNavigator = () => {
10+
export const PlanetNavigator = () => {
1111
return (
1212
<Stack.Navigator
1313
screenOptions={{
1414
headerShown: false,
1515
}}
1616
>
17-
<Stack.Screen name={Routes.EXPLORE_SCREEN} component={ExploreScreen} />
17+
<Stack.Screen name={Routes.PLANETS} component={PlanetsScreen} />
1818
<Stack.Screen
1919
name={Routes.PLANET_DETAILS_SCREEN}
2020
component={PlanetDetailsScreen}

hackathon/spacecraft/src/navigation/Routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const Routes = {
77
PILOT_SCREEN: "Pilots",
88
PILOT_STACK: "Pilots Stack",
99
PILOT_DETAILS_SCREEN: "Pilot",
10-
EXPLORE_SCREEN: "Explore",
10+
PLANETS: "Planets",
1111
PLANET_DETAILS_SCREEN: "Planet",
1212
PLUS_STACK: "Plus Stack",
1313
PLUS_SCREEN: "Plus",

hackathon/spacecraft/src/navigation/StarshipNavigator.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export const StarshipNavigator = () => {
3434
name={Routes.STARSHIP_DETAILS_SCREEN}
3535
component={StarshipDetailsScreen}
3636
options={{
37-
presentation: "transparentModal",
38-
animation: "fade",
37+
presentation: "modal",
3938
contentStyle: {
4039
backgroundColor: "#fff",
4140
},

hackathon/spacecraft/src/screens/ExploreScreen.tsx renamed to hackathon/spacecraft/src/screens/PlanetsScreen.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { usePlanets } from "~/hooks/usePlanets";
66
import { Routes } from "~/navigation/Routes";
77
import { getTerrainColor } from "~/utils/getTerrainColor";
88

9-
interface ExploreScreenProps {}
9+
interface PlanetsScreenProps {
10+
navigation: any;
11+
}
1012

11-
export function ExploreScreen({ navigation }: ExploreScreenProps) {
13+
export function PlanetsScreen({ navigation }: PlanetsScreenProps) {
1214
const { data, isLoading, isError, error } = usePlanets();
1315

1416
if (isLoading) {
@@ -35,8 +37,10 @@ export function ExploreScreen({ navigation }: ExploreScreenProps) {
3537
const backgroundColor = getTerrainColor(item.terrain);
3638
const size = item.diameter / 100;
3739

40+
const randomMarginTop = Math.floor(Math.random() * 100);
41+
3842
return (
39-
<View style={{ padding: 64 }}>
43+
<View style={{ padding: 64, paddingTop: randomMarginTop }}>
4044
<TouchableOpacity
4145
onPress={() =>
4246
navigation.navigate(Routes.PLANET_DETAILS_SCREEN, { planet: item })
@@ -51,7 +55,7 @@ export function ExploreScreen({ navigation }: ExploreScreenProps) {
5155
width: size,
5256
height: size,
5357
backgroundColor: backgroundColor,
54-
borderRadius: "100%",
58+
borderRadius: 1000,
5559
margin: 8,
5660
}}
5761
/>
@@ -64,7 +68,7 @@ export function ExploreScreen({ navigation }: ExploreScreenProps) {
6468
<FlatList
6569
data={data.results}
6670
renderItem={renderItem}
67-
keyExtractor={(ship) => ship.model}
71+
keyExtractor={(planet) => planet.name}
6872
horizontal={true}
6973
/>
7074
</ScreenContainer>

hackathon/spacecraft/src/screens/StarshipDetailsScreen.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ import {
77
StyleSheet,
88
TouchableOpacity,
99
ScrollView,
10-
Alert,
1110
} from "react-native";
1211
import { Text, DataTable, List, FAB, Chip } from "react-native-paper";
13-
import { withAnimated } from "~/utils/withAnimated";
14-
15-
const AnimatedFAB = withAnimated(FAB);
1612
import { useSharedValue, withSpring } from "react-native-reanimated";
1713

1814
import type { StarshipProps } from "../../api/types";
1915

16+
import { withAnimated } from "~/utils/withAnimated";
2017
import { Image } from "~/components/Image";
2118

19+
const AnimatedFAB = withAnimated(FAB);
20+
2221
interface StarshipDetailsScreenProps {
2322
route: {
2423
params: StarshipProps;

hackathon/spacecraft/src/utils/getTerrainColor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const terrainColorMap = {
1818
};
1919

2020
export function getTerrainColor(terrain: string) {
21-
console.log("🚀 ~ terrain:", terrain);
2221
for (const [key, color] of Object.entries(terrainColorMap)) {
2322
if (terrain.includes(key)) {
2423
return color;

0 commit comments

Comments
 (0)