diff --git a/WKWebView.ios.js b/WKWebView.ios.js index f9a37eb1..2179dba3 100644 --- a/WKWebView.ios.js +++ b/WKWebView.ios.js @@ -18,7 +18,7 @@ import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource' import deprecatedPropType from 'react-native/Libraries/Utilities/deprecatedPropType'; import invariant from 'fbjs/lib/invariant'; import keyMirror from 'fbjs/lib/keyMirror'; -const WKWebViewManager = NativeModules.WKWebViewManager; +const WKWebViewManager = NativeModules.CRAWKWebViewManager; var BGWASH = 'rgba(255,255,255,0.8)'; @@ -295,7 +295,7 @@ class WKWebView extends React.Component { ); } else if (this.state.viewState !== WebViewState.IDLE) { console.error( - 'RCTWKWebView invalid state encountered: ' + this.state.loading + 'CRAWKWebView invalid state encountered: ' + this.state.loading ); } @@ -329,7 +329,7 @@ class WKWebView extends React.Component { const messagingEnabled = typeof this.props.onMessage === 'function'; const webView = - { this.webview = ref; }} key="webViewKey" style={webViewStyles} @@ -375,7 +375,7 @@ class WKWebView extends React.Component { goForward = () => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RCTWKWebView.Commands.goForward, + UIManager.CRAWKWebView.Commands.goForward, null ); }; @@ -386,7 +386,7 @@ class WKWebView extends React.Component { goBack = () => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RCTWKWebView.Commands.goBack, + UIManager.CRAWKWebView.Commands.goBack, null ); }; @@ -412,7 +412,7 @@ class WKWebView extends React.Component { this.setState({ viewState: WebViewState.LOADING }); UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RCTWKWebView.Commands.reload, + UIManager.CRAWKWebView.Commands.reload, null ); }; @@ -423,7 +423,7 @@ class WKWebView extends React.Component { stopLoading = () => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RCTWKWebView.Commands.stopLoading, + UIManager.CRAWKWebView.Commands.stopLoading, null ) }; @@ -441,7 +441,7 @@ class WKWebView extends React.Component { postMessage = (data) => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RCTWKWebView.Commands.postMessage, + UIManager.CRAWKWebView.Commands.postMessage, [String(data)] ); }; @@ -517,7 +517,7 @@ class WKWebView extends React.Component { } } -const RCTWKWebView = requireNativeComponent('RCTWKWebView', WKWebView, { +const CRAWKWebView = requireNativeComponent('CRAWKWebView', WKWebView, { nativeOnly: { onLoadingStart: true, onLoadingError: true, diff --git a/ios/RCTWKWebView/RCTWKWebView.h b/ios/RCTWKWebView/RCTWKWebView.h index 1327bdfd..fe6e2346 100644 --- a/ios/RCTWKWebView/RCTWKWebView.h +++ b/ios/RCTWKWebView/RCTWKWebView.h @@ -2,7 +2,7 @@ #import -@class RCTWKWebView; +@class CRAWKWebView; /** * Special scheme used to pass messages to the injectedJavaScript @@ -12,19 +12,19 @@ */ extern NSString *const RCTJSNavigationScheme; -@protocol RCTWKWebViewDelegate +@protocol CRAWKWebViewDelegate -- (BOOL)webView:(RCTWKWebView *)webView +- (BOOL)webView:(CRAWKWebView *)webView shouldStartLoadForRequest:(NSMutableDictionary *)request withCallback:(RCTDirectEventBlock)callback; @end -@interface RCTWKWebView : RCTView +@interface CRAWKWebView : RCTView - (instancetype)initWithProcessPool:(WKProcessPool *)processPool; -@property (nonatomic, weak) id delegate; +@property (nonatomic, weak) id delegate; @property (nonatomic, copy) NSDictionary *source; @property (nonatomic, assign) UIEdgeInsets contentInset; diff --git a/ios/RCTWKWebView/RCTWKWebView.m b/ios/RCTWKWebView/RCTWKWebView.m index e1348c81..afc3c7c3 100644 --- a/ios/RCTWKWebView/RCTWKWebView.m +++ b/ios/RCTWKWebView/RCTWKWebView.m @@ -24,7 +24,7 @@ -(id)inputAccessoryView } @end -@interface RCTWKWebView () +@interface CRAWKWebView () @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart; @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish; @@ -40,7 +40,7 @@ @interface RCTWKWebView () +@interface CRAWKWebViewManager () @end -@implementation RCTWKWebViewManager +@implementation CRAWKWebViewManager { NSConditionLock *_shouldStartLoadLock; BOOL _shouldStartLoad; @@ -37,7 +37,7 @@ @implementation RCTWKWebViewManager - (UIView *)view { - RCTWKWebView *webView = [[RCTWKWebView alloc] initWithProcessPool:[WKProcessPool sharedProcessPool]]; + CRAWKWebView *webView = [[CRAWKWebView alloc] initWithProcessPool:[WKProcessPool sharedProcessPool]]; webView.delegate = self; return webView; } @@ -73,10 +73,10 @@ - (UIView *)view RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; - if (![view isKindOfClass:[RCTWKWebView class]]) { - RCTLogError(@"Invalid view returned from registry, expecting RCTWKWebView, got: %@", view); + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; + if (![view isKindOfClass:[CRAWKWebView class]]) { + RCTLogError(@"Invalid view returned from registry, expecting CRAWKWebView, got: %@", view); } else { [view goBack]; } @@ -85,10 +85,10 @@ - (UIView *)view RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; - if (![view isKindOfClass:[RCTWKWebView class]]) { - RCTLogError(@"Invalid view returned from registry, expecting RCTWKWebView, got: %@", view); + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; + if (![view isKindOfClass:[CRAWKWebView class]]) { + RCTLogError(@"Invalid view returned from registry, expecting CRAWKWebView, got: %@", view); } else { [view goForward]; } @@ -99,8 +99,8 @@ - (UIView *)view resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; resolve([NSNumber numberWithBool:[view canGoBack]]); }]; @@ -110,8 +110,8 @@ - (UIView *)view resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; resolve([NSNumber numberWithBool:[view canGoForward]]); }]; @@ -119,10 +119,10 @@ - (UIView *)view RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; - if (![view isKindOfClass:[RCTWKWebView class]]) { - RCTLogError(@"Invalid view returned from registry, expecting RCTWKWebView, got: %@", view); + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; + if (![view isKindOfClass:[CRAWKWebView class]]) { + RCTLogError(@"Invalid view returned from registry, expecting CRAWKWebView, got: %@", view); } else { [view reload]; } @@ -131,10 +131,10 @@ - (UIView *)view RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; - if (![view isKindOfClass:[RCTWKWebView class]]) { - RCTLogError(@"Invalid view returned from registry, expecting RCTWKWebView, got: %@", view); + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; + if (![view isKindOfClass:[CRAWKWebView class]]) { + RCTLogError(@"Invalid view returned from registry, expecting CRAWKWebView, got: %@", view); } else { [view stopLoading]; } @@ -143,10 +143,10 @@ - (UIView *)view RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)message) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; - if (![view isKindOfClass:[RCTWKWebView class]]) { - RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view); + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; + if (![view isKindOfClass:[CRAWKWebView class]]) { + RCTLogError(@"Invalid view returned from registry, expecting CRAWKWebView, got: %@", view); } else { [view postMessage:message]; } @@ -158,10 +158,10 @@ - (UIView *)view resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTWKWebView *view = viewRegistry[reactTag]; - if (![view isKindOfClass:[RCTWKWebView class]]) { - RCTLogError(@"Invalid view returned from registry, expecting RCTWKWebView, got: %@", view); + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + CRAWKWebView *view = viewRegistry[reactTag]; + if (![view isKindOfClass:[CRAWKWebView class]]) { + RCTLogError(@"Invalid view returned from registry, expecting CRAWKWebView, got: %@", view); } else { [view evaluateJavaScript:js completionHandler:^(id result, NSError *error) { if (error) { @@ -176,7 +176,7 @@ - (UIView *)view #pragma mark - Exported synchronous methods -- (BOOL)webView:(__unused RCTWKWebView *)webView +- (BOOL)webView:(__unused CRAWKWebView *)webView shouldStartLoadForRequest:(NSMutableDictionary *)request withCallback:(RCTDirectEventBlock)callback {