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.

Animating Images from scale 0 to 1

See original GitHub issue

Issue Description

When using Animated.event to map the user’s scroll position to the scale of an image, if the scroll position is such that the scale of the image is zero when the view is first rendered then the image will never be displayed.

Gifs speak a thousand words…

d

The yellow box error is complaining about fetch,

Unable to symbolicate stack trace: fetch is not a function

Most likely because I am using Apollo Client, #9605

Steps to Reproduce / Code Snippets

constructor(props) {
    super(props);

    this.state = {
      scrollY: new Animated.Value(SCROLL_MIN)
    };

    this.onScroll = Animated.event([{
      nativeEvent: {
        contentOffset: {
          y: this.state.scrollY
        }
      }
    }]);
  }

renderAvatar() {
    if(this.props.presentationStyle !== expanded) {
      return null;
    }

    const props = {
      style: [styles.avatar],
      source: {
        uri: this.state.business.avatar
      }
    };

    const interpolate = {
      inputRange: [SCROLL_MIN, SCROLL_MAX_AVATAR],
      extrapolate: 'clamp'
    };

    const scale = this.state.scrollY.interpolate({
      ...interpolate,
      outputRange: [1, 0]
    });

    const translateY = this.state.scrollY.interpolate({
      ...interpolate,
      outputRange: [0, TRANSLATE_AVATAR_MAX]
    });

    props.style.push({
      transform: [{translateY}, {scale}]
    });

    return <Animated.Image {...props} />
  }

Expected Results

The image should scale from 0 to 1 when the initial scale is 0.

Additional Information

  • React Native version: 0.35.0
  • Platform(s) (iOS, Android, or both?): IOS
  • Operating System (macOS, Linux, or Windows?): OSX

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
Daniel-Goodwincommented, Oct 31, 2016

In the meantime set the initial scale value to 0.01, that will force it to be rendered but is not big enough to be visible.

0reactions
kevinmcamposcommented, Aug 3, 2017

@Daniel-Goodwin you sir, has just saved my day!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Premiere Pro : How to Animate Increasing Image ... - YouTube
A tutorial on how to increase the image size with animation in Adobe ... This is also known as animating the scale. ......
Read more >
Scaling Responsive Animations - CSS-Tricks
Guidelines for scaling responsive animations. 1. Size the animations based on a container ... .container { height: 0; padding-top: 100%; }.
Read more >
Can I scale 1 image in animation to bigger and still maintain ...
Go to the start frame, select the image of the e.g. earth. Press "S" and scale it to the wanted start size. Now...
Read more >
How do I use css transitions to scale an image and move it at ...
Codepen example: http://codepen.io/anon/pen/fipaL. Instead of top and left properties you shoud use translate3d CSS3 property, so to get ...
Read more >
Animating CSS Width And Height Without The Squish Effect
This is called the 9-slice scaling method. Tis method allows you to scale the element and stretch image 2, 4, 6, and 8,...
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