This commit is contained in:
2018-08-22 23:44:26 +02:00
parent 7e635595f3
commit c8f41d45ea
24 changed files with 352 additions and 163 deletions

View File

@@ -2,11 +2,15 @@ import React from 'react';
import {
StyleSheet,
View,
Alert,
Clipboard,
} from 'react-native';
import Tab from './Tab';
import Console from './Console';
import Requests from './Requests';
import Storage from './Storage';
import log from '../../log';
import network from '../../network';
const styles = StyleSheet.create({
container: {
@@ -18,22 +22,65 @@ const DevTool = ({
style,
includeStackTrace,
onClose,
}) => (
<View style={style || styles.container}>
<Tab
tabs={[{
name: 'Console',
view: <Console includeStackTrace={includeStackTrace} />,
}, {
name: 'Network',
view: <Requests />,
}, {
name: 'Storage',
view: <Storage />,
}]}
onClose={onClose}
/>
</View>
);
showNetwork = true,
showStorage = true,
showConsole = true,
additionTools = [],
}) => {
const views = [];
if (showConsole) {
views.push({
name: 'Console',
view: <Console includeStackTrace={includeStackTrace} />,
getData: log.get,
});
}
if (showNetwork) {
views.push({
name: 'Network',
view: <Requests />,
getData: network.get,
});
}
if (showStorage) {
views.push({
name: 'Storage',
view: <Storage />,
});
}
additionTools.forEach(tool => {
views.push(tool);
});
const getData = async () => {
const result = {};
for (let i = 0; i < views.length; i++) {
const view = views[i];
if (view.getData) {
result[view.name] = await view.getData();
}
};
Clipboard.setString(JSON.stringify(result, null, ' '));
Alert.alert(
'Copied to clipboard',
);
}
return (
<View style={style || styles.container}>
<Tab
tabs={views}
onClose={onClose}
onDownload={getData}
/>
</View>
);
};
export default DevTool;