1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #import "RNNBridgeModule.h"
-
- #import "RNN.h"
- #import "RNNControllerFactory.h"
- #import "RNNReactRootViewCreator.h"
- #import "RNNStore.h"
- #import "RNNModalManager.h"
-
- @implementation RNNBridgeModule
-
- RCT_EXPORT_MODULE();
-
- - (dispatch_queue_t)methodQueue
- {
- return dispatch_get_main_queue();
- }
-
- RCT_EXPORT_METHOD(setRoot:(NSDictionary*)layout)
- {
- [self assertReady];
- RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
- UIViewController *vc = [factory createLayoutAndSaveToStore:layout];
-
- UIApplication.sharedApplication.delegate.window.rootViewController = vc;
- [UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
- }
-
- RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout)
- {
- [self assertReady];
- RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
- UIViewController *newVc = [factory createLayoutAndSaveToStore:layout];
- UIViewController *vc = [[RNN instance].store findContainerForId:containerId];
-
- [[vc navigationController] pushViewController:newVc animated:true];
- }
-
- RCT_EXPORT_METHOD(pop:(NSString*)containerId)
- {
- [self assertReady];
- UIViewController *vc = [[RNN instance].store findContainerForId:containerId];
-
- if([[vc navigationController] topViewController] == vc ) {
- [[vc navigationController] popViewControllerAnimated:YES];
- }
- else {
- NSMutableArray * vcs = [vc navigationController].viewControllers.mutableCopy;
- [vcs removeObject:vc];
- [[vc navigationController] setViewControllers:vcs animated:NO];
- }
- [[RNN instance].store removeContainer:containerId];
- }
-
- RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout)
- {
- [self assertReady];
- RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
- UIViewController *newVc = [factory createLayoutAndSaveToStore:layout];
- [[[RNNModalManager alloc] initWithStore:[RNN instance].store] showModal:newVc];
- }
-
- RCT_EXPORT_METHOD(dismissModal:(NSString*)containerId)
- {
- [self assertReady];
- [[[RNNModalManager alloc] initWithStore:[RNN instance].store] dismissModal:containerId];
- }
-
- RCT_EXPORT_METHOD(dismissAllModals)
- {
- [self assertReady];
- [[[RNNModalManager alloc] initWithStore:[RNN instance].store] dismissAllModals];
- }
-
-
-
- - (void)assertReady
- {
- if (![RNN instance].isReadyToReceiveCommands) {
- @throw [NSException exceptionWithName:@"BridgeNotLoadedError" reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called." userInfo:nil];
- }
- }
-
-
-
-
-
- @end
-
|