Added web support

This commit is contained in:
2019-07-05 11:35:56 +02:00
parent 59cb7142e3
commit ffa64f3ef1
11 changed files with 133 additions and 70 deletions

View File

@@ -8,12 +8,12 @@
"license": "MIT",
"dependencies": {
"react-native-json-tree": "^1.2.0",
"styled-components": "^4.3.1"
"styled-components": "^5.0.0-beta.8"
},
"peerDependencies": {
"prop-types": "^15.6.0",
"react": "^16.8.3",
"react-native": "^0.59.8"
"prop-types": "^15.6.0",
"react": "^16.8.3",
"react-native": "^0.59.8"
},
"devDependencies": {}
}

View File

@@ -1,4 +1,4 @@
import React, { Fragment } from 'react';
import React, { Fragment, createRef } from 'react';
import styled from 'styled-components/native';
import JSONTree from 'react-native-json-tree';
import {
@@ -102,28 +102,32 @@ const Console = ({
logs,
includeStackTrace,
filter = [],
}) => (
<ScrollView
ref={ref => this.scrollView = ref}
onContentSizeChange={(contentWidth, contentHeight)=>{
this.scrollView.scrollToEnd({animated: true});
}}
>
<Wrapper>
{logs.filter(l => filter.includes(l.type)).map((log, i) => (
<Row key={i}>
<Emphasis color={getColor(log.type)}>
{log.type}
</Emphasis>
<OutputList
items={log.data}
includeStackTrace={includeStackTrace}
color={getColor(log.type)}
/>
</Row>
))}
</Wrapper>
</ScrollView>
);
}) => {
// const ref = createRef();
return (
<ScrollView
onContentSizeChange={(contentWidth, contentHeight)=>{
/*if (ref.current) {
ref.current.scrollView.scrollToEnd({animated: true});
}*/
}}
>
<Wrapper>
{logs.filter(l => filter.includes(l.type)).map((log, i) => (
<Row key={i}>
<Emphasis color={getColor(log.type)}>
{log.type}
</Emphasis>
<OutputList
items={log.data}
includeStackTrace={includeStackTrace}
color={getColor(log.type)}
/>
</Row>
))}
</Wrapper>
</ScrollView>
);
};
export default Console;

View File

@@ -1,12 +1,11 @@
import React, { Component } from 'react';
import {
Button,
Modal,
SafeAreaView,
KeyboardAvoidingView,
} from 'react-native';
import events from '../../events';
import DevTool from './index';
import Modal from '../base/Modal';
class Events extends Component {

View File

@@ -0,0 +1,5 @@
import {
Modal
} from 'react-native';
export default Modal;

View File

@@ -0,0 +1,41 @@
import React, { useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
import styled from 'styled-components';
const Wrapper = styled.div`
position: fixed;
background: #fff;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
`;
const Modal = ({
visible,
children
}) => {
const [root, setRoot] = useState();
useEffect(() => {
const elm = document.createElement('div');
document.body.appendChild(elm);
setRoot(elm);
}, []);
const elm = visible ? (
<Wrapper>{children}</Wrapper>
) : null;
if (!root) {
return null;
}
return createPortal(
elm,
root,
);
};
export default Modal;

View File

@@ -3,18 +3,15 @@ import {
SafeAreaView,
TouchableOpacity,
} from 'react-native';
import styled from 'styled-components/native';
import State from '../../data/State';
import Button from './Button';
import Row from '../Row';
import Icon from '../Icon';
import Modal from '../Modal';
import {
Body,
} from '../text';
const Modal = styled.Modal`
`;
const Selector = ({
multiSelect = false,
onSelect,

View File

@@ -27,6 +27,9 @@ class Log {
}
log(type, data, keep) {
if (data && data[0] && data[0].indexOf && data[0].indexOf('Warning: Using the "className" prop on') === 0) {
return;
}
const entry = {
type,
data,
@@ -68,9 +71,11 @@ class Log {
debug: (...data) => this.debug(data, keep),
verbose: (...data) => this.debug(data, keep),
};
ErrorUtils.setGlobalHandler((err, fatal) => {
this.error([err], keep);
});
if (global.ErrorUtils) {
global.ErrorUtils.setGlobalHandler((err, fatal) => {
this.error([err], keep);
});
}
}
detach() {