All Projects → vonovak → React Navigation Backhandler

vonovak / React Navigation Backhandler

Licence: mit
Easily handle Android back button behavior with React-Navigation.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Navigation Backhandler

Gas Oil Mixture Mobile
Mobile app for calculation of gasoline/oil ratio for 2 stroke engines built with React Native.
Stars: ✭ 61 (-65.54%)
Mutual labels:  react-navigation
Expo Disneyplus
Disney+ UI Clone with React Native & Expo
Stars: ✭ 130 (-26.55%)
Mutual labels:  react-navigation
Typescript React Native Starter
A highly scalable foundation with a focus on best pratices and simplicity to start your React Native project in seconds.
Stars: ✭ 141 (-20.34%)
Mutual labels:  react-navigation
Lego Expo
Play with Lego bricks anywhere using Expo
Stars: ✭ 65 (-63.28%)
Mutual labels:  react-navigation
Jmusic
重构一款音乐app
Stars: ✭ 108 (-38.98%)
Mutual labels:  react-navigation
React Native Navigation Animation
Transition navigation component for React Native
Stars: ✭ 133 (-24.86%)
Mutual labels:  react-navigation
Mobile Boilerplate
React Native boilerplate (TypeScript, MobX-State-Tree, NativeBase, React Navigation, Enzyme) by Prominent Edge
Stars: ✭ 57 (-67.8%)
Mutual labels:  react-navigation
Slopeninja Native
 Slope Ninja App 🎿❄️⛄️
Stars: ✭ 160 (-9.6%)
Mutual labels:  react-navigation
Rnexample
一个基于mobx、react-navigation、teaset的react-native框架
Stars: ✭ 114 (-35.59%)
Mutual labels:  react-navigation
React Native Feature Boilerplate
Feature based Architecture for developing Scalable React Native Apps 🚀 using react, redux, sagas and hooks
Stars: ✭ 139 (-21.47%)
Mutual labels:  react-navigation
Book Of Spices
An educational app to help you learn about spices, built on top of react-native, react-native-navigation from wix and lottie-react-native for animations.
Stars: ✭ 94 (-46.89%)
Mutual labels:  react-navigation
Reactnativeauth
Mobile user authentication flow with React Native, Expo, and AWS Amplify: Sign In, Sign Up, Confirm Sign Up, Forget Password, Reset Password.
Stars: ✭ 108 (-38.98%)
Mutual labels:  react-navigation
Yaba Social
Yet Another Boilerplate App showing off react-navigation and the excellent new tools from Apollo
Stars: ✭ 133 (-24.86%)
Mutual labels:  react-navigation
Re Navigate
Example of React Native Navigation with re-frame/re-natal
Stars: ✭ 61 (-65.54%)
Mutual labels:  react-navigation
React Native Screens
Native navigation primitives for your React Native app.
Stars: ✭ 2,148 (+1113.56%)
Mutual labels:  react-navigation
Dooboo Native Ts
Complete boilerplate for react-native app. Contains, typescript, react-hook, context-api, ts-jest, localization, navigation and etc.
Stars: ✭ 61 (-65.54%)
Mutual labels:  react-navigation
React Navigation Magic Move
Bindings for using react-navigation with react-native-magic-move 🐰🎩✨
Stars: ✭ 132 (-25.42%)
Mutual labels:  react-navigation
Reactnavigationrelaymodern
React Navigation integration with Relay
Stars: ✭ 170 (-3.95%)
Mutual labels:  react-navigation
Redux React Navigation Demos
React-Native + Redux + Redux-Persist + React Navigation ( Authentication Flow with Redux demos)
Stars: ✭ 151 (-14.69%)
Mutual labels:  react-navigation
React Native Boilerplate
A React Native boilerplate with Expo, Redux, React Navigation, Styled Components and some 💕 included.
Stars: ✭ 135 (-23.73%)
Mutual labels:  react-navigation

react-navigation-backhandler

Easily handle Android back button behavior with React-Navigation.

NOTE use version 1 of this package for react-navigation version 4 and lower

use version 2 of this package for react-navigation version 5

Installation

Install with npm:

$ npm install react-navigation-backhandler

Install with yarn:

$ yarn add react-navigation-backhandler

Usage

The following snippet demonstrates the usage. Note that onBackButtonPressAndroid will only be called if SomeComponent is placed in a screen that is focused (the one user is directly interacting with).

Behind the scenes, the onBackButtonPressAndroid handler is registered before a screen is focused, and unregistered before going away from it, leaving you with a declarative interface to interact with. Internally, this package uses apis that are provided by react-navigation.

You may use useAndroidBackHandler or AndroidBackHandler component anywhere in your app's React tree, it does not need to be placed directly in the screen component.

There are two ways of using this library:

  1. As hook
  2. As component

Use as hook

import { useAndroidBackHandler } from "react-navigation-backhandler";

const SomeComponent = () => {
  useAndroidBackHandler(() => {
    /*
     *   Returning `true` denotes that we have handled the event,
     *   and react-navigation's lister will not get called, thus not popping the screen.
     *
     *   Returning `false` will cause the event to bubble up and react-navigation's listener will pop the screen.
     * */

    if (youWantToHandleTheBackButtonPress) {
      // do something
      return true;
    }

    return false;
  });

  return <BodyOfYourScreen />;
};

Use as component

Note: You can also use the component "inline" without children: <AndroidBackHandler onBackPress={this.onBackButtonPressAndroid} />

import { AndroidBackHandler } from "react-navigation-backhandler";

class SomeComponent extends React.Component {
  onBackButtonPressAndroid = () => {
    /*
     *   Returning `true` from `onBackButtonPressAndroid` denotes that we have handled the event,
     *   and react-navigation's lister will not get called, thus not popping the screen.
     *
     *   Returning `false` will cause the event to bubble up and react-navigation's listener will pop the screen.
     * */

    if (youWantToHandleTheBackButtonPress) {
      // do something
      return true;
    }

    return false;
  };

  render() {
    return (
      <AndroidBackHandler onBackPress={this.onBackButtonPressAndroid}>
        <BodyOfYourScreen />
      </AndroidBackHandler>
    );
  }
}

Warning

The package was only tested to be used in screens in stack navigator, other use cases may not work.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].