Repository: adnxy/optic-react-native Branch: main Commit: e445c8f77b4c Files: 32 Total size: 60.8 KB Directory structure: gitextract_9wjfwnn8/ ├── .eslintrc.json ├── .gitignore ├── .npmignore ├── App.tsx ├── CONTRIBUTING.md ├── README.md ├── app.json ├── babel.config.js ├── metro.config.js ├── package.json ├── src/ │ ├── components/ │ │ ├── OpticProvider.tsx │ │ └── PerformanceOverlay.tsx │ ├── core/ │ │ └── initOptic.ts │ ├── hoc/ │ │ └── withScreenTracking.tsx │ ├── hooks/ │ │ ├── useAutoScreenName.ts │ │ └── useScreenName.ts │ ├── index.ts │ ├── index.tsx │ ├── metrics/ │ │ ├── fps.ts │ │ ├── globalRenderTracking.ts │ │ ├── network.ts │ │ ├── reRenders.ts │ │ ├── screen.ts │ │ ├── startup.ts │ │ └── trace.ts │ ├── overlay/ │ │ └── Overlay.tsx │ ├── providers/ │ │ └── OpticProvider.tsx │ ├── store/ │ │ └── metricsStore.ts │ ├── types/ │ │ └── global.d.ts │ └── utils/ │ └── logger.ts ├── tsconfig.json └── tsup.config.ts ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc.json ================================================ { "env": { "browser": true, "es2021": true, "node": true }, "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react/recommended", "plugin:react-hooks/recommended" ], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaFeatures": { "jsx": true }, "ecmaVersion": 12, "sourceType": "module" }, "plugins": [ "react", "@typescript-eslint" ], "rules": { "react/react-in-jsx-scope": "off", "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/no-explicit-any": "warn", "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }] }, "settings": { "react": { "version": "detect" } } } ================================================ FILE: .gitignore ================================================ # OSX .DS_Store Thumbs.db # Xcode build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout *.moved-aside DerivedData *.hmap *.ipa *.xcuserstate ios/.xcode.env.local # Android/IntelliJ build/ .idea .gradle local.properties *.iml *.hprof .cxx/ *.keystore !debug.keystore # node.js node_modules/ npm-debug.log* yarn-debug.log* yarn-error.log* # fastlane **/fastlane/report.xml **/fastlane/Preview.html **/fastlane/screenshots **/fastlane/test_output # Bundle artifact *.jsbundle # Ruby / CocoaPods /ios/Pods/ /vendor/bundle/ # Temporary files created by Metro to check the health of the file watcher .metro-health-check* # testing /coverage # Production build /dist /build # TypeScript *.tsbuildinfo # Environment variables .env .env.* !.env.example # IDE .vscode/ .idea/ *.swp *.swo # Logs logs *.log # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variable files .env .env.development.local .env.test.local .env.production.local .env.local # Expo .expo/ web-build/ dist/ # Dependencies .pnp/ .pnp.js ================================================ FILE: .npmignore ================================================ # Source src/ tests/ __tests__/ *.test.ts *.test.tsx *.spec.ts *.spec.tsx # Development .git/ .github/ .gitignore .eslintrc.json .prettierrc jest.config.js tsconfig.json tsup.config.ts *.config.js *.config.ts # IDE .idea/ .vscode/ *.swp *.swo *.sublime-* # OS .DS_Store Thumbs.db desktop.ini # Logs logs/ *.log npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* # Environment .env .env.* !.env.example # Build coverage/ .nyc_output/ dist/ build/ *.tgz # Dependencies node_modules/ .pnp/ .pnp.js # TypeScript *.tsbuildinfo ================================================ FILE: App.tsx ================================================ import React from 'react'; import { View, StyleSheet } from 'react-native'; import { initOptic } from './src'; import { Overlay } from './src/overlay/Overlay'; import { RenderTest } from './src/components/RenderTest'; import { OpticProvider } from './src/providers/OpticProvider'; import { initRenderTracking } from './src/metrics/globalRenderTracking'; // Initialize Optic with all metrics enabled initOptic({ enabled: true, network: true, startup: true, reRenders: true, traces: true }); // Initialize re-render tracking initRenderTracking(); export default function App() { return ( ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', }, }); ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing to optic-react-native We love your input! We want to make contributing to optic-react-native as easy and transparent as possible, whether it's: - Reporting a bug - Discussing the current state of the code - Submitting a fix - Proposing new features - Becoming a maintainer ## We Develop with Github We use GitHub to host code, to track issues and feature requests, as well as accept pull requests. ## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html) Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests: 1. Fork the repo and create your branch from `main`. 2. If you've added code that should be tested, add tests. 3. If you've changed APIs, update the documentation. 4. Ensure the test suite passes. 5. Make sure your code lints. 6. Issue that pull request! ## Any contributions you make will be under the MIT Software License In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern. ## Report bugs using Github's [issue tracker](https://github.comoptic-react-native/issues) We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.comoptic-react-native/issues/new); it's that easy! ## Write bug reports with detail, background, and sample code **Great Bug Reports** tend to have: - A quick summary and/or background - Steps to reproduce - Be specific! - Give sample code if you can. - What you expected would happen - What actually happens - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) ## Development Process 1. Clone the repository 2. Install dependencies: ```bash npm install ``` 3. Make your changes 4. Build the project: ```bash npm run build ``` 5. Test your changes 6. Submit a pull request ## License By contributing, you agree that your contributions will be licensed under its MIT License. ================================================ FILE: README.md ================================================ # optic-react-native A lightweight performance monitoring tool for React Native applications. Track startup time, network requests, FPS, and custom traces in real-time. ![npm version](https://img.shields.io/npm/v/optic-react-native) ## Features - App startup time measurement - Network request tracking - Custom interaction tracing - Draggable overlay display - Send metrics to custom API ## Demo Optic Performance Monitor Screenshot ## Installation ```bash npm install optic-react-native # or yarn add optic-react-native ``` ## Quick Start 1. Initialize Optic in your app's entry point: ```typescript import { initOptic } from 'optic-react-native'; initOptic(); ``` 2. Add the overlay component to your app: ```typescript import { OpticProvider } from 'optic-react-native'; const App = () => ( <> ); ``` ## Custom Metrics ### Tracking Custom Interactions Use the tracing API to measure specific interactions in your app: ```typescript import { startTrace, endTrace } from 'optic-react-native'; const handleButtonPress = async () => { startTrace('ButtonPress'); try { await someAsyncOperation(); } finally { endTrace('ButtonPress', 'ButtonComponent'); } }; ``` ### Tracking Re-renders Monitor component re-renders using the `useRenderMonitor` hook: ```typescript import { useRenderMonitor } from 'optic-react-native; const MyComponent = () => { useRenderMonitor('MyComponent'); // ... your component code }; ``` ## Configuration ```typescript interface InitOpticOptions { enabled?: boolean; // Enable/disable all metrics (default: true) startup?: boolean; // Track startup time (default: true) network?: boolean; // Track network requests (default: true) reRenders?: boolean; // Track component re-renders (default: true) traces?: boolean; // Enable custom tracing (default: true) onMetricsLogged?: (metrics: any) => void; // Callback for metrics updates } ``` ## Contributing We welcome contributions! Here's how you can help: 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request ### Development Setup 1. Clone the repository 2. Install dependencies: `yarn install` 3. Run tests: `yarn test` 4. Build the package: `yarn build` ### Code Style - Follow the existing code style - Write tests for new features - Update documentation as needed - Keep commits atomic and well-described ## License MIT © Optic Copyright (c) 2024 Optic Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ## Optic React Native ### Initialization Options #### `enabled` - **Type:** `boolean` - **Default:** `true` - **Description:** If set to `false`, disables all metrics and hides the overlay. Useful for turning off performance tracking in production or for specific builds. #### `onMetricsLogged` - **Type:** `(metrics: any) => void` - **Description:** Callback function that is called whenever metrics are updated. You can use this to log metrics, send them to an API, or perform custom analytics. #### Example Usage ```js import { initOptic } from 'optic-react-native'; initOptic({ enabled: true, // Set to false to disable metrics and overlay onMetricsLogged: (metrics) => { // Log metrics or send to your API fetch('https://your-api.com/metrics', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(metrics), }); }, // ...other options }); ``` --- For more details on all options, see the API documentation section. ## Testing Re-render Tracking with `useRenderMonitor` To test and visualize component re-renders in the overlay, use the `useRenderMonitor` hook in your components. This will increment the re-render count for the component in the metrics overlay. ### Example Usage ```tsx import React from 'react'; import { useRenderMonitor } from 'optic-react-native'; export const TestComponent = () => { useRenderMonitor('Home'); const [count, setCount] = React.useState(0); return ( Render count: {count}