mirror of
https://github.com/status-im/react-native-webview.git
synced 2025-02-22 16:58:34 +00:00
feat(toggle scroll bar): added new props showsVerticalScrollIndicator / showsHorizontalScrollIndicator (#250)
This commit is contained in:
parent
405421dece
commit
92c20581ae
@ -503,6 +503,16 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
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) {
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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<NSNumber *, RNCWKWebView *> *viewRegistry) {
|
||||
|
@ -182,6 +182,8 @@ class WebView extends React.Component<WebViewSharedProps, State> {
|
||||
mixedContentMode={this.props.mixedContentMode}
|
||||
saveFormDataDisabled={this.props.saveFormDataDisabled}
|
||||
urlPrefixesForDefaultIntent={this.props.urlPrefixesForDefaultIntent}
|
||||
showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator}
|
||||
showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator}
|
||||
{...nativeConfig.props}
|
||||
/>
|
||||
);
|
||||
|
@ -284,6 +284,8 @@ class WebView extends React.Component<WebViewSharedProps, State> {
|
||||
dataDetectorTypes={this.props.dataDetectorTypes}
|
||||
useSharedProcessPool={this.props.useSharedProcessPool}
|
||||
allowsLinkPreview={this.props.allowsLinkPreview}
|
||||
showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator}
|
||||
showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator}
|
||||
{...nativeConfig.props}
|
||||
/>
|
||||
);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user