Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@bam.tech/flow-navigator
Advanced tools
Flow Navigator provides a simplified API for managing navigation flows in your React Native applications with React Navigation. It abstracts the complexity of flow management, allowing individual screens to navigate through the flow using simple methods like goToNextStep
and goToPreviousStep
, without the need to understand the entire navigation stack, or knowing which page exactly is the next one.
The flow navigator is built on top of react-navigation's native stack navigator. So it requires both react-navigation and the native stack navigator installed.
To install the flow navigator, run:
yarn add @bam.tech/flow-navigator
# or
npm install @bam.tech/flow-navigator
import { createFlowNavigator } from '@bam.tech/flow-navigator';
const FlowNavigator = createFlowNavigator();
export const FlowNavigatorExample = () => {
// Define your screens and their order in the flow
return (
<FlowNavigator.Navigator>
<FlowNavigator.Screen name="Step1" component={Step1Page} />
<FlowNavigator.Screen name="Step2" component={Step2Page} />
<FlowNavigator.Screen name="Step3" component={Step2Page} />
</FlowNavigator.Navigator>
);
};
In each screen component, you can navigate through the flow using:
import { useFlow } from '@bam.tech/flow-navigator';
const Step1Page = () => {
const { goToNextStep, goToPreviousStep, currentStep } = useFlow();
return (
<Button title="Go to next page" onPress={() => goToNextStep()} />
)
};
You can find a fully working example in the example folder.
In certain scenarios, a flow may include steps that are conditional. These steps might be dependent on user-specific conditions or based on whether certain actions have already been completed. You can manage such conditional steps declaratively in your navigation flow.
Here's an example where "Step 2" is conditionally displayed based on the hasToPassStep2 variable. This variable could be a piece of data fetched from the backend or a state within your application. In our case, we use jotai to store our user data locally.
import { createFlowNavigator } from '@bam.tech/flow-navigator';
export const flagAtom = atom(false);
const FlowNavigator = createFlowNavigator();
export const FlowNavigatorExample = () => {
const [flag] = useAtom(flagAtom);
return (
<FlowNavigator.Navigator>
<FlowNavigator.Screen name="Step1" component={Step1Page} />
{flag && <FlowNavigator.Screen name="Step2" component={Step2Page} />}
<FlowNavigator.Screen name="Step3" component={Step3Page} />
</FlowNavigator.Navigator>
);
};
In this example, the Step2 screen is only included in the flow if hasToPassStep2 evaluates to true.
You can enable or disable routes at anytime in your flow by setting your boolean state: setFlag(false)
import { useFlow } from '@bam.tech/flow-navigator';
export const Step1Page = () => {
const {goBack, goToNextStep} = useFlow();
const [flag] = useAtom(flagAtom);
const onNextPress = async () => {
setFlag(false);
goToNextStep();
};
const onBackPress = () => {
goBack();
};
return (
<View style={styles.container}>
<Text style={styles.pageTitle}>Current page: 1</Text>
<FlowInfos />
<Button title="next" onPress={onNextPress} />
<Button title="back" onPress={onBackPress} />
</View>
);
};
You can check out a fully working example in the example folder
In some scenarios, a single step in a flow may encompass several screens. To group these screens within one step, you have a couple of options: using Groups or Nested navigators.
Examples of both approaches can be found in the example folder.
We recommend using groups if they suit your use-case. However, one limitation to note is that the currentStep
will reflect the name of the screen that is currently focused, not the group name. So all the screens in the step won't have the same currentStep
value. With nested navigator, currentStep
is the name of the subnavigator, which provides a more cohesive representation of the step. Note that all the pages of a subnavigator will correspond to one increment of the progress index, that will stay constant throughout the whole step.
Flows are sequences of pages with a pre-defined order, guiding users through a specific process within your app. Whether complex or straightforward, flows are a fundamental part of the user experience in many applications. Here are some common examples where Flow Navigator can be particularly useful:
The Flow Navigator is built upon the foundation of the native stack, it inherits the same API.
Inside a screen defined below a Flow Navigator, you can use the useFlow
useFlow
provides the following helpers:
goToNextStep
: To navigate to the next step in the flow, based on the order of the screens in the navigation flow.goToPreviousStep
: To navigate to the previous step in the flow, based on the order of the screens in the navigation flow.quitFlow
: To exit the flow.useFlow
also provides information about the current step of the flow. It contains the following properties:
currentStep
: A string representing the identifier of the current step in the flow. Based on the name of the screen.progress
: A number indicating the progress through the flow. It is calculated as the ratio of the current index to the total number of routes.canGoToPreviousStep
: A boolean indicating whether navigation to a previous step is possible.canGoToNextStep
: A boolean indicating whether navigation to the next step is possible.Pull requests and feature suggestions are more than welcome!
You can try out your changes in the example folder. Use yarn link to try out your local library version:
@bam.tech/flow-navigator
, run cd packages/lib
yarn link
cd packages/example
yarn link "@bam.tech/flow-navigator"
yarn transpile:lib
cd packages/example
yarn unlink "@bam.tech/flow-navigator"
yarn install
git tag vx.x.x && git push --tags
yarn publish:lib
FAQs
A flow navigator for react-navigation
The npm package @bam.tech/flow-navigator receives a total of 215 weekly downloads. As such, @bam.tech/flow-navigator popularity was classified as not popular.
We found that @bam.tech/flow-navigator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 21 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.