Skip to content

Commit d46a6d3

Browse files
billxie1988BillHsiehxietianTitozzz
authored
feat(iOS 13+): automaticallyAdjustsScrollIndicatorInsets prop (react-native-webview#1077)
* fix:iOS13 scrollView.automaticallyAdjustsScrollIndicatorInsets default value YES which make the webview vertical indicator position in wrong offset * added types and doc Co-authored-by: BillHsieh <xietian@meitunmama.com> Co-authored-by: xietian <xietian@innotechx.com> Co-authored-by: Thibault Malbranche <thibault.malbranche@epitech.eu> Co-authored-by: Thibault Malbranche <malbranche.thibault@gmail.com>
1 parent 4b479d6 commit d46a6d3

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

apple/RNCWebView.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ @implementation RNCWebView
109109
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
110110
UIScrollViewContentInsetAdjustmentBehavior _savedContentInsetAdjustmentBehavior;
111111
#endif
112+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
113+
BOOL _savedAutomaticallyAdjustsScrollIndicatorInsets;
114+
#endif
112115
}
113116

114117
- (instancetype)initWithFrame:(CGRect)frame
@@ -140,6 +143,10 @@ - (instancetype)initWithFrame:(CGRect)frame
140143
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
141144
_savedContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
142145
#endif
146+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
147+
_savedAutomaticallyAdjustsScrollIndicatorInsets = NO;
148+
#endif
149+
143150
}
144151

145152
#if !TARGET_OS_OSX
@@ -299,6 +306,9 @@ - (void)didMoveToWindow
299306
_webView.scrollView.contentInsetAdjustmentBehavior = _savedContentInsetAdjustmentBehavior;
300307
}
301308
#endif
309+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
310+
_webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = _savedAutomaticallyAdjustsScrollIndicatorInsets;
311+
#endif
302312

303313
[self addSubview:_webView];
304314
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
@@ -445,7 +455,17 @@ - (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBeh
445455
}
446456
}
447457
#endif
448-
458+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
459+
- (void)setAutomaticallyAdjustsScrollIndicatorInsets:(BOOL)automaticallyAdjustsScrollIndicatorInsets{
460+
_savedAutomaticallyAdjustsScrollIndicatorInsets = automaticallyAdjustsScrollIndicatorInsets;
461+
if (_webView == nil) {
462+
return;
463+
}
464+
if ([_webView.scrollView respondsToSelector:@selector(setAutomaticallyAdjustsScrollIndicatorInsets:)]) {
465+
_webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = automaticallyAdjustsScrollIndicatorInsets;
466+
}
467+
}
468+
#endif
449469
/**
450470
* This method is called whenever JavaScript running within the web view calls:
451471
* - window.webkit.messageHandlers[MessageHandlerName].postMessage

apple/RNCWebViewManager.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ - (RCTUIView *)view
8080
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
8181
RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentBehavior)
8282
#endif
83+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
84+
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustsScrollIndicatorInsets, BOOL)
85+
#endif
8386

8487
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
8588
RCT_EXPORT_VIEW_PROPERTY(contentMode, WKContentMode)

docs/Reference.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This document lays out the current public properties and methods for the React N
66

77
- [`source`](Reference.md#source)
88
- [`automaticallyAdjustContentInsets`](Reference.md#automaticallyadjustcontentinsets)
9+
- [`automaticallyAdjustsScrollIndicatorInsets`](Reference.md#automaticallyAdjustsScrollIndicatorInsets)
910
- [`injectedJavaScript`](Reference.md#injectedjavascript)
1011
- [`injectedJavaScriptBeforeContentLoaded`](Reference.md#injectedjavascriptbeforecontentloaded)
1112
- [`injectedJavaScriptForMainFrameOnly`](Reference.md#injectedjavascriptformainframeonly)
@@ -131,6 +132,16 @@ Controls whether to adjust the content inset for web views that are placed behin
131132

132133
---
133134

135+
### `automaticallyAdjustsScrollIndicatorInsets`[](#props-index)<!-- Link generated with jump2header -->
136+
137+
Controls whether to adjust the scroll indicator inset for web views that are placed behind a navigation bar, tab bar, or toolbar. The default value `false`. (iOS 13+)
138+
139+
| Type | Required | Platform |
140+
| ---- | -------- | -------- |
141+
| bool | No | iOS(13+) |
142+
143+
---
144+
134145
### `injectedJavaScript`[](#props-index)<!-- Link generated with jump2header -->
135146

136147
Set this to provide JavaScript that will be injected into the web page after the document finishes loading, but before other subresources finish loading.

src/WebViewTypes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ export interface IOSWebViewProps extends WebViewSharedProps {
402402
*/
403403
automaticallyAdjustContentInsets?: boolean;
404404

405+
/**
406+
* Controls whether to adjust the scroll indicator inset for web views that are
407+
* placed behind a navigation bar, tab bar, or toolbar. The default value
408+
* is `false`. (iOS 13+)
409+
* @platform ios
410+
*/
411+
automaticallyAdjustsScrollIndicatorInsets?: boolean;
412+
405413
/**
406414
* This property specifies how the safe area insets are used to modify the
407415
* content area of the scroll view. The default value of this property is

0 commit comments

Comments
 (0)