Files
NativeScript/nativescript-core/ui/layouts/layout-base-common.ts
Alexander Vakrilov cc97a16800 feat: Scoped Packages (#7911)
* chore: move tns-core-modules to nativescript-core

* chore: preparing compat generate script

* chore: add missing definitions

* chore: no need for http-request to be private

* chore: packages chore

* test: generate tests for tns-core-modules

* chore: add anroid module for consistency

* chore: add .npmignore

* chore: added privateModulesWhitelist

* chore(webpack): added bundle-entry-points

* chore: scripts

* chore: tests changed to use @ns/core

* test: add scoped-packages test project

* test: fix types

* test: update test project

* chore: build scripts

* chore: update build script

* chore: npm scripts cleanup

* chore: make the compat pgk work with old wp config

* test: generate diff friendly tests

* chore: create barrel exports

* chore: move files after rebase

* chore: typedoc config

* chore: compat mode

* chore: review of barrels

* chore: remove tns-core-modules import after rebase

* chore: dev workflow setup

* chore: update developer-workflow

* docs: experiment with API extractor

* chore: api-extractor and barrel exports

* chore: api-extractor configs

* chore: generate d.ts rollup with api-extractor

* refactor: move methods inside Frame

* chore: fic tests to use Frame static methods

* refactor: create Builder class

* refactor: use Builder class in tests

* refactor: include Style in ui barrel

* chore: separate compat build script

* chore: fix tslint errors

* chore: update NATIVESCRIPT_CORE_ARGS

* chore: fix compat pack

* chore: fix ui-test-app build with linked modules

* chore: Application, ApplicationSettings, Connectivity and Http

* chore: export Trace, Profiling and Utils

* refactor: Static create methods for ImageSource

* chore: fix deprecated usages of ImageSource

* chore: move Span and FormattedString to ui

* chore: add events-args and ImageSource to index files

* chore: check for CLI >= 6.2 when building for IOS

* chore: update travis build

* chore: copy Pod file to compat package

* chore: update error msg ui-tests-app

* refactor: Apply suggestions from code review

Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com>

* chore: typings and refs

* chore: add missing d.ts files for public API

* chore: adress code review FB

* chore: update api-report

* chore: dev-workflow for other apps

* chore: api update

* chore: update api-report
2019-10-17 00:45:33 +03:00

159 lines
4.4 KiB
TypeScript

import { LayoutBase as LayoutBaseDefinition } from "./layout-base";
import { View, CustomLayoutView, Property, AddChildFromBuilder, getViewById, Length, booleanConverter } from "../core/view";
export * from "../core/view";
export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefinition, AddChildFromBuilder {
private _subViews = new Array<View>();
public _addChildFromBuilder(name: string, value: any) {
if (value instanceof View) {
this.addChild(value);
}
}
getChildrenCount(): number {
return this._subViews.length;
}
// overrides the base property.
get _childrenCount(): number {
return this._subViews.length;
}
getChildAt(index: number): View {
return this._subViews[index];
}
getChildIndex(child: View): number {
return this._subViews.indexOf(child);
}
public getChildById(id: string) {
return getViewById(this, id);
}
public _registerLayoutChild(child: View) {
//Overridden
}
public _unregisterLayoutChild(child: View) {
//Overridden
}
public addChild(child: View): void {
// TODO: Do we need this method since we have the core logic in the View implementation?
this._subViews.push(child);
this._addView(child);
this._registerLayoutChild(child);
}
public insertChild(child: View, atIndex: number): void {
this._subViews.splice(atIndex, 0, child);
this._addView(child, atIndex);
this._registerLayoutChild(child);
}
public removeChild(child: View): void {
this._removeView(child);
// TODO: consider caching the index on the child.
const index = this._subViews.indexOf(child);
this._subViews.splice(index, 1);
this._unregisterLayoutChild(child);
}
public removeChildren(): void {
while (this.getChildrenCount() !== 0) {
this.removeChild(this._subViews[this.getChildrenCount() - 1]);
}
}
get padding(): string | Length {
return this.style.padding;
}
set padding(value: string | Length) {
this.style.padding = value;
}
get paddingTop(): Length {
return this.style.paddingTop;
}
set paddingTop(value: Length) {
this.style.paddingTop = value;
}
get paddingRight(): Length {
return this.style.paddingRight;
}
set paddingRight(value: Length) {
this.style.paddingRight = value;
}
get paddingBottom(): Length {
return this.style.paddingBottom;
}
set paddingBottom(value: Length) {
this.style.paddingBottom = value;
}
get paddingLeft(): Length {
return this.style.paddingLeft;
}
set paddingLeft(value: Length) {
this.style.paddingLeft = value;
}
public clipToBounds: boolean;
public isPassThroughParentEnabled: boolean;
public _childIndexToNativeChildIndex(index?: number): number {
if (index === undefined) {
return undefined;
}
let result = 0;
for (let i = 0; i < index && i < this._subViews.length; i++) {
result += this._subViews[i]._getNativeViewsCount();
}
return result;
}
public eachChildView(callback: (child: View) => boolean): void {
for (let i = 0, length = this._subViews.length; i < length; i++) {
const retVal = callback(this._subViews[i]);
if (retVal === false) {
break;
}
}
}
public eachLayoutChild(callback: (child: View, isLast: boolean) => void): void {
let lastChild: View = null;
this.eachChildView((cv) => {
cv._eachLayoutView((lv) => {
if (lastChild && !lastChild.isCollapsed) {
callback(lastChild, false);
}
lastChild = lv;
});
return true;
});
if (lastChild && !lastChild.isCollapsed) {
callback(lastChild, true);
}
}
}
export const clipToBoundsProperty = new Property<LayoutBaseCommon, boolean>({ name: "clipToBounds", defaultValue: true, valueConverter: booleanConverter });
clipToBoundsProperty.register(LayoutBaseCommon);
export const isPassThroughParentEnabledProperty = new Property<LayoutBaseCommon, boolean>({ name: "isPassThroughParentEnabled", defaultValue: false, valueConverter: booleanConverter });
isPassThroughParentEnabledProperty.register(LayoutBaseCommon);