1

I have an iOS native framework written in swift, which eventually needs to be wrapped as a react native component for a client. I managed to show the base view and make interactions with the buttons work (toast messages and date pickers displayed in the same view), but I cannot make it push a new view controller (which is internally pushed in the SDK).

I created a react native library with react-native-create-library and I installed my framework through the library's .podspec file as vendor_framework.

I linked the library to a sample react-native app, and so I started working on the .xcworkspace of the app.

Then I wrote some code in the default myLib.m and myLib.h to expose the module to JS.

myLib.h:

@interface RNHellLib : RCTViewManager <RCTBridgeModule>

+ (instancetype)sharedInstance;

- (void)configureSDK: (UIViewController *)rootController;

@end

myLib.m:

@implementation RNHellLib

- (dispatch_queue_t)methodQueue
{
    return dispatch_get_main_queue();
}

RCT_EXPORT_MODULE(RNSearchBox)
RCT_EXPORT_VIEW_PROPERTY(rootController, UIViewController)

SearchBox *mySearchBox;

- (UIView *)view {
    return mySearchBox;
}

+ (instancetype)sharedInstance {
    static RNHellLib *sharedInstance = nil;
    static dispatch_once_t onceToken = 0;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[RNHellLib alloc] init];

    });
    return sharedInstance;
}

- (void) configureSDK: (UINavigationController *)rootController {
    mySearchBox = [[SearchBox alloc] init];
    mySearchBox.rootController = rootController;
}

@end

The framework requires a UINavigationController to be assigned form the host app, so I modified a bit the appDelegate.m from SampleApp to use a UINavigationController instead of the default UIViewManager, and assigned it to my component as you see in myLib.m > configureSDK. The code in appDelegate.h:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

  UIViewController *rootViewController = [UIViewController new];
  UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];


  [[RNHellLib sharedInstance] configureSDK: navigationController];


  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"HellApp"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  navigationController.view = rootView;
  self.window.rootViewController = navigationController;

  [self.window makeKeyAndVisible];

  return YES;
}

Inside the framework, I have a public class SearchBox: UIView as entry door for the view stack. Then, to perform the segues, I do a vc.show as follows:

func show(_ viewControllerToShow:UIViewController, sender: Any?) {
        guard let vc = self.rootController else {
            return print("ERROR: Please set a rootController for the SearchBox");
        }
        vc.show(viewControllerToShow, sender: sender)
}

Depending on the element I interact with in the base view, I push a different controller from the function above. Among them, I have a UITextField that should push a new controller that manages an autocompletion view. Instead, the simulator access it as a regular TextInput and lets me write inside. Apart from it, I have a "Search" button that should, again, push another controller that manages a results view (which now is just throwing me a toast saying that I need to select something from the autocompletion).

I have thought of two possible problems here:

  1. (Most likely) The UINavigationController I configured at react-native is not able to manage the segues with vc.show.

  2. Actually the problem is related with the fact that the UITextField is being considered a TextInput for some reason.

Any ideas? I'm I approaching the whole thing wrongly? Thank you in advance for your support.

toni_piu
  • 135
  • 3
  • 11

0 Answers0