@trycourier/courier-react-native
Version:
Inbox, Push Notifications, and Preferences for React Native
27 lines (26 loc) • 1.19 kB
JavaScript
import { NativeModules, Platform, UIManager, requireNativeComponent } from "react-native";
export class Modules {
static LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';
static Client = Modules.getNativeModule(NativeModules.CourierClientModule);
static Shared = Modules.getNativeModule(NativeModules.CourierSharedModule);
static System = Modules.getNativeModule(NativeModules.CourierSystemModule);
static getNativeModule(nativeModule) {
return nativeModule
? nativeModule
: new Proxy({}, {
get() {
throw new Error(Modules.LINKING_ERROR);
},
});
}
static getNativeComponent(componentName) {
return UIManager.getViewManagerConfig(componentName) != null
? requireNativeComponent(componentName)
: () => {
throw new Error(Modules.LINKING_ERROR);
};
}
}