@talkjs/expo
Version:
Official TalkJS SDK for React Native (Expo)
47 lines (43 loc) • 2.36 kB
JavaScript
;
/* (Victor August 2024):`require.context` has been available on React Native since v0.72.1 (2023: https://github.com/facebook/metro/issues/52#issuecomment-2072494624)
It is still considered experimental however, the Expo guys have it enabled
in the Expo Metro bundler as it is needed for their Expo Router feature.
As noted in this comment: https://github.com/facebook/metro/pull/822/#issuecomment-1807132897
the fact that this has been working just fine on Expo for quite some time now
means that it should probably be considered stable.
While testing I discovered that `require.context`'s first parameter has to
be a static string hence why there's a lot of code duplication=related to
dynamic imports. I tried making a generic function for dynamic importing
libraries and that's when I made the above discovery.
*/
// @react-native-firebase before version 23.8.0
const FirebaseMessagingContextLib = require.context('../../../../@react-native-firebase/messaging/lib', false, /index\.js$/);
// @react-native-firebase after version 23.8.0
const FirebaseMessagingContextDist = require.context('../../../../@react-native-firebase/messaging/dist/module', false, /index\.js$/);
const ExpoNotificationsContext = require.context('../../../../expo-notifications/build', false, /index\.js$/);
const ExpoTaskManagerContext = require.context('../../../../expo-task-manager/build', false, /\.js$/);
function isInstalled(context) {
return context.keys().length !== 0;
}
export function isFirebaseInstalled() {
return isInstalled(FirebaseMessagingContextLib) || isInstalled(FirebaseMessagingContextDist);
}
export function isExpoNotificationsInstalled() {
return isInstalled(ExpoNotificationsContext);
}
export function getFirebaseMessaging() {
if (isInstalled(FirebaseMessagingContextLib)) {
return FirebaseMessagingContextLib('./index.js');
}
if (isInstalled(FirebaseMessagingContextDist)) {
return FirebaseMessagingContextDist('./index.js');
}
return undefined;
}
export function getExpoNotifications() {
return isInstalled(ExpoNotificationsContext) ? ExpoNotificationsContext('./index.js') : undefined;
}
export function getExpoTaskManager() {
return isInstalled(ExpoTaskManagerContext) ? ExpoTaskManagerContext('./TaskManager.js') : undefined;
}
//# sourceMappingURL=Imports.js.map