# react-native-debugtools

> react-native-debugtools是一个简单的针对RN开发实际需要而做的一个app端调试工具集，目前主要包括两个主要功能， - 切换测试环境 - 查看网络日志 其他计划中功能 - 扫描二维码打开Webview - 添加原生交互日志(针对原生RN混合开发模式)

Latest version **1.1.7** (published 2018-12-25) · 0 weekly downloads

## Install

```sh
npm install react-native-debugtools
pnpm add react-native-debugtools
yarn add react-native-debugtools
bun add react-native-debugtools
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.7 |
| Published | 2018-12-25 |
| First published | 2018-11-30 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | heioray |
| Keywords | react-native |

## Links

- npm: https://www.npmjs.com/package/react-native-debugtools
- Repository: https://github.com/ZhishengZhao/react-native-debugtools
- Homepage: https://github.com/ZhishengZhao/react-native-debugtools#readme
- Issues: https://github.com/ZhishengZhao/react-native-debugtools/issues
- npm.io page: https://npm.io/package/react-native-debugtools

## Dependencies (3)

- [react-native-storage](https://npm.io/package/react-native-storage.md) ^0.2.3
- [react-native-action-button](https://npm.io/package/react-native-action-button.md) ^2.8.5
- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) ^3.1.6

## Recent versions

- 1.1.7 (latest) — 2018-12-25
- 1.1.4 (alpha) — 2018-12-07
- 1.1.6 — 2018-12-07
- 1.1.5 — 2018-12-07
- 1.1.3 — 2018-12-07
- 1.1.2 — 2018-12-06
- 1.1.1 — 2018-12-06
- 1.1.0 — 2018-12-06
- 1.0.8 — 2018-12-03
- 1.0.7 — 2018-12-03
- 1.0.6 — 2018-11-30
- 1.0.5 — 2018-11-30
- 1.0.4 — 2018-11-30
- 1.0.3 — 2018-11-30
- 1.0.2 — 2018-11-30
- … 2 more at https://npm.io/package/react-native-debugtools/versions

## README

react-native-debugtools是一个简单的针对RN开发实际需要而做的一个app端调试工具集，目前主要包括两个主要功能，
- 切换测试环境
- 查看网络日志
其他计划中功能
- 扫描二维码打开Webview
- 添加原生交互日志(针对原生RN混合开发模式)


### 效果
![主界面](https://img2018.cnblogs.com/blog/461976/201812/461976-20181207172118519-1951404747.png)
![网络日志列表](https://img2018.cnblogs.com/blog/461976/201812/461976-20181207172136120-1033721915.png)
![日志详情](https://img2018.cnblogs.com/blog/461976/201812/461976-20181207172153508-529165139.png)
![切换环境](https://img2018.cnblogs.com/blog/461976/201812/461976-20181207172206370-2089394660.png)
![切换响应](https://img2018.cnblogs.com/blog/461976/201812/461976-20181207172215307-904724557.png)

### 使用方式
```bash
npm install react-native-debugtools --save
```
目前主要暴露出两个方法initDTs与generateDebugBtn以及两个对象debugRoute与storage，以下为具体使用Demo
```javascript
import {
  initDTs,
  debugRoute,
  generateDebugBtn,
  storage
} from 'react-native-debugtools'

class App extends Component {
  ...

  componentWillMount() {
    initDTs({
      envList: ['env1', 'env2', 'env3'],
      currentEnv: this.state.curEnv
    })
  }

  componentDidMount() {
    generateDebugBtn(this.props.navigation, null)
  }

  render() {
    return (
      <View style={styles.page}>
        <View style={styles.container_top}>
          <Text style={styles.welcome}>debug demos</Text>
        </View>
      </View>
    );
  }
}

const AppWithDebug = createStackNavigator({
  Home: {
    screen: App
  },
  ...debugRoute
});

export default class AppEntry extends Component {
    render() {
      return <AppWithDebug screenProps={ this.props }/>
  }
};
```


首先在项目路由中添加debug路由节点
```javascript
const AppWithDebug = createStackNavigator({
  Home: {
    screen: App
  },
  ...debugRoute
});
```

在你的项目Root组件中调用初始化函数，进行环境列表、当前环境的设置存储以及开启http监听器：
initDTs({
    envList: ['online', 'test', 'develop'], // 环境列表，如线上、测试、开发
    curEnv: 'online' // 指定当前环境未指定时，初始化默认选择环境列表第一项为当前环境
})

在根页面中调用generateDebugBtn函数，初始化debug控制容器
generateDebugBtn(navigation, envSwitchCallBack) // navigation即当前环境的this.props.navigation对象，envSwitchCallBack为切换环境之后的回调函数

---
_Source: https://npm.io/package/react-native-debugtools · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
