Ios 本机视图显示本机视图
有人知道如何让本机UIViewController出现或推送React本机视图,并在两者之间来回切换吗 如果可能,我希望在UIViewController中加载React本机视图,以便保留导航栏,但使用React本机视图 我一直在读这本书,但没有找到任何有效的 我尝试了以下几种组合:Ios 本机视图显示本机视图,ios,view,react-native,Ios,View,React Native,有人知道如何让本机UIViewController出现或推送React本机视图,并在两者之间来回切换吗 如果可能,我希望在UIViewController中加载React本机视图,以便保留导航栏,但使用React本机视图 我一直在读这本书,但没有找到任何有效的 我尝试了以下几种组合: // RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:nil launchOptions:nil]; // RCTRootView *reactV
// RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:nil launchOptions:nil];
// RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"My Test" initialProperties:nil];
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *reactView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"My Test"
initialProperties:nil
launchOptions:nil];
reactView.frame = self.view.frame;
[self.view addSubview:reactView];
我不太清楚它是如何知道我希望它使用什么.js React文件的,或者我是如何指定它的。要使这种方法起作用,您至少需要:
RCTrotView
s都可以共享的桥接器。如果希望每个根视图从同一个捆绑包加载不同的RN组件,则它们需要共享相同的RCTBridge
UIViewController
,它的视图是一个rcrootview
。然后,您可以使用此视图控制器作为导航控制器的根,以模态方式显示它,等等,就像您已经尝试过的那样#import <Foundation/Foundation.h>
#import "RCTBridge.h"
@interface ReactBridgeManager : NSObject
@property (nonatomic, strong, readonly) RCTBridge *bridge;
-(instancetype)initWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions;
@end
3.用法示例
现在,您可以在必要时使用react组件名称(这是在JS端的RNAppRegistry
中注册的组件)创建ReactViewController
的实例,并将其推送到本机导航堆栈中,显示为模式,等等
//when your app is initialized, create the bridge manager and hold a reference to it.
ReactBridgeManager *bridgeManager = [[ReactBridgeManager alloc] initWithBundleURL:jsCodeLocation launchOptions:launchOptions];
//create a view controller that's controlling a react root view
ReactViewController *reactViewController = [[ReactViewController alloc] initWithBridge:bridgeManager.bridge moduleName:@"MyComponent" initialProps:nil];
把它带到下一个层次
您可以看一看基本上使用相同概念为react本机应用程序提供完全本机导航解决方案的应用程序。免责声明:我是开发此软件包的团队的一员:)要使这种方法起作用,您至少需要:
RCTrotView
s都可以共享的桥接器。如果希望每个根视图从同一个捆绑包加载不同的RN组件,则它们需要共享相同的RCTBridge
UIViewController
,它的视图是一个rcrootview
。然后,您可以使用此视图控制器作为导航控制器的根,以模态方式显示它,等等,就像您已经尝试过的那样#import <Foundation/Foundation.h>
#import "RCTBridge.h"
@interface ReactBridgeManager : NSObject
@property (nonatomic, strong, readonly) RCTBridge *bridge;
-(instancetype)initWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions;
@end
3.用法示例
现在,您可以在必要时使用react组件名称(这是在JS端的RNAppRegistry
中注册的组件)创建ReactViewController
的实例,并将其推送到本机导航堆栈中,显示为模式,等等
//when your app is initialized, create the bridge manager and hold a reference to it.
ReactBridgeManager *bridgeManager = [[ReactBridgeManager alloc] initWithBundleURL:jsCodeLocation launchOptions:launchOptions];
//create a view controller that's controlling a react root view
ReactViewController *reactViewController = [[ReactViewController alloc] initWithBridge:bridgeManager.bridge moduleName:@"MyComponent" initialProps:nil];
把它带到下一个层次
您可以看一看基本上使用相同概念为react本机应用程序提供完全本机导航解决方案的应用程序。免责声明:我是开发此软件包的团队的一员:)好的,我做了所有这些,它运行良好。然而,我仍然不清楚jsCodeLocation应该指向什么。有什么想法吗?我使用的是:NSURL*jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@/src/components/“fallbackResource:nil];//初始化应用程序时,创建网桥管理器并保留对它的引用。self.bridgeManager=[[ReactBridgeManager alloc]initWithBundleURL:jsCodeLocation启动选项:启动选项];jsCodeLocation应该与任何RN项目相同,使用
jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@“index.ios”fallbackResource:nil]
@Artal你能看一下吗:我相信这应该是jsCodeLocation=[[rctbundleurlprovidersharedsettings]jsBundleURLForBundleRoot:@“index.js”fallbackResource:nil]代码>(即使用index.js而不是index.ios)好的,我做了所有这些,它运行良好。然而,我仍然不清楚jsCodeLocation应该指向什么。有什么想法吗?我使用的是:NSURL*jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@/src/components/“fallbackResource:nil];//初始化应用程序时,创建网桥管理器并保留对它的引用。self.bridgeManager=[[ReactBridgeManager alloc]initWithBundleURL:jsCodeLocation启动选项:启动选项];jsCodeLocation应该与任何RN项目相同,使用jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@“index.ios”fallbackResource:nil]
@Artal你能看一下吗:我相信这应该是jsCodeLocation=[[rctbundleurlprovidersharedsettings]jsBundleURLForBundleRoot:@“index.js”fallbackResource:nil]代码>(即使用index.js而不是index.ios)
//when your app is initialized, create the bridge manager and hold a reference to it.
ReactBridgeManager *bridgeManager = [[ReactBridgeManager alloc] initWithBundleURL:jsCodeLocation launchOptions:launchOptions];
//create a view controller that's controlling a react root view
ReactViewController *reactViewController = [[ReactViewController alloc] initWithBridge:bridgeManager.bridge moduleName:@"MyComponent" initialProps:nil];