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-shortcutmanager

v1.0.4

Published

This is a category for icon menu, desktop icon management

Downloads

13

Readme

ShortcutManager 管理 API(Reat Native 0.63 上测试开发)

React Native Version Version NPM

捷径管理 API:v 1.0.4 ,效果如图所示

waCPTP waCFFf

第一步安装
npm install react-native-shortcutmanager --save

RN 0.60 以下需要
react-native link react-native-shortcutmanager(或)
react-native unlink react-native-shortcutmanager
第二步,配置代码(注意导包)
没有请创建 MyReactPackage -> createNativeModules 并,注册
MainApplication -> packages.add(new MyReactPackage())

在代码 MyNativeModule.java 下,导包:import com.shortcut.manager.ExtraData; 添加如下代码
public MyNativeModule(ReactApplicationContext reactContext){
    ...
    //把 MainActivity.class 添加到连接库里 lib
    ExtraData.setActivityClass(MainActivity.class);
}

在代码 MainActivity.java 下,导包:import com.shortcut.manager.ShortcutManagerModule;
在生命周期 onCreate 和 onNewIntent 分别添加如下代码
@Override
public void onCreate(Bundle savedInstanceState) {
  ...
  //--添加这段代码
  ShortcutManagerModule.AppUninitiIntent(getIntent());
}
@Override
public void onNewIntent(final Intent intent) {
  ...
  //--添加这段代码
  ShortcutManagerModule.newIntent(intent);
}
第三步,拷贝图标
菜单图标(android\app\src\main\res\drawable)用 png 格式,放到此目录下,注意先调用 getIconWeightAndHeight
查看图标尺寸,单位 px

使用方法

import * as shortcutManager from 'react-native-shortcutmanager'

shortcutManager.addShortcut("这是菜单名1", "telephone", "这儿传递数据1")
.then((res)=>{
    alert("menuId:" + res);
    that.setState({menuId: res});
})
.catch((err)=>{
    alert("对不起,Android 版本不支持。")
});

shortcutManager.removeAllItem().then(()=>{
  alert('删除成功');
})
以下9个 API 用于菜单图标管理(9 API)
addShortcut -> 添加动态图标菜单
removeItem -> 移除指定项
removeAllItem -> 删除所有动态图标
getIconWeightAndHeight -> 获取菜单图标支持宽高
getShortcutList -> 获取菜单列表
updateShortcut -> 更新指定菜单
addPinShortcut -> 添加桌面菜单,需要权限
getPinShortcutList -> 获取添加(成功)桌面菜单
getExtraData -> 异步获取参数
getExtraDataHook -> 指定全局事件(Hook),回调方法(callback)
removeShortcutEvent -> 注销全局事件
参数除了通过 getExtraData 获取外,还可通过异步回调事件,事件名:ShortcutClick,参数:extra
因 componentDidMount 生命周期原因,APP 启动中,可考虑异步回调事件方式,改变路由等等。

代码如下:
//导入 react-native-shortcutmanager,就会注册,全局事件 Hook
componentDidMount(){
  shortcutManager.getExtraDataHook((data)=>{
    alert(data)
  })
}
//注销全局事件
shortcutManager.removeShortcutEvent()

菜单管理 APIs 详解

添加动态图标菜单
addShortcut(label, icon, extra)

参数说明
  label:菜单标题,长短标签都是此值(setShortLabel、setLongLabel)(必填)
  icon:菜单图标,无扩展名:因为 Android 带深色、浅色,图标最好带底色(Icon)(必填)
  extra:菜单传值(JSON,最好用 JSON.stringify(Object),序列成字符串)(必填)

返回值(通过 Promise)
  成功(then)返回菜单ID(menuId,是一个 UUID)
  失败(catch)返回错误对象(err) Tip: 9523 版本不支持,请使用(API 25 以上)
移除指定菜单项(仅限动态菜单,桌面图标自行移除)
removeItem(menuId)

参数说明
  menuId:菜单Id(添加菜单返回的 UUID,必填)

返回值(通过 Promise)
  成功(then)返回成功(true)
  失败(catch)返回错误对象(err)
    * code: 9523 版本不支持,请使用(API 25 以上)
    * code: -1 menuId 不能为空
移除所有菜单项(仅限动态菜单,桌面图标自行移除)
removeAllItem()

参数说明
  无参数

返回值(通过 Promise)
  成功(then)返回成功(true)
  失败(catch)返回错误对象(err) Tip: 9523 版本不支持,请使用(API 25 以上)
获取系统支持的图标宽高(设计图标前,先获取查看一下宽高 px)
getIconWeightAndHeight()

参数说明
  无参数

返回值(通过 Promise)
  成功(then)返回系统支持的 Icon (width、height),单位 px
  失败(catch)返回错误对象(err) Tip: 9523 版本不支持,请使用(API 25 以上)
获取所有菜单列表
getShortcutList()

参数说明
  无参数

返回值(通过 Promise)
  成功(then)返回菜单列表(size:0,result:[{id, label}])
  失败(catch)返回错误对象(err) Tip: 9523 版本不支持,请使用(API 25 以上)
根据菜单Id,更新指定菜单项
updateShortcut(menuId, label, icon, extra)

参数说明
  menuId:需要更新的菜单ID(必填)
  label:菜单标题(必填)
  icon:菜单图标(必填)
  extra:菜单传值(必填,不要传空字符串)

返回值(通过 Promise)
  成功(then)返回菜单ID(menuId,是一个 UUID)
  失败(catch)返回错误对象(err)
    * code: 9523 版本不支持,请使用(API 25 以上)
    * code: -1 menuId 不能为空
添加桌面图标(需要权限执行)
addPinShortcut(label, icon, extra)

参数说明
  label:图标的标题(必填)
  icon:图标(用上面的路径)(必填)
  extra:传递参数(JSON,最好用 JSON.stringify(Object),序列成字符串)(必填)

返回值(通过 Promise)
  成功(then)返回图标ID(iconId,是一个 UUID,可能因权限而失败,图标 ID 不一定有效)
  失败(catch)返回错误对象(err) Tip: 9523 版本不支持,请使用(API 25 以上)
    Tip:不知道是否成功,添加后需手工删除。
获取添加成功的桌面图标
getPinShortcutList()

参数说明
  无参数

返回值(通过 Promise)
  成功(then)返回图标ID(size:0,result:[{id, label}])
  失败(catch)返回错误对象(err) Tip: 9523 版本不支持,请使用(API 25 以上)
异步获取参数对象(可在 componentDidMount 里获取,以判断 APP 启动类型,做相应的事情)
getExtraData(callback)

参数说明
  callback:异步方法回调(extra)

例如(e.g):
componentDidMount(){
  var that = this;
  getExtraData((extra)=>{
    ...判断后做你的事情,如跳转路由传参,等等
  })
}
注意:参数只能获取一次,阅后即焚。
导入 react-native-shortcutmanager,就会注册,全局事件 Hook
getExtraDataHook(callback)

参数说明
  callback:异步方法回调(extra)

例如(e.g):
componentDidMount(){
  shortcutManager.getExtraDataHook((data)=>{
    alert(data)
  })
}
注销全局事件(Hook)
removeShortcutEvent()

参数说明
  无参数

例如(e.g):
componentWillUnmount(){
  shortcutManager.removeShortcutEvent()
}