<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Puru Singh  on Medium]]></title>
        <description><![CDATA[Stories by Puru Singh  on Medium]]></description>
        <link>https://medium.com/@puru.singh.6541?source=rss-6dbef81348bc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BbihW1yzVTsCRiJ3</url>
            <title>Stories by Puru Singh  on Medium</title>
            <link>https://medium.com/@puru.singh.6541?source=rss-6dbef81348bc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:44:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@puru.singh.6541/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Smooth Marker Movement in React Native Maps with Dynamic Bearing Rotation]]></title>
            <link>https://medium.com/@puru.singh.6541/smooth-marker-movement-in-react-native-maps-with-dynamic-bearing-rotation-10975549dd23?source=rss-6dbef81348bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/10975549dd23</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[geolocation]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Puru Singh ]]></dc:creator>
            <pubDate>Thu, 07 Aug 2025 18:31:47 GMT</pubDate>
            <atom:updated>2025-08-07T18:31:47.520Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*zzgY2z-LAe_qbJsHFLnTGg.avif" /></figure><p>Working with maps in React Native? If you’re building something like a trip playback feature or real-time vehicle tracking, you know just placing a marker isn’t enough. The key to great UX is <strong>accurate movement and realistic orientation</strong>, and that’s where calculating the <strong>bearing angle</strong> plays a major role.</p><p>In this post, I’ll walk you through how I implemented a live GPS route playback feature using react-native-maps, and explain why computing the bearing (rotation angle) is a good practice — especially for a polished and natural user experience.<br>What is Bearing and Why Does it Matter?</p><p>When a vehicle moves from one point to another, it’s not just “jumping” — it’s <strong>facing a direction</strong>. That direction is the <em>bearing</em>. If you’re displaying a moving car on a map, just updating its position will feel clunky unless you <strong>rotate the marker to point toward the direction it’s headed</strong>.</p><p>This not only improves realism but also enhances:</p><ul><li><strong>User orientation</strong>: Users immediately know which way the vehicle is going.</li><li><strong>Playback accuracy</strong>: In trip replay mode, users can visually follow the journey with better understanding.</li><li><strong>Professional polish</strong>: Feels more like Google Maps or Uber than a prototype.</li></ul><h3>The Setup — MapView with Marker Rotation</h3><p>Here’s a high-level look at the architecture:</p><pre>const ViewMap: React.FC&lt;ViewMapProps&gt; = ({ paused, currentTime }) =&gt; {<br>  const { gpsCordinates } = useAppSelector((state) =&gt; state.settings);<br>  const [currentIndex, setCurrentIndex] = useState(0);<br>  const mapRef = useRef&lt;MapView&gt;(null);<br>  const [bearing, setBearing] = useState(0);<br>  const isUserInteracting = useRef(false);<br><br>  // Auto-move marker unless user is touching the map<br>  useEffect(() =&gt; {<br>    if (paused || gpsCordinates.length &lt; 2 || isUserInteracting.current) return;<br><br>    const index = Math.floor(currentTime);<br>    setCurrentIndex(index + 1);<br><br>    const newBearing = getBearing(gpsCordinates[index], gpsCordinates[index + 1]);<br>    setBearing(newBearing);<br><br>    const region = {<br>      latitude: gpsCordinates[index].latitude,<br>      longitude: gpsCordinates[index].longitude,<br>      latitudeDelta: 0.001,<br>      longitudeDelta: 0.001,<br>    };<br><br>    mapRef.current?.animateToRegion(region, 500);<br>  }, [paused, currentTime, gpsCordinates]);</pre><h3>Calculating the Bearing Between Two Points</h3><p>The real magic is in this simple yet powerful function:</p><pre>const getBearing = (start, end) =&gt; {<br>  const { latitude: lat1, longitude: lon1 } = start;<br>  const { latitude: lat2, longitude: lon2 } = end;<br><br>  const y = Math.sin(lon2 - lon1) * Math.cos(lat2);<br>  const x =<br>    Math.cos(lat1) * Math.sin(lat2) -<br>    Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);<br><br>  const bearing = Math.atan2(y, x) * (180 / Math.PI);<br>  return (bearing + 360) % 360;<br>};</pre><p>This uses the <strong>haversine formula</strong> concept, converting lat/lng to radians and determining the angle to rotate the vehicle marker. This ensures your car or arrow icon is always pointing <strong>toward the next point</strong>, even during tight turns or reverse directions.</p><h3>Why This is a Good Practice</h3><ol><li><strong>Better UX</strong>: Users can instinctively understand the path and direction of motion.</li><li><strong>Map standards</strong>: Every major navigation app (Google Maps, Uber, etc.) uses dynamic marker rotation.</li><li><strong>Smooth playback</strong>: Ideal for features like trip replays or animated routes.</li><li><strong>Visual storytelling</strong>: For apps that show movement over time (e.g. fitness, logistics, delivery), it’s not just about data — it’s about narrative.</li><li><strong>Accurate reroutes</strong>: If the route is recalculated mid-trip, bearing helps adjust the marker instantly.</li></ol><h3>Final Touch — Don’t Interrupt the User</h3><p>Another UX detail we added:</p><pre>const isUserInteracting = useRef(false);<br><br>const handleMapTouchStart = () =&gt; {<br>  isUserInteracting.current = true;<br>};<br><br>const handleMapTouchEnd = () =&gt; {<br>  setTimeout(() =&gt; {<br>    isUserInteracting.current = false;<br>  }, 2000);<br>};</pre><p>We <strong>pause auto-centering and auto-rotation</strong> if the user is manually exploring the map. This is essential because unexpected movements while interacting can feel frustrating.</p><h3>Result</h3><p>With this setup:</p><ul><li>The marker glides smoothly across the path.</li><li>It <strong>points</strong> in the right direction.</li><li>The map <strong>auto-follows</strong> the marker, unless the user is interacting.</li><li>You get a <strong>natural, immersive, polished</strong> GPS visualization.</li></ul><h3>In Summary</h3><ul><li>Always compute <strong>bearing</strong> if you’re animating movement on a map.</li><li>Use getBearing() logic between GPS coordinates to get realistic orientation.</li><li>Respect the user’s gestures (pause auto-center while interacting).</li><li>Focus on motion <strong>direction</strong>, not just position.</li></ul><p>If you’re building map-heavy apps or playback tools, this approach will help your app feel smarter, more intuitive, and truly mobile-first.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10975549dd23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create an Android Package Name Using the Reserved Keyword new (Not Recommended, But Possible!]]></title>
            <link>https://medium.com/@puru.singh.6541/how-to-create-an-android-package-name-using-the-reserved-keyword-new-not-recommended-but-possible-dcf184f75c59?source=rss-6dbef81348bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcf184f75c59</guid>
            <category><![CDATA[best-practices-in-android]]></category>
            <category><![CDATA[java-reserved-keywords]]></category>
            <category><![CDATA[hacks-and-workarounds]]></category>
            <category><![CDATA[package-naming-in-android]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Puru Singh ]]></dc:creator>
            <pubDate>Wed, 11 Jun 2025 18:20:27 GMT</pubDate>
            <atom:updated>2025-06-11T18:20:27.562Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rlpk_PGAuVFpnKlxuZqcbw.png" /></figure><h3>How to Create an Android Package Name Using the Reserved Keyword new (Not Recommended, But Possible!)</h3><p>If you’ve been working with Android development, you know that package names are crucial. They uniquely identify your app across the Play Store and your project files. But what if you have a <strong>very specific reason</strong> to create a package name that starts with new?</p><p>Well, Java isn’t going to make it easy for you.<br> Why?<br> Because new is a <strong>reserved keyword</strong> in Java, and using it directly in your package name is <strong>technically not allowed.</strong></p><p>But wait — there’s a trick.<br> It’s not generally recommended, but if you absolutely need this (maybe you’re dealing with a legacy system, a client constraint, or something unavoidable), you can make it work by <strong>manually creating the folder structure.</strong></p><p>Let’s break it down step by step in a fun, conversational way!</p><p><strong>The Problem:-</strong></p><p>When you try to create a package name like:</p><pre>new.abc.xyz</pre><p>Android Studio (and Java) will scream at you:</p><p>“new is a reserved keyword and cannot be used as a package name!”</p><p>Direct creation? Not happening.</p><h3>The Solution (Manual Trick)</h3><p>While you <strong>can’t directly create the package using Android Studio’s UI</strong>, you can <strong>manually create the folder structure</strong> in your project’s file system.</p><h3>Here’s How:</h3><p>Let’s say you want this package name:</p><pre>new.abc.xyz</pre><h3>Steps:</h3><ol><li><strong>Go to your project’s </strong><strong>java directory</strong> in the file explorer (outside Android Studio).</li></ol><p><strong>2. Manually create folders:</strong></p><pre>new/abc/xyz</pre><p><strong>3. Move your Java/Kotlin files into the </strong><strong>xyz folder.</strong></p><p><strong>4. Update the package declaration at the top of your files:</strong></p><pre>package new.abc.xyz;</pre><p><strong>5. Sync your project.</strong></p><p>Done! Android Studio will now recognize the structure, and it will compile.</p><h3>Important Notes</h3><ul><li><strong>Java will allow this at the filesystem level</strong> but remember that using reserved keywords in package names can lead to confusion and potential issues with other developers or future tooling updates.</li><li><strong>This is not a recommended practice.</strong><br> Use it only when you <strong>have a very strong, unavoidable reason.</strong></li></ul><h3>Why It’s Not Recommended</h3><ul><li>Reserved keywords like new can create conflicts in certain contexts.</li><li>It makes your project <strong>harder to maintain</strong>.</li><li>Some third-party tools, linters, or future SDK updates might not handle this gracefully.</li></ul><h3>When Should You Do This?</h3><ul><li>Legacy projects where the package name is fixed.</li><li>Integration with systems that already expect this structure.</li><li>Very specific client requirements.</li></ul><p>But always try to find alternatives first.</p><h3>Final Thoughts</h3><p>Sometimes, in engineering, we face weird, edge-case scenarios.<br> This is one of them.</p><p>You now know <strong>how to hack around Java’s reserved keywords in Android package names</strong>, but use this power responsibly.</p><p>If you found this helpful, give it a 👏 or drop a comment if you’ve faced similar tricky situations!</p><p>If you want, I can help you make this into a fully formatted Medium post with emojis, headers, and callouts. Would you like me to do that?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcf184f75c59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Regained 58% of My Website’s Performance After GTM Slowed It Down.]]></title>
            <link>https://medium.com/@puru.singh.6541/how-i-regained-58-of-my-websites-performance-after-gtm-slowed-it-down-7aacb289b4a4?source=rss-6dbef81348bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/7aacb289b4a4</guid>
            <category><![CDATA[frontend-performance-tips]]></category>
            <category><![CDATA[gtm-best-practices]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[pagespeed-insights]]></category>
            <category><![CDATA[javascript-snippet-hacks]]></category>
            <dc:creator><![CDATA[Puru Singh ]]></dc:creator>
            <pubDate>Sun, 11 May 2025 19:11:52 GMT</pubDate>
            <atom:updated>2025-05-11T19:11:52.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*lz-SdhFhY_XZLMKUD0LGMw.png" /></figure><p>Everything was running smooth.<br>My website was fast, optimized, and clocking a PageSpeed Insights score well above <strong>90%</strong>.</p><p>Then, I added <strong>Google Tag Manager</strong> to track events and set up analytics — and boom 💣<br>The score tanked to <strong>just 57%</strong>.</p><p>I thought: <em>Wait… what just happened?</em></p><p>I didn’t change anything else. Just a tiny GTM snippet.<br>Yet somehow, it <strong>cut my performance nearly in half</strong>.</p><h3>GTM: The Silent Performance Killer?</h3><p>Here’s the thing: GTM is powerful — no doubt. But most of us just copy-paste the default snippet Google gives without thinking twice.</p><p>That default snippet loads as soon as possible, often before your page content does. That means:</p><ul><li>Longer <strong>First Contentful Paint</strong></li><li>Slower <strong>Largest Contentful Paint</strong></li><li>Delayed <strong>Time to Interactive</strong></li><li>A noticeably sluggish experience for your users</li></ul><p>In short: GTM was jumping the queue and slowing everything down.</p><h3>The Fix I Couldn’t Find on Stack Overflow</h3><p>I spent hours searching.</p><p>Post after post confirmed GTM could hurt performance… but no one had a <strong>clear, working fix</strong>. Some people recommended tag sequencing. Others talked about using Google’s Server-Side GTM (which, let’s be honest, is overkill for small sites).</p><p>So I thought:<br> <em>“What if I just wait a few seconds before loading GTM?”</em></p><p>Not forever. Just enough to let the page load first.</p><p><strong>The Simple </strong><strong>setTimeout Trick</strong></p><p>Here’s the tweak I made:</p><pre>&lt;script&gt;<br>  setTimeout(function() {<br>    (function(w,d,s,l,i){<br>      w[l]=w[l]||[];<br>      w[l].push({&#39;gtm.start&#39;: new Date().getTime(), event:&#39;gtm.js&#39;});<br>      var f = d.getElementsByTagName(s)[0],<br>          j = d.createElement(s),<br>          dl = l != &#39;dataLayer&#39; ? &#39;&amp;l=&#39; + l : &#39;&#39;;<br>      j.async = true;<br>      j.src = &#39;https://www.googletagmanager.com/gtm.js?id=&#39; + i + dl;<br>      f.parentNode.insertBefore(j, f);<br>    })(window, document, &#39;script&#39;, &#39;dataLayer&#39;, &#39;GTM-XXXXXXXXX&#39;);<br>  }, 3000); // Delay GTM load by 3 seconds<br>&lt;/script&gt;</pre><p>That’s it.</p><p>Just delayed the script by <strong>3 seconds</strong> using setTimeout.</p><h3>The Result? A 58% Performance Boost</h3><p>After adding that delay, I ran the PageSpeed test again.</p><p>📉 Before GTM: <strong>~92%</strong><br>📉 After GTM (no delay): <strong>57%</strong><br>✅ After GTM with delay: <strong>Back to 90%</strong></p><p>I recovered <strong>58% of my performance score</strong> by simply waiting a few seconds to load GTM.</p><h3>Is This Safe?</h3><p>You might be wondering — is it okay to delay GTM?</p><p><strong>Yes — with conditions.</strong></p><h3>Delay GTM if:</h3><ul><li>You use it for analytics, ad tracking, or marketing tags</li><li>You want to prioritize <strong>performance</strong> and <strong>SEO</strong></li><li>Most of your users stay on the page for more than 3 seconds</li></ul><h3>Don’t delay GTM if:</h3><ul><li>You use GTM for critical UX features like cookie consent or A/B testing</li><li>You need <strong>full tracking</strong> from the first moment of page load</li></ul><h3>Final Thoughts</h3><p>We often think performance optimizations require complex tools or hours of tweaking. But sometimes, it’s just about loading the <strong>right things at the right time</strong>.</p><p>Google Tag Manager isn’t the villain — but how you load it matters.</p><p>That tiny 3-second delay helped me recover a <strong>58% drop in performance</strong> — and gave my users a snappier experience without losing tracking.</p><p>So next time your performance score tanks unexpectedly?<br> Check your GTM.</p><p>Have you faced performance drops after adding GTM or third-party scripts? I’d love to hear your experience — or help troubleshoot it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7aacb289b4a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Every React Native Developer Should Know a Bit of Native Android and iOS Development]]></title>
            <link>https://medium.com/@puru.singh.6541/why-every-react-native-developer-should-know-a-bit-of-native-android-and-ios-development-f608239c17b2?source=rss-6dbef81348bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f608239c17b2</guid>
            <category><![CDATA[native-modules]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[react-native-bridge]]></category>
            <dc:creator><![CDATA[Puru Singh ]]></dc:creator>
            <pubDate>Sat, 10 May 2025 10:30:59 GMT</pubDate>
            <atom:updated>2025-05-10T10:30:59.906Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MyIoUN7XwzykZxRXTSTC_A.png" /></figure><p>As React.js/React Native developer , we often rely on the incredible ecosystem of packages and libraries built by the community. This ecosystem makes it easy to build cross-platform apps without diving into the native codebase of Android or iOS.</p><p>But what happens when none of those packages solve your problem?</p><p>Recently, I encountered a challenge while working on a React Native project that forced me to go beyond JavaScript and into the world of native Android and iOS code.</p><h3>The Problem</h3><p>I needed to check whether <strong>mobile data (cellular data)</strong> was enabled on the device.</p><p>At first, I thought this was a common feature — something many apps might want. A quick search led me to several React Native libraries that claim to detect network state, such as:</p><ul><li>@react-native-community/netinfo</li><li>react-native-network-info</li><li>And several others…</li></ul><p>But here’s the catch: <strong>none of them could reliably tell if mobile data was turned on — especially when Wi-Fi was also enabled and connected.</strong> Most of these libraries only tell you if the device is online, not <em>how</em>.</p><h3>The Android Solution (Java)</h3><p>After some research, I discovered that Android offers a native way to get this information using the TelephonyManager class.</p><p>Here’s the Java code I wrote to get the mobile data state:</p><h3>Java Code (Android Native)</h3><pre>@Override<br>public boolean getMobileDataInfo() {<br>  try {<br>    Context context = getReactApplicationContext();<br>    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);<br>    return tm.isDataEnabled();<br>  } catch (Exception e) {<br>    return false;<br>  }<br>}</pre><p>I wrapped this in a custom native module and bridged it to React Native. And just like that, I was able to access accurate mobile data state.</p><h3>The iOS Side (Swift)</h3><p>On iOS, the challenge is slightly different: Apple does not provide a public API to directly determine whether mobile data is enabled. However, we can infer it by checking the radioAccessTechnology of the current cellular connection using CTTelephonyNetworkInfo.</p><p>Here’s a Swift-based workaround that I used:</p><pre>@objc(MobileDataManager)<br>class MobileDataManager: NSObject {<br><br>  @objc<br>  func isCellularDataEnabled(_ resolve: @escaping RCTPromiseResolveBlock,<br>                              rejecter reject: @escaping RCTPromiseRejectBlock) {<br>    let networkInfo = CTTelephonyNetworkInfo()<br>    <br>    if let _ = networkInfo.serviceCurrentRadioAccessTechnology {<br>      resolve(true)<br>    } else {<br>      resolve(false)<br>    }<br>  }<br><br>  @objc<br>  static func requiresMainQueueSetup() -&gt; Bool {<br>    return false<br>  }<br>}</pre><p>While this doesn’t tell you whether the user has disabled cellular data completely (since iOS doesn’t expose that directly), it gives you a good enough indication if any radio access tech (like LTE, 5G, etc.) is currently active.</p><h3>Bridging It All Together</h3><p>Using <strong>React Native’s Native Modules and Bridges</strong>, I was able to:</p><ul><li>Write a small Android Java module using TelephonyManager</li><li>Write an iOS Swift module using CTTelephonyNetworkInfo</li><li>Bridge both of them to React Native using the NativeModules interface</li></ul><p>Now I can call a single JS function like getMobileDataStatus() and get platform-specific, reliable results.</p><h3>Why You Should Learn Native Modules</h3><p>This experience taught me a powerful lesson:</p><blockquote><em>You don’t need to be a native developer — but knowing just enough can make you a 10x React Native developer.</em></blockquote><p>Here’s why every React Native dev should know the basics of native module creation:</p><h3>1. Unlock Platform-Specific Power</h3><p>Sometimes the functionality you need is simply <strong>not accessible through JavaScript</strong>. Native APIs offer full control.</p><h3>2. Avoid Library Fatigue</h3><p>Sometimes the libraries are outdated, abandoned, or buggy. Writing your own bridge is often more reliable.</p><h3>3. Debug Like a Pro</h3><p>Understanding how native code interacts with JS helps you debug complex issues with confidence.</p><h3>4. Extend Your App’s Capabilities</h3><p>You can customize, optimize, and innovate beyond what’s currently possible in existing community libraries.</p><h3>Final Thoughts</h3><p>You don’t have to become a full-time native developer — but understanding the basics of how Android (Java/Kotlin) and iOS (Swift/Obj-C) modules work will make you a much stronger React Native developer.</p><p>Learn how the React Native Bridge works. Learn how to write a small native module. It’ll save you one day — just like it saved me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f608239c17b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>