Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React native support #23

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

React native support #23

wants to merge 22 commits into from

Conversation

aidenybai
Copy link
Owner

@aidenybai aidenybai commented Nov 21, 2024

Hi! We're ready to show you an early preview of React Scan for Native. It's not 100% feature parity with web yet, and a lot of technical decisions are up for change, but we'd love for you to try it out.

Please leave all React Native bugs/feedback within this PR until it is merged.

SimulatorScreenRecording-iPhone16-2024-11-27at16.25.23-ezgif.com-crop-video.mp4

Setup guide

First, install the required dependencies:

npm install @shopify/react-native-skia@^1.5.10 react-native-reanimated react-scan@native

Then, wrap your root component with ReactScan:

import { ReactScan } from 'react-scan/native';

// For Expo, in _layout.tsx:
export default function Layout() {
  return (
    <ReactScan
        options={{
           enabled: true,
           log: true,
           animationWhenFlashing: false,
        }}
     >
      <Stack>{/* Your app content */}</Stack>
    </ReactScan>
  );
}

// For vanilla React Native, wrap your root component similarly

The React Native version supports most of the options described in the API Reference section below, with a few differences:

  • Not Available: playSound, runInProduction, includeChildren, onPaintFinish, and onPaintStart
  • Additional Options:
    {
      /**
       * Controls the animation of the re-render overlay.
       * When set to "fade-out", the overlay will fade out after appearing.
       * When false, no animation will be applied.
       * Note: Enabling animations may impact performance.
       * @default false
       */
      animationWhenFlashing?: 'fade-out' | false;
    }

Example usage with options:

<ReactScan
  options={{
    enabled: true,
    log: true,
    animationWhenFlashing: 'fade-out',
  }}
>
  {/* Your app content */}
</ReactScan>

Important

By default, Metro bundler includes React Scan in production builds, which can add up to 6MB to your bundle size. To prevent this, use our babel plugin:

  1. If you are not using expo, install expo-babel-preset (works outside of expo):
    npm install babel-preset-expo

  2. Create or modify your babel.config.js:

const { withReactScanTreeShake } = require('react-scan/babel');
module.exports = withReactScanTreeShake({
  // Your existing babel options go here
});

This will automatically remove React Scan from production builds while keeping it available during development.

Contributing

Please leave all React Native bugs/feedback within this PR until it is merged.

To setup:

git clone https://github.com/aidenybai/react-scan.git
cd react-scan
git checkout react-native

You'll need to create a React Native test repo to get it spun up

Copy link

vercel bot commented Nov 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-scan ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2024 6:30pm

@izakfilmalter
Copy link

image

@RobPruzan
Copy link
Collaborator

Coming soon, we put this on the back burner in favor of https://x.com/aidenybai/status/1861079416480383159, but we're hoping to ship this soon!

Only todo is to make sure we don't bloat your production bundle with 6mb of react-native-skia (probably requires a metro plugin)

@slorber
Copy link

slorber commented Nov 27, 2024

For my curious readers 😇 here's what it should look like:

https://x.com/aidenybai/status/1861612714537427045

ssstwitter.com_1732702337955.mp4

@vlanemcev
Copy link

vlanemcev commented Nov 28, 2024

Hi, for now my app is crashing with "Maximum call stack size exceeded" when I try to use it with Tamagui.
If it's not crashing - it is super laggy.

I know that it's still in development and in early adoption, but it would be so nice to have it work together.
@natew

@RobPruzan
Copy link
Collaborator

Hi, for now my app is crashing with "Maximum call stack size exceeded" when I try to use it with Tamagui. If it's not crashing - it is super laggy.

I know that it's still in development and in early adoption, but it would be so nice to have it work together. @natew

Checking this out!

@ice-cap0
Copy link

i'm not using it with tamagui and getting max call stack error too

RangeError: Maximum call stack size exceeded, js engine: hermes

@yunusyavuz16
Copy link

Here is the question that comes from my software team: Would there any web or any project be to store scanning data of the project. So that, we can put react-scanner into our pipelines.

@mbilenko-florio
Copy link

Hi, for now my app is crashing with "Maximum call stack size exceeded" when I try to use it with Tamagui. If it's not crashing - it is super laggy.

I know that it's still in development and in early adoption, but it would be so nice to have it work together. @natew

Essentially JS thread is running at zero FPS, react scan takes all CPU power away.
Screenshot 2024-11-29 at 07 59 35

@RobPruzan
Copy link
Collaborator

Hi, for now my app is crashing with "Maximum call stack size exceeded" when I try to use it with Tamagui. If it's not crashing - it is super laggy.
I know that it's still in development and in early adoption, but it would be so nice to have it work together. @natew

Essentially JS thread is running at zero FPS, react scan takes all CPU power away. Screenshot 2024-11-29 at 07 59 35

I have some ideas for performance improvements, will keep thread updated when progress is made

@berhanserin
Copy link

Now we are getting a javascript bad request error.

Screenshot 2024-11-29 at 14 38 43

@AleCatSS
Copy link

AleCatSS commented Nov 29, 2024

Hello, thank you very much for this tool!
I'm testing it on our project and currently getting the following errors:
Simulator Screenshot - iPhone 15 Pro - 2024-11-29 at 10 03 39
Simulator Screenshot - iPhone 15 Pro - 2024-11-29 at 10 03 28

Our project is using RN 0.74.5 and I followed the vanilla RN instruction above.
Thank you!

@berhanserin
Copy link

@AleCatSS Greetings, you probably missed something during the installation process. I think you should check it again. Because I was able to install it without any problems. But I am encountering errors on native codes.

@vkukade-altir
Copy link

Excited about this product. Tested on React native version 0.72.4. Experiencing this issue.

RangeError: Maximum call stack size exceeded, js engine: hermes

Error: ENOENT: no such file or directory, open '/Users/distiller/react-native/packages/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js'

Screenshot 2024-11-29 at 8 02 39 PM

@AleCatSS
Copy link

@AleCatSS Greetings, you probably missed something during the installation process. I think you should check it again. Because I was able to install it without any problems. But I am encountering errors on native codes.

got it working thanks, for some reason 'react-native-skia' pod was not installed
, I run pod install manually and fixed it.

@Nikunj-bisht
Copy link

simulator_screenshot_63940F1D-E3A4-4EE4-B7C2-A68CBA0C45BE

getting this error and app is very laggy

@metkm
Copy link

metkm commented Nov 30, 2024

Currently It's so laggy and I can't click some stuff like inputs

@a-eid
Copy link

a-eid commented Nov 30, 2024

should RN skia be installed as a dev deps, since we don't really use it in production ?

@burakgokcinarr
Copy link

Hello, first of all, health to your hand. I have a question. I implemented the react-scan library to experience it myself. Something here caught my attention. When I change ‘setState’, it seems like all my components are rebuilt. I understand this from the continuous increase of the numbers in the animation. (x10, x17, x22 .....) What exactly does the library aim or is there someone who can explain what I don't understand? I apologise in advance :(
Simulator Screenshot - iPhone 16 Pro Max - 2024-12-01 at 09 26 30

@RobPruzan
Copy link
Collaborator

RobPruzan commented Dec 2, 2024

Update on existing bugs relating to max call stack exceeded and perf issues

max call stack problem

have fix, will be in a future release

perf issues

  • the root cause of the perf issues is too many UIManager.measure calls, some ideas to fix that:
    • stop UIManager.measure entirely, re-implement the visualization by overriding the default react-native view and injecting styles into user views. I've seen this done in other projects (something like require("//defaut-view).default = OverridedView), so I know it's possible, but this is probably a last resort if we can't make skia canvas work
    • aggressive caching strategies & smart revalidation strategies for UIManager.measure calls
      • we already cache measurements based on time, but we can do more
      • we can also do things like "prefetch" the component measurement in background when event loop is idle
    • limit how granular we show render outlines
      • for ex. if there are thousands of re-rendered component instances, limit number of components we calculate UIManager.measure , and create new UI to represent "this component also has more children that re-rendered, but we will not draw the rectangles for it"
      • this is probably the safest/most robust solution

We have some other backlog items for react scan before I will get to fixing the perf problems, so contributions/suggestions welcome till then :)

@joaquinvaz
Copy link

Please improve perf, it's not usable right now, great job, love the library!

@DavidAmunga
Copy link

This is good, Can't wait for this to be released !

@321paranoiawhy
Copy link

321paranoiawhy commented Dec 13, 2024

Since react native 0.76, you can try the new react native devtools, just type j in the terminal to open it and navigate to Components tab, click the setting button and toggle Hightlight updates when components render.. That's all, hope u have fun with it!

image

@tanjwGit
Copy link

hi boss, Can I not use react-native-reanimated?

I think maybe many people are like us and cannot use react-native-reanimated for some reason

@RobPruzan
Copy link
Collaborator

hi boss, Can I not use react-native-reanimated?

I think maybe many people are like us and cannot use react-native-reanimated for some reason

Currently its required, but most likely in the next release for react-scan@native we will drop this requirement

@RobPruzan RobPruzan force-pushed the main branch 2 times, most recently from 7526d13 to 47c46ca Compare December 21, 2024 01:52
@ice-cap0
Copy link

any dice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.