Skip to content

Commit

Permalink
use superview instead of RNCWebViewMapManager on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldchen committed Mar 28, 2023
1 parent c1465a9 commit d1e4433
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 60 deletions.
20 changes: 3 additions & 17 deletions apple/RNCWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#import <React/RCTAutoInsetsProtocol.h>
#import "RNCWKProcessPoolManager.h"
#import "RNCWKWebViewMapManager.h"
#import "RNCWebViewMapManager.h"
#import "RNCScriptMessageManager.h"
#import "ScriptMessageEventEmitter.h"

Expand Down Expand Up @@ -437,8 +436,8 @@ - (void)didMoveToWindow
WKWebView *webViewForKey = sharedWKWebViewDictionary[_webViewKey];
if (webViewForKey != nil) {
_webView = webViewForKey;
NSMutableDictionary *sharedRNCWebViewDictionary= [[RNCWebViewMapManager sharedManager] sharedRNCWebViewDictionary];
RNCWebView *rncWebView = sharedRNCWebViewDictionary[_webViewKey];
RNCWebView *rncWebView = webViewForKey.superview;

if (rncWebView != nil) {
[self removeWKWebViewFromSuperView:rncWebView];
}
Expand All @@ -456,8 +455,6 @@ - (void)didMoveToWindow
}

if (_webViewKey != nil) {
NSMutableDictionary *sharedRNCWebViewDictionary= [[RNCWebViewMapManager sharedManager] sharedRNCWebViewDictionary];
sharedRNCWebViewDictionary[_webViewKey] = self;
if (_webView != nil) {
sharedWKWebViewDictionary[_webViewKey] = _webView;
}
Expand Down Expand Up @@ -538,14 +535,7 @@ - (void)removeFromSuperview
}

if (_webViewKey != nil) {
NSMutableDictionary *sharedRNCWebViewDictionary= [[RNCWebViewMapManager sharedManager] sharedRNCWebViewDictionary];
RNCWebView *rncWebView = sharedRNCWebViewDictionary[_webViewKey];

// When this view is being unmounted, only remove the WKWebView from the superview
// if this RNCWebView is the "active" view.
if (rncWebView == self) {
[self removeWKWebViewFromSuperView:self];
}
[self removeWKWebViewFromSuperView:self];
}

[super removeFromSuperview];
Expand All @@ -572,10 +562,6 @@ - (void)removeWKWebViewFromSuperView:(RNCWebView *)webViewObserver
{
// If _webView is getting added to a new super view, we need to first both remove it from the old
// superview and also remove the observer which can reference the old super view.
if (_webViewKey != nil) {
NSMutableDictionary *sharedRNCWebViewDictionary = [[RNCWebViewMapManager sharedManager] sharedRNCWebViewDictionary];
sharedRNCWebViewDictionary[_webViewKey] = nil;
}
[_webView removeObserver:webViewObserver forKeyPath:@"estimatedProgress"];
[_webView removeFromSuperview];
}
Expand Down
7 changes: 3 additions & 4 deletions apple/RNCWebViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#import <React/RCTDefines.h>
#import "RNCWebView.h"
#import "RNCWKWebViewMapManager.h"
#import "RNCWebViewMapManager.h"
#import <WebKit/WebKit.h>

@interface RNCWebViewManager () <RNCWebViewDelegate>
Expand Down Expand Up @@ -317,15 +316,15 @@ - (BOOL) webView:(RNCWebView *)webView
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, __unused NSDictionary<NSNumber *, RNCWebView *> *viewRegistry) {
NSMutableDictionary *sharedWKWebViewDictionary = [[RNCWKWebViewMapManager sharedManager] sharedWKWebViewDictionary];
NSMutableDictionary *sharedRNCWebViewDictionary= [[RNCWebViewMapManager sharedManager] sharedRNCWebViewDictionary];

WKWebView *wkWebView = sharedWKWebViewDictionary[webViewKey];

sharedWKWebViewDictionary[webViewKey] = nil;

RNCWebView *rncWebView = sharedRNCWebViewDictionary[webViewKey];
RNCWebView *rncWebView = wkWebView.superview;

if (rncWebView != nil) {
[rncWebView cleanUpWebView];
sharedRNCWebViewDictionary[webViewKey] = nil;
}
}];
}
Expand Down
4 changes: 0 additions & 4 deletions apple/RNCWebViewMapManager.h

This file was deleted.

29 changes: 0 additions & 29 deletions apple/RNCWebViewMapManager.m

This file was deleted.

6 changes: 0 additions & 6 deletions ios/RNCWebView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
40136746283E927300EAE5F2 /* RNCScriptMessageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 40136745283E927300EAE5F2 /* RNCScriptMessageManager.m */; };
40136749283E92C600EAE5F2 /* ScriptMessageEventEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 40136748283E92C600EAE5F2 /* ScriptMessageEventEmitter.m */; };
40EE00F6281AED0000A0BA29 /* RNCWKWebViewMapManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EE00F5281AED0000A0BA29 /* RNCWKWebViewMapManager.m */; };
40EE00FC281C5D1200A0BA29 /* RNCWebViewMapManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EE00FB281C5D1200A0BA29 /* RNCWebViewMapManager.m */; };
E91B351D21446E6C00F9801F /* RNCWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E91B351B21446E6C00F9801F /* RNCWebViewManager.m */; };
E91B351E21446E6C00F9801F /* RNCWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = E91B351C21446E6C00F9801F /* RNCWebView.m */; };
/* End PBXBuildFile section */
Expand All @@ -38,8 +37,6 @@
40136748283E92C600EAE5F2 /* ScriptMessageEventEmitter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ScriptMessageEventEmitter.m; path = ../apple/ScriptMessageEventEmitter.m; sourceTree = "<group>"; };
40EE00F4281AECE600A0BA29 /* RNCWKWebViewMapManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNCWKWebViewMapManager.h; path = ../apple/RNCWKWebViewMapManager.h; sourceTree = "<group>"; };
40EE00F5281AED0000A0BA29 /* RNCWKWebViewMapManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNCWKWebViewMapManager.m; path = ../apple/RNCWKWebViewMapManager.m; sourceTree = "<group>"; };
40EE00FA281C5CF500A0BA29 /* RNCWebViewMapManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNCWebViewMapManager.h; path = ../apple/RNCWebViewMapManager.h; sourceTree = "<group>"; };
40EE00FB281C5D1200A0BA29 /* RNCWebViewMapManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNCWebViewMapManager.m; path = ../apple/RNCWebViewMapManager.m; sourceTree = "<group>"; };
E91B351921446E6C00F9801F /* RNCWebViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNCWebViewManager.h; path = ../apple/RNCWebViewManager.h; sourceTree = "<group>"; };
E91B351A21446E6C00F9801F /* RNCWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNCWebView.h; path = ../apple/RNCWebView.h; sourceTree = "<group>"; };
E91B351B21446E6C00F9801F /* RNCWebViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNCWebViewManager.m; path = ../apple/RNCWebViewManager.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -72,8 +69,6 @@
40136747283E929E00EAE5F2 /* ScriptMessageEventEmitter.h */,
40136745283E927300EAE5F2 /* RNCScriptMessageManager.m */,
40136744283E924500EAE5F2 /* RNCScriptMessageManager.h */,
40EE00FB281C5D1200A0BA29 /* RNCWebViewMapManager.m */,
40EE00FA281C5CF500A0BA29 /* RNCWebViewMapManager.h */,
40EE00F5281AED0000A0BA29 /* RNCWKWebViewMapManager.m */,
40EE00F4281AECE600A0BA29 /* RNCWKWebViewMapManager.h */,
E91B351A21446E6C00F9801F /* RNCWebView.h */,
Expand Down Expand Up @@ -144,7 +139,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
40EE00FC281C5D1200A0BA29 /* RNCWebViewMapManager.m in Sources */,
E91B351D21446E6C00F9801F /* RNCWebViewManager.m in Sources */,
40EE00F6281AED0000A0BA29 /* RNCWKWebViewMapManager.m in Sources */,
E91B351E21446E6C00F9801F /* RNCWebView.m in Sources */,
Expand Down

0 comments on commit d1e4433

Please sign in to comment.