All files / src/components/navigation-direction NavigationDirectionHUDBottom.tsx

100% Statements 22/22
96% Branches 24/25
100% Functions 6/6
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206                1x 1x     3x                                     1x                                                                               6x 6x   6x   5x 5x 5x   5x   5x     5x       5x 5x   5x                                                         1x                                         3x                           1x                                                                                                  
import React, { useState } from "react";
import { View, Text, StyleSheet, ScrollView, Pressable } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import BottomDrawer from "../BottomDrawer";
import { Step } from "../../api/outdoorDirectionsApi";
import { getManeuverIcon } from "./navigationDirectionUtils";
import useNavigationProgress from "../../hooks/useNavigationProgress";
 
const BURGUNDY = "#800020";
const BURGUNDY_DARK = "#5a0016";
 
function StepRow({ step }: { readonly step: Step }) {
  return (
    <View style={stepStyles.row}>
      <View style={stepStyles.iconWrap}>
        <Ionicons
          name={getManeuverIcon(step.maneuverType)}
          size={18}
          color="#fff"
        />
      </View>
      <View style={stepStyles.text}>
        <Text style={stepStyles.instruction} numberOfLines={2}>
          {step.instruction}
        </Text>
        <Text style={stepStyles.meta}>{step.distance}</Text>
      </View>
    </View>
  );
}
 
const stepStyles = StyleSheet.create({
  row: {
    flexDirection: "row",
    alignItems: "center",
    paddingVertical: 10,
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderBottomColor: "rgba(255,255,255,0.2)",
    gap: 12,
  },
  iconWrap: {
    width: 32,
    height: 32,
    borderRadius: 16,
    backgroundColor: BURGUNDY_DARK,
    alignItems: "center",
    justifyContent: "center",
  },
  text: { flex: 1 },
  instruction: {
    color: "#fff",
    fontSize: 14,
    fontWeight: "500",
    lineHeight: 19,
  },
  meta: { color: "rgba(255,255,255,0.6)", fontSize: 12, marginTop: 2 },
});
 
export interface NavigationDirectionHudProps {
  readonly visible: boolean;
  readonly steps: Step[];
  readonly onClose?: () => void;
  readonly onSnapIndexChange?: (index: number) => void;
}
 
export default function NavigationDirectionHUDBottom({
  visible,
  steps,
  onClose,
  onSnapIndexChange,
}: NavigationDirectionHudProps) {
  const [expanded, setExpanded] = useState(true);
  const dynamicDistance = useNavigationProgress((s) => s.distanceToNextStep);
 
  if (!steps || steps.length === 0) return null;
 
  const currentStep = steps[0];
  const upcomingManeuver = steps.length > 1 ? steps[1] : null;
  const laterSteps = steps.slice(2);
 
  const distanceToDisplay = dynamicDistance || currentStep.distance;
 
  const primaryIcon = upcomingManeuver
    ? getManeuverIcon(upcomingManeuver.maneuverType)
    : "flag";
  const primaryInstruction = upcomingManeuver
    ? upcomingManeuver.instruction
    : currentStep.instruction;
 
  const laterStepsSuffix = laterSteps.length > 1 ? "s" : "";
  const laterStepsLabel = `${laterSteps.length} more step${laterStepsSuffix}`;
 
  return (
    <BottomDrawer
      visible={visible}
      snapPoints={["17%", "37%"]}
      initialSnapIndex={1}
      enablePanDownToClose={false}
      enableDynamicSizing={false}
      backgroundColor={BURGUNDY}
      handleMode={"toggle"}
      handleColor="rgba(255,255,255,0.4)"
      contentContainerStyle={styles.drawerContent}
      onClose={onClose}
      onSnapIndexChange={onSnapIndexChange}
    >
      {/* Upcoming maneuver card — shows the NEXT action, like Google Maps */}
      <View style={styles.primaryCard}>
        <View style={styles.primaryIconWrap}>
          <Ionicons name={primaryIcon} size={36} color="#fff" />
        </View>
        <View style={styles.primaryText}>
          <Text style={styles.primaryInstruction} numberOfLines={2}>
            {primaryInstruction}
          </Text>
          <Text style={styles.primaryDistance}>{distanceToDisplay}</Text>
        </View>
      </View>
 
      {laterSteps.length > 0 && (
        <Pressable
          onPress={() => setExpanded((v) => !v)}
          style={styles.expandToggle}
        >
          <Text style={styles.expandLabel}>
            {expanded ? "Hide steps" : laterStepsLabel}
          </Text>
          <Ionicons
            name={expanded ? "chevron-up" : "chevron-down"}
            size={16}
            color="rgba(255,255,255,0.7)"
          />
        </Pressable>
      )}
 
      {expanded && laterSteps.length > 0 && (
        <ScrollView
          style={styles.stepList}
          showsVerticalScrollIndicator={false}
          nestedScrollEnabled
        >
          {laterSteps.map((step) => (
            <StepRow
              key={
                step.polyline ||
                `${step.maneuverType}-${step.instruction}-${step.distance}-${step.duration}`
              }
              step={step}
            />
          ))}
        </ScrollView>
      )}
    </BottomDrawer>
  );
}
 
const styles = StyleSheet.create({
  drawerContent: {
    paddingHorizontal: 4,
    paddingTop: 0,
    alignItems: "stretch",
  },
  primaryCard: {
    flexDirection: "row",
    alignItems: "center",
    gap: 16,
    marginBottom: 12,
  },
  primaryIconWrap: {
    width: 64,
    height: 64,
    borderRadius: 16,
    backgroundColor: BURGUNDY_DARK,
    alignItems: "center",
    justifyContent: "center",
  },
  primaryText: { flex: 1 },
  primaryInstruction: {
    color: "#fff",
    fontSize: 20,
    fontWeight: "700",
    lineHeight: 26,
  },
  primaryDistance: {
    color: "rgba(255,255,255,0.7)",
    fontSize: 14,
    marginTop: 4,
    fontWeight: "500",
  },
  expandToggle: {
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "center",
    paddingVertical: 10,
    gap: 6,
    borderTopWidth: StyleSheet.hairlineWidth,
    borderTopColor: "rgba(255,255,255,0.2)",
  },
  expandLabel: {
    color: "rgba(255,255,255,0.7)",
    fontSize: 13,
    fontWeight: "500",
  },
  stepList: { maxHeight: 220 },
});