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

2
  • is an advice to never use React Native going to get me banned? I think that's the best option really. Commented Feb 5, 2023 at 1: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. Commented Feb 5, 2023 at 4:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.