mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
refactor: remove ununsed Layout class (#6228)
This commit is contained in:
@ -5,16 +5,15 @@ import { Page } from "tns-core-modules/ui/page";
|
||||
import { Button } from "tns-core-modules/ui/button";
|
||||
import { Label } from "tns-core-modules/ui/label";
|
||||
import { Color } from "tns-core-modules/color";
|
||||
import { Layout } from "tns-core-modules/ui/layouts/layout";
|
||||
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
||||
import { AbsoluteLayout } from "tns-core-modules/ui/layouts/absolute-layout";
|
||||
import * as utils from "tns-core-modules/utils/utils";
|
||||
import * as types from "tns-core-modules/utils/types";
|
||||
import * as helper from "../../ui/helper";
|
||||
import * as observable from "tns-core-modules/data/observable";
|
||||
import * as bindable from "tns-core-modules/ui/core/bindable";
|
||||
import * as definition from "./view-tests";
|
||||
import { isIOS, isAndroid } from "tns-core-modules/platform";
|
||||
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base";
|
||||
|
||||
export function test_eachDescendant() {
|
||||
const test = function (views: Array<View>) {
|
||||
@ -292,7 +291,7 @@ const customShortHandProperty = new ShorthandProperty<Style, string>({
|
||||
});
|
||||
customShortHandProperty.register(Style);
|
||||
|
||||
class TestView extends Layout {
|
||||
class TestView extends LayoutBase {
|
||||
public inheritanceTest: number;
|
||||
public booleanInheritanceTest: boolean;
|
||||
public dummy: number;
|
||||
|
@ -1,109 +0,0 @@
|
||||
import { Layout as LayoutDefinition } from "./layout";
|
||||
import { LayoutBase, View, layout, traceEnabled, traceWrite, traceCategories } from "./layout-base";
|
||||
|
||||
export * from "./layout-base";
|
||||
|
||||
const OWNER = Symbol("_owner");
|
||||
|
||||
interface NativeViewGroup {
|
||||
new (context: android.content.Context): android.view.ViewGroup;
|
||||
}
|
||||
|
||||
let NativeViewGroup: NativeViewGroup;
|
||||
function initializeNativeViewGroup() {
|
||||
if (NativeViewGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
class NativeViewGroupImpl extends android.view.ViewGroup {
|
||||
constructor(context: android.content.Context) {
|
||||
super(context);
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
const owner: View = this[OWNER];
|
||||
owner.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.setMeasuredDimension(owner.getMeasuredWidth(), owner.getMeasuredHeight());
|
||||
}
|
||||
|
||||
onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
|
||||
const owner: View = this[OWNER];
|
||||
owner.onLayout(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
NativeViewGroup = NativeViewGroupImpl;
|
||||
}
|
||||
|
||||
export class Layout extends LayoutBase implements LayoutDefinition {
|
||||
nativeViewProtected: android.view.ViewGroup;
|
||||
_measuredWidth: number;
|
||||
_measuredHeight: number;
|
||||
|
||||
public createNativeView() {
|
||||
initializeNativeViewGroup();
|
||||
return new NativeViewGroup(this._context);
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
super.initNativeView();
|
||||
(<any>this.nativeViewProtected)[OWNER] = this;
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
(<any>this.nativeViewProtected)[OWNER] = undefined;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
this._setCurrentMeasureSpecs(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
const view = this.nativeViewProtected;
|
||||
if (view) {
|
||||
if (traceEnabled()) {
|
||||
traceWrite(`${this} :measure: ${layout.measureSpecToString(widthMeasureSpec)}, ${layout.measureSpecToString(heightMeasureSpec)}`, traceCategories.Layout);
|
||||
}
|
||||
view.measure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
||||
public layout(left: number, top: number, right: number, bottom: number): void {
|
||||
this._setCurrentLayoutBounds(left, top, right, bottom);
|
||||
|
||||
var view = this.nativeViewProtected;
|
||||
if (view) {
|
||||
this.layoutNativeView(left, top, right, bottom);
|
||||
if (traceEnabled()) {
|
||||
traceWrite(`${this} :layout: ${left}, ${top}, ${right - left}, ${bottom - top}`, traceCategories.Layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
// Don't call super because it will trigger measure again.
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
// Don't call super because it will trigger layout again.
|
||||
}
|
||||
|
||||
// NOTE: overriden so we cache measuredWidth & measuredHeight.
|
||||
public setMeasuredDimension(measuredWidth: number, measuredHeight: number): void {
|
||||
super.setMeasuredDimension(measuredWidth, measuredHeight);
|
||||
this._measuredWidth = measuredWidth;
|
||||
this._measuredHeight = measuredHeight;
|
||||
}
|
||||
|
||||
// NOTE: base implementation use the nativeView.getMeasuredWidth which should
|
||||
// not be called while we are in onMeasure.
|
||||
public getMeasuredWidth(): number {
|
||||
return this._measuredWidth;
|
||||
}
|
||||
|
||||
// NOTE: base implementation use the nativeView.getMeasuredWidth which should
|
||||
// not be called while we are in onMeasure.
|
||||
public getMeasuredHeight(): number {
|
||||
return this._measuredHeight;
|
||||
}
|
||||
}
|
12
tns-core-modules/ui/layouts/layout.d.ts
vendored
12
tns-core-modules/ui/layouts/layout.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* @module "ui/layouts/layout"
|
||||
*/ /** */
|
||||
|
||||
import { LayoutBase } from "./layout-base";
|
||||
|
||||
/**
|
||||
* Base class for all views that supports children positioning in cross platform manner.
|
||||
*/
|
||||
export class Layout extends LayoutBase {
|
||||
//
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import { Layout as LayoutDefinition } from "./layout";
|
||||
import { LayoutBase } from "./layout-base";
|
||||
|
||||
export * from "./layout-base";
|
||||
export class Layout extends LayoutBase implements LayoutDefinition {
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
// Don't call super because it will measure the native element.
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user