diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index fa3766b..7f7fd0e 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -503,6 +503,16 @@ public class RNCWebViewManager extends SimpleViewManager { view.getSettings().setJavaScriptEnabled(enabled); } + @ReactProp(name = "showsHorizontalScrollIndicator") + public void setShowsHorizontalScrollIndicator(WebView view, boolean enabled) { + view.setHorizontalScrollBarEnabled(enabled); + } + + @ReactProp(name = "showsVerticalScrollIndicator") + public void setShowsVerticalScrollIndicator(WebView view, boolean enabled) { + view.setVerticalScrollBarEnabled(enabled); + } + @ReactProp(name = "cacheEnabled") public void setCacheEnabled(WebView view, boolean enabled) { if (enabled) { diff --git a/docs/Reference.md b/docs/Reference.md index aea51ce..8dbd492 100644 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -454,6 +454,26 @@ Boolean value that determines whether scrolling is enabled in the `WebView`. The --- +### `showsHorizontalScrollIndicator` + +Boolean value that determines whether a horizontal scroll indicator is shown in the `WebView`. The default value is `true`. + +| Type | Required | +| ---- | -------- | +| bool | No | + +--- + +### `showsVerticalScrollIndicator` + +Boolean value that determines whether a vertical scroll indicator is shown in the `WebView`. The default value is `true`. + +| Type | Required | +| ---- | -------- | +| bool | No | + +--- + ### `geolocationEnabled` Set whether Geolocation is enabled in the `WebView`. The default value is `false`. Used only in Android. diff --git a/ios/RNCUIWebViewManager.m b/ios/RNCUIWebViewManager.m index 7b6180d..0a980c9 100644 --- a/ios/RNCUIWebViewManager.m +++ b/ios/RNCUIWebViewManager.m @@ -41,6 +41,8 @@ RCT_EXPORT_VIEW_PROPERTY(onShouldStartLoadWithRequest, RCTDirectEventBlock) RCT_REMAP_VIEW_PROPERTY(allowsInlineMediaPlayback, _webView.allowsInlineMediaPlayback, BOOL) RCT_REMAP_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, _webView.mediaPlaybackRequiresUserAction, BOOL) RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDetectorTypes) +RCT_REMAP_VIEW_PROPERTY(showsHorizontalScrollIndicator, _webView.scrollView.showsHorizontalScrollIndicator, BOOL) +RCT_REMAP_VIEW_PROPERTY(showsVerticalScrollIndicator, _webView.scrollView.showsVerticalScrollIndicator, BOOL) RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag) { diff --git a/ios/RNCWKWebView.h b/ios/RNCWKWebView.h index 328ca9d..a11b5e5 100644 --- a/ios/RNCWKWebView.h +++ b/ios/RNCWKWebView.h @@ -43,6 +43,8 @@ @property (nonatomic, copy) NSString *userAgent; @property (nonatomic, assign) BOOL cacheEnabled; @property (nonatomic, assign) BOOL allowsLinkPreview; +@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator; +@property (nonatomic, assign) BOOL showsVerticalScrollIndicator; + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential; - (void)postMessage:(NSString *)message; diff --git a/ios/RNCWKWebView.m b/ios/RNCWKWebView.m index f505657..a008b9e 100644 --- a/ios/RNCWKWebView.m +++ b/ios/RNCWKWebView.m @@ -69,6 +69,8 @@ static NSURLCredential* clientAuthenticationCredential; super.backgroundColor = [UIColor clearColor]; _bounces = YES; _scrollEnabled = YES; + _showsHorizontalScrollIndicator = YES; + _showsVerticalScrollIndicator = YES; _automaticallyAdjustContentInsets = YES; _contentInset = UIEdgeInsetsZero; } @@ -150,6 +152,8 @@ static NSURLCredential* clientAuthenticationCredential; _webView.scrollView.scrollEnabled = _scrollEnabled; _webView.scrollView.pagingEnabled = _pagingEnabled; _webView.scrollView.bounces = _bounces; + _webView.scrollView.showsHorizontalScrollIndicator = _showsHorizontalScrollIndicator; + _webView.scrollView.showsVerticalScrollIndicator = _showsVerticalScrollIndicator; _webView.allowsLinkPreview = _allowsLinkPreview; [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil]; _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures; @@ -357,6 +361,18 @@ static NSURLCredential* clientAuthenticationCredential; _webView.scrollView.scrollEnabled = scrollEnabled; } +- (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator +{ + _showsHorizontalScrollIndicator = showsHorizontalScrollIndicator; + _webView.scrollView.showsHorizontalScrollIndicator = showsHorizontalScrollIndicator; +} + +- (void)setShowsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator +{ + _showsVerticalScrollIndicator = showsVerticalScrollIndicator; + _webView.scrollView.showsVerticalScrollIndicator = showsVerticalScrollIndicator; +} + - (void)postMessage:(NSString *)message { NSDictionary *eventInitDict = @{@"data": message}; diff --git a/ios/RNCWKWebViewManager.m b/ios/RNCWKWebViewManager.m index 73a664b..009bfcf 100644 --- a/ios/RNCWKWebViewManager.m +++ b/ios/RNCWKWebViewManager.m @@ -85,6 +85,14 @@ RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RNCWKWebView) { view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json]; } +RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWKWebView) { + view.showsHorizontalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json]; +} + +RCT_CUSTOM_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL, RNCWKWebView) { + view.showsVerticalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json]; +} + RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script) { [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { diff --git a/js/WebView.android.js b/js/WebView.android.js index ec959ee..562829f 100644 --- a/js/WebView.android.js +++ b/js/WebView.android.js @@ -182,6 +182,8 @@ class WebView extends React.Component { mixedContentMode={this.props.mixedContentMode} saveFormDataDisabled={this.props.saveFormDataDisabled} urlPrefixesForDefaultIntent={this.props.urlPrefixesForDefaultIntent} + showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator} + showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator} {...nativeConfig.props} /> ); diff --git a/js/WebView.ios.js b/js/WebView.ios.js index b724b5a..1a85f93 100644 --- a/js/WebView.ios.js +++ b/js/WebView.ios.js @@ -284,6 +284,8 @@ class WebView extends React.Component { dataDetectorTypes={this.props.dataDetectorTypes} useSharedProcessPool={this.props.useSharedProcessPool} allowsLinkPreview={this.props.allowsLinkPreview} + showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator} + showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator} {...nativeConfig.props} /> ); diff --git a/js/WebViewTypes.js b/js/WebViewTypes.js index bba8b7d..7b79e72 100644 --- a/js/WebViewTypes.js +++ b/js/WebViewTypes.js @@ -449,6 +449,18 @@ export type WebViewSharedProps = $ReadOnly<{| */ injectedJavaScript?: ?string, + /** + * Boolean value that determines whether a horizontal scroll indicator is + * shown in the `WebView`. The default value is `true`. + */ + showsHorizontalScrollIndicator?: ?boolean, + + /** + * Boolean value that determines whether a vertical scroll indicator is + * shown in the `WebView`. The default value is `true`. + */ + showsVerticalScrollIndicator?: ?boolean, + /** * Boolean that controls whether the web content is scaled to fit * the view and enables the user to change the scale. The default value