mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix scrollview
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<ScrollView orientation="horizontal" class="scroll">
|
<ScrollView orientation="horizontal" class="scroll">
|
||||||
<GridLayout rows="auto, auto" columns="auto, auto" backgroundColor="CadetBlue">
|
<GridLayout rows="*, *" columns="auto, auto" backgroundColor="CadetBlue">
|
||||||
<StackLayout row="0" col="0" backgroundColor="SkyBlue">
|
<StackLayout row="0" col="0" backgroundColor="SkyBlue">
|
||||||
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
||||||
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<ScrollView orientation="vertical" class="scroll">
|
<ScrollView orientation="vertical" class="scroll">
|
||||||
<GridLayout rows="auto, auto" columns="auto, auto" backgroundColor="CadetBlue">
|
<GridLayout rows="auto, auto" columns="*, *" backgroundColor="CadetBlue">
|
||||||
<StackLayout row="0" col="0" backgroundColor="SkyBlue">
|
<StackLayout row="0" col="0" backgroundColor="SkyBlue">
|
||||||
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
||||||
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
<Label text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"></Label>
|
||||||
|
|||||||
@@ -776,9 +776,9 @@ export namespace ios {
|
|||||||
const inWindowRight = inWindowLeft + layout.round(layout.toDevicePixels(frame.size.width));
|
const inWindowRight = inWindowLeft + layout.round(layout.toDevicePixels(frame.size.width));
|
||||||
const inWindowBottom = inWindowTop + layout.round(layout.toDevicePixels(frame.size.height));
|
const inWindowBottom = inWindowTop + layout.round(layout.toDevicePixels(frame.size.height));
|
||||||
|
|
||||||
const parentWithController = ios.getParentWithViewController(view);
|
const availableSpace = getAvailableSpaceFromParent(view);
|
||||||
const safeArea = parentWithController.viewController.view.safeAreaLayoutGuide.layoutFrame;
|
const safeArea = availableSpace.safeArea;
|
||||||
const fullscreen = parentWithController.viewController.view.frame;
|
const fullscreen = availableSpace.fullscreen;
|
||||||
|
|
||||||
const position = ios.getPositionFromFrame(frame);
|
const position = ios.getPositionFromFrame(frame);
|
||||||
const safeAreaPosition = ios.getPositionFromFrame(safeArea);
|
const safeAreaPosition = ios.getPositionFromFrame(safeArea);
|
||||||
@@ -830,6 +830,31 @@ export namespace ios {
|
|||||||
layoutParent(view.parent);
|
layoutParent(view.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAvailableSpaceFromParent(view: View): { safeArea: CGRect, fullscreen: CGRect } {
|
||||||
|
// Search for ViewController or UIScrollView parent to get their content size.
|
||||||
|
let parent = view.parent;
|
||||||
|
while (parent && !parent.viewController && !(parent.nativeViewProtected instanceof UIScrollView)) {
|
||||||
|
parent = parent.parent as View;
|
||||||
|
}
|
||||||
|
|
||||||
|
let fullscreen = null;
|
||||||
|
let safeArea = null;
|
||||||
|
|
||||||
|
if (parent.viewController) {
|
||||||
|
const nativeView = parent.viewController.view;
|
||||||
|
safeArea = nativeView.safeAreaLayoutGuide.layoutFrame;
|
||||||
|
fullscreen = nativeView.frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parent.nativeViewProtected instanceof UIScrollView) {
|
||||||
|
const nativeView = parent.nativeViewProtected;
|
||||||
|
safeArea = nativeView.safeAreaLayoutGuide.layoutFrame;
|
||||||
|
fullscreen = CGRectMake(0, 0, nativeView.contentSize.width, nativeView.contentSize.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { safeArea: safeArea, fullscreen: fullscreen}
|
||||||
|
}
|
||||||
|
|
||||||
export class UILayoutViewController extends UIViewController {
|
export class UILayoutViewController extends UIViewController {
|
||||||
public owner: WeakRef<View>;
|
public owner: WeakRef<View>;
|
||||||
|
|
||||||
|
|||||||
@@ -143,8 +143,9 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||||
let width = (right - left);
|
const insets = this.getSafeAreaInsets();
|
||||||
let height = (bottom - top);
|
let width = (right - left - insets.right - insets.left);
|
||||||
|
let height = (bottom - top - insets.bottom - insets.top);
|
||||||
|
|
||||||
const nativeView = this.nativeViewProtected;
|
const nativeView = this.nativeViewProtected;
|
||||||
|
|
||||||
@@ -155,16 +156,21 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
nativeView.contentInsetAdjustmentBehavior = 2;
|
nativeView.contentInsetAdjustmentBehavior = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const insets = this.getSafeAreaInsets();
|
let scrollWidth = width;
|
||||||
|
let scrollHeight = height;
|
||||||
if (this.orientation === "horizontal") {
|
if (this.orientation === "horizontal") {
|
||||||
width = Math.max(this._contentMeasuredWidth + insets.left + insets.right, width);
|
scrollWidth = Math.max(this._contentMeasuredWidth + insets.left + insets.right, width);
|
||||||
|
scrollHeight = height + insets.top + insets.bottom;
|
||||||
|
width = Math.max(this._contentMeasuredWidth, width);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
height = Math.max(this._contentMeasuredHeight + insets.top + insets.bottom, height);
|
scrollHeight = Math.max(this._contentMeasuredHeight + insets.top + insets.bottom, height);
|
||||||
|
scrollWidth = width + insets.left + insets.right;
|
||||||
|
height = Math.max(this._contentMeasuredHeight, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
nativeView.contentSize = CGSizeMake(layout.toDeviceIndependentPixels(width), layout.toDeviceIndependentPixels(height));
|
nativeView.contentSize = CGSizeMake(layout.toDeviceIndependentPixels(scrollWidth), layout.toDeviceIndependentPixels(scrollHeight));
|
||||||
View.layoutChild(this, this.layoutView, insets.left, insets.top, width, height);
|
View.layoutChild(this, this.layoutView, insets.left, insets.top, insets.left + width, insets.top + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onOrientationChanged() {
|
public _onOrientationChanged() {
|
||||||
|
|||||||
Reference in New Issue
Block a user