Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
Rename RTCWKWebview
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Mar 5, 2019
1 parent 4d9a7e7 commit 26c75b8
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 106 deletions.
5 changes: 0 additions & 5 deletions ios/RCTWKWebViewManager.h

This file was deleted.

24 changes: 12 additions & 12 deletions ios/React-Native-Webview-Bridge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
9EF4097B1E0929E900B7C524 /* RCTWKWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EF4097A1E0929E900B7C524 /* RCTWKWebView.m */; };
9EF4097E1E092A2500B7C524 /* RCTWKWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EF4097D1E092A2500B7C524 /* RCTWKWebViewManager.m */; };
9EF4097B1E0929E900B7C524 /* StatusWKWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EF4097A1E0929E900B7C524 /* StatusWKWebView.m */; };
9EF4097E1E092A2500B7C524 /* StatusWKWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EF4097D1E092A2500B7C524 /* StatusWKWebViewManager.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -26,10 +26,10 @@
/* Begin PBXFileReference section */
4114DC4C1C187C3A003CD988 /* libReact-Native-Webview-Bridge.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libReact-Native-Webview-Bridge.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4114DC5F1C187CE4003CD988 /* webviewbridge.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = webviewbridge.js; sourceTree = "<group>"; };
9EF409791E0929C900B7C524 /* RCTWKWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTWKWebView.h; sourceTree = SOURCE_ROOT; };
9EF4097A1E0929E900B7C524 /* RCTWKWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTWKWebView.m; sourceTree = SOURCE_ROOT; };
9EF4097C1E092A1400B7C524 /* RCTWKWebViewManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTWKWebViewManager.h; sourceTree = SOURCE_ROOT; };
9EF4097D1E092A2500B7C524 /* RCTWKWebViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTWKWebViewManager.m; sourceTree = SOURCE_ROOT; };
9EF409791E0929C900B7C524 /* StatusWKWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StatusWKWebView.h; sourceTree = SOURCE_ROOT; };
9EF4097A1E0929E900B7C524 /* StatusWKWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StatusWKWebView.m; sourceTree = SOURCE_ROOT; };
9EF4097C1E092A1400B7C524 /* StatusWKWebViewManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StatusWKWebViewManager.h; sourceTree = SOURCE_ROOT; };
9EF4097D1E092A2500B7C524 /* StatusWKWebViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StatusWKWebViewManager.m; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -63,10 +63,10 @@
4114DC4E1C187C3A003CD988 /* React-Native-Webview-Bridge */ = {
isa = PBXGroup;
children = (
9EF409791E0929C900B7C524 /* RCTWKWebView.h */,
9EF4097A1E0929E900B7C524 /* RCTWKWebView.m */,
9EF4097C1E092A1400B7C524 /* RCTWKWebViewManager.h */,
9EF4097D1E092A2500B7C524 /* RCTWKWebViewManager.m */,
9EF409791E0929C900B7C524 /* StatusWKWebView.h */,
9EF4097A1E0929E900B7C524 /* StatusWKWebView.m */,
9EF4097C1E092A1400B7C524 /* StatusWKWebViewManager.h */,
9EF4097D1E092A2500B7C524 /* StatusWKWebViewManager.m */,
);
path = "React-Native-Webview-Bridge";
sourceTree = "<group>";
Expand Down Expand Up @@ -136,8 +136,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9EF4097B1E0929E900B7C524 /* RCTWKWebView.m in Sources */,
9EF4097E1E092A2500B7C524 /* RCTWKWebViewManager.m in Sources */,
9EF4097B1E0929E900B7C524 /* StatusWKWebView.m in Sources */,
9EF4097E1E092A2500B7C524 /* StatusWKWebViewManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 3 additions & 3 deletions ios/RCTWKWebView.h → ios/StatusWKWebView.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "React/RCTView.h"

@class RCTWKWebView;
@class StatusWKWebView;

/**
* Special scheme used to pass messages to the injectedJavaScript
Expand All @@ -12,13 +12,13 @@ extern NSString *const RCTJSNavigationScheme;

@protocol RCTWKWebViewDelegate <NSObject>

- (BOOL)webView:(RCTWKWebView *)webView
- (BOOL)webView:(StatusWKWebView *)webView
shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
withCallback:(RCTDirectEventBlock)callback;

@end

@interface RCTWKWebView : RCTView
@interface StatusWKWebView : RCTView

@property (nonatomic, weak) id<RCTWKWebViewDelegate> delegate;

Expand Down
23 changes: 11 additions & 12 deletions ios/RCTWKWebView.m → ios/StatusWKWebView.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "RCTWKWebView.h"
#import "StatusWKWebView.h"

#import <WebKit/WebKit.h>
#import <UIKit/UIKit.h>
Expand All @@ -18,7 +18,7 @@

NSString *const RCTWebViewBridgeSchema = @"wvb";

@interface RCTWKWebView () <WKNavigationDelegate, RCTAutoInsetsProtocol, WKScriptMessageHandler, WKUIDelegate>
@interface StatusWKWebView () <WKNavigationDelegate, RCTAutoInsetsProtocol, WKScriptMessageHandler, WKUIDelegate>

@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
@property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
Expand All @@ -30,7 +30,7 @@ @interface RCTWKWebView () <WKNavigationDelegate, RCTAutoInsetsProtocol, WKScrip

@end

@implementation RCTWKWebView
@implementation StatusWKWebView
{
WKWebView *_webView;
NSString *_injectedJavaScript;
Expand All @@ -40,22 +40,22 @@ - (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
super.backgroundColor = [UIColor clearColor];

_automaticallyAdjustContentInsets = YES;
_contentInset = UIEdgeInsetsZero;

WKWebViewConfiguration* config = [[WKWebViewConfiguration alloc] init];
WKUserContentController* userController = [[WKUserContentController alloc]init];
[userController addScriptMessageHandler:self name:@"reactNative"];
[userController addScriptMessageHandler:self name:@"sendRequest"];
config.userContentController = userController;

WKUserScript* bridgeScript = [[WKUserScript alloc]
initWithSource: [self webViewBridgeScript]
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
forMainFrameOnly:NO];
[config.userContentController addUserScript:bridgeScript];

_webView = [[WKWebView alloc] initWithFrame:self.bounds configuration:config];
_webView.UIDelegate = self;
_webView.navigationDelegate = self;
Expand All @@ -77,7 +77,7 @@ - (void)loadRequest:(NSURLRequest *)request
request = mutableRequest;
}
}

[_webView loadRequest:request];
}

Expand Down Expand Up @@ -123,14 +123,13 @@ - (void)sendIt:(NSString *)body
NSData *data = [body dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *responseDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSString *callbackId = [responseDic objectForKey:@"callbackId"];
NSString *host = [responseDic objectForKey:@"host"];
NSString *payload = [responseDic objectForKey:@"payload"];

NSString *response = StatusgoCallRPC(payload);
NSString *trimmedResponse = [response stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSString *format = @"httpCallback('%@', '%@');";

NSString *command = [NSString stringWithFormat: format, callbackId, trimmedResponse];
dispatch_async( dispatch_get_main_queue(), ^{
[_webView evaluateJavaScript:command completionHandler:nil];
Expand Down
5 changes: 5 additions & 0 deletions ios/StatusWKWebViewManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "React/RCTViewManager.h"

@interface StatusWKWebViewManager : RCTViewManager

@end
50 changes: 25 additions & 25 deletions ios/RCTWKWebViewManager.m → ios/StatusWKWebViewManager.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#import "RCTWKWebViewManager.h"
#import "StatusWKWebViewManager.h"

#import "React/RCTBridge.h"
#import "React/RCTUtils.h"
#import "React/RCTUIManager.h"
#import "React/UIView+React.h"
#import "RCTWKWebView.h"
#import "StatusWKWebView.h"

#import <WebKit/WebKit.h>

@interface RCTWKWebViewManager () <RCTWKWebViewDelegate>
@interface StatusWKWebViewManager () <RCTWKWebViewDelegate>

@end

@implementation RCTWKWebViewManager
@implementation StatusWKWebViewManager
{
NSConditionLock *_shouldStartLoadLock;
BOOL _shouldStartLoad;
Expand All @@ -22,7 +22,7 @@ @implementation RCTWKWebViewManager

- (UIView *)view
{
RCTWKWebView *webView = [RCTWKWebView new];
StatusWKWebView *webView = [StatusWKWebView new];
webView.delegate = self;
return webView;
}
Expand All @@ -45,10 +45,10 @@ - (UIView *)view

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 RCTWKWebView, got: %@", view);
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, StatusWKWebView *> *viewRegistry) {
StatusWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[StatusWKWebView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting StatusWKWebView, got: %@", view);
} else {
[view goBack];
}
Expand All @@ -57,10 +57,10 @@ - (UIView *)view

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 RCTWKWebView, got: %@", view);
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, StatusWKWebView *> *viewRegistry) {
StatusWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[StatusWKWebView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting StatusWKWebView, got: %@", view);
} else {
[view goForward];
}
Expand All @@ -69,10 +69,10 @@ - (UIView *)view

RCT_EXPORT_METHOD(reload:(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 RCTWKWebView, got: %@", view);
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, StatusWKWebView *> *viewRegistry) {
StatusWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[StatusWKWebView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting StatusWKWebView, got: %@", view);
} else {
[view reload];
}
Expand All @@ -84,10 +84,10 @@ - (UIView *)view
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
[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 RCTWKWebView, got: %@", view);
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, StatusWKWebView *> *viewRegistry) {
StatusWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[StatusWKWebView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting StatusWKWebView, got: %@", view);
} else {
[view evaluateJavaScript:js completionHandler:^(id result, NSError *error) {
if (error) {
Expand All @@ -103,9 +103,9 @@ - (UIView *)view
RCT_EXPORT_METHOD(sendToBridge:(nonnull NSNumber *)reactTag
value:(NSString*)message)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
RCTWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[RCTWKWebView class]]) {
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, StatusWKWebView *> *viewRegistry) {
StatusWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[StatusWKWebView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting RCTWebViewBridge, got: %@", view);
} else {
[view sendToBridge: message];
Expand All @@ -115,7 +115,7 @@ - (UIView *)view

#pragma mark - Exported synchronous methods

- (BOOL)webView:(__unused RCTWKWebView *)webView
- (BOOL)webView:(__unused StatusWKWebView *)webView
shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
withCallback:(RCTDirectEventBlock)callback
{
Expand Down
Loading

0 comments on commit 26c75b8

Please sign in to comment.