Skip to content

Latest commit

 

History

History
26 lines (14 loc) · 3.69 KB

File metadata and controls

26 lines (14 loc) · 3.69 KB

Subscribing to important application events

Your app or library may need to subscribe to application events such as onCreate (Android), applicationDidFinishLaunching (iOS) and more. Often times, it's necessary to hook into these events to perform, for example, a third-party SDK setup.

Expo Modules API supports integrating with these APIs from your modules, without needing to modify the underlying native project. This can be achieved with Android lifecycle listeners and iOS AppDelegate subscribers. We'll collectively call these "Subscribers" in this document.

Migrating legacy config plugins

You may be using a config plugin to add code inside the same methods that the Subscribers allow hooking into. Using Subscribers is the recommended approach, as they are more robust and less error-prone, since they compose well with multiple listeners compared to modifying code with a regular expression in a config plugin. For example, in SDK 53, AppDelegate was migrated from Objective-C to Swift, which would break config plugins that only supported Objective-C.

If you are using a config plugin to perform a task that can be done by a Subscriber, we recommend you switch to Subscribers. Alternatively, read instructions below to migrate your config plugin to support Swift.

Migrating to Subscribers (recommended)

Read more about this approach and see examples in "Developing and debugging a plugin". For a step-by-step guide for libraries, follow "integrate Expo Modules API into an existing library".

A good, minimal example of using Subscribers in a community Expo Module is react-native-app-security: see its Android lifecycle listener and iOS AppDelegate subscriber.

Updating the config plugin

If you want to make modifications using a config plugin, make use of utility functions exported from expo/config-plugins listed below. For an example of a config plugin that modifies the AppDelegate.swift/mm and MainActivity.kt/java, refer to react-native-bootsplash config plugin.

This list is non-exhaustive.