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...

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
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} />
}
The image should scale from 0 to 1 when the initial scale is 0.
0.35.0To help narrow the issue down, can you listen to the animated value and tell us what it logs? This will tell us if the issue is with Animated.event or something wrong with Animated.Image
@ericvicenti It logs the current scroll position even when the image is not rendered so It seems like Animated.event is working as expected.
Maybe we could simplify the example repro case. Does this issue also happen on Android?
I do not have an android device to test on. I can try to put together a simple app to reproduce the issue.
Try rnplay.org, it should be an easy way to share the sample app and test on Android
I created a demo app to reproduce this issue. The animation is really bad in the simulator but the image is supposed to scale from 0 to 1 as you scroll.
You will notice on IOS the image is never rendered. On Android the image will scale as you scroll but the initial scale is not correctly set to 0. It is initially rendered with a scale of 1 and as you begin scrolling the scale jumps to 0 and then increases back to 1.
cc @janicduplessis
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.
Might not be related, but I've just debugged a problem where touch events were being swallowed because a view had transform: {scale: 0} (zero from an animated value). The -[UIWindow hitTest:withEvent:] method was returning this invisible view every time.
Doing an interpolate so that the minimum scale is 0.001 fixes the problem.
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
What about using a scale of 0.00001?
@Daniel-Goodwin you sir, has just saved my day!
Most helpful comment
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.