Gathering detailed insights and metrics for @fsujob1984/react-native-adapter
Gathering detailed insights and metrics for @fsujob1984/react-native-adapter
Gathering detailed insights and metrics for @fsujob1984/react-native-adapter
Gathering detailed insights and metrics for @fsujob1984/react-native-adapter
npm install @fsujob1984/react-native-adapter
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
2
A React Native adapter for Expo Universal Modules. It requires @unimodules/core
to be installed and linked.
1$ yarn add @unimodules/react-native-adapter 2 3# or 4 5$ npm install @unimodules/react-native-adapter --save
If you are using react-native-unimodules
, this package will already be installed and configured!
If you're using Cocoapods, add the dependency to your Podfile
:
pod 'UMReactNativeAdapter', path: '../node_modules/@unimodules/react-native-adapter/ios', inhibit_warnings: true
and run npx pod-install
.
android/settings.gradle
:
1include ':unimodules-react-native-adapter' 2project(':unimodules-react-native-adapter').projectDir = new File(rootProject.projectDir, '../node_modules/@unimodules/react-native-adapter/android')
android/app/build.gradle
:
1compile project(':unimodules-react-native-adapter')
Open the AppDelegate.m
of your application.
Import <UMCore/UMModuleRegistry.h>
, <UMReactNativeAdapter/UMNativeModulesProxy.h>
and <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
.
Make AppDelegate
implement RCTBridgeDelegate
protocol (@interface AppDelegate () <RCTBridgeDelegate>
).
Add a new instance variable to your AppDelegate
:
1@interface AppDelegate () <RCTBridgeDelegate> 2 3// add this line 4@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; 5 6@end
In -application:didFinishLaunchingWithOptions:
add the following at the top of the implementation:
1self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];
Add two methods to the AppDelegate
's implementation:
1- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge 2{ 3 NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge]; 4 // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here! 5 return extraModules; 6} 7 8- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { 9 return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 10}
When initializing RCTBridge
, make the AppDelegate
a delegate of the bridge:
1RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
or, if you use react-native-navigation
, add the bridgeManagerDelegate
parameter of self
, like:
1-[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions]; 2+[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:self];
That's it! All in all, your AppDelegate.m
should look similar to:
1#import "AppDelegate.h" 2 3#import <React/RCTBundleURLProvider.h> 4#import <React/RCTRootView.h> 5 6#import <UMCore/UMModuleRegistry.h> 7#import <UMReactNativeAdapter/UMNativeModulesProxy.h> 8#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h> 9 10@interface AppDelegate () <RCTBridgeDelegate> 11 12@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; 13 14@end 15 16@implementation AppDelegate 17 18- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19{ 20 self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; 21 RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 22 RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"YOUR_MODULE_NAME" initialProperties:nil]; 23 rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 24 25 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 26 UIViewController *rootViewController = [UIViewController new]; 27 rootViewController.view = rootView; 28 self.window.rootViewController = rootViewController; 29 [self.window makeKeyAndVisible]; 30 return YES; 31} 32 33- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge 34{ 35 NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge]; 36 // If you'd like to export some custom RCTBridgeModules that are not universal modules, add them here! 37 return extraModules; 38} 39 40- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { 41 return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 42} 43 44@end
MainApplication.java
of your application.1import org.unimodules.adapters.react.ModuleRegistryAdapter; 2import org.unimodules.adapters.react.ReactAdapterPackage; 3import org.unimodules.adapters.react.ReactModuleRegistryProvider; 4import org.unimodules.core.interfaces.Package;
Application
:
1private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(Arrays.<Package>asList( 2 new ReactAdapterPackage() 3 // more packages, like 4 // new CameraPackage(), if you use expo-camera 5 // etc. 6), /* singletonModules */ null);
new ModuleRegistryAdapter(mModuleRegistryProvider)
to the list returned by protected List<ReactPackage> getPackages()
.Native modules are available behind the proxy (NativeModulesProxy
of @unimodules/core
).
To call an exported method, use NativeModulesProxy[clientCodeName].exportedMethod(...arguments)
, like this:
1// For UM_REGISTER_MODULE(FileSystem,) or UM_REGISTER_UMPORTED_MODULE(FileSystem) 2// and UM_EXPORT_METHOD_AS(getInfo, getInfo:(NSString *)path) 3 4// or for method 5// @ExpoMethod 6// public void getInfo(String path, Promise promise) 7// defined in native module with name FileSystem 8 9import { NativeModulesProxy } from '@unimodules/core'; 10 11const { FileSystem } = NativeModulesProxy; 12 13FileSystem.getInfo('file:///...');
Note that all the methods return Promise
s.
When creating web universal modules, you may find that you need to send events back to the API layer.
In this case you will want to use the shared SyntheticPlatformEmitter
instance from @unimodules/core
. The shared emitter emit events to react-native
's NativeEventEmitter
and @unimodules/core
's EventEmitter
.
ExponentGyroscope.web.ts
1// Example from expo-sensors native web gyroscope sensor 2 3import { SyntheticPlatformEmitter } from '@unimodules/core'; 4 5SyntheticPlatformEmitter.emit('gyroscopeDidUpdate', { x, y, z });
This emitted event is then received with a EventEmitter
in the developer-facing API.
1import { EventEmitter } from '@unimodules/core'; 2 3import ExponentGyroscope from './ExponentGyroscope'; 4 5const nativeEmitter = new EventEmitter(ExponentGyroscope); 6 7// On Android and iOS, `nativeEmitter` receives events sent from Objective-C and Java. On web, it 8// receives events from the shared `SyntheticPlatformEmitter` instance. 9nativeEmitter.addListener('gyroscopeDidUpdate', ({ x, y, z }) => {});
No vulnerabilities found.
No security vulnerabilities found.