I have developed a bottom tab navigator and used Lottie animations as icons. I want them to autoplay and get played only once when it's in focus (like the Binance app). I have tried with loop={false}
but that stops it from animating altogether. The code is as follow:
import React from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import LottieView from 'lottie-react-native';
import Home from './Home';
import Create from './Create';
import Messages from './Messages';
import Forum from './Forum';
import Profile from './Profile';
const Tab = createBottomTabNavigator();
export default function Tabs() {
return (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let filePath;
switch (route.name) {
case 'Home':
filePath = require('../tabanimations/hometab.json');
break;
case 'Messages':
filePath = require('../tabanimations/messagestab.json');
break;
case 'Create':
filePath = require('../tabanimations/hometab.json');
break;
case 'Forum':
filePath = require('../tabanimations/forumtab.json');
case 'Profile':
filePath = require('../tabanimations/profiletab.json');
break;
}
return <LottieView source={filePath} autoPlay={focused} />;
},
})}>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Messages" component={Messages} />
<Tab.Screen name="Create" component={Create} />
<Tab.Screen name="Forum" component={Forum} />
<Tab.Screen name="Profile" component={Profile} />
</Tab.Navigator>
);
}
How to play the animation only once on focus?