feat:add view tag and findViewByTag
This commit is contained in:
parent
42a8eb4069
commit
f693719974
@ -9,13 +9,15 @@ class CounterView extends ViewHolder {
|
|||||||
build(root: Group) {
|
build(root: Group) {
|
||||||
vlayout(
|
vlayout(
|
||||||
[
|
[
|
||||||
this.number = text({
|
text({
|
||||||
textSize: 40,
|
textSize: 40,
|
||||||
|
tag:"tvNumber"
|
||||||
}),
|
}),
|
||||||
|
|
||||||
this.counter = text({
|
text({
|
||||||
text: "Click To Count",
|
text: "Click To Count 1",
|
||||||
textSize: 20,
|
textSize: 20,
|
||||||
|
tag:"tvCounter"
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
@ -24,6 +26,8 @@ class CounterView extends ViewHolder {
|
|||||||
space: 20,
|
space: 20,
|
||||||
}
|
}
|
||||||
).in(root)
|
).in(root)
|
||||||
|
this.number= root.findViewByTag("tvNumber")!
|
||||||
|
this.counter= root.findViewByTag("tvCounter")!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +169,12 @@ class View {
|
|||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
/** Anchor start*/
|
/** Anchor start*/
|
||||||
get left() {
|
get left() {
|
||||||
return this.x;
|
return this.x;
|
||||||
@ -405,6 +411,21 @@ class Superview extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return this.findViewTraversal(this, tag);
|
||||||
|
}
|
||||||
|
findViewTraversal(view, tag) {
|
||||||
|
for (let v of view.allSubviews()) {
|
||||||
|
let find = v.findViewByTag(tag);
|
||||||
|
if (find) {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
isDirty() {
|
isDirty() {
|
||||||
if (super.isDirty()) {
|
if (super.isDirty()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -59,18 +59,8 @@ var doric = (function (exports) {
|
|||||||
|
|
||||||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
||||||
|
|
||||||
function createCommonjsModule(fn, basedir, module) {
|
function createCommonjsModule(fn, module) {
|
||||||
return module = {
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
||||||
path: basedir,
|
|
||||||
exports: {},
|
|
||||||
require: function (path, base) {
|
|
||||||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
||||||
}
|
|
||||||
}, fn(module, module.exports), module.exports;
|
|
||||||
}
|
|
||||||
|
|
||||||
function commonjsRequire () {
|
|
||||||
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! *****************************************************************************
|
/*! *****************************************************************************
|
||||||
@ -2855,6 +2845,10 @@ var doric = (function (exports) {
|
|||||||
|
|
||||||
hiddenKeys[METADATA] = true;
|
hiddenKeys[METADATA] = true;
|
||||||
});
|
});
|
||||||
|
var internalMetadata_1 = internalMetadata.REQUIRED;
|
||||||
|
var internalMetadata_2 = internalMetadata.fastKey;
|
||||||
|
var internalMetadata_3 = internalMetadata.getWeakData;
|
||||||
|
var internalMetadata_4 = internalMetadata.onFreeze;
|
||||||
|
|
||||||
var onFreeze = internalMetadata.onFreeze;
|
var onFreeze = internalMetadata.onFreeze;
|
||||||
|
|
||||||
|
@ -1628,6 +1628,12 @@ class View {
|
|||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
/** Anchor start*/
|
/** Anchor start*/
|
||||||
get left() {
|
get left() {
|
||||||
return this.x;
|
return this.x;
|
||||||
@ -1864,6 +1870,21 @@ class Superview extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return this.findViewTraversal(this, tag);
|
||||||
|
}
|
||||||
|
findViewTraversal(view, tag) {
|
||||||
|
for (let v of view.allSubviews()) {
|
||||||
|
let find = v.findViewByTag(tag);
|
||||||
|
if (find) {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
isDirty() {
|
isDirty() {
|
||||||
if (super.isDirty()) {
|
if (super.isDirty()) {
|
||||||
return true;
|
return true;
|
||||||
|
3
doric-js/index.d.ts
vendored
3
doric-js/index.d.ts
vendored
@ -162,6 +162,7 @@ declare module 'doric/lib/src/ui/view' {
|
|||||||
alpha?: number;
|
alpha?: number;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
viewId: string;
|
viewId: string;
|
||||||
|
tag?: string;
|
||||||
padding?: {
|
padding?: {
|
||||||
left?: number;
|
left?: number;
|
||||||
right?: number;
|
right?: number;
|
||||||
@ -172,6 +173,7 @@ declare module 'doric/lib/src/ui/view' {
|
|||||||
onClick?: Function;
|
onClick?: Function;
|
||||||
superview?: Superview;
|
superview?: Superview;
|
||||||
callbacks: Map<String, Function>;
|
callbacks: Map<String, Function>;
|
||||||
|
findViewByTag(tag: string): View | undefined;
|
||||||
constructor();
|
constructor();
|
||||||
/** Anchor start*/
|
/** Anchor start*/
|
||||||
get left(): number;
|
get left(): number;
|
||||||
@ -246,6 +248,7 @@ declare module 'doric/lib/src/ui/view' {
|
|||||||
}
|
}
|
||||||
export abstract class Superview extends View {
|
export abstract class Superview extends View {
|
||||||
subviewById(id: string): View | undefined;
|
subviewById(id: string): View | undefined;
|
||||||
|
findViewByTag(tag: string): View | undefined;
|
||||||
abstract allSubviews(): Iterable<View>;
|
abstract allSubviews(): Iterable<View>;
|
||||||
isDirty(): boolean;
|
isDirty(): boolean;
|
||||||
clean(): void;
|
clean(): void;
|
||||||
|
4
doric-js/lib/src/ui/view.d.ts
vendored
4
doric-js/lib/src/ui/view.d.ts
vendored
@ -41,6 +41,7 @@ export declare abstract class View implements Modeling {
|
|||||||
alpha?: number;
|
alpha?: number;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
viewId: string;
|
viewId: string;
|
||||||
|
tag?: string;
|
||||||
padding?: {
|
padding?: {
|
||||||
left?: number;
|
left?: number;
|
||||||
right?: number;
|
right?: number;
|
||||||
@ -53,6 +54,7 @@ export declare abstract class View implements Modeling {
|
|||||||
callbacks: Map<String, Function>;
|
callbacks: Map<String, Function>;
|
||||||
private callback2Id;
|
private callback2Id;
|
||||||
private id2Callback;
|
private id2Callback;
|
||||||
|
findViewByTag(tag: string): View | undefined;
|
||||||
constructor();
|
constructor();
|
||||||
/** Anchor start*/
|
/** Anchor start*/
|
||||||
get left(): number;
|
get left(): number;
|
||||||
@ -130,6 +132,8 @@ export declare abstract class View implements Modeling {
|
|||||||
}
|
}
|
||||||
export declare abstract class Superview extends View {
|
export declare abstract class Superview extends View {
|
||||||
subviewById(id: string): View | undefined;
|
subviewById(id: string): View | undefined;
|
||||||
|
findViewByTag(tag: string): View | undefined;
|
||||||
|
private findViewTraversal;
|
||||||
abstract allSubviews(): Iterable<View>;
|
abstract allSubviews(): Iterable<View>;
|
||||||
isDirty(): boolean;
|
isDirty(): boolean;
|
||||||
clean(): void;
|
clean(): void;
|
||||||
|
@ -54,6 +54,12 @@ export class View {
|
|||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
/** Anchor start*/
|
/** Anchor start*/
|
||||||
get left() {
|
get left() {
|
||||||
return this.x;
|
return this.x;
|
||||||
@ -290,6 +296,21 @@ export class Superview extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return this.findViewTraversal(this, tag);
|
||||||
|
}
|
||||||
|
findViewTraversal(view, tag) {
|
||||||
|
for (let v of view.allSubviews()) {
|
||||||
|
let find = v.findViewByTag(tag);
|
||||||
|
if (find) {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
isDirty() {
|
isDirty() {
|
||||||
if (super.isDirty()) {
|
if (super.isDirty()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -69,6 +69,8 @@ export abstract class View implements Modeling {
|
|||||||
|
|
||||||
viewId = uniqueId('ViewId')
|
viewId = uniqueId('ViewId')
|
||||||
|
|
||||||
|
tag?: string
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
padding?: {
|
padding?: {
|
||||||
left?: number,
|
left?: number,
|
||||||
@ -101,6 +103,13 @@ export abstract class View implements Modeling {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findViewByTag(tag: string): View | undefined {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
return new Proxy(this, {
|
return new Proxy(this, {
|
||||||
get: (target, p, receiver) => {
|
get: (target, p, receiver) => {
|
||||||
@ -343,6 +352,23 @@ export abstract class Superview extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findViewByTag(tag: string): View | undefined {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
return this.findViewTraversal(this, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
private findViewTraversal(view: Superview, tag: string): View | undefined {
|
||||||
|
for (let v of view.allSubviews()) {
|
||||||
|
let find = v.findViewByTag(tag);
|
||||||
|
if (find) {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
abstract allSubviews(): Iterable<View>
|
abstract allSubviews(): Iterable<View>
|
||||||
|
|
||||||
isDirty() {
|
isDirty() {
|
||||||
|
21
doric-web/dist/index.js
vendored
21
doric-web/dist/index.js
vendored
@ -1686,6 +1686,12 @@ class View {
|
|||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
/** Anchor start*/
|
/** Anchor start*/
|
||||||
get left() {
|
get left() {
|
||||||
return this.x;
|
return this.x;
|
||||||
@ -1922,6 +1928,21 @@ class Superview extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
findViewByTag(tag) {
|
||||||
|
if (tag === this.tag) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return this.findViewTraversal(this, tag);
|
||||||
|
}
|
||||||
|
findViewTraversal(view, tag) {
|
||||||
|
for (let v of view.allSubviews()) {
|
||||||
|
let find = v.findViewByTag(tag);
|
||||||
|
if (find) {
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
isDirty() {
|
isDirty() {
|
||||||
if (super.isDirty()) {
|
if (super.isDirty()) {
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user