Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated regular/calculated issue #504

Open
MoOx opened this issue May 17, 2019 · 7 comments
Open

Animated regular/calculated issue #504

MoOx opened this issue May 17, 2019 · 7 comments
Labels

Comments

@MoOx
Copy link
Member

MoOx commented May 17, 2019

I am currently having an optional interpolation depending on an optional animated value

~transform=[|
  Transform.translateY(
    ~translateY=
      Animated.(
        animatedFloat(
          scrollYAnimatedValue
          ->Option.map(scrollYAnimatedValue =>
              Animated.Value.add(
                state.animation,
                Value.interpolate(
                  scrollYAnimatedValue,
                  Interpolation.(
                    config(
                      ~inputRange=[|(-200.), 1.|],
                      ~outputRange=
                        fromFloatArray([|(-200.), 1.|]),
                      (),
                    )
                  ),
                ),
              )
            )
          ->Option.getWithDefault(state.animation),
        )
      ),
  ),
|],

This code should work but doesn't compile, complaining that ->Option.getWithDefault(state.animation) isn't the same type as the interpolation.

Error: This expression has type
         ReactNative.Animated.value(ReactNative.Animated.regular) =
           ReactNative.Animated.value(ReactNative.Animated.regular)
       but an expression was expected of type
         ReactNative.Animated.value(ReactNative.Animated.calculated) =
           ReactNative.Animated.value(ReactNative.Animated.calculated)
       Type ReactNative.Animated.regular = ReactNative.Animated.regular
       is not compatible with type
         ReactNative.Animated.calculated = ReactNative.Animated.calculated

We should have something to tell that a regular & calculated are the same at the end, don't we?

@wokalski
Copy link
Collaborator

ReactNative.Animated.value('a) is a polymorphic Animated.value type. I suggest you change the order of the execution so that the output from different branches is Transform. You might also try playing with the type system in some other way.

@sgny
Copy link
Collaborator

sgny commented May 18, 2019

I suppose we could use a method to convert a value(calculated) to value(regular) but perhaps we don't really need to differentiate between those types in the first place. I had that opinion when reworking the Animated module, but as I don't know the motivation behind the differentiation in the first place, decided against raising the point as I might be missing the intention.

@grabbou Since this came from your Rebolt effort, perhaps you know the intention behind it? It appears first with reasonml-community/bs-react-native@ccb44f4.

@wokalski
Copy link
Collaborator

If you plug regular in functions that expect calculated (and vice versa) you’ll get runtime errors (unless something changed in more recent RN versions)

@sgny
Copy link
Collaborator

sgny commented May 18, 2019

If you plug regular in functions that expect calculated (and vice versa) you’ll get runtime errors (unless something changed in more recent RN versions)

Do you have any concrete examples to try? Looking at function types, I'd expect chaining Interpolation.interpolate would be what causes runtime errors, such as

x -> Interpolation.interpolate(configA) -> Interpolation.interpolate(configB)

However, perhaps add or multiply can still be `(value('a), value('a)) => value('a)'.

@wokalski
Copy link
Collaborator

@sgny you'd have to try. My memory might be failing me but I think those type definitions are correct.

@sgny
Copy link
Collaborator

sgny commented May 19, 2019

@sgny you'd have to try. My memory might be failing me but I think those type definitions are correct.

@wokalski I've been trying and it appears that the disctinction is still necessary. Chained interpolation is fine (at least so far as not causing runtime errors), but setValue on value(calculated) is definitely not allowed, whether it is the result of interpolation or add. I was under the mistaken impression that operations such as add created a new Animated value, separate from the components (which I suppose would be mostly useless were that true), but as the result should track changes in its components, then operations such as setValue are meaningless.

TLDR; current bindings represent a subtle understanding of provided functionality.

@MoOx
Copy link
Member Author

MoOx commented May 20, 2019

Ok, thanks for the explanation @wokalski @sgny. I will close this issue when this will be explained in the doc to avoid future similar question :)

@MoOx MoOx added the question label May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants