mirror of
https://github.com/morten-olsen/react-native-debug-console.git
synced 2026-02-08 00:36:26 +01:00
update
This commit is contained in:
10
demo/App.js
10
demo/App.js
@@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
Button,
|
||||
KeyboardAvoidingView,
|
||||
@@ -17,7 +16,7 @@ import {
|
||||
} from 'react-native-debug-console';
|
||||
|
||||
network.attach();
|
||||
log.attach();
|
||||
log.attach(true);
|
||||
|
||||
console.log('fooo');
|
||||
let xhr = new XMLHttpRequest();
|
||||
@@ -117,8 +116,13 @@ export default class App extends React.Component {
|
||||
style={{
|
||||
flex: 1,
|
||||
}}
|
||||
storageProvider={AsyncStorage}
|
||||
context={global}
|
||||
/>
|
||||
<DevToolModal
|
||||
storageProvider={AsyncStorage}
|
||||
context={global}
|
||||
/>
|
||||
<DevToolModal storage={AsyncStorage} />
|
||||
</KeyboardAvoidingView>
|
||||
</SafeAreaView>
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
StyleSheet,
|
||||
View,
|
||||
TextInput,
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import styled from 'styled-components/native';
|
||||
import { createContext } from '../../../console';
|
||||
@@ -33,11 +34,29 @@ const styles = StyleSheet.create({
|
||||
|
||||
const Input = ({
|
||||
provider,
|
||||
logs,
|
||||
context: baseContext,
|
||||
}) => {
|
||||
const [text, setText] = useState('');
|
||||
const [history, setHistory] = useState([]);
|
||||
const [historyOffset, setHistoryOffset] = useState();
|
||||
|
||||
const send = () => {
|
||||
const newHistory = [...history, text];
|
||||
const context = createContext({
|
||||
logProvider: provider,
|
||||
}, baseContext);
|
||||
const contextKeys = Object.keys(context);
|
||||
const contextValues = Object.values(context);
|
||||
const fn = new Function(...contextKeys, text);
|
||||
try {
|
||||
fn(...contextValues);
|
||||
setText('');
|
||||
setHistoryOffset(undefined);
|
||||
setHistory(newHistory);
|
||||
} catch (err) {
|
||||
provider.error([err]);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Button
|
||||
@@ -75,25 +94,16 @@ const Input = ({
|
||||
style={styles.input}
|
||||
value={text}
|
||||
onChangeText={text => setText(text)}
|
||||
/>
|
||||
<Button
|
||||
onPress={() => {
|
||||
const newHistory = [...history, text];
|
||||
const context = createContext({
|
||||
logProvider: provider,
|
||||
});
|
||||
const contextKeys = Object.keys(context);
|
||||
const contextValues = Object.values(context);
|
||||
const fn = new Function(...contextKeys, text);
|
||||
try {
|
||||
fn(...contextValues);
|
||||
setText('');
|
||||
setHistoryOffset(undefined);
|
||||
setHistory(newHistory);
|
||||
} catch (err) {
|
||||
provider.error([err]);
|
||||
onKeyPress={(evt) => {
|
||||
global.proxyConsole.log(Platform.OS === 'web' && evt.key === 'Enter' && evt.shiftKey);
|
||||
if (Platform.OS === 'web' && evt.key === 'Enter' && !evt.shiftKey) {
|
||||
send();
|
||||
return false;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
onPress={() => send()}
|
||||
>
|
||||
<Icon name="play" />
|
||||
</Button>
|
||||
|
||||
@@ -32,6 +32,7 @@ const initFilters = [
|
||||
const Console = ({
|
||||
includeStackTrace,
|
||||
provider,
|
||||
context,
|
||||
}) => {
|
||||
const logs = useLog(provider);
|
||||
const [filters, setFilters] = useState(initFilters);
|
||||
@@ -55,7 +56,7 @@ const Console = ({
|
||||
/>
|
||||
</Toolbar>
|
||||
<Output filter={filters.filter(f => f.selected).map(f => f.name)} logs={logs} includeStackTrace={includeStackTrace} />
|
||||
<Input provider={provider} />
|
||||
<Input provider={provider} context={context} />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ class Events extends Component {
|
||||
}}
|
||||
>
|
||||
<SafeAreaView
|
||||
forceInset={{ top: 'always', vertical: 'always' }}
|
||||
forceInset={{ top: 'always', vertical: 'always', bottom: 'always' }}
|
||||
style={{flex: 1}}
|
||||
>
|
||||
<KeyboardAvoidingView
|
||||
|
||||
@@ -24,6 +24,7 @@ const DevTool = ({
|
||||
onClose,
|
||||
logProvider = log,
|
||||
storageProvider,
|
||||
context = {},
|
||||
requestProvider = network,
|
||||
additionalTools = [],
|
||||
}) => {
|
||||
@@ -36,6 +37,7 @@ const DevTool = ({
|
||||
<Console
|
||||
includeStackTrace={includeStackTrace}
|
||||
provider={logProvider}
|
||||
context={context}
|
||||
/>
|
||||
),
|
||||
getData: log.get,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
export const createContext = ({
|
||||
logProvider,
|
||||
}) => ({
|
||||
}, baseContext = {}) => ({
|
||||
log: (...args) => logProvider.log(...args),
|
||||
clear: logProvider.clear,
|
||||
window: baseContext,
|
||||
global: baseContext,
|
||||
context: baseContext,
|
||||
});
|
||||
@@ -60,11 +60,12 @@ class Log {
|
||||
|
||||
handleError(err) {
|
||||
if (err && err.error) {
|
||||
this.error([err.error], true);
|
||||
this.error([err.error]);
|
||||
}
|
||||
}
|
||||
|
||||
attach(keep) {
|
||||
global.proxyConsole = proxyConsole;
|
||||
const redirected = Object.keys(proxyConsole).reduce((output, key) => ({
|
||||
...output,
|
||||
[key]: keep ? (...args) => proxyConsole[key](...args) : () => {},
|
||||
|
||||
Reference in New Issue
Block a user