react-nativeexpolottiebodymovin

How do I use ColorFilter with React-Native-Lottie?


I cannot seem to get the colorFilter prop working with my .json file. There are no errors but the colours are clearly not changing.

<LottieView
     style={{
         width: 90,
         height: 90,
     }}
     colorFilters={
       [
         {
         keypath: "asdf",
         color: "#abcdef",
         }
       ]
     }
     source={badge.icon}
     loop={false}
/>

I'm importing the .json from After Effects using BodyMovin but am I changing the layer name correctly? If not why on earth is this not working? enter image description here


Solution

  • I can't get colorFilters to work but you can try doing the following:

    
    import myAnimation from "./../img/myAnimation.json";
    
    

    in the render part use LottieView with the import and not with the require inline

    <LottieView        
      //source={require("./../img/radius.json")}
      source={myAnimation}
    />
    
    

    Now you can manipulate the properties directly from the json object, just for example here I manipulate the color based on the actual color (from black to white or from white to black)

    myAnimation.layers[1].shapes[0].it[1].c.k = myAnimation.layers[1].shapes[0].it[1].c.k[0] == 0 ?  [1,1,1,1] : [0,0,0,1];
    

    To find out what is the property you need, check the json, it is not very clear but with some trial and error you can understand the structure.