Below is a proposed design that aims to meet your requirements for flexible, conditional flows with a persistent progress bar and smooth in-flow transitions.
- Overall Architecture
Single Flow Container:Use a dedicated “flow screen” that stays mounted during the entire onboarding/verification process. This screen will render two main parts:
Persistent Progress Bar:Stays fixed at the top.
Animated Content Area:Dynamically swaps out the “step” component using custom in-place animations (e.g., cross-fade, slide) so that native navigation animations don’t interfere.
Persistent Progress Bar:Stays fixed at the top.
Animated Content Area:Dynamically swaps out the “step” component using custom in-place animations (e.g., cross-fade, slide) so that native navigation animations don’t interfere.
Flow Context:Leverage React Context (or a similar state management solution) to hold the flow’s state (e.g., current step index, answers). This makes it easy for any step to:
Read prior answers.
Update the flow state.
Trigger navigation to the next (or previous) step.
Read prior answers.
Update the flow state.
Trigger navigation to the next (or previous) step.
- Flow Definition & Conditional Branching
Flow Configuration Object:Define each flow (e.g., onboarding, identity verification) as a configuration array. Each step in the array is an object containing:
id:A unique identifier.
component:The JSX component to render.
condition ( function that evaluates the current answers to determine if this step (and possibly subsequent steps) should be shown.
meta/animation options (optional):If needed, you can specify custom animation parameters or any extra props.
id:A unique identifier.
component:The JSX component to render.
condition ( function that evaluates the current answers to determine if this step (and possibly subsequent steps) should be shown.
meta/animation options (optional):If needed, you can specify custom animation parameters or any extra props.
For example:
────────────────────────────────────────────────────────────────────
jsCopy code// flowConfig.js
export const onboardingFlow = [
{
id: "welcome",
component: WelcomeScreen,
},
{
id: "phone",
component: PhoneScreen,
// Only show if welcome was completed
condition: (answers) => answers.welcomeCompleted === true,
},
{
id: "profile",
component: ProfileScreen,
// For example, if user opts out of providing extra info, this might be skipped.
condition: (answers) => !answers.skipProfile,
},
// …more steps as needed.
];
The flow manager can recalculate the “active” steps on the fly based on the answers. This supports both linear and branching paths as well as skipping multiple screens if needed.
- Flow Manager Component
Create aFlowManagercomponent that:
Manages the Current Step:Holds the current step index (or a pointer to the current step in the filtered config).
Stores Answers:Keeps a local state object (or uses a context provider) to store user responses.
Handles Navigation:Provides functions (e.g.,goNext(),goBack()) that update the step index, while re-evaluating conditions and triggering any required animations.
Renders the Current Step:Dynamically renders the component for the current step, passing down:Callbacks to update answers.Navigation functions.Any extra props (e.g., for custom behaviors).
Callbacks to update answers.
Navigation functions.
Any extra props (e.g., for custom behaviors).
Manages the Current Step:Holds the current step index (or a pointer to the current step in the filtered config).
Stores Answers:Keeps a local state object (or uses a context provider) to store user responses.
Handles Navigation:Provides functions (e.g.,goNext(),goBack()) that update the step index, while re-evaluating conditions and triggering any required animations.
Renders the Current Step:Dynamically renders the component for the current step, passing down:
Callbacks to update answers.
Navigation functions.
Any extra props (e.g., for custom behaviors).
Callbacks to update answers.
Navigation functions.
Any extra props (e.g., for custom behaviors).
A simplified pseudocode outline might look like this:
────────────────────────────────────────────────────────────────────
jsxCopy codeimport React, { useState, createContext, useContext } from "react";
import { Animated, View } from "react-native";
import { onboardingFlow } from "";
// Create a Flow Context
const FlowContext = createContext();
export const useFlow = () => useContext(FlowContext);
export const FlowManager = ({ flowConfig, onComplete }) => {
const [currentIndex, setCurrentIndex] = useState(0);
const [answers, setAnswers] = useState({});
// Function to update answers
const updateAnswer = (key, value) => {
setAnswers((prev) => ({ ...prev, [key]: value }));
};
// Calculate the filtered steps based on conditions
const activeSteps = flowConfig.filter(
(step) => !step.condition || step.condition(answers)
);
const currentStep = activeSteps[currentIndex];
// Navigation functions
const goNext = () => {
if (currentIndex + 1 < activeSteps.length) {
setCurrentIndex(currentIndex + 1);
} else {
// Completed the flow
onComplete(answers);
}
};
const goBack = () => {
if (currentIndex > 0) setCurrentIndex(currentIndex - 1);
};
// (Optional) Implement animated transitions here using React Native's Animated API.
// For example, you can wrap the currentStep component in an Animated.View
// and animate its opacity or position on change.
return (
<FlowContext.Provider value={{ answers, updateAnswer, goNext, goBack }}>
<View style={{ flex: 1 }}>
<ProgressBar currentStep={currentIndex + 1} totalSteps={activeSteps.length} />
<Animated.View style={{ flex: 1 }}>
{/* Render the current step component. */}
{currentStep && <currentStep.component />}
</Animated.View>
</FlowContext.Provider>
);
};
Key Points:
Persistent Progress Bar:TheProgressBarcomponent receives the current step and total steps so it can display progress (and animate if needed).
Custom Animations:By keeping the entire flow inside one native screen, you can use the Animated API (or Reanimated) to animate the transitions between step components.
Back Navigation:ThegoBackfunction lets you intercept native back gestures (if desired, you might disable the default gesture or override it to callgoBack()), ensuring the user only moves within the flow.
Persistent Progress Bar:TheProgressBarcomponent receives the current step and total steps so it can display progress (and animate if needed).
Custom Animations:By keeping the entire flow inside one native screen, you can use the Animated API (or Reanimated) to animate the transitions between step components.
Back Navigation:ThegoBackfunction lets you intercept native back gestures (if desired, you might disable the default gesture or override it to callgoBack()), ensuring the user only moves within the flow.
- Extensibility & Customization
Any JSX Component:Each step’scomponentcan be any valid React component. This allows you to mix in custom behavior (e.g., image uploads, multimedia content) without changing the flow logic.
Animation Options:If different steps need custom animations, you can extend the config to pass animation parameters that theFlowManageruses during transitions.
Conditional Branching:The condition functions give you full control over which steps are included. This allows for not only skipping a screen but also skipping subsequent screens if needed. You could even design the conditions to “jump” the flow index further if that suits your requirements.
Any JSX Component:Each step’scomponentcan be any valid React component. This allows you to mix in custom behavior (e.g., image uploads, multimedia content) without changing the flow logic.
Animation Options:If different steps need custom animations, you can extend the config to pass animation parameters that theFlowManageruses during transitions.
Conditional Branching:The condition functions give you full control over which steps are included. This allows for not only skipping a screen but also skipping subsequent screens if needed. You could even design the conditions to “jump” the flow index further if that suits your requirements.
- Integration with React Navigation
Since you want to avoid native navigation animations affecting the progress bar:
Single Navigation Route for Flows:Place the entire flow inside one React Navigation route (e.g.,FlowScreen). Once the flow completes, you can navigate to another route (like the main part of your app).
Override Swipe Gestures:If necessary, disable or override the native swipe back gesture on this route so that going “back” only navigates within the flow rather than leaving it.
Single Navigation Route for Flows:Place the entire flow inside one React Navigation route (e.g.,FlowScreen). Once the flow completes, you can navigate to another route (like the main part of your app).
Override Swipe Gestures:If necessary, disable or override the native swipe back gesture on this route so that going “back” only navigates within the flow rather than leaving it.
Final Thoughts
This design offers:
Modularity:Easily define new flows (or modify existing ones) by simply adjusting the flow configuration.
Dynamic & Conditional Flow Control:Conditions in your config allow for branching and skipping.
Smooth UX:Keeping the progress bar and flow container fixed ensures that transitions feel like a continuous experience (similar to ).
Extensibility:Any JSX component can serve as a step, and you have a centralized state management solution through context.
Modularity:Easily define new flows (or modify existing ones) by simply adjusting the flow configuration.
Dynamic & Conditional Flow Control:Conditions in your config allow for branching and skipping.
Smooth UX:Keeping the progress bar and flow container fixed ensures that transitions feel like a continuous experience (similar to ).
Extensibility:Any JSX component can serve as a step, and you have a centralized state management solution through context.
Let me know if you have any questions or need further clarification on any part of this design!