Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
How to move in AND OUT of Native Module in React Native?

My question has to do with native modules in React and how to switch between Js views and a Swift written native modules. The code I have is pretty boilerplate from various examples.

The goToNativeView function below swaps out the rootViewController to enter the Swift code (through the Main storyboard file). How would I instrument a function call from Swift to return back to my Javascript application?

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"RNImageCollectorV2"
                                            initialProperties:nil];

  if (@available(iOS 13.0, *)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
      rootView.backgroundColor = [UIColor whiteColor];
  }

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

// this method will be called from the RCTBridge
- (void) goToNativeView {
    NSLog(@"RN binding - Native View - CameraViewController.swift - Load From main storyboard");
    UIViewController *vc = [UIStoryboard storyboardWithName:@"Main" bundle:nil].instantiateInitialViewController;
    self.window.rootViewController = vc;
}

In my React Component, I have a simple function that enables the native module. I'm assuming I need a callback or listener for the exit call

App.tsx

class App extends Component {

  constructor(props) {
    super(props)
  }

  _changeView = () => {
    // this.done = true;
    // this.render();
    NativeModules.ChangeViewBridge.changeToNativeView();
  };

  render() {
    return (
       <TouchableHighlight onPress={() => this._changeView()}>
                <Text color="#336699">Press to Change to Native View</Text>
              </TouchableHighlight>
  )}
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda