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?