Overview
TheParkingMap component renders an interactive visual representation of a 10-spot parking lot using React Native SVG. It provides real-time occupancy status, spot selection, and visual feedback for user interactions.
Component Interface
components/ParkingMap.tsx
Props
The currently selected parking spot ID (1-10). When set, the spot is highlighted in yellow (#FFE100).
Callback function invoked when a user taps an available parking spot. Receives the spot ID as a parameter. Only fires for unoccupied spots.
Array of spot IDs that are currently occupied. Occupied spots are rendered in red (#FF4444) with reduced opacity (0.7) and display a ⛔ indicator.
Spot Layout Configuration
The parking lot consists of 10 spots arranged in two columns:components/ParkingMap.tsx:20-34
Visual States
The component uses a color-coded system to represent spot status:components/ParkingMap.tsx:38-42
| State | Color | Hex Code | Behavior |
|---|---|---|---|
| Available | Green | #4CAF50 | Clickable, full opacity |
| Occupied | Red | #FF4444 | Non-clickable, 0.7 opacity, shows ⛔ |
| Selected | Yellow | #FFE100 | Clickable, shows black label text |
Android Touch Handling
The component implements a workaround for Android touch sensitivity issues:components/ParkingMap.tsx:104-110
Usage Example
SVG Structure
The component renders a 280x440px SVG canvas with:- Background: Dark asphalt rectangle (#333) with 15px border radius
- Center Lane: Dashed white line (138px x-offset, 4px wide) running vertically
- Parking Spots: Two columns of 5 spots each
- Entry Indicator: Yellow ”⬆ ENTRADA ⬆” text at bottom (y: 430)
- Legend: Color-coded status indicators below the map
State Management
The component is controlled - it does not manage selection state internally. Parent components must:- Maintain
selectedSpotstate - Provide
occupiedSpotsarray (typically from Firestore real-time listener) - Handle
onSelectSpotcallback to update state and trigger reservation logic
Interactive Behavior
components/ParkingMap.tsx:62-69
- Tapping an available spot triggers
onSelectSpot - Tapping an occupied spot does nothing (no callback)
- Tapping the selected spot triggers
onSelectSpotagain (allows deselection if desired)
Styling
The map wrapper includes elevation and shadow effects:components/ParkingMap.tsx:142-151
Legend Component
The legend displays three status indicators with colored dots:- Libre (Available): Green dot
- Ocupado (Occupied): Red dot
- Seleccionado (Selected): Yellow dot
flexWrap: 'wrap' to ensure responsive layout on smaller screens.
Dependencies
Performance Considerations
- Renders 10 spots with minimal re-renders (React.memo candidate)
- SVG rendering is performant for static layouts
- Touch handlers only fire on unoccupied spots
- Consider memoizing
getSpotColorfor optimization
Accessibility
The component currently lacks accessibility features. Recommended improvements:- Add
accessibilityLabelto each spot group - Provide
accessibilityStatefor occupied/selected states - Include
accessibilityHintfor interactive guidance - Consider text alternatives for emoji indicators