diff --git a/app/components/route-details-header/route-details-header.tsx b/app/components/route-details-header/route-details-header.tsx index 4594394e..7eb1632e 100644 --- a/app/components/route-details-header/route-details-header.tsx +++ b/app/components/route-details-header/route-details-header.tsx @@ -1,6 +1,7 @@ /* eslint-disable react/display-name */ -import React, { useMemo, useLayoutEffect } from "react" -import { Image, ImageBackground, View, ViewStyle, TextStyle, ImageStyle, Alert, Linking } from "react-native" +import React, { useMemo, useLayoutEffect, useRef, useEffect } from "react" +import { Image, ImageBackground, View, ViewStyle, TextStyle, ImageStyle, Alert, Linking, Animated } from "react-native" +import TouchableScale from "react-native-touchable-scale" import analytics from "@react-native-firebase/analytics" import { useNavigation } from "@react-navigation/native" import { observer } from "mobx-react-lite" @@ -15,6 +16,9 @@ import * as Burnt from "burnt" import * as AddCalendarEvent from "react-native-add-calendar-event" import { CalendarIcon } from "../calendar-icon/calendar-icon" import { RouteItem } from "../../services/api" +import { TouchableOpacity } from "react-native-gesture-handler" + +const AnimatedTouchable = Animated.createAnimatedComponent(TouchableScale) const arrowIcon = require("../../../assets/arrow-left.png") @@ -91,16 +95,19 @@ export interface RouteDetailsHeaderProps { /** * The screen name we're displaying the header inside */ - screenName?: "routeDetails" | "activeRide" + screenName?: "routeList" | "routeDetails" | "activeRide" style?: ViewStyle eventConfig?: AddCalendarEvent.CreateOptions } export const RouteDetailsHeader = observer(function RouteDetailsHeader(props: RouteDetailsHeaderProps) { const { routeItem, originId, destinationId, screenName, style } = props - const { favoriteRoutes } = useStores() + const { favoriteRoutes, routePlan } = useStores() const navigation = useNavigation() + const routeEditDisabled = props.screenName !== "routeList" + const stationCardScale = useRef(new Animated.Value(1)).current + const addToCalendar = () => { analytics().logEvent("add_route_to_calendar") const eventConfig = createEventConfig(routeItem) @@ -125,6 +132,48 @@ export const RouteDetailsHeader = observer(function RouteDetailsHeader(props: Ro const routeId = `${originId}${destinationId}` + const swapDirection = () => { + scaleStationCards() + HapticFeedback.trigger("impactMedium") + + // Delay the actual switch so it'll be synced with the animation + setTimeout(() => { + routePlan.switchDirection() + }, 50) + } + + const changeOriginStation = () => { + navigation.navigate("selectStation", { selectionType: "origin" }) + } + + const changeDestinationStation = () => { + navigation.navigate("selectStation", { selectionType: "destination" }) + } + + useEffect(() => { + if (routePlan.origin.id !== routePlan.destination.id) { + navigation.setParams({ + originId: routePlan.origin.id, + destinationId: routePlan.destination.id, + } as any) + } + }, [routePlan.origin.id, routePlan.destination.id]) + + const scaleStationCards = () => { + Animated.sequence([ + Animated.timing(stationCardScale, { + toValue: 0.94, + duration: 175, + useNativeDriver: true, + }), + Animated.timing(stationCardScale, { + toValue: 1, + duration: 175, + useNativeDriver: true, + }), + ]).start() + } + const isFavorite: boolean = useMemo( () => !!favoriteRoutes.routes.find((favorite) => favorite.id === routeId), [favoriteRoutes.routes.length], @@ -171,19 +220,37 @@ export const RouteDetailsHeader = observer(function RouteDetailsHeader(props: Ro - + {originName} - - + + - - + + {destinationName} - + diff --git a/app/navigators/main-navigator.tsx b/app/navigators/main-navigator.tsx index 01c58f4e..95215cd6 100644 --- a/app/navigators/main-navigator.tsx +++ b/app/navigators/main-navigator.tsx @@ -60,7 +60,7 @@ export function MainNavigator() { 20 ? insets.top : Platform.select({ ios: 27.5, android: 5 }) }]} > - navigation.navigate("planner")}> +