React-native-reanimated: How to interpolate values into percentage?

Created on 9 Aug 2019  路  4Comments  路  Source: software-mansion/react-native-reanimated

I'm trying to run the next code:
const shiftPercentage = shift.interpolate({ inputRange: [0, 100], outputRange: ['0%', '100%'], });

and getting an error:
outputRange cannot include 0%.

Most helpful comment

@Haper take a look here:
https://github.com/kmagiera/react-native-reanimated#concat

you can do sth like:

const shiftPercentage = concat(interpolate(shift, { inputRange: [0,100], outputRange: [0,100] }), '%')

EDIT:

You have full example here too: https://github.com/kmagiera/react-native-reanimated/blob/06b03a84619cae3c4d9c044b89b7f01d4be8713b/Example/rotations/index.js#L62

All 4 comments

@Haper take a look here:
https://github.com/kmagiera/react-native-reanimated#concat

you can do sth like:

const shiftPercentage = concat(interpolate(shift, { inputRange: [0,100], outputRange: [0,100] }), '%')

EDIT:

You have full example here too: https://github.com/kmagiera/react-native-reanimated/blob/06b03a84619cae3c4d9c044b89b7f01d4be8713b/Example/rotations/index.js#L62

Thanks a lot!

@Haper take a look here:
https://github.com/kmagiera/react-native-reanimated#concat

you can do sth like:

const shiftPercentage = concat(interpolate(shift, { inputRange: [0,100], outputRange: [0,100] }), '%')

EDIT:

You have full example here too: https://github.com/kmagiera/react-native-reanimated/blob/06b03a84619cae3c4d9c044b89b7f01d4be8713b/Example/rotations/index.js#L62

How to do the same using Reanimated V2?

How to do the same using Reanimated V2?

Highly depends on "where" you use it, but as an example

const aStyles = useAnimatedStyle(() => {
  const value = interpolate(progress.value, [0, 100], [100, 0]);

  return {
    width: `${value}%`,
  };
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hosseinmd picture hosseinmd  路  3Comments

nextriot picture nextriot  路  3Comments

dinhmai74 picture dinhmai74  路  3Comments

sa8ab picture sa8ab  路  3Comments

robertgonzales picture robertgonzales  路  3Comments