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-split-screen

v0.1.2

Published

![预览图](https://s3.bmp.ovh/imgs/2022/12/22/602e25854a2ff0af.gif)

Downloads

23

Readme

react-native-split-screen

预览图

基于 retyuireact-native-split-view-demo 提取和整理代码;

项目依赖于 react-navigation,分屏采用两个路由栈实现:

import { setMasterNavigator, setDetailNavigator } from 'react-native-split-screen'

// 注册不同的路由栈
export const RegisterStack = ({ isMaster, target, extendTarget }: ScreenStackType) => {
  return (
    <NavigationContainer
      independent
      ref={isMaster ? setMasterNavigator : setDetailNavigator}
    >
      <Stack.Navigator
        initialRouteName={target}
        screenOptions={{ headerBackTitleVisible: false }}
      >
        {Object.entries(RegisterScreen(screens, [target, ...extendTarget])).map(([key, value]) => (
          <Stack.Screen key={key} name={key} component={value} />
        ))}
      </Stack.Navigator>
    </NavigationContainer>
  )
}

全局路由初始化:

import { isTablet } from 'react-native-device-info'

export const Index = () => {
  const _isTablet = isTablet()
  return (
    <TabletContextProvider isTablet={_isTablet}>
      <NavigationContainer>
        ...
      </NavigationContainer>
    </TabletContextProvider>
  )
}

主路由页面:

import { navigate } from 'react-native-split-screen'

const SplitViewMaster: React.FC<{ navigation: any }> = ({ navigation }) => {
  return (
    <View style={styles.container}>
      {/* 默认路由提供的跳转方法 */}
      <Button label={'page'} onPress={() => navigation.navigate('page')} />
      {/* 主路由跳转至子路由,需要使用组件提供的 navigate 或 push 方法 */}
      <Button label={'SplitViewDetail'} onPress={() => navigate('SplitViewDetail')} />
    </View>
  )
}

分屏路由:

const SplitViewDetail: React.FC<{ navigation: any }> = ({ navigation }) => {
  return (
    <View style={styles.container}>
      <Text>SplitViewDetailScreen</Text>
    </View>
  )
}

合并之后的页面:

import { SplitView, useIsTablet } from 'react-native-split-screen'

const SplitViewScreen = () => {
  // 判断当前是否为平板
  const [isTablet] = useIsTablet()

  /**
   * 平板模式下采用分屏显示:
   * 左侧为主路由,一般为列表页,右侧为子路由,一般为详情页;
   * 非平板模式只显示主路由;
   * @param target       主路由名称
   * @param extendTarget 扩展路由名称 *注:需要将默认子路由注册到主路由的扩展路由里
   */
  return isTablet ? (
    <SplitView
      master={
        <RegisterStack
          isMaster
          target={'SplitViewMaster'}
          extendTarget={['SplitViewDetail', ...otherRoute]}
        />
      }
      detail={<RegisterStack target={'SplitViewDetail'} extendTarget={[...otherRoute]} />}
    />
  ) : (
    <RegisterStack isMaster target={'SplitViewMaster'} extendTarget={['SplitViewDetail', ...otherRoute]} />
  )
}