{"id":16453722,"url":"https://github.com/vonovak/react-navigation-backhandler","last_synced_at":"2025-04-04T16:14:44.346Z","repository":{"id":41423603,"uuid":"125557032","full_name":"vonovak/react-navigation-backhandler","owner":"vonovak","description":"Easily handle Android back button behavior with React-Navigation.","archived":false,"fork":false,"pushed_at":"2023-11-21T07:21:01.000Z","size":32,"stargazers_count":200,"open_issues_count":1,"forks_count":27,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-25T03:22:08.791Z","etag":null,"topics":["react-native","react-navigation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vonovak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["vonovak"]}},"created_at":"2018-03-16T18:48:22.000Z","updated_at":"2024-06-18T15:19:16.405Z","dependencies_parsed_at":"2024-06-18T15:19:15.818Z","dependency_job_id":"9b86e2cb-31a3-4b71-b906-9bf520870965","html_url":"https://github.com/vonovak/react-navigation-backhandler","commit_stats":{"total_commits":37,"total_committers":10,"mean_commits":3.7,"dds":0.2432432432432432,"last_synced_commit":"bbe6a1c0894f9198214f0c7e8a4e3543a0a4f6ad"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonovak%2Freact-navigation-backhandler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonovak%2Freact-navigation-backhandler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonovak%2Freact-navigation-backhandler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonovak%2Freact-navigation-backhandler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vonovak","download_url":"https://codeload.github.com/vonovak/react-navigation-backhandler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208150,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react-native","react-navigation"],"created_at":"2024-10-11T10:16:36.791Z","updated_at":"2025-04-04T16:14:44.329Z","avatar_url":"https://github.com/vonovak.png","language":"JavaScript","funding_links":["https://github.com/sponsors/vonovak"],"categories":[],"sub_categories":[],"readme":"# react-navigation-backhandler\n\nEasily handle Android back button behavior with React-Navigation.\n\n\u003e NOTE use version 1 of this package for `react-navigation` version 4 and lower\n\u003e\n\u003e use version 2 of this package for `react-navigation` version 5 and later\n\n## Installation\n\nInstall with npm:\n\n```sh\n$ npm install react-navigation-backhandler\n```\n\nInstall with yarn:\n\n```sh\n$ yarn add react-navigation-backhandler\n```\n\n## Usage\n\nThe 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).\n\nBehind 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`.\n\nYou 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.\n\nThere are two ways of using this library:\n\n1. [As hook](#use-as-hook)\n1. [As component](#use-as-component)\n\n### Use as hook\n\n```js\nimport { useAndroidBackHandler } from \"react-navigation-backhandler\";\n\nconst SomeComponent = () =\u003e {\n  const onBackPress = useCallback(() =\u003e {\n    /*\n     *   Returning `true` denotes that we have handled the event,\n     *   and react-navigation's lister will not get called, thus not popping the screen.\n     *\n     *   Returning `false` will cause the event to bubble up and react-navigation's listener will pop the screen.\n     * */\n\n    if (youWantToHandleTheBackButtonPress) {\n      // do something\n      return true\n    }\n\n    return false\n  }, [])\n\n  useAndroidBackHandler(onBackPress)\n\n  return \u003cBodyOfYourScreen /\u003e\n}\n```\n\n### Use as component\n\n\u003e **Note:** You can also use the component \"inline\" without children: `\u003cAndroidBackHandler onBackPress={this.onBackButtonPressAndroid} /\u003e`\n\n```js\nimport { AndroidBackHandler } from \"react-navigation-backhandler\";\n\nclass SomeComponent extends React.Component {\n  onBackButtonPressAndroid = () =\u003e {\n    /*\n     *   Returning `true` from `onBackButtonPressAndroid` denotes that we have handled the event,\n     *   and react-navigation's lister will not get called, thus not popping the screen.\n     *\n     *   Returning `false` will cause the event to bubble up and react-navigation's listener will pop the screen.\n     * */\n\n    if (youWantToHandleTheBackButtonPress) {\n      // do something\n      return true;\n    }\n\n    return false;\n  };\n\n  render() {\n    return (\n      \u003cAndroidBackHandler onBackPress={this.onBackButtonPressAndroid}\u003e\n        \u003cBodyOfYourScreen /\u003e\n      \u003c/AndroidBackHandler\u003e\n    );\n  }\n}\n```\n\n## Warning\n\nThe package was only tested to be used in screens in stack navigator, other use cases may not work.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvonovak%2Freact-navigation-backhandler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvonovak%2Freact-navigation-backhandler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvonovak%2Freact-navigation-backhandler/lists"}