使用Wix React Native Navigation(RNN)时将属性从native传递给React Native

时间:2019-06-01 02:41:11

标签: react-native react-native-navigation wix-react-native-navigation

here描述了将属性从本地传递到React Native。这是一个摘要:

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。根据文档,这是最小的RNN设置在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

我们如何从本地传递道具?

2 个答案:

答案 0 :(得分:1)

您需要为此create a native module。该模块公开了公共方法,这些方法通过resolving a promise返回结果。

答案 1 :(得分:0)

当我将属性从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);