0

Preface: this error message with requireNativeComponent appears often on StackOverflow, mostly resolved with the suggestions such as disintegrating the pods, and then performing a new pod install and recompiling.

Unfortunately this has not worked out in my case.

--

I am trying to lift a simple view, written in Swift, into my React Native 0.71.x project.

iOS Swift code TestViewManager.swift

import Foundation
import UIKit

@objc (TestViewManager)
class TestViewManager: RCTViewManager {
  override func view() -> UIView! {

    let label = UILabel()
    label.text = "Hello from parent"
    label.sizeToFit()
    label.textAlignment = .center
    label.textColor = .link
    
    return label
  }
  
  override static func requiresMainQueueSetup() -> Bool {
    return true
  }
  
}

The Objective-C implementation file TestViewManager.m

#import <Foundation/Foundation.h>

#import "React/RCTBridgeModule.h"
#import "React/RCTViewManager.h"

@interface RCT_EXTERN_MODULE(TestViewManager, RCTViewManager);

@end

In React Native, the TestView.js file

import React, {Component} from 'react';
import {requireNativeComponent} from 'react-native';

const RNTestView = requireNativeComponent('TestViewManager');

export default class TestView extends Component {
    render() {
        return <RNTestView />;
    }
}

Everything appears to be extremely vanilla, similar to this person's set up (with same issue, unanswered)

However, the outcome is the message: Invariant Violation: requireNativeComponent: "TestViewManager" was not found in the UIManager.

What am I doing incorrectly?

enter image description here

daspianist
  • 5,336
  • 8
  • 50
  • 94
  • is an advice to never use React Native going to get me banned? I think that's the best option really. – timbre timbre Feb 05 '23 at 01:57
  • I am in your boat @rapiddevice, but unfortunately this task requires the use of react native. In fact, it is based on a react native project, and I am tasked with writing a poorly optimized component in native Swift. Any tips would be much appreciated. – daspianist Feb 05 '23 at 04:55

0 Answers0