From db398b4307170ab026c2af7aceae2e97d1ad2363 Mon Sep 17 00:00:00 2001 From: Matan Mashraki <12946462+planecore@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:19:24 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=89=20-=20Edit=20the=20current=20route?= =?UTF-8?q?=20from=20the=20routes=20list=20(#283)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #248 Change origin and destination stations, and swap the direction directly from the route list: image --------- Co-authored-by: Guy Tepper --- .../route-details-header.tsx | 87 ++++++++++++++++--- app/navigators/main-navigator.tsx | 2 +- app/screens/route-list/route-list-screen.tsx | 1 + .../select-station/select-station-screen.tsx | 2 +- 4 files changed, 80 insertions(+), 12 deletions(-) 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")}> +