react-native-network-lens 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +207 -2
- package/lib/module/backHandler.js +31 -0
- package/lib/module/backHandler.js.map +1 -0
- package/lib/module/components/BodyViewer.js +207 -0
- package/lib/module/components/BodyViewer.js.map +1 -0
- package/lib/module/components/CodeList.js +104 -0
- package/lib/module/components/CodeList.js.map +1 -0
- package/lib/module/components/JsonTree/JsonTreeView.js +206 -0
- package/lib/module/components/JsonTree/JsonTreeView.js.map +1 -0
- package/lib/module/components/JsonTree/model.js +194 -0
- package/lib/module/components/JsonTree/model.js.map +1 -0
- package/lib/module/components/NetworkLens.js +110 -0
- package/lib/module/components/NetworkLens.js.map +1 -0
- package/lib/module/components/NetworkLensOverlay.js +158 -0
- package/lib/module/components/NetworkLensOverlay.js.map +1 -0
- package/lib/module/components/RawTextView.js +119 -0
- package/lib/module/components/RawTextView.js.map +1 -0
- package/lib/module/components/RequestDetails/RequestDetails.js +251 -0
- package/lib/module/components/RequestDetails/RequestDetails.js.map +1 -0
- package/lib/module/components/RequestList/FilterBar.js +138 -0
- package/lib/module/components/RequestList/FilterBar.js.map +1 -0
- package/lib/module/components/RequestList/RequestList.js +163 -0
- package/lib/module/components/RequestList/RequestList.js.map +1 -0
- package/lib/module/components/RequestList/RequestRow.js +161 -0
- package/lib/module/components/RequestList/RequestRow.js.map +1 -0
- package/lib/module/components/RequestList/filters.js +57 -0
- package/lib/module/components/RequestList/filters.js.map +1 -0
- package/lib/module/components/ui/ActionSheet.js +94 -0
- package/lib/module/components/ui/ActionSheet.js.map +1 -0
- package/lib/module/components/ui/Button.js +90 -0
- package/lib/module/components/ui/Button.js.map +1 -0
- package/lib/module/components/ui/Pill.js +53 -0
- package/lib/module/components/ui/Pill.js.map +1 -0
- package/lib/module/components/ui/SearchInput.js +77 -0
- package/lib/module/components/ui/SearchInput.js.map +1 -0
- package/lib/module/components/ui/Section.js +147 -0
- package/lib/module/components/ui/Section.js.map +1 -0
- package/lib/module/components/ui/SegmentedControl.js +65 -0
- package/lib/module/components/ui/SegmentedControl.js.map +1 -0
- package/lib/module/components/ui/index.js +9 -0
- package/lib/module/components/ui/index.js.map +1 -0
- package/lib/module/core/Logger.js +230 -0
- package/lib/module/core/Logger.js.map +1 -0
- package/lib/module/core/NetworkRequest.js +155 -0
- package/lib/module/core/NetworkRequest.js.map +1 -0
- package/lib/module/core/XHRInterceptor.js +104 -0
- package/lib/module/core/XHRInterceptor.js.map +1 -0
- package/lib/module/core/har.js +72 -0
- package/lib/module/core/har.js.map +1 -0
- package/lib/module/core/loggerSingleton.js +12 -0
- package/lib/module/core/loggerSingleton.js.map +1 -0
- package/lib/module/hooks.js +42 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +34 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/theme.js +136 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/body.js +179 -0
- package/lib/module/utils/body.js.map +1 -0
- package/lib/module/utils/debounce.js +18 -0
- package/lib/module/utils/debounce.js.map +1 -0
- package/lib/module/utils/format.js +45 -0
- package/lib/module/utils/format.js.map +1 -0
- package/lib/module/utils/logger.js +6 -0
- package/lib/module/utils/logger.js.map +1 -0
- package/lib/module/utils/search.js +70 -0
- package/lib/module/utils/search.js.map +1 -0
- package/lib/module/utils/url.js +50 -0
- package/lib/module/utils/url.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/backHandler.d.ts +15 -0
- package/lib/typescript/src/backHandler.d.ts.map +1 -0
- package/lib/typescript/src/components/BodyViewer.d.ts +16 -0
- package/lib/typescript/src/components/BodyViewer.d.ts.map +1 -0
- package/lib/typescript/src/components/CodeList.d.ts +21 -0
- package/lib/typescript/src/components/CodeList.d.ts.map +1 -0
- package/lib/typescript/src/components/JsonTree/JsonTreeView.d.ts +21 -0
- package/lib/typescript/src/components/JsonTree/JsonTreeView.d.ts.map +1 -0
- package/lib/typescript/src/components/JsonTree/model.d.ts +53 -0
- package/lib/typescript/src/components/JsonTree/model.d.ts.map +1 -0
- package/lib/typescript/src/components/NetworkLens.d.ts +31 -0
- package/lib/typescript/src/components/NetworkLens.d.ts.map +1 -0
- package/lib/typescript/src/components/NetworkLensOverlay.d.ts +32 -0
- package/lib/typescript/src/components/NetworkLensOverlay.d.ts.map +1 -0
- package/lib/typescript/src/components/RawTextView.d.ts +14 -0
- package/lib/typescript/src/components/RawTextView.d.ts.map +1 -0
- package/lib/typescript/src/components/RequestDetails/RequestDetails.d.ts +9 -0
- package/lib/typescript/src/components/RequestDetails/RequestDetails.d.ts.map +1 -0
- package/lib/typescript/src/components/RequestList/FilterBar.d.ts +12 -0
- package/lib/typescript/src/components/RequestList/FilterBar.d.ts.map +1 -0
- package/lib/typescript/src/components/RequestList/RequestList.d.ts +18 -0
- package/lib/typescript/src/components/RequestList/RequestList.d.ts.map +1 -0
- package/lib/typescript/src/components/RequestList/RequestRow.d.ts +11 -0
- package/lib/typescript/src/components/RequestList/RequestRow.d.ts.map +1 -0
- package/lib/typescript/src/components/RequestList/filters.d.ts +17 -0
- package/lib/typescript/src/components/RequestList/filters.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ActionSheet.d.ts +15 -0
- package/lib/typescript/src/components/ui/ActionSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Button.d.ts +21 -0
- package/lib/typescript/src/components/ui/Button.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Pill.d.ts +11 -0
- package/lib/typescript/src/components/ui/Pill.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/SearchInput.d.ts +17 -0
- package/lib/typescript/src/components/ui/SearchInput.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Section.d.ts +16 -0
- package/lib/typescript/src/components/ui/Section.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/SegmentedControl.d.ts +14 -0
- package/lib/typescript/src/components/ui/SegmentedControl.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/index.d.ts +7 -0
- package/lib/typescript/src/components/ui/index.d.ts.map +1 -0
- package/lib/typescript/src/core/Logger.d.ts +48 -0
- package/lib/typescript/src/core/Logger.d.ts.map +1 -0
- package/lib/typescript/src/core/NetworkRequest.d.ts +48 -0
- package/lib/typescript/src/core/NetworkRequest.d.ts.map +1 -0
- package/lib/typescript/src/core/XHRInterceptor.d.ts +29 -0
- package/lib/typescript/src/core/XHRInterceptor.d.ts.map +1 -0
- package/lib/typescript/src/core/har.d.ts +65 -0
- package/lib/typescript/src/core/har.d.ts.map +1 -0
- package/lib/typescript/src/core/loggerSingleton.d.ts +9 -0
- package/lib/typescript/src/core/loggerSingleton.d.ts.map +1 -0
- package/lib/typescript/src/hooks.d.ts +11 -0
- package/lib/typescript/src/hooks.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +33 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/theme.d.ts +49 -0
- package/lib/typescript/src/theme.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +80 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/body.d.ts +19 -0
- package/lib/typescript/src/utils/body.d.ts.map +1 -0
- package/lib/typescript/src/utils/debounce.d.ts +4 -0
- package/lib/typescript/src/utils/debounce.d.ts.map +1 -0
- package/lib/typescript/src/utils/format.d.ts +7 -0
- package/lib/typescript/src/utils/format.d.ts.map +1 -0
- package/lib/typescript/src/utils/logger.d.ts +2 -0
- package/lib/typescript/src/utils/logger.d.ts.map +1 -0
- package/lib/typescript/src/utils/search.d.ts +17 -0
- package/lib/typescript/src/utils/search.d.ts.map +1 -0
- package/lib/typescript/src/utils/url.d.ts +15 -0
- package/lib/typescript/src/utils/url.d.ts.map +1 -0
- package/package.json +186 -4
- package/src/backHandler.ts +29 -0
- package/src/components/BodyViewer.tsx +240 -0
- package/src/components/CodeList.tsx +120 -0
- package/src/components/JsonTree/JsonTreeView.tsx +304 -0
- package/src/components/JsonTree/model.ts +264 -0
- package/src/components/NetworkLens.tsx +176 -0
- package/src/components/NetworkLensOverlay.tsx +187 -0
- package/src/components/RawTextView.tsx +163 -0
- package/src/components/RequestDetails/RequestDetails.tsx +313 -0
- package/src/components/RequestList/FilterBar.tsx +168 -0
- package/src/components/RequestList/RequestList.tsx +226 -0
- package/src/components/RequestList/RequestRow.tsx +150 -0
- package/src/components/RequestList/filters.ts +98 -0
- package/src/components/ui/ActionSheet.tsx +109 -0
- package/src/components/ui/Button.tsx +120 -0
- package/src/components/ui/Pill.tsx +53 -0
- package/src/components/ui/SearchInput.tsx +97 -0
- package/src/components/ui/Section.tsx +133 -0
- package/src/components/ui/SegmentedControl.tsx +79 -0
- package/src/components/ui/index.ts +6 -0
- package/src/core/Logger.ts +293 -0
- package/src/core/NetworkRequest.ts +216 -0
- package/src/core/XHRInterceptor.ts +179 -0
- package/src/core/har.ts +71 -0
- package/src/core/loggerSingleton.ts +14 -0
- package/src/hooks.ts +51 -0
- package/src/index.tsx +56 -0
- package/src/theme.ts +174 -0
- package/src/types.ts +83 -0
- package/src/utils/body.ts +194 -0
- package/src/utils/debounce.ts +18 -0
- package/src/utils/format.ts +50 -0
- package/src/utils/logger.ts +3 -0
- package/src/utils/search.ts +72 -0
- package/src/utils/url.ts +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stains M Johnson
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,208 @@
|
|
|
1
|
-
#
|
|
1
|
+
# react-native-network-lens
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-network-lens)
|
|
4
|
+
[](https://github.com/stainsmjohnson/react-native-network-lens/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
In-app HTTP inspector for React Native, built for small screens.
|
|
8
|
+
|
|
9
|
+
| Request list | JSON tree | Search | Raw view |
|
|
10
|
+
| --- | --- | --- | --- |
|
|
11
|
+
|  |  |  |  |
|
|
12
|
+
|
|
13
|
+
A modern take on `react-native-network-logger`: the same zero-dependency XHR
|
|
14
|
+
capture (so `fetch`, `axios`, Apollo, etc. are all covered), with a UI that is
|
|
15
|
+
actually usable on a phone:
|
|
16
|
+
|
|
17
|
+
- **Tabbed request details** – *Overview* (URL, timings, query params, request
|
|
18
|
+
and response headers), *Request* payload and *Response* payload each get the
|
|
19
|
+
full screen instead of a 300 px box.
|
|
20
|
+
- **Collapsible JSON tree** – payloads render like the JavaScript console:
|
|
21
|
+
expand only the object you care about, collapse the noise, long-press a node
|
|
22
|
+
to copy or share it.
|
|
23
|
+
- **No line wrapping** – both the tree and the pretty-printed *Raw* view scroll
|
|
24
|
+
horizontally, so indentation and structure stay readable.
|
|
25
|
+
- **Search inside payloads** – with match count and next/previous navigation
|
|
26
|
+
that auto-expands and scrolls to the hit. Works in both Tree and Raw views.
|
|
27
|
+
- **Better list** – colour-coded method and status, path/host split, duration,
|
|
28
|
+
size, GraphQL operation names, pending spinners, failed/timed-out/aborted
|
|
29
|
+
states, filters by method / status group / host, and a free-text filter.
|
|
30
|
+
- **Feature flag built in** – `startNetworkLogging({ enabled })` and the
|
|
31
|
+
`enabled` prop on every component turn the whole thing into a no-op, so it
|
|
32
|
+
can be driven by `__DEV__`, a remote config value or a hidden dev setting.
|
|
33
|
+
- **Floating overlay** – `<NetworkLensOverlay />` adds a badge button that opens
|
|
34
|
+
the inspector in a modal. One line, done.
|
|
35
|
+
- **Light / dark / auto themes**, cURL export, HAR export, share full request.
|
|
36
|
+
- **Zero dependencies**, pure TypeScript, no native code. Works with the New
|
|
37
|
+
Architecture and React Native **0.83+**.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
yarn add react-native-network-lens
|
|
43
|
+
# or
|
|
44
|
+
npm install react-native-network-lens
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
No pod install, no Gradle changes.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// index.js – as early as possible so nothing is missed
|
|
53
|
+
import { startNetworkLogging } from 'react-native-network-lens';
|
|
54
|
+
|
|
55
|
+
startNetworkLogging({ enabled: __DEV__ });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
// App.tsx – the one-liner overlay
|
|
60
|
+
import { NetworkLensOverlay } from 'react-native-network-lens';
|
|
61
|
+
|
|
62
|
+
export default function App() {
|
|
63
|
+
return (
|
|
64
|
+
<>
|
|
65
|
+
<RootNavigator />
|
|
66
|
+
<NetworkLensOverlay enabled={__DEV__} />
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Tap the floating **NET** button to open the inspector. It shows the number of
|
|
73
|
+
captured requests and turns red when something failed.
|
|
74
|
+
|
|
75
|
+
### Rendering it as a screen instead
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { NetworkLens } from 'react-native-network-lens';
|
|
79
|
+
|
|
80
|
+
const NetworkScreen = () => <NetworkLens theme="dark" />;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`NetworkLens` fills its parent (`flex: 1`). Put it inside your own screen /
|
|
84
|
+
navigator; it handles the Android hardware back button for the details view.
|
|
85
|
+
|
|
86
|
+
### Conditionally enabling (feature flag)
|
|
87
|
+
|
|
88
|
+
Everything respects a single flag:
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
const inspectorEnabled = __DEV__ || remoteConfig.getBoolean('network_inspector');
|
|
92
|
+
|
|
93
|
+
startNetworkLogging({ enabled: inspectorEnabled });
|
|
94
|
+
|
|
95
|
+
<NetworkLensOverlay enabled={inspectorEnabled} />
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
When `enabled` is `false`, `XMLHttpRequest` is left untouched and the
|
|
99
|
+
components render `null`. You can also call `stopNetworkLogging()` at runtime
|
|
100
|
+
to turn it off and free the captured data.
|
|
101
|
+
|
|
102
|
+
## API
|
|
103
|
+
|
|
104
|
+
### `startNetworkLogging(options?)`
|
|
105
|
+
|
|
106
|
+
| Option | Type | Default | Description |
|
|
107
|
+
| ----------------- | ---------- | ------- | ----------- |
|
|
108
|
+
| `enabled` | `boolean` | `true` | Master switch. `false` makes the call a no-op (and stops a running logger). |
|
|
109
|
+
| `maxRequests` | `number` | `500` | Ring-buffer size. |
|
|
110
|
+
| `ignoredHosts` | `string[]` | | Hosts to skip, e.g. `['localhost:8081']`. |
|
|
111
|
+
| `ignoredUrls` | `string[]` | | Exact URLs to skip. |
|
|
112
|
+
| `ignoredPatterns` | `RegExp[]` | | Tested against `"${method} ${url}"`. |
|
|
113
|
+
| `refreshRate` | `number` | `50` | UI update throttle in ms. |
|
|
114
|
+
|
|
115
|
+
Other functions: `stopNetworkLogging()`, `isNetworkLoggingEnabled()`,
|
|
116
|
+
`getRequests()`, `clearRequests()`, `setNetworkLoggingPaused(bool)`,
|
|
117
|
+
`getBackHandler(fn)` and `createHar(requests)`.
|
|
118
|
+
|
|
119
|
+
### `<NetworkLens />`
|
|
120
|
+
|
|
121
|
+
| Prop | Type | Default |
|
|
122
|
+
| -------------------- | -------------------------------------- | ------------ |
|
|
123
|
+
| `enabled` | `boolean` | `true` |
|
|
124
|
+
| `theme` | `'light' \| 'dark' \| 'auto' \| Partial<Theme>` | `'auto'` |
|
|
125
|
+
| `sort` | `'asc' \| 'desc'` | `'desc'` |
|
|
126
|
+
| `compact` | `boolean` | `false` |
|
|
127
|
+
| `maxRows` | `number` | |
|
|
128
|
+
| `copyToClipboard` | `(text: string) => void` | |
|
|
129
|
+
| `header` | `ReactNode` rendered above the search bar | |
|
|
130
|
+
|
|
131
|
+
A `ref` gives you `goBack(): boolean`, which returns from the details view to
|
|
132
|
+
the list. Use it to wire your own back button or modal `onRequestClose`.
|
|
133
|
+
|
|
134
|
+
The library ships no native code, so there is no clipboard access by default.
|
|
135
|
+
Pass your clipboard function to get **Copy** buttons everywhere:
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import Clipboard from '@react-native-clipboard/clipboard';
|
|
139
|
+
|
|
140
|
+
<NetworkLensOverlay copyToClipboard={Clipboard.setString} />
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### `<NetworkLensOverlay />`
|
|
144
|
+
|
|
145
|
+
All `NetworkLens` props plus:
|
|
146
|
+
|
|
147
|
+
| Prop | Type | Default |
|
|
148
|
+
| ----------------- | ----------------------------------------------------------- | ---------------- |
|
|
149
|
+
| `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` |
|
|
150
|
+
| `offset` | `{ x?: number; y?: number }` | `{ x: 16, y: 32 }` |
|
|
151
|
+
| `visible` / `onVisibleChange` | controlled visibility of the modal | |
|
|
152
|
+
| `hideButton` | `boolean` – open it from your own dev menu instead | `false` |
|
|
153
|
+
| `title` | `string` | `'Network'` |
|
|
154
|
+
|
|
155
|
+
### Hooks and building blocks
|
|
156
|
+
|
|
157
|
+
- `useNetworkRequests()` – live array of `NetworkRequest` objects.
|
|
158
|
+
- `useLoggerEnabled()`, `useLoggerPaused()`.
|
|
159
|
+
- `JsonTreeView` is exported so you can reuse the collapsible JSON viewer
|
|
160
|
+
elsewhere in your debug tooling.
|
|
161
|
+
|
|
162
|
+
### Theming
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
<NetworkLens theme={{ colors: { primary: '#ff5c8a', jsonKey: '#ffd166' } }} />
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Any colour you omit falls back to the light or dark theme depending on the
|
|
169
|
+
system appearance. See `Theme` in `src/theme.ts` for every token.
|
|
170
|
+
|
|
171
|
+
## How it works
|
|
172
|
+
|
|
173
|
+
The library patches `XMLHttpRequest.prototype` (`open`, `setRequestHeader`,
|
|
174
|
+
`send`) when `startNetworkLogging()` runs and restores the originals on
|
|
175
|
+
`stopNetworkLogging()`. Every callback is wrapped so a bug in the inspector can
|
|
176
|
+
never break a request. Captured requests live in a single store on
|
|
177
|
+
`globalThis`, which survives Fast Refresh, and React reads it through
|
|
178
|
+
`useSyncExternalStore`. There is no native code, so nothing to link.
|
|
179
|
+
|
|
180
|
+
## Security
|
|
181
|
+
|
|
182
|
+
The inspector keeps captured headers and bodies in memory, including
|
|
183
|
+
authorization tokens and cookies, and lets the user share or export them.
|
|
184
|
+
Ship it behind `__DEV__` or an internal flag only, and use `ignoredHosts` /
|
|
185
|
+
`ignoredPatterns` for endpoints that must never be captured. See
|
|
186
|
+
[SECURITY.md](SECURITY.md) for details and how to report issues.
|
|
187
|
+
|
|
188
|
+
## Migrating from `react-native-network-logger`
|
|
189
|
+
|
|
190
|
+
The public API is a superset: `startNetworkLogging`, `stopNetworkLogging`,
|
|
191
|
+
`getRequests`, `clearRequests`, `getBackHandler` and the default-exported
|
|
192
|
+
component keep working. Differences:
|
|
193
|
+
|
|
194
|
+
- `theme` accepts `'auto'` and defaults to it.
|
|
195
|
+
- Requests expose `state` (`pending | done | failed`) and `failureReason`
|
|
196
|
+
(`error | timeout | abort`) instead of staying "pending" forever.
|
|
197
|
+
- Bodies are parsed into `{ kind: 'json' | 'form' | 'text' | 'binary' | 'empty' }`
|
|
198
|
+
via `request.getRequestBody()` / `await request.getResponseBody()`.
|
|
199
|
+
|
|
200
|
+
## Contributing
|
|
201
|
+
|
|
202
|
+
See the [contributing guide](CONTRIBUTING.md). The example app in `example/`
|
|
203
|
+
fires a variety of requests (large JSON, nested objects, forms, GraphQL-like,
|
|
204
|
+
errors, timeouts, binary) so you can try every screen.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
let appBackHandler;
|
|
4
|
+
let lensBackHandler;
|
|
5
|
+
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const setLensBackHandler = handler => {
|
|
8
|
+
lensBackHandler = handler;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export const hasAppBackHandler = () => !!appBackHandler;
|
|
13
|
+
const goBack = () => {
|
|
14
|
+
if (lensBackHandler?.()) return;
|
|
15
|
+
appBackHandler?.();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Wrap your screen's back action so the back button first navigates inside the
|
|
20
|
+
* inspector (details -> list) and only then falls back to your own navigation.
|
|
21
|
+
*
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const onBack = getBackHandler(navigation.goBack);
|
|
24
|
+
* <Button title="Back" onPress={onBack} />
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const getBackHandler = backHandler => {
|
|
28
|
+
appBackHandler = backHandler;
|
|
29
|
+
return goBack;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=backHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["appBackHandler","lensBackHandler","setLensBackHandler","handler","hasAppBackHandler","goBack","getBackHandler","backHandler"],"sourceRoot":"../../src","sources":["backHandler.ts"],"mappings":";;AAAA,IAAIA,cAA2C;AAC/C,IAAIC,eAA4C;;AAEhD;AACA,OAAO,MAAMC,kBAAkB,GAAIC,OAAuB,IAAK;EAC7DF,eAAe,GAAGE,OAAO;AAC3B,CAAC;;AAED;AACA,OAAO,MAAMC,iBAAiB,GAAGA,CAAA,KAAM,CAAC,CAACJ,cAAc;AAEvD,MAAMK,MAAM,GAAGA,CAAA,KAAM;EACnB,IAAIJ,eAAe,GAAG,CAAC,EAAE;EACzBD,cAAc,GAAG,CAAC;AACpB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,cAAc,GAAIC,WAA0B,IAAK;EAC5DP,cAAc,GAAGO,WAAW;EAC5B,OAAOF,MAAM;AACf,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { ActivityIndicator, Share, StyleSheet, Text, View } from 'react-native';
|
|
5
|
+
import { useTheme } from "../theme.js";
|
|
6
|
+
import { bodySize, stringifyJson } from "../utils/body.js";
|
|
7
|
+
import { formatBytes } from "../utils/format.js";
|
|
8
|
+
import JsonTreeView from "./JsonTree/JsonTreeView.js";
|
|
9
|
+
import RawTextView from "./RawTextView.js";
|
|
10
|
+
import { ActionSheet, EmptyState, SearchInput, SegmentedControl, TextButton } from "./ui/index.js";
|
|
11
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const KIND_LABEL = {
|
|
13
|
+
json: 'JSON',
|
|
14
|
+
form: 'Form data',
|
|
15
|
+
text: 'Text',
|
|
16
|
+
binary: 'Binary',
|
|
17
|
+
empty: 'Empty'
|
|
18
|
+
};
|
|
19
|
+
const share = text => Share.share({
|
|
20
|
+
message: text
|
|
21
|
+
}).catch(() => undefined);
|
|
22
|
+
const valueText = value => typeof value === 'string' ? value : stringifyJson(value);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Payload viewer used by the Request and Response tabs. Structured bodies can
|
|
26
|
+
* be shown as a collapsible tree or as pretty-printed raw text; both keep lines
|
|
27
|
+
* unwrapped, scroll horizontally and support search with next/previous.
|
|
28
|
+
*/
|
|
29
|
+
const BodyViewer = ({
|
|
30
|
+
body,
|
|
31
|
+
loading,
|
|
32
|
+
emptyTitle,
|
|
33
|
+
emptySubtitle,
|
|
34
|
+
copyToClipboard
|
|
35
|
+
}) => {
|
|
36
|
+
const theme = useTheme();
|
|
37
|
+
const structured = body?.kind === 'json' || body?.kind === 'form';
|
|
38
|
+
const [mode, setMode] = useState('tree');
|
|
39
|
+
const [query, setQuery] = useState('');
|
|
40
|
+
const [matchCount, setMatchCount] = useState(0);
|
|
41
|
+
const [matchIndex, setMatchIndex] = useState(0);
|
|
42
|
+
const [nodeMenu, setNodeMenu] = useState(null);
|
|
43
|
+
const treeRef = useRef(null);
|
|
44
|
+
const effectiveMode = structured ? mode : 'raw';
|
|
45
|
+
useEffect(() => setMatchIndex(0), [query, effectiveMode, body]);
|
|
46
|
+
const onMatchCountChange = useCallback(count => {
|
|
47
|
+
setMatchCount(count);
|
|
48
|
+
setMatchIndex(index => count === 0 ? 0 : Math.min(index, count - 1));
|
|
49
|
+
}, []);
|
|
50
|
+
const matches = {
|
|
51
|
+
count: matchCount,
|
|
52
|
+
index: matchIndex,
|
|
53
|
+
onNext: () => matchCount && setMatchIndex(i => (i + 1) % matchCount),
|
|
54
|
+
onPrev: () => matchCount && setMatchIndex(i => (i - 1 + matchCount) % matchCount)
|
|
55
|
+
};
|
|
56
|
+
const meta = useMemo(() => {
|
|
57
|
+
if (!body || body.kind === 'empty') return '';
|
|
58
|
+
const parts = [KIND_LABEL[body.kind]];
|
|
59
|
+
if (body.kind === 'binary' && body.mimeType) parts.push(body.mimeType);
|
|
60
|
+
const size = bodySize(body);
|
|
61
|
+
if (size) parts.push(formatBytes(size));
|
|
62
|
+
if (body.kind !== 'binary') parts.push(`${body.text.split('\n').length} lines`);
|
|
63
|
+
return parts.join(' · ');
|
|
64
|
+
}, [body]);
|
|
65
|
+
if (loading) {
|
|
66
|
+
return /*#__PURE__*/_jsx(View, {
|
|
67
|
+
style: styles.center,
|
|
68
|
+
children: /*#__PURE__*/_jsx(ActivityIndicator, {
|
|
69
|
+
color: theme.colors.primary
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (!body || body.kind === 'empty') {
|
|
74
|
+
return /*#__PURE__*/_jsx(EmptyState, {
|
|
75
|
+
title: emptyTitle,
|
|
76
|
+
subtitle: emptySubtitle
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
80
|
+
style: styles.container,
|
|
81
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
82
|
+
style: styles.toolbar,
|
|
83
|
+
children: [structured ? /*#__PURE__*/_jsx(SegmentedControl, {
|
|
84
|
+
value: effectiveMode,
|
|
85
|
+
onChange: setMode,
|
|
86
|
+
options: [{
|
|
87
|
+
value: 'tree',
|
|
88
|
+
label: 'Tree'
|
|
89
|
+
}, {
|
|
90
|
+
value: 'raw',
|
|
91
|
+
label: 'Raw'
|
|
92
|
+
}],
|
|
93
|
+
style: styles.modeSwitch
|
|
94
|
+
}) : /*#__PURE__*/_jsx(Text, {
|
|
95
|
+
style: [styles.meta, {
|
|
96
|
+
color: theme.colors.textMuted
|
|
97
|
+
}],
|
|
98
|
+
numberOfLines: 1,
|
|
99
|
+
children: meta
|
|
100
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
101
|
+
style: styles.spacer
|
|
102
|
+
}), effectiveMode === 'tree' && /*#__PURE__*/_jsxs(_Fragment, {
|
|
103
|
+
children: [/*#__PURE__*/_jsx(TextButton, {
|
|
104
|
+
label: "Expand",
|
|
105
|
+
onPress: () => treeRef.current?.expandAll()
|
|
106
|
+
}), /*#__PURE__*/_jsx(TextButton, {
|
|
107
|
+
label: "Collapse",
|
|
108
|
+
onPress: () => treeRef.current?.collapseAll()
|
|
109
|
+
})]
|
|
110
|
+
}), copyToClipboard && body.kind !== 'binary' && /*#__PURE__*/_jsx(TextButton, {
|
|
111
|
+
label: "Copy",
|
|
112
|
+
onPress: () => copyToClipboard(body.text)
|
|
113
|
+
}), /*#__PURE__*/_jsx(TextButton, {
|
|
114
|
+
label: "Share",
|
|
115
|
+
onPress: () => share(body.text)
|
|
116
|
+
})]
|
|
117
|
+
}), body.kind !== 'binary' && /*#__PURE__*/_jsx(SearchInput, {
|
|
118
|
+
value: query,
|
|
119
|
+
onChangeText: setQuery,
|
|
120
|
+
placeholder: effectiveMode === 'tree' ? 'Search keys and values' : 'Search text',
|
|
121
|
+
matches: matches,
|
|
122
|
+
style: styles.search
|
|
123
|
+
}), structured && /*#__PURE__*/_jsx(Text, {
|
|
124
|
+
style: [styles.meta, styles.metaBelow, {
|
|
125
|
+
color: theme.colors.textMuted
|
|
126
|
+
}],
|
|
127
|
+
numberOfLines: 1,
|
|
128
|
+
children: meta
|
|
129
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
130
|
+
style: [styles.viewer, {
|
|
131
|
+
borderColor: theme.colors.border
|
|
132
|
+
}],
|
|
133
|
+
children: body.kind === 'binary' ? /*#__PURE__*/_jsx(EmptyState, {
|
|
134
|
+
title: "Binary content",
|
|
135
|
+
subtitle: body.text
|
|
136
|
+
}) : effectiveMode === 'tree' && structured ? /*#__PURE__*/_jsx(JsonTreeView, {
|
|
137
|
+
ref: treeRef,
|
|
138
|
+
value: body.value,
|
|
139
|
+
query: query,
|
|
140
|
+
activeMatch: matchIndex,
|
|
141
|
+
onMatchCountChange: onMatchCountChange,
|
|
142
|
+
onLongPressNode: setNodeMenu
|
|
143
|
+
}) : /*#__PURE__*/_jsx(RawTextView, {
|
|
144
|
+
text: body.text,
|
|
145
|
+
query: query,
|
|
146
|
+
activeMatch: matchIndex,
|
|
147
|
+
onMatchCountChange: onMatchCountChange
|
|
148
|
+
})
|
|
149
|
+
}), /*#__PURE__*/_jsx(ActionSheet, {
|
|
150
|
+
visible: nodeMenu !== null,
|
|
151
|
+
onClose: () => setNodeMenu(null),
|
|
152
|
+
title: nodeMenu?.path,
|
|
153
|
+
actions: nodeMenu ? [...(copyToClipboard ? [{
|
|
154
|
+
label: 'Copy value',
|
|
155
|
+
onPress: () => copyToClipboard(valueText(nodeMenu.value))
|
|
156
|
+
}] : []), {
|
|
157
|
+
label: 'Share value',
|
|
158
|
+
onPress: () => share(valueText(nodeMenu.value))
|
|
159
|
+
}, ...(copyToClipboard ? [{
|
|
160
|
+
label: 'Copy path',
|
|
161
|
+
onPress: () => copyToClipboard(nodeMenu.path)
|
|
162
|
+
}] : [])] : []
|
|
163
|
+
})]
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
const styles = StyleSheet.create({
|
|
167
|
+
container: {
|
|
168
|
+
flex: 1
|
|
169
|
+
},
|
|
170
|
+
center: {
|
|
171
|
+
flex: 1,
|
|
172
|
+
alignItems: 'center',
|
|
173
|
+
justifyContent: 'center'
|
|
174
|
+
},
|
|
175
|
+
toolbar: {
|
|
176
|
+
flexDirection: 'row',
|
|
177
|
+
alignItems: 'center',
|
|
178
|
+
paddingHorizontal: 12,
|
|
179
|
+
paddingTop: 10,
|
|
180
|
+
gap: 6
|
|
181
|
+
},
|
|
182
|
+
modeSwitch: {
|
|
183
|
+
width: 130
|
|
184
|
+
},
|
|
185
|
+
spacer: {
|
|
186
|
+
flex: 1
|
|
187
|
+
},
|
|
188
|
+
search: {
|
|
189
|
+
marginHorizontal: 12,
|
|
190
|
+
marginTop: 8
|
|
191
|
+
},
|
|
192
|
+
meta: {
|
|
193
|
+
fontSize: 12,
|
|
194
|
+
flexShrink: 1
|
|
195
|
+
},
|
|
196
|
+
metaBelow: {
|
|
197
|
+
paddingHorizontal: 14,
|
|
198
|
+
paddingTop: 6
|
|
199
|
+
},
|
|
200
|
+
viewer: {
|
|
201
|
+
flex: 1,
|
|
202
|
+
marginTop: 8,
|
|
203
|
+
borderTopWidth: StyleSheet.hairlineWidth
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
export default BodyViewer;
|
|
207
|
+
//# sourceMappingURL=BodyViewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useMemo","useRef","useState","ActivityIndicator","Share","StyleSheet","Text","View","useTheme","bodySize","stringifyJson","formatBytes","JsonTreeView","RawTextView","ActionSheet","EmptyState","SearchInput","SegmentedControl","TextButton","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","KIND_LABEL","json","form","text","binary","empty","share","message","catch","undefined","valueText","value","BodyViewer","body","loading","emptyTitle","emptySubtitle","copyToClipboard","theme","structured","kind","mode","setMode","query","setQuery","matchCount","setMatchCount","matchIndex","setMatchIndex","nodeMenu","setNodeMenu","treeRef","effectiveMode","onMatchCountChange","count","index","Math","min","matches","onNext","i","onPrev","meta","parts","mimeType","push","size","split","length","join","style","styles","center","children","color","colors","primary","title","subtitle","container","toolbar","onChange","options","label","modeSwitch","textMuted","numberOfLines","spacer","onPress","current","expandAll","collapseAll","onChangeText","placeholder","search","metaBelow","viewer","borderColor","border","ref","activeMatch","onLongPressNode","visible","onClose","path","actions","create","flex","alignItems","justifyContent","flexDirection","paddingHorizontal","paddingTop","gap","width","marginHorizontal","marginTop","fontSize","flexShrink","borderTopWidth","hairlineWidth"],"sourceRoot":"../../../src","sources":["components/BodyViewer.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzE,SAASC,iBAAiB,EAAEC,KAAK,EAAEC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAC/E,SAASC,QAAQ,QAAQ,aAAU;AAEnC,SAASC,QAAQ,EAAEC,aAAa,QAAQ,kBAAe;AACvD,SAASC,WAAW,QAAQ,oBAAiB;AAC7C,OAAOC,YAAY,MAA+B,4BAAyB;AAC3E,OAAOC,WAAW,MAAM,kBAAe;AACvC,SACEC,WAAW,EACXC,UAAU,EACVC,WAAW,EACXC,gBAAgB,EAChBC,UAAU,QACL,eAAM;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAYd,MAAMC,UAA8C,GAAG;EACrDC,IAAI,EAAE,MAAM;EACZC,IAAI,EAAE,WAAW;EACjBC,IAAI,EAAE,MAAM;EACZC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE;AACT,CAAC;AAED,MAAMC,KAAK,GAAIH,IAAY,IACzBxB,KAAK,CAAC2B,KAAK,CAAC;EAAEC,OAAO,EAAEJ;AAAK,CAAC,CAAC,CAACK,KAAK,CAAC,MAAMC,SAAS,CAAC;AACvD,MAAMC,SAAS,GAAIC,KAAc,IAC/B,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG1B,aAAa,CAAC0B,KAAK,CAAC;;AAE1D;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAGA,CAAC;EAClBC,IAAI;EACJC,OAAO;EACPC,UAAU;EACVC,aAAa;EACbC;AACK,CAAC,KAAK;EACX,MAAMC,KAAK,GAAGnC,QAAQ,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E,QAAQ;IACpBG,iBAAiB,EAAE,EAAE;IACrBC,UAAU,EAAE,EAAE;IACdC,GAAG,EAAE;EACP,CAAC;EACD7B,UAAU,EAAE;IAAE8B,KAAK,EAAE;EAAI,CAAC;EAC1B3B,MAAM,EAAE;IAAEoB,IAAI,EAAE;EAAE,CAAC;EACnBb,MAAM,EAAE;IAAEqB,gBAAgB,EAAE,EAAE;IAAEC,SAAS,EAAE;EAAE,CAAC;EAC9CtD,IAAI,EAAE;IAAEuD,QAAQ,EAAE,EAAE;IAAEC,UAAU,EAAE;EAAE,CAAC;EACrCvB,SAAS,EAAE;IAAEgB,iBAAiB,EAAE,EAAE;IAAEC,UAAU,EAAE;EAAE,CAAC;EACnDhB,MAAM,EAAE;IAAEW,IAAI,EAAE,CAAC;IAAES,SAAS,EAAE,CAAC;IAAEG,cAAc,EAAEvH,UAAU,CAACwH;EAAc;AAC5E,CAAC,CAAC;AAEF,eAAexF,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { FlatList, ScrollView, StyleSheet, View } from 'react-native';
|
|
5
|
+
import { useTheme } from "../theme.js";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
/**
|
|
8
|
+
* A vertical FlatList inside a horizontal ScrollView. Rows are fixed height and
|
|
9
|
+
* never wrap, so long JSON lines stay on one line and can be panned sideways,
|
|
10
|
+
* just like a code editor. We measure the container once and size the inner
|
|
11
|
+
* list explicitly, which keeps both scroll axes stable while rows virtualise.
|
|
12
|
+
*/
|
|
13
|
+
export function CodeList({
|
|
14
|
+
data,
|
|
15
|
+
renderItem,
|
|
16
|
+
keyExtractor,
|
|
17
|
+
contentWidth,
|
|
18
|
+
rowHeight,
|
|
19
|
+
activeIndex,
|
|
20
|
+
extraData
|
|
21
|
+
}) {
|
|
22
|
+
const theme = useTheme();
|
|
23
|
+
const listRef = useRef(null);
|
|
24
|
+
const [layout, setLayout] = useState({
|
|
25
|
+
width: 0,
|
|
26
|
+
height: 0
|
|
27
|
+
});
|
|
28
|
+
const getItemLayout = useCallback((_, index) => ({
|
|
29
|
+
length: rowHeight,
|
|
30
|
+
offset: rowHeight * index,
|
|
31
|
+
index
|
|
32
|
+
}), [rowHeight]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (activeIndex === undefined || activeIndex < 0 || activeIndex >= data.length) return;
|
|
35
|
+
// Defer so a freshly expanded tree has rendered before we scroll.
|
|
36
|
+
const handle = setTimeout(() => {
|
|
37
|
+
listRef.current?.scrollToIndex({
|
|
38
|
+
index: activeIndex,
|
|
39
|
+
viewPosition: 0.3,
|
|
40
|
+
animated: true
|
|
41
|
+
});
|
|
42
|
+
}, 16);
|
|
43
|
+
return () => clearTimeout(handle);
|
|
44
|
+
}, [activeIndex, data.length]);
|
|
45
|
+
const width = Math.max(contentWidth, layout.width);
|
|
46
|
+
return /*#__PURE__*/_jsx(View, {
|
|
47
|
+
style: [styles.container, {
|
|
48
|
+
backgroundColor: theme.colors.surface
|
|
49
|
+
}],
|
|
50
|
+
onLayout: event => {
|
|
51
|
+
const {
|
|
52
|
+
width: w,
|
|
53
|
+
height: h
|
|
54
|
+
} = event.nativeEvent.layout;
|
|
55
|
+
setLayout(prev => prev.width === w && prev.height === h ? prev : {
|
|
56
|
+
width: w,
|
|
57
|
+
height: h
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
children: layout.height > 0 && /*#__PURE__*/_jsx(ScrollView, {
|
|
61
|
+
horizontal: true,
|
|
62
|
+
bounces: false,
|
|
63
|
+
showsHorizontalScrollIndicator: true,
|
|
64
|
+
nestedScrollEnabled: true,
|
|
65
|
+
keyboardShouldPersistTaps: "handled",
|
|
66
|
+
children: /*#__PURE__*/_jsx(FlatList, {
|
|
67
|
+
ref: listRef,
|
|
68
|
+
data: data,
|
|
69
|
+
extraData: extraData,
|
|
70
|
+
renderItem: renderItem,
|
|
71
|
+
keyExtractor: keyExtractor,
|
|
72
|
+
getItemLayout: getItemLayout,
|
|
73
|
+
nestedScrollEnabled: true,
|
|
74
|
+
keyboardShouldPersistTaps: "handled",
|
|
75
|
+
initialNumToRender: 30,
|
|
76
|
+
maxToRenderPerBatch: 40,
|
|
77
|
+
windowSize: 9,
|
|
78
|
+
removeClippedSubviews: false,
|
|
79
|
+
onScrollToIndexFailed: ({
|
|
80
|
+
index
|
|
81
|
+
}) => {
|
|
82
|
+
listRef.current?.scrollToOffset({
|
|
83
|
+
offset: index * rowHeight,
|
|
84
|
+
animated: false
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
style: {
|
|
88
|
+
width,
|
|
89
|
+
height: layout.height
|
|
90
|
+
},
|
|
91
|
+
contentContainerStyle: styles.content
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const styles = StyleSheet.create({
|
|
97
|
+
container: {
|
|
98
|
+
flex: 1
|
|
99
|
+
},
|
|
100
|
+
content: {
|
|
101
|
+
paddingVertical: 6
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=CodeList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useRef","useState","FlatList","ScrollView","StyleSheet","View","useTheme","jsx","_jsx","CodeList","data","renderItem","keyExtractor","contentWidth","rowHeight","activeIndex","extraData","theme","listRef","layout","setLayout","width","height","getItemLayout","_","index","length","offset","undefined","handle","setTimeout","current","scrollToIndex","viewPosition","animated","clearTimeout","Math","max","style","styles","container","backgroundColor","colors","surface","onLayout","event","w","h","nativeEvent","prev","children","horizontal","bounces","showsHorizontalScrollIndicator","nestedScrollEnabled","keyboardShouldPersistTaps","ref","initialNumToRender","maxToRenderPerBatch","windowSize","removeClippedSubviews","onScrollToIndexFailed","scrollToOffset","contentContainerStyle","content","create","flex","paddingVertical"],"sourceRoot":"../../../src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