Ever tried fixing something that looked like a simple UI issue… but turned into a full-stack puzzle? 😄 Recently, I faced one such problem with image aspect ratios in a market feed. 🎯 The Starting Point We had a clean setup: 👉 Admin selects ratio: 16:9, 4:3, 1:1, 9:16 👉 Frontend renders based on that Simple, right? --- 😅 Reality Hit Then came real-world images: - Charts 📊 - Screenshots 📱 - Random uploads And suddenly: - Important parts were getting cropped - Some images looked stretched - Feed consistency broke --- 🧠 First Thought “Okay, let’s calculate ratio on frontend using "Image.getSize()"” ✔ Works ❌ But async → slight flicker ❌ Not ideal for lists --- 🔄 Next Iteration (Better) “Let’s fix it at the source” 👉 On admin upload: - Used "img.onload" - Calculated actual ratio (width / height) - Sent that to backend Now new posts were perfect ✅ --- 🚨 Plot Twist Old posts already existed with: "9:16", "4:3" And not all images actually matched those ratios 😬 So now I had two worlds: - 🟢 New posts → correct ratio - 🟡 Old posts → unreliable ratio --- ⚖️ Final Strategy (The Real Solution) Instead of choosing one approach, I combined both: 👉 If backend gives valid numeric ratio → use it directly (fast, no flicker) 👉 If backend gives old string ratio ("9:16") → fallback to "Image.getSize()" (only when needed) --- 💡 What Changed - No more distorted images - Minimal flicker (fallback is conditional) - Backward compatibility maintained - System became smarter, not heavier --- 🧠 Biggest Learning «“Good systems don’t assume data is perfect — they adapt to it.”» Also: - Fix problems as early as possible (admin/backend) - Keep frontend efficient, not overloaded - Handle legacy data like a real product, not a side case --- What looked like a small UI fix turned into a lesson in: 👉 data flow 👉 backward compatibility 👉 performance trade-offs --- Curious — how do you handle image rendering inconsistencies in your apps? #reactnative #frontend #engineering #softwaredevelopment #mobiledev #learning #performance #buildinpublic

To view or add a comment, sign in

Explore content categories