What is expo-modules-core?
The expo-modules-core package is a core library for Expo modules, providing essential utilities and base classes for building and integrating native modules in Expo and React Native applications. It helps in creating consistent and efficient modules that can be used across different platforms.
What are expo-modules-core's main functionalities?
Module Registry
The Module Registry feature allows you to access native modules registered in the Expo environment. This example demonstrates how to import and use a native module called 'MyModule' to perform an action.
import { NativeModulesProxy } from 'expo-modules-core';
const { MyModule } = NativeModulesProxy;
MyModule.doSomething();
Event Emitters
Event Emitters in expo-modules-core enable you to listen to and handle events emitted by native modules. This example shows how to create an event emitter for a module and add a listener for a specific event.
import { EventEmitter } from 'expo-modules-core';
const emitter = new EventEmitter(MyModule);
emitter.addListener('eventName', (event) => {
console.log(event);
});
Platform-specific Code
The Platform module allows you to write platform-specific code by checking the operating system at runtime. This example demonstrates how to log different messages based on whether the app is running on iOS or Android.
import { Platform } from 'expo-modules-core';
if (Platform.OS === 'ios') {
console.log('Running on iOS');
} else if (Platform.OS === 'android') {
console.log('Running on Android');
}
Other packages similar to expo-modules-core
react-native
React Native is a popular framework for building mobile applications using JavaScript and React. It provides a set of core components and APIs for building cross-platform apps. Compared to expo-modules-core, React Native offers a broader range of functionalities but requires more setup and configuration for native modules.
react-native-device-info
react-native-device-info is a library that provides device information for React Native apps. It offers functionalities similar to the Platform module in expo-modules-core but focuses specifically on retrieving device-related information such as device model, OS version, and more.
react-native-event-listeners
react-native-event-listeners is a library for managing event listeners in React Native applications. It provides similar functionality to the EventEmitter in expo-modules-core, allowing you to add and remove event listeners easily.
expo-modules-core
The core of Expo Modules architecture.
Installation in managed Expo projects
For managed managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release. If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
Installation in bare React Native projects
For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules
package before continuing.
Add the package to your npm dependencies
npm install expo-modules-core
Configure for iOS
Run npx pod-install
after installing the npm package.
Configure for Android
No additional set up necessary.
Contributing
Contributions are very welcome! Please refer to guidelines described in the contributing guide.