Sagar Karki
Sagar Karki

Reputation: 419

Adding animation on screen focus React Native

I want to run my animations from react-native-reanimated everytime my screen is focused. How can I achieve this.

Upvotes: 0

Views: 910

Answers (1)

Faras Al Kharusi
Faras Al Kharusi

Reputation: 23

I am not sure whether I understand your question correctly, but in most cases you can use the useIsFocused hook from react navigation.

like this:

import React from "react";
import { useIsFocused } from '@react-navigation/native';

function YourScreenScreen() {
  const isFocused = useIsFocused();

   React.useEffect(() => {
    
   //put whatever you want here when the screen is focused

  }, [isFocused]);

  return <>......</>;
}

more reference here Hope this answers your question, Gl!

Upvotes: 1

Related Questions