Skip to content

Commit

Permalink
feat: debugging enabled prop (react-native-webview#2937)
Browse files Browse the repository at this point in the history
* feat: add webviewDebuggingEnabled prop & Android implementation

fix: use static RNCWebView.setWebContentsDebuggingEnabled

* feat: add iOS webviewDebuggingEnabled prop

* chore: remove "link generted with jump2header" comments

* chore: add missing props-index links in Reference.md

* feat: add webviewDebuggingEnabled reference docs

* fix: surround inspectable code blocks with compiler preprocessor to include only on appropriate versions


---------

Co-authored-by: Tom Bury <tom.bury@twipemobile.com>
  • Loading branch information
Tom-Bury and Tom-Bury committed Jun 10, 2023
1 parent c6125b0 commit f9a5277
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,8 @@ class RNCWebViewManagerImpl {
fun setThirdPartyCookiesEnabled(view: RNCWebView, enabled: Boolean) {
CookieManager.getInstance().setAcceptThirdPartyCookies(view, enabled)
}

fun setWebviewDebuggingEnabled(view: RNCWebView, enabled: Boolean) {
RNCWebView.setWebContentsDebuggingEnabled(enabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ public void setThirdPartyCookiesEnabled(RNCWebView view, boolean value) {
mRNCWebViewManagerImpl.setThirdPartyCookiesEnabled(view, value);
}

@Override
@ReactProp(name = "webviewDebuggingEnabled")
public void setWebviewDebuggingEnabled(RNCWebView view, boolean value) {
mRNCWebViewManagerImpl.setWebviewDebuggingEnabled(view, value);
}

/* iOS PROPS - no implemented here */
@Override
public void setAllowingReadAccessToURL(RNCWebView view, @Nullable String value) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ public void setThirdPartyCookiesEnabled(RNCWebView view, boolean value) {
mRNCWebViewManagerImpl.setThirdPartyCookiesEnabled(view, value);
}

@ReactProp(name = "webviewDebuggingEnabled")
public void setWebviewDebuggingEnabled(RNCWebView view, boolean value) {
mRNCWebViewManagerImpl.setWebviewDebuggingEnabled(view, value);
}

@ReactProp(name = "userAgent")
public void setUserAgent(RNCWebView view, @Nullable String value) {
mRNCWebViewManagerImpl.setUserAgent(view, value);
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
REMAP_WEBVIEW_PROP(allowFileAccessFromFileURLs)
REMAP_WEBVIEW_PROP(allowUniversalAccessFromFileURLs)
REMAP_WEBVIEW_PROP(allowsInlineMediaPlayback)
REMAP_WEBVIEW_PROP(webviewDebuggingEnabled)
REMAP_WEBVIEW_PROP(allowsAirPlayForMediaPlayback)
REMAP_WEBVIEW_PROP(mediaPlaybackRequiresUserAction)
REMAP_WEBVIEW_PROP(automaticallyAdjustContentInsets)
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebViewImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
@property (nonatomic, assign) BOOL pagingEnabled;
@property (nonatomic, assign) CGFloat decelerationRate;
@property (nonatomic, assign) BOOL allowsInlineMediaPlayback;
@property (nonatomic, assign) BOOL webviewDebuggingEnabled;
@property (nonatomic, assign) BOOL allowsAirPlayForMediaPlayback;
@property (nonatomic, assign) BOOL bounces;
@property (nonatomic, assign) BOOL mediaPlaybackRequiresUserAction;
Expand Down
17 changes: 17 additions & 0 deletions apple/RNCWebViewImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ - (void)didMoveToWindow
}
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 || \
__TV_OS_VERSION_MAX_ALLOWED >= 160400
if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *))
_webView.inspectable = _webviewDebuggingEnabled;
#endif

[self addSubview:_webView];
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
[self setKeyboardDisplayRequiresUserAction: _savedKeyboardDisplayRequiresUserAction];
Expand All @@ -495,6 +502,16 @@ - (void)setAllowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigation
_webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
}

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 || \
__TV_OS_VERSION_MAX_ALLOWED >= 160400
- (void)setWebviewDebuggingEnabled:(BOOL)webviewDebuggingEnabled {
_webviewDebuggingEnabled = webviewDebuggingEnabled;
if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *))
_webView.inspectable = _webviewDebuggingEnabled;
}
#endif

#ifdef RCT_NEW_ARCH_ENABLED
- (void)destroyWebView
#else
Expand Down
1 change: 1 addition & 0 deletions apple/RNCWebViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ - (RNCView *)view
RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowUniversalAccessFromFileURLs, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
RCT_EXPORT_VIEW_PROPERTY(webviewDebuggingEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsAirPlayForMediaPlayback, BOOL)
RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
RCT_EXPORT_VIEW_PROPERTY(dataDetectorTypes, WKDataDetectorTypes)
Expand Down
Loading

0 comments on commit f9a5277

Please sign in to comment.