question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Q: How to render current point data correctly?

See original GitHub issue

Initially, the UI on gestures works pretty well.

without setState

But if I try to render the current point price and timestamp I get a laggy thing. Here is an example of code with setState:

    const onPointSelected = useCallback(
        (p) => {
            console.log(p);

            const selectedPrice = formatAmount(p.value, fiatCurrency.code as CurrencyName, "fiat");
            const timestamp = DateTime.fromSeconds(p.date);

            setAmountTitle(selectedPrice);
            setTimestamp(timestamp);
        },
        [fiatCurrency.code],
    );

As a result with setState I get slow UI:

with setState

So the question is how to render it properly and smoothly?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
DDushkincommented, May 6, 2022

Yeah, that’s because of React Native. It isn’t really fast at state updates. Maybe this will improve with concurrent mode. The way to solve this is to use Reanimated Shared Values and update the Text using ReanimatedText.

Thanks, I installed AnimateableText from "react-native-animateable-text", and here is the new code

    const title = useSharedValue(assetBalanceFormatted);
    const subtitle = useSharedValue(`${t("main.value")}: ${fiatBalanceFormatted}`);

    const animatedTitle = useAnimatedProps(() => ({
        text: title.value,
    }));
    const animatedSubtitle = useAnimatedProps(() => ({
        text: subtitle.value,
    }));

    const onPointSelected = useCallback(
        (p) => {
            console.log(p);

            const selectedPrice = formatAmount(p.value, fiatCurrency.code as CurrencyName, "fiat");
            const timestamp = DateTime.fromSeconds(p.date);

            title.value = selectedPrice;
            subtitle.value = timestamp.toFormat("d MMM yyyy HH:mm");
        },
        [fiatCurrency.code, subtitle, title],
    );
//...
    <AnimateableText animatedProps={animatedTitle} style={styles.title} />
    <AnimateableText animatedProps={animatedSubtitle} style={styles.subtitle} />

UPD: works now

But I can see now that Cursor is not rendered

Запись экрана 2022-05-06 в 15 50 43

1reaction
mrousavycommented, May 6, 2022

Yeah, that’s because of React Native. It isn’t really fast at state updates. Maybe this will improve with concurrent mode. The way to solve this is to use Reanimated Shared Values and update the Text using ReanimatedText.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basics of rendering and exporting in After Effects CC
Learn how to render and export in After Effects using the Render Queue panel and Media Encoder and what are the supported output...
Read more >
Highcharts not rendering data points - Stack Overflow
It's pulling the correct data and echoing how I expect it to. <?php $expAddress = "URL"; $expUser = "USERNAME"; $expPwd = "PASSWORD"; $database...
Read more >
How to save renders correctly in Blender? - Artisticrender.com
Start you render from the menu, Render -> Render image, or by pressing F12. Once the render has finnished, go to Image ->...
Read more >
French point cloud data won't render properly in QGIS 3.22.3
It is possible that the problem is due to entwine utilities. Try to generate entwine data manually from your initial laz (the process...
Read more >
Rasterization: a Practical Implementation (Perspective Correct ...
As you already know, we need to store the z-coordinates of the original vertices (camera space vertices) in the z-coordinate of our projected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found