> For the complete documentation index, see [llms.txt](https://colorfy-software.gitbook.io/react-native-modalfy/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://colorfy-software.gitbook.io/react-native-modalfy/guides/events.md).

# Subscribing to events

#### [**> ModalComponentProp API**](/react-native-modalfy/api/types/modalcomponentprop.md)

Once in a while, we might want to perform some animations alongside the ones applied to our modals.

One example could be animating the modal and something inside it at the same time. But to do so and have those animations happening in sync, we'd need to have access to the `animatedValue` Modalfy uses under the hood.

Another example could be that you'd like to be notified when your modal is about to be closed by Modalfy. Being able to access a `closingAction` could be very valuable here!

Use cases like this are the reason why we decided to provide a way to hook into the library's internal events, thanks to `modal.addListener()`:

{% tabs %}
{% tab title="React JSX" %}
{% code title="./modals/EmptyModal.tsx" %}

```jsx
import React, { useEffect, useRef }  from 'react'

const EmptyModal = ({ modal: { addListener }) => {
  const onAnimateListener = useRef()
  const onCloseListener = useRef()


  const handleAnimation = (value) => {
    console.log('Modal animatedValue:', value)
  }
  
  const handleClose = useCallback(
    closingAction => {
      console.log(`Modal by: ${closingAction.type} • ${closingAction.origin}`)
    },
  )

  useEffect(() => {
    onAnimateListener.current = addListener('onAnimate', handleAnimation)
    onCloseListener.current = addListener('onClose', handleClose)
    
    return () => {
      onAnimateListener.current?.remove()
      onCloseListener.current?.remove()
    }
  }, [])

  return (
    //...
  )
}

export default EmptyModal
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
`onAnimate` & `onClose` are the only events we support for now. If there is another one you'd like to have, please: [let us know](https://github.com/colorfy-software/react-native-modalfy/issues/new)!
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://colorfy-software.gitbook.io/react-native-modalfy/guides/events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
