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.

Layout animations performing bad on Android

See original GitHub issue

Description

I’ve created a transition which extends the width property of a search bar to smoothly push buttons next to the search bar away. The goal is to make a unified search bar which gets used across horizontal tabs, where the user can use swipe gestures to navigate between.

I tried to only use transform translations instead of the width, but that would’ve not been so easily possible because the Search Bar actually resizes and gets wider. I’d have to recalculate borderRadius proportional to the scale if I’m going to animate scaleX etc.

So animating width looks fine on iOS, even on lower end devices (iPhone 6).

Here’s a demo:

iOS

ezgif com-video-to-gif

Android

ezgif com-video-to-gif-2

Of course you can’t really see it in a 25 FPS GIF, but on a real device it looks pretty stuttery on Android, even on newer flagship models.

Steps To Reproduce

  1. Create animation that adjusts a layout property (e.g. width) in the flexbox system which moves something out of the way (e.g. the buttons to the right)
  2. Run that “animation”/transition on drag, so interpolated from translateX in my case
  3. Compare iOS vs Android performance

Expected behavior

I expect the width transition to run somewhat smoothly

Actual behavior

It runs at very low FPS and has weird stuttering effects which looks like it’s jumping around.

Snack or minimal code example

Animated Style
  const searchBarStyle = useAnimatedStyle(() => {
    const index = translateX.value / -SCREEN_WIDTH;
    const width = interpolate(
      index,
      [0, 1, 2],
      [
        // those are just sample values, assuming that one button has 20px width
        180, // 1 button
        200, // 0 buttons
        160, // 2 buttons
      ]
    );

    return { width };
  }, []);
JSX View
      <Reanimated.View style={[styles.searchBar, searchBarStyle]}>
        <HeaderSearchBarContainer style={styles.fill} />
      </Reanimated.View>


      {visibleButtons === "chats" && (
        <>
          <InboxButton
            style={styles.button}
          />
          <NewChatButton
            style={styles.button}
          />
        </>
      )}
      {visibleButtons === "camera" && (
        <AddEventButton
          style={styles.button}
        />
      )}

Note: I am actually unmounting the buttons (see visibleButtons state) depending on the Swiper’s position. That’s done with a useAnimatedReaction and only triggers state updates once per page switching, so that can’t be the source of the problem.

Package versions

  • React: 16.13.1
  • React Native: 0.63.3
  • React Native Reanimated: 2.0.0-rc.0
  • NodeJS: v14.15.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
karol-bisztygacommented, Jan 13, 2021

Doesn’t seem like it is, but I’ll check once it’s resolved and there will be a repro.

1reaction
likerncommented, Dec 4, 2020

@gorhom @karol-bisztyga Thank you.

This is s bug in v3 bottomsheet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Low performance of layout params animation in Android
However, animation is very laggy even on simple layouts. Is there any way to improve the performance of layoutParams-changing animation? android ...
Read more >
Improve layout performance - Android Developers
Optimize layout hierarchies: In the same way that a complex web page can slow down load time, a complex layout hierarchy can also...
Read more >
Chapter 4. Screen and UI Performance - O'Reilly
We'll talk about that issue in “Overdrawing the Screen”. The more views your app has, the more time it will take to measure,...
Read more >
Using hardware layers to improve Android animation ...
All that said - there's no hard rules here. The Android rendering system is complex and often surprises me. As with all performance...
Read more >
Is Animations Bad or Good for Android - OnePlus Community
HeyI have a questions, Is the animations are good or bad for Android device's?Does the animation cause any damage or drop to the...
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