microsoft / reactxp

Library for cross-platform app development.
https://microsoft.github.io/reactxp/
Other
8.29k stars 494 forks source link

Interpolated animation values as strings don't work in Android #1189

Open kg-currenxie opened 4 years ago

kg-currenxie commented 4 years ago

const interpolatedValue = Animated.interpolate(animatedValue, [0.0, 1.0], ['0', '-5'])

The typed values in the second array are supposed to be strings. However Android doesn't like that.

Changing above strings to numbers does work! But TypeScript complains about it.

Screenshot 2020-03-11 at 09 59 23

// Works in iOS
const interpolatedValue = Animated.interpolate(animatedValue, [0.0, 1.0], ['0', '-5'])

const animatedStyle = Styles.createAnimatedViewStyle({
  transform: [{ translateY: interpolatedValue }],
})

return (
  <View style={styles.loadingWrapper}>
    <Animated.View style={[styles.loadingDot, animatedStyle]} />
  </View>
)

The type is as follows: let interpolate: (value: Animated.Value, inputRange: number[], outputRange: string[]) => Animated.Value

Edit: I've now tried Android, iOS, and web. All 3 work with just a number. Is this just a mis-typed parameter, or is there any other reason it was made a string?

kg-currenxie commented 4 years ago

Is this project dead? Not even a response

fbartho commented 4 years ago

You may have noticed that the world was a little busy since March. I suspect that this ticket just got forgotten! I certainly don't remember seeing the initial email.

-- I haven't contributed to the ReactXP Animated API or even used it very much, so I'm no expert as to why the typings are the way they are.

My guesses:

kg-currenxie commented 4 years ago

Good guesses :) I've tried without px on the web, and things animate as expected. So we can rule out that one. I'm thinking number should always work :) Accident? maybe :)

fbartho commented 4 years ago

@kg-currenxie -- would you be interested in contributing a fix here?

kg-currenxie commented 4 years ago

@fbartho yes I could :) Maybe end of the week

erictraut commented 4 years ago

The types need to be strings to support animatable types such as colors. If Android requires that some animatable types be expressed in terms of numbers, the ReactXP implementation should be converting the strings into numbers before passing them to RN.

fbartho commented 4 years ago

@erictraut, would it be appropriate to widen the type permit numbers, and do the conversion inside ReactXP?

fbartho commented 4 years ago

Or even: we don’t do any conversion? If outputrange is a number-range, interpolate numerically

erictraut commented 4 years ago

Whatever the approach, it should work consistently across all platforms.