npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-root-back-behavior

v1.0.4

Published

react native handle root screen hardware back press

Downloads

1

Readme

Original Intention

When using native Android apps, if you're in the root view of the Tab and hit the virtual Back button, you'll get a toast prompt that says "Press again to quit the app". When we're developing in React Native and using react-navigation to manage navigation, hitting the virtual Back key actually takes us to Stack.Navigator. To achieve the same effect, react-native-root-back-behavior was created.

Usage

Call it from within the rootScreen function:

import useRootBackBehavior from 'react-native-root-back-behavior'

const RootNavigator = () => {
  // add here, if omitted the param, the default is '再按一次退出应'.
  useRootBackBehavior()

  return (
    <Tab.Navigator screenOptions={screenOptions}>
      <Tab.Screen name="Home" options={{ title: '首页' }} component={HomePage} />
      <Tab.Screen name="Explore" options={{ title: '发现' }} component={ExplorePage} />
      <Tab.Screen name="LittleWorld" options={{ title: '小世界' }} component={LittleWorldPage} />
      <Tab.Screen name="Message" options={{ title: '消息' }} component={MessagePage} />
      <Tab.Screen name="Profile" options={{ title: '我的' }} component={ProfilePage} />
    </Tab.Navigator>
  )
}

初衷

在使用原生Android应用的时候,如果你处于 Tab 的根视图页面,点击虚拟返回按键时,会吐司提示"再按一次退出应用"。而当我们用 React Native 开发,使用 react-navigation 管理导航,点按虚拟返回键实际上是跳到上级 Stack.Navigator。为了达到同样的效果,于是就有了 react-native-root-back-behavior

使用

rootScreen 的函数里调用即可:

import useRootBackBehavior from 'react-native-root-back-behavior'

const RootNavigator = () => {
  // 加在这里,如果忽略参数, 默认是'再按一次退出应用'
  useRootBackBehavior()

  return (
    <Tab.Navigator screenOptions={screenOptions}>
      <Tab.Screen name="Home" options={{ title: '首页' }} component={HomePage} />
      <Tab.Screen name="Explore" options={{ title: '发现' }} component={ExplorePage} />
      <Tab.Screen name="LittleWorld" options={{ title: '小世界' }} component={LittleWorldPage} />
      <Tab.Screen name="Message" options={{ title: '消息' }} component={MessagePage} />
      <Tab.Screen name="Profile" options={{ title: '我的' }} component={ProfilePage} />
    </Tab.Navigator>
  )
}