Advance React Navigation: Handling Complicated Flows Like a Pro

Sep 18, 2024

Advance React Navigation: Handling Complicated Flows Like a Pro

Learn how Charlotte, React Native Tech Lead at Theodo Apps, simplifies complex app flows using state machines and a custom Flow Navigator for efficient navigation.

Author

Aditi Dixit
Aditi DixitContent Writer

Editor's Note: This blog highlights Charlotte, a React Native Tech Lead at Feodo Apps, as she delves into the intricacies of React Navigation. By integrating state machines and custom navigators, she demonstrates how to streamline complex app flows, making navigation simpler and more efficient for developers.

Hi everyone, Iโ€™m Charlotte, a React Native Tech Lead at Feodo apps, and today weโ€™re diving into a topic that impacts all of usโ€”flows. Flows are the backbone of many apps, from onboarding sequences to complex payment funnels. But when these flows grow in complexity, they can become an overwhelming challenge for developers.

When Simplicity Turns Complex

Most apps have flowsโ€”a structured sequence of pages where we control the userโ€™s journey. In a perfect world, this structure would remain manageable, but as complexity creeps in, itโ€™s easy for the code to become convoluted. I faced this firsthand when I joined a new project with already implemented flows. My task? Add a simple page to an existing flow.

It sounded easy, right? However, the reality was far from it. The flowโ€™s code had grown into a tangled mess. The challenge wasnโ€™t just adding a pageโ€”it was deciphering the logic hidden beneath layers of complexity. As the sole developer tasked with this, I found myself lost in the maze of navigation paths.

A Developerโ€™s Nightmare: Complex Navigation

Fast forward a few monthsโ€”I had the opportunity to start fresh on a new flow. This time, I was determined to make it right from the start. Today, I want to share how we leveraged the power of state machines to clarify React Navigation and simplify even the most complex flows.

But before we dive into the solution, letโ€™s take a step back and define what we mean by โ€œflows.โ€

What Exactly is a Flow?

A flow is a predetermined series of pages where the userโ€™s path is predefined, like an onboarding sequence or checkout process. Unlike regular navigation, where users are free to jump from page to page, a flow guides users along a set path, ensuring they click "Next" to reach the subsequent step.

However, things can get messy when logic and conditions start piling up within a flow.

The Hidden Problem of Complex Flows

Consider the flow I had to implementโ€”it looked simple on the surface, but was riddled with conditions and logic. The problem? Using regular page-to-page navigation for such a flow made it almost impossible to get a clear overview of the entire sequence. You had to dive into every page to understand the navigation paths hidden within conditional logic. This made debugging and adding new steps a developerโ€™s nightmare.

So how do we fix this? How can we write code that screams, โ€œThese are all the possible pathways!โ€?

The Ideal Flow Solution: State Machines to the Rescue

Imagine an ideal solutionโ€”a system where you can see the entire flow in one place. A system where pages donโ€™t have to โ€œknowโ€ which page comes next. Sounds perfect, right?

Well, this is where state machines come in. State machines allow us to define the entire flowโ€”every page and every transitionโ€”in one clear place. Letโ€™s break it down with a simple analogy: traffic lights. A traffic light system is a state machine, where each color (red, yellow, green) represents a state, and transitions occur based on predefined events.

In a flow, our states are our pages. Each time the user clicks "Next," we send an event that transitions to the next page. This way, all the logic and pathways are stored in one placeโ€”easy to read and understand.

The First Step: Implementing State Machines in React Native

Letโ€™s visualize this. We define a state machine with our flow's stepsโ€”pages A, B, C, and D. Each time the user hits "Next," we transition from one state (page) to the next. This is a great start, but thereโ€™s a problemโ€”our state is split between the state machine and the navigation.

Whenever we transition states, we also need to update the navigation to display the correct page. If these two states get out of sync, we risk bugs. Itโ€™s easy to forget a navigation update, leading to issues that are hard to track down.

The Breakthrough: Merging State and Navigation

This leads us to our next evolution: a more declarative approach. Instead of defining pages inside a traditional navigation stack, we define them based on the state machineโ€™s value. This eliminates the need for manual navigation calls, making the flow much more robust.

But we still encountered issuesโ€”most notably, losing out on transition animations. And even worse, we still faced potential bugs due to configuration mistakes.

Building a Custom Navigator: A Game-Changer

And then came the breakthrough: building a custom navigator. One of my colleagues asked, "Why not create a navigator tailored to our specific needs?" And thatโ€™s exactly what we did. By building a custom flow navigator, we were able to combine the state machine and navigation into a single, coherent system.

Let me introduce you to the Flow Navigator.

The Flow Navigator: Simplifying Complex Logic

The Flow Navigator looks and behaves like a regular navigator but with one critical differenceโ€”you define the flowโ€™s order in one place. Hereโ€™s an example: cart review, payment, success. In one glance, you can see the entire flow and its order. And inside each page, like Cart Review, you simply call a methodโ€”goToNextStepโ€”to advance to the next page without worrying about its position in the flow.

Internally, this works through an index that tracks which page is currently active. As the user moves through the flow, the index bumps up, ensuring seamless navigation from one step to the next.

Handling Conditional Logic with Ease

Of course, not all flows are linear. What about conditional pagesโ€”like a document signing step that only appears once? With the Flow Navigator, we can handle conditional logic effortlessly. For example, we use a Boolean value to determine whether the document signing page appears or not.

Once the condition is met, the page is removed from the flow, and the user moves on. This allows for dynamic, adaptive navigation based on user input or other conditions.

Limitations and Future Possibilities

The Flow Navigator solves many architectural issues, but like any solution, it has limitations. For instance, you canโ€™t always see all the possible pathways at a glance. And while it works well with React Navigation, we havenโ€™t built it for Explore Router yet. However, these are challenges we are actively working on.

Rethinking Flow Architectures

Today, we explored how state machines can transform complex flows into clear, manageable systems. By building custom navigators like the Flow Navigator, weโ€™ve created a tool that makes navigating complex flows easier and more intuitive.

I hope this reflection on flow architecture has inspired you to think about your own appโ€™s navigation in new ways. Next time you face scattered logic, remember the power of state machines and custom navigatorsโ€”they could be your key to clarity and simplicity.

Subscribe to Our Newsletter

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Building Local LLMs Using Dart FFI And llama.cpp: Beyond Wrapper Packages
Sep 11, 2026

Building Local LLMs Using Dart FFI And llama.cpp: Beyond Wrapper Packages

Build local LLMs in Flutter with Dart FFI and llama.cpp, and see how native bridges, GGUF models, memory management, and token streaming enable private, on-device AI.

Insight
My Flutter App Froze With Three Photos on Screen. Here's What I Was Doing Wrong
Sep 11, 2026

My Flutter App Froze With Three Photos on Screen. Here's What I Was Doing Wrong

This blog explains how rethinking Flutterโ€™s image-processing architecture fixed severe performance issues and improved rendering efficiency.

Insight
Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15
Sep 10, 2026

Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15

This blog explains how to build a production-ready canvas editor with Konva.js, React, and Next.js, covering architecture, performance, and key engineering decisions.

Insight
Why AI Agents Fail in Production: Building Systems That Recover | Pushkar
Sep 10, 2026

Why AI Agents Fail in Production: Building Systems That Recover | Pushkar

Pushkarโ€™s thegeekconf mini talk explores why AI agents that perform well in demos often struggle in production, and how loud failures, clean context, step monitoring, guardrails, and better agent loops can make them more reliable and predictable.

Insight
What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust
Sep 8, 2026

What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust

This blog explores the architecture, security, performance, and documentation lessons from migrating a legacy PHP/Laravel banking platform to NestJS.

Insight
Building Is Not Shipping: An AI Agent for App Store Submissions | Gracey Dugar
Sep 8, 2026

Building Is Not Shipping: An AI Agent for App Store Submissions | Gracey Dugar

Gracey Dugar's thegeekconf mini 2026 talk explores why app store submission stalls most AI agent workflows, what an agent needs to finish the job, and a live demo from a single prompt to a published app.

Insight
Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs
Sep 7, 2026

Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs

This blog explains how to build responsive video thumbnail scrubbing in the browser for local files and HLS streams, covering frame extraction, caching, and performance trade-offs.

The Right Conversation Can

Save You Six Months.

Book a call