I am in the process of creating my own custom ui component for react native in objective-c and so far everything works, except I can't seem to call any methods on my component. This is my objective-c
#import "RNTWebViewManager.h"
#import <WebKit/WebKit.h>
@interface RNTWebViewManager()
@property (strong, nonatomic) WKWebView *webView;
@end
@implementation RNTWebViewManager
@synthesize webView;
RCT_EXPORT_MODULE()
- (UIView *)view {
webView = [[WKWebView alloc] init];
return webView;
}
RCT_EXPORT_METHOD(loadWebsite:(NSString *)url)
{
RCTLogInfo(@"Opening url %@",url);
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
};
@end
And here is my corresponding javascript code:
import React, { Component } from 'react';
import {
requireNativeComponent,
AppRegistry,
StyleSheet,
Button,
Text,
View
} from 'react-native';
// Load Native iOS Components
var RNTWebView = requireNativeComponent('RNTWebView', null);
class WebView extends Component {
render() {
return (
<RNTWebView style={styles.webView} />
)
}
}
export default class iOSComponents extends Component {
componentDidMount() {
RNTWebView.loadWebsite("http://www.google.com/");
}
render() {
return (
<View style={styles.webView}>
<View style={styles.statusBar} />
<WebView />
</View>
);
}
}
const styles = StyleSheet.create({
statusBar: {
height:22,
},
webView: {
flex:1,
}
});
AppRegistry.registerComponent('iOSComponents', () => iOSComponents);
When I try calling RNTWebView.loadWebsite("http://www.google.com") I get an error saying RNTWebView.loadWebsite is not a function.