85 lines
2.8 KiB
Objective-C
85 lines
2.8 KiB
Objective-C
#import "RCTWKWebViewManager.h"
|
|
|
|
#import "RCTUIManager.h"
|
|
#import "RCTWKWebView.h"
|
|
|
|
@implementation RCTWKWebViewManager
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
- (UIView *)view
|
|
{
|
|
return [RCTWKWebView new];
|
|
}
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
|
|
RCT_EXPORT_VIEW_PROPERTY(onLoadingStart, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onLoadingFinish, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onLoadingError, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
|
|
|
|
/**
|
|
* Expose methods to enable messaging the webview.
|
|
*/
|
|
RCT_EXPORT_VIEW_PROPERTY(messagingEnabled, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(onMessage, RCTDirectEventBlock)
|
|
|
|
RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)message)
|
|
{
|
|
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
|
|
RCTWKWebView *view = viewRegistry[reactTag];
|
|
if (![view isKindOfClass:[RCTWKWebView class]]) {
|
|
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
|
} else {
|
|
[view postMessage:message];
|
|
}
|
|
}];
|
|
}
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL)
|
|
RCT_CUSTOM_VIEW_PROPERTY(scrollEnabled, BOOL, RCTWKWebView) {
|
|
view.scrollEnabled = json == nil ? true : [RCTConvert BOOL: json];
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RCTWKWebView) {
|
|
view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
|
|
{
|
|
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
|
|
RCTWKWebView *view = viewRegistry[reactTag];
|
|
if (![view isKindOfClass:[RCTWKWebView class]]) {
|
|
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
|
} else {
|
|
[view injectJavaScript:script];
|
|
}
|
|
}];
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
|
|
{
|
|
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
|
|
RCTWKWebView *view = viewRegistry[reactTag];
|
|
if (![view isKindOfClass:[RCTWKWebView class]]) {
|
|
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
|
} else {
|
|
[view goBack];
|
|
}
|
|
}];
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
|
|
{
|
|
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
|
|
RCTWKWebView *view = viewRegistry[reactTag];
|
|
if (![view isKindOfClass:[RCTWKWebView class]]) {
|
|
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
|
} else {
|
|
[view goForward];
|
|
}
|
|
}];
|
|
}
|
|
|
|
@end
|