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

@heytea/taro-router-rn

v0.4.16

Published

taro-router-rn

Downloads

2

Readme

@heytea/taro-router-rn

Install

  1. add @heytea/taro-router-rn to your project

    $ npm i @heytea/taro-router-rn
  2. add compile setting to your config/index.js file

    class BuildPlugin {
        apply(builder) {
            builder.hooks.beforeBuild.tap('BuildPlugin', (config) => {
              console.log('process.env.TARO_ENV', process.env.TARO_ENV)
              if (process.env.TARO_ENV !== 'rn') {
                  return;
              }
              // 初始化app.js文件
              const path = __dirname + '/../rn_temp/';
              const fileName = 'app.js';
              const fileExist = fs.existsSync(path + fileName);
              if (!fileExist) {
                  const pathExist = fs.existsSync(path);
                  if (!pathExist) {
                    fs.mkdirSync(path);
                  }
                  fs.writeFileSync(path + fileName, '');
              }
              // 监听rn_temp/app.js的变化,将 @tarojs/taro-router-rn 替换为 @heytea/taro-router-rn
              const watcher = fs.watch(path + fileName, (event, file) => {
                  console.log('beforeBuild event', event);
                  console.log('beforeBuild file', file);
                  if (event === 'change') {
                  fs.readFile(path + fileName, (err, data) => {
                      if (err)
                        return
                      const codeStr = data.toString();
                      if (codeStr === '')
                        return
                      if (codeStr.indexOf('@heytea/taro-router-rn') !== -1) {
                      // if (process.env.TARO_APP_API === 'prod') {
                      //    watcher.close();
                      // }
                      // watcher.close();
                        return
                      }
                      const newCode = codeStr.replace('@tarojs/taro-router-rn', '@heytea/taro-router-rn')
                      fs.writeFile(path + fileName, newCode, (err) => {
                      console.log('beforeBuild write new code, err', err);
                      })
                  })
                  }
              })
              })
              // 这个设置不生效,Taro里面没有调用
              builder.hooks.afterBuild.tap('BuildPlugin', (stats) => {
              // TODO: 去除
              // console.log('afterBuild', stats)
              })
          }
        }
    
    
    const config = { 
        plugins: [
            new BuildPlugin()
        ],
    }

Run

$ yarn dev:rn-api-dev

喜茶增强功能

  1. react-navigation 升级至 4.x 和 5.x,目前主要维护在 4.x,当然 5.x 支持 hooks,如果需要支持 Taro.useRouter,则需要使用 5.x 版本,同时还需修改 @tarojs/taro-rn 里的内容,涉及到多个源码包的改动,暂未实施开展。Taro 文档传送门:http://taro-docs.jd.com/taro/docs/hooks/#userouter
  2. 补充 window RN端配置 navigationStyle='custom',原 Taro 不支持 RN。Taro 文档传送门:http://taro-docs.jd.com/taro/docs/next/tutorial/#window
  3. 完善RN端 Taro.setTabBarStyle,原 Taro 未实现。Taro 文档传送门:http://taro-docs.jd.com/taro/docs/1.3.42/apis/interface/tabbar/setTabBarStyle/

待定:

  1. 移除了 ScrollView 作为父容器,原 Taro 使用 ScrollView 作为父容器来支持 Taro.startPullDownRefresh、Taro.stopPullDownRefresh。这项功能可能会导致子容器的高度发生变化。我们在考虑是否使用 native 代码进行实现,然后以 react-native 插件的形式提供这个原生能力。

喜茶添加功能

由于 react-navigation 默认的标题栏实现并不符合我们当前的需求,所以针对 RN 端添加了一些定制标题栏的能力,同时考虑到不能影响微信小程序等其它端的编译,所以在 window/config 下,增加 rn 属性,用于配置 RN 的专属能力。

该自定义导航条同时支持 Taro.setNavigationBarTitle 来设置标题文字,保持与小程序端在通用API上的对齐。相关配置API,查看下面注释。

在 App.js 的 config 下配置

  window: {
    backgroundTextStyle: 'light',
    navigationBarBackgroundColor: '#fff',
    navigationBarTitleText: '',
    navigationBarTextStyle: 'black',
    enablePullDownRefresh: true,
    // 增加 rn,喜茶自定义
    rn: {
      // 手机状态栏
      statusBar: { 
        backgroundColor: 'blue', // 状态栏背景色
        barStyle: 'light-content', // 状态栏文本主题
        translucent: false, // 指定状态栏是否透明。设置为true时,应用会延伸到状态栏之下绘制(即所谓“沉浸式”——被状态栏遮住一部分)。常和带有半透明背景色的状态栏搭配使用。
      }, 
      // 标题文本样式
      navigationBarTitleStyle: {
        color: '',
        fontSize: 13,
        fontFamily: 'xxx',
        fontWeight: '400',
      },
      navigationBarBackgroundColor: '#fff', // 导航条背景色
      navigationBarHeight: 50, // 导航条高度
      navigationBarShadow: false, // 导航条是否有阴影
      // 导航条底线样式
      navigationBarBottomStyle: {
        height: 2,
        width: '100%',
        backgroundColor: '#eee',
      },
      navigationBarTitlePosition: 'left', // 导航栏标题位置,'left', 'center'
      navigationBarBackIcon: '', // 导航栏返回按钮图标,支持http和require
      // 导航栏菜单按钮
      navigationBarMenus: [
        {
          icon: '', // 图片, 支持http和require, 当设置图片时,文字不显示
          text: '', // 文字,当设置图片时text不显示
          color: '', // 文字颜色
          click: () => {}, // 点击回调
        },
      ], 
    },
  },

或者在页面的 config 下添加 rn: {},它的会覆盖 window.config.rn

export default class HomeScreen extends React.Component<IProps> {
  static config = {
    rn: {
      navigationBarMenus: [
        {
          text: '按钮1',
          color: '#9e9e9e',
          click: () => {
            console.log('按钮1');
          },
        },
        {
          icon: 'http://static.heytea.com/taro_trial/v1/img/bar/home-icon-normal.png',
          text: '按钮2',
          color: '#9e9e9e',
          click: () => {
            console.log('按钮2');
          },
        },
      ],
    },
  };