diff --git a/ANDROID_FIX.md b/ANDROID_FIX.md index b066762..1f31019 100644 --- a/ANDROID_FIX.md +++ b/ANDROID_FIX.md @@ -1,107 +1,94 @@ -# To AI Agent: Fix Mobile Dropdown Layout Displacement and Eliminate `.filter is not a function` Runtime Crashes +# To AI Agent: Fix Mobile Dropdown Displacement and Eliminate `.filter` Array Runtime Crashes -## 1. Bug Analysis & Context -We are resolving three critical layout and runtime bugs observed during Android Simulator testing (`image.png`): - -1. **Dropdown Menu Displacement:** The menu drawer/dropdown container is losing its absolute coordinate anchor pool. Instead of floating gracefully on top of the map layer as a neat dropdown card, it wraps below the viewport grid, conflicting with the lower navigation action buttons ("Khám phá", "Chụp ảnh") and community photo streams. -2. **`g.filter is not a function` (Friends List Crash):** Triggering the Friend List components crashes the UI thread into a White Screen of Death (WSoD). -3. **`Error fetching connections: TypeError: ...filter is not a function` (LiveChat Crash):** Opening the Live Chat view displays the exact same array mutation failure. - - *Root Cause for 2 & 3:* The asynchronous API network response payload or socket stream data returned from the server backend is **not a clean Array structure**. It is likely either wrapped inside an object wrapper (e.g., `{ success: true, friends: [] }`) or returns `null`/`undefined` due to network delays. Invoking `.filter()` directly on a non-array object instantly freezes the React rendering lifecycle. +## 1. Context & Identified Bugs +During Android Simulator testing, the frontend app encounters three critical layout and runtime execution failures: +1. **Dropdown Menu Displacement:** The profile/avatar menu container gets forced down to the extreme bottom of the viewport instead of floating as an absolute element directly beneath the user's top-bar avatar anchor. +2. **`Uncaught TypeError: g.filter is not a function`:** Triggering the Friend List components crashes the interface into a blank white screen. +3. **`Error fetching connections: TypeError: (intermediate value).filter is not a function`:** Opening the Live Chat view crashes identical array loops. + - *Root Cause for 2 & 3:* The API response payload from the backend server is **not returning a clean primitive Array**. It returns an object wrapper (e.g., `{ success: true, data: [...] }`) or `undefined`/`null` due to connection timing gaps. Invoking `.filter()` on a non-array instantly kills the React rendering thread. --- -## 2. Refactoring Strategy +## 2. Refactoring Blueprint -### 2.1. Fix Dropdown Layout Context for Mobile/Android Viewports -On mobile viewports, traditional hover/click absolute dropdown boxes overflow or clip out. We must force the dropdown menu container inside `MapProfileDropdown.tsx` to act as a structured **Sticky Floating Overlay** or a dedicated **Mobile Bottom-Sheet Box** with a precise `z-index`. - -### 2.2. Implement Defensive Array Architecture (Fix Crashes 2 & 3) -We must implement a protective array fallback guard across all data mapping blocks (`friends.filter`, `connections.filter`) using **`Array.isArray()`** validation, coupled with unified error boundaries. - ---- - -## 3. Code Refactoring Blueprint - -### Step 1: Overhaul Dropdown Styling for Mobile Boundaries (`MapProfileDropdown.tsx`) -Ensure the menu card isolates itself perfectly above the underlying view map layout and handles sizing dimensions cleanly: +### Step 1: Fix Dropdown Positioning Context (`MapProfileDropdown.tsx`) +On desktop, absolute drop panels function normally. However, on mobile viewports or custom wrappers, they lose anchoring. We must force the container component to lock its coordinate space relative to the top bar element using modern CSS constraints: ```jsx -{/* ✅ RESPONSIVE FIX: Mobile-optimized absolute floating panel structure */} +{/* ✅ RESPONSIVE REFACTOR: Force absolute rendering locked beneath the profile button context */}