|
1 | 1 | import { ScrollEventData } from "."; |
2 | 2 | import { View, layout, ScrollViewBase, scrollBarIndicatorVisibleProperty } from "./scroll-view-common"; |
| 3 | +import { ios as iosUtils } from "../../utils/utils"; |
3 | 4 | // HACK: Webpack. Use a fully-qualified import to allow resolve.extensions(.ios.js) to |
4 | 5 | // kick in. `../utils` doesn't seem to trigger the webpack extensions mechanism. |
5 | 6 | import * as uiUtils from "tns-core-modules/ui/utils"; |
6 | 7 |
|
7 | 8 | export * from "./scroll-view-common"; |
8 | 9 |
|
| 10 | +const majorVersion = iosUtils.MajorVersion; |
| 11 | + |
9 | 12 | class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate { |
10 | 13 | private _owner: WeakRef<ScrollView>; |
11 | 14 |
|
@@ -61,7 +64,7 @@ export class ScrollView extends ScrollViewBase { |
61 | 64 | this.nativeViewProtected.showsHorizontalScrollIndicator = value; |
62 | 65 | } else { |
63 | 66 | this.nativeViewProtected.showsVerticalScrollIndicator = value; |
64 | | - } |
| 67 | + } |
65 | 68 | } |
66 | 69 |
|
67 | 70 | get horizontalOffset(): number { |
@@ -92,7 +95,7 @@ export class ScrollView extends ScrollViewBase { |
92 | 95 | return true; |
93 | 96 | } |
94 | 97 | [scrollBarIndicatorVisibleProperty.setNative](value: boolean) { |
95 | | - this.updateScrollBarVisibility(value); |
| 98 | + this.updateScrollBarVisibility(value); |
96 | 99 | } |
97 | 100 |
|
98 | 101 | public scrollToVerticalOffset(value: number, animated: boolean) { |
@@ -120,6 +123,16 @@ export class ScrollView extends ScrollViewBase { |
120 | 123 | const child = this.layoutView; |
121 | 124 | this._contentMeasuredWidth = this.effectiveMinWidth; |
122 | 125 | this._contentMeasuredHeight = this.effectiveMinHeight; |
| 126 | + |
| 127 | + // `_automaticallyAdjustsScrollViewInsets` is set to true only if the first child |
| 128 | + // of UIViewController (Page, TabView e.g) is UIScrollView (ScrollView, ListView e.g). |
| 129 | + // On iOS 11 by default UIScrollView automatically adjusts the scroll view insets, but they s |
| 130 | + if (majorVersion > 10 && !this.parent._automaticallyAdjustsScrollViewInsets) { |
| 131 | + // Disable automatic adjustment of scroll view insets when ScrollView |
| 132 | + // is not the first child of UIViewController. |
| 133 | + this.nativeViewProtected.contentInsetAdjustmentBehavior = 2; |
| 134 | + } |
| 135 | + |
123 | 136 | if (child) { |
124 | 137 | let childSize: { measuredWidth: number; measuredHeight: number }; |
125 | 138 | if (this.orientation === "vertical") { |
@@ -165,7 +178,7 @@ export class ScrollView extends ScrollViewBase { |
165 | 178 | } |
166 | 179 |
|
167 | 180 | public _onOrientationChanged() { |
168 | | - this.updateScrollBarVisibility(this.scrollBarIndicatorVisible); |
| 181 | + this.updateScrollBarVisibility(this.scrollBarIndicatorVisible); |
169 | 182 | } |
170 | 183 | } |
171 | 184 |
|
|
0 commit comments