Trying to use Motion-Framer to animate my componen...
# javascript
n
Trying to use Motion-Framer to animate my components, the API looks like this
Copy code
<motion.div 
   animate= {{x: [50, 0], opacity: [0,1]}} // X will go from 50% to 0%  and opacity from 0% to 100%
I tried to translate the animate property with dynamics
Copy code
val animate = js("{}")
animate.x = listOf(50, 0)
animate.opacity = listOf(0, 1)
When it gets converted to JS, the lists are ArrayLists instead of what I'd expect to be a List and even adding
.toList
results in the same transformation. For some reason this doesn't work, and I have to use
Copy code
animate.x = js("[50,0]")
animate.opacity = js("[0,1]")
For it to work as expected , which doesn't allow me to pass parameters as
js()
only accepts string literals
1.5.31
Kotlin
b
listOf() uses kotlin implementation of list. If you want to get JS arrays, use arrayOf()
👍 1
n
This seems to have done the trick, thanks! Got confused as the Console was specifying the type
List
for the
js("[50,0]")
h
I don't understand why
kotlin.List
converts to the useful and common
Swift.Array
in Objective-C, but on JS to a custom Kotlin class. Only on JS you have to use
kotlin.Array
...
b
Not entirely true.
kotlin.Array
maps to primitive arrays on JVM as well. I've always did my best to stay away from apple stuff so can't comment on why swift interop deviates from this convention for
kotlin.List
. What does
kotlin.Array
translates to when compiled to obj-c? Does obj-c have a distinction between arrays and lists?
h
Yeah, okay, I forgot primitive arrays on JVM 😄
Kotlin IntArray to objective c results into a
KotlinIntArray
😄 Not really, objective-c has NSArray and NSMutableArray.
b
Just like JS. In that case I'd expect kotlin.List to not map to NSArray and have that reserved for kotlin.Array only. Consistency is key.
For it to work as expected , which doesn't allow me to pass parameters as 
js()
 only accepts string literals
For completeness, this can be hacked as well
Copy code
fun main() {
  var myVar = "Hello there!"
  js("console.log(myVar)")
  tmp = "General Kenobi"
  js("console.log(myVar)")
}