使用 Wix React Native Navigation (RNN) 时将属性从本机传递到 React Native
Passing properties from native to React Native when using Wix React Native Navigation (RNN)
描述了将属性从本机传递到 React Native here。总结如下:
NSArray *imageList = @[@"http://foo.com/bar1.png",
@"http://foo.com/bar2.png"];
NSDictionary *props = @{@"images" : imageList};
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"ImageBrowserApp"
initialProperties:props];
然而,当使用Wix React Native Navigation时,没有rootView
。根据文档,这是 iOS:
上最小 RNN 设置的样子
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <ReactNativeNavigation/ReactNativeNavigation.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
return YES;
}
@end
我们如何从本地传递道具?
当我将 属性 从 React Native 传递到原生 iOS 时,您需要检查原生 iOS 到 React Native 属性 的传递。这是我的代码
在iOS
Appdelegate.h
#import <UIKit/UIKit.h>
#import "React/RCTBridgeModule.h"
@import Firebase;
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeModule>
@property (strong, nonatomic) UIWindow *window;
@end
Appdelegate.m
#import "RCTBundleURLProvider.h"
#import <React/RCTLog.h>
@implementation AppDelegate
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(addEvent:(NSString *)propertyName)
{
//Here you get your property value
var property = propertyName;
RCTLogInfo(@"Pretending to create an event %@ at %@", areaId);
}
在 React Native 中
MyComponent.js
import { NativeModules } from 'react-native';
var AppDelegate = NativeModules.AppDelegate;
AppDelegate.addEvent(value);
您需要create a native module for that. The module exposes public methods which return results by resolving a promise。
描述了将属性从本机传递到 React Native here。总结如下:
NSArray *imageList = @[@"http://foo.com/bar1.png",
@"http://foo.com/bar2.png"];
NSDictionary *props = @{@"images" : imageList};
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"ImageBrowserApp"
initialProperties:props];
然而,当使用Wix React Native Navigation时,没有rootView
。根据文档,这是 iOS:
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <ReactNativeNavigation/ReactNativeNavigation.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
return YES;
}
@end
我们如何从本地传递道具?
当我将 属性 从 React Native 传递到原生 iOS 时,您需要检查原生 iOS 到 React Native 属性 的传递。这是我的代码
在iOS
Appdelegate.h
#import <UIKit/UIKit.h>
#import "React/RCTBridgeModule.h"
@import Firebase;
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeModule>
@property (strong, nonatomic) UIWindow *window;
@end
Appdelegate.m
#import "RCTBundleURLProvider.h"
#import <React/RCTLog.h>
@implementation AppDelegate
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(addEvent:(NSString *)propertyName)
{
//Here you get your property value
var property = propertyName;
RCTLogInfo(@"Pretending to create an event %@ at %@", areaId);
}
在 React Native 中
MyComponent.js
import { NativeModules } from 'react-native';
var AppDelegate = NativeModules.AppDelegate;
AppDelegate.addEvent(value);
您需要create a native module for that. The module exposes public methods which return results by resolving a promise。