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

rn-beginner-guidance-decorator

v1.0.3

Published

[![npm](https://img.shields.io/npm/v/rn-beginner-guidance-decorator.svg)](https://www.npmjs.com/package/rn-beginner-guidance-decorator) [![npm](https://img.shields.io/npm/dm/rn-beginner-guidance-decorator.svg)](https://www.npmjs.com/package/rn-beginner-gu

Downloads

6

Readme

rn-beginner-guidance-decorator

npm npm npm npm

这是一个可以更快速、简便地为 React Naitve App 添加新手引导的轻便 Decorator 。App 中可能有多个页面需要添加新手引导,且实现逻辑大同小异,如果每个页面都实现一遍,代码冗余,耦合度也高。使用该组件,只要在目标页面,按需注入需要的新手引导组件即可。

安装

使用 npm

npm install rn-beginner-guidance-decorator --save

yarn

yarn add rn-beginner-guidance-decorator

使用示例

import { injectGuidance } from 'rn-beginner-guidance-decorator';
import BeginnerGuidanceView from './components/BeginnerGuidanceView';

// 1 Decorator 方式
@injectGuidance(BeginnerGuidanceView, {displayName: 'HomePage', dismissEnabled: false})
export default class HomePage extends Component {
  ...
}

// 2 function 方式
class HomePage extends Component {}
or
const HomePage = () => {}
export default injectGuidance(BeginnerGuidanceView, {displayName: 'HomePage'})(HomePage)

涉及参数说明

Name             | Default     | Description ---------------- | ----------- | ----------- displayName | | 表示当前注入后的高阶组件名称,必须唯一,必传 dismissEnabled | true | 表示是否支持点击屏幕任意位置关闭引导组件

引导页组件的定义

参数 dismissEnabled 的默认值为 true,适用于不点击屏幕任一位置隐藏引导页的情况。如引导页存在多步骤操作,需要根据时机自定义隐藏,则引导页组件应向外暴露 onDismissprops。示例:

export default class NewerGuideDialog extends Component {
  static propTypes = {
    onDismiss: PropTypes.func, // 暴露该 props
  };

  /**
   * 按需调用 this.props.onDismiss() 来隐藏引导页
   **/
  handleDismiss = () => {
    const { onDismiss } = this.props;
    onDismiss && onDismiss();
  };

  render() {
    return (
      <View style={styles.root}>
        <Text style={styles.text} onPress={this.handleDismiss}>Dismiss</Text>
      </View>
    );
  }
}

同时在引用组件时,dismissEnabled 设置为 false。如:

import { injectGuidance } from 'rn-beginner-guidance-decorator';
import NewerGuideDialog from './components/NewerGuideDialog';

@injectGuidance(NewerGuideDialog, {displayName: 'HomePage', dismissEnabled: false})
export default class HomePage extends Component {
  ...
}

原则

  • 组件支持 Decorator 语法调用,前提是已经配置了相应的语法支持
  • 调用 injectGuidance(GuidanceComponent, {displayName})(TargetComponent) 注入时,displayName 是必传的,将用于生成高阶组件的名称和本地缓存标识位