-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
16,791 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
nodeLinker: node-modules | ||
nmHoistingLimits: workspaces | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs | ||
spec: "@yarnpkg/plugin-interactive-tools" | ||
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs | ||
spec: "@yarnpkg/plugin-workspace-tools" | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.6.1.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,89 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { StyleSheet, View, Text } from 'react-native'; | ||
import { multiply } from 'react-native-xenon-inspector'; | ||
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; | ||
import XenonInspector from 'react-native-xenon-inspector'; | ||
|
||
export default function App() { | ||
const [result, setResult] = useState<number | undefined>(); | ||
|
||
useEffect(() => { | ||
multiply(3, 7).then(setResult); | ||
}, []); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Result: {result}</Text> | ||
<TouchableOpacity | ||
onPress={() => { | ||
fetch('https://jsonplaceholder.typicode.com/posts?userId=1') | ||
.then(res => res.json()) | ||
.then(console.log); | ||
}} | ||
> | ||
<Text>FetchAPI: Get posts</Text> | ||
</TouchableOpacity> | ||
|
||
<TouchableOpacity | ||
onPress={() => { | ||
fetch('https://jsonplaceholder.typicode.com/posts', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
title: 'foo', | ||
body: 'bar', | ||
userId: 1, | ||
}), | ||
headers: { | ||
'Content-type': 'application/json; charset=UTF-8', | ||
}, | ||
}) | ||
.then(res => res.json()) | ||
.then(console.log); | ||
}} | ||
> | ||
<Text>FetchAPI: Create post</Text> | ||
</TouchableOpacity> | ||
|
||
<TouchableOpacity | ||
onPress={() => { | ||
// Create WebSocket connection. | ||
const socket = new WebSocket('wss://echo.websocket.org'); | ||
|
||
const message = `Hello Server! It's ${new Date().toISOString()}`; | ||
|
||
// Connection opened | ||
socket.onopen = () => { | ||
socket.send(message); | ||
console.log('send', message); | ||
}; | ||
|
||
socket.onmessage = event => { | ||
console.log('onmessage', event.data); | ||
if (event.data === message) { | ||
socket.close(); | ||
} | ||
}; | ||
}} | ||
> | ||
<Text>Echo Websocket</Text> | ||
</TouchableOpacity> | ||
|
||
<TouchableOpacity | ||
onPress={() => { | ||
XenonInspector.show(); | ||
}} | ||
> | ||
<Text>Show Inspector</Text> | ||
</TouchableOpacity> | ||
|
||
<TouchableOpacity | ||
onPress={() => { | ||
XenonInspector.hide(); | ||
}} | ||
> | ||
<Text>Hide Inspector</Text> | ||
</TouchableOpacity> | ||
|
||
<XenonInspector.Component logInspectorAutoEnabled networkInspectorAutoEnabled /> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
box: { | ||
width: 60, | ||
height: 60, | ||
marginVertical: 20, | ||
alignItems: 'center', | ||
backgroundColor: 'white', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const NETWORK_INSPECTOR_REQUEST_HEADER = 'X-React-Native-Network-Inspector'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interface XMLHttpRequest { | ||
_interceptionId?: string; | ||
} | ||
|
||
declare module 'react-native/Libraries/WebSocket/NativeWebSocketModule' { | ||
interface NativeWebSocketModule extends NativeModule { | ||
connect( | ||
uri: string, | ||
protocols?: string | string[] | null, | ||
options?: { | ||
headers: { [headerName: string]: string }; | ||
[optionName: string]: any; | ||
} | null, | ||
socketId: number, | ||
): void; | ||
|
||
send(data: string, socketId: number): void; | ||
|
||
sendBinary(data: string, socketId: number): void; | ||
|
||
close(code: number, reason: string, socketId: number): void; | ||
|
||
addListener: (eventType: string) => void; | ||
removeListeners: (count: number) => void; | ||
} | ||
|
||
const NativeWebSocketModule: NativeWebSocketModule; | ||
export default NativeWebSocketModule; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as useLogInterceptor } from './useLogInterceptor'; | ||
export { default as useNetworkInterceptor } from './useNetworkInterceptor'; | ||
export { default as useScrollToBottom } from './useScrollToBottom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { useImmer } from 'use-immer'; | ||
import LogInterceptor from '../interceptors/LogInterceptor'; | ||
import type { LogRecord } from '../types'; | ||
|
||
interface LogInterceptorParams { | ||
autoEnabled?: boolean; | ||
} | ||
|
||
export default function useLogInterceptor(params: LogInterceptorParams) { | ||
const { autoEnabled = false } = params || {}; | ||
|
||
const [isInterceptorEnabled, setIsInterceptorEnabled] = useState(autoEnabled); | ||
|
||
const [logRecords, setLogRecords] = useImmer<LogRecord[]>([]); | ||
|
||
const clearAllRecords = () => { | ||
setLogRecords([]); | ||
}; | ||
|
||
const _isInterceptorEnabled = () => LogInterceptor.instance.isInterceptorEnabled; | ||
|
||
const enableInterception = useCallback(() => { | ||
if (_isInterceptorEnabled()) return; | ||
|
||
LogInterceptor.instance | ||
.setCallback((type, args) => { | ||
setLogRecords(draft => { | ||
draft.push({ type, values: Array.from(args) }); | ||
}); | ||
}) | ||
.enableInterception(); | ||
|
||
setIsInterceptorEnabled(true); | ||
}, [setLogRecords]); | ||
|
||
const disableInterception = useCallback(() => { | ||
if (!_isInterceptorEnabled()) return; | ||
|
||
LogInterceptor.instance.disableInterception(); | ||
|
||
setIsInterceptorEnabled(false); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (autoEnabled) enableInterception(); | ||
|
||
if (autoEnabled) return disableInterception; | ||
}, [autoEnabled, disableInterception, enableInterception]); | ||
|
||
return { | ||
isInterceptorEnabled, | ||
enableInterception, | ||
disableInterception, | ||
clearAllRecords, | ||
logRecords, | ||
}; | ||
} |
Oops, something went wrong.