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) {
|
||||
vlayout(
|
||||
[
|
||||
this.number = text({
|
||||
text({
|
||||
textSize: 40,
|
||||
tag:"tvNumber"
|
||||
}),
|
||||
|
||||
this.counter = text({
|
||||
text: "Click To Count",
|
||||
text({
|
||||
text: "Click To Count 1",
|
||||
textSize: 20,
|
||||
tag:"tvCounter"
|
||||
}),
|
||||
],
|
||||
{
|
||||
@ -24,6 +26,8 @@ class CounterView extends ViewHolder {
|
||||
space: 20,
|
||||
}
|
||||
).in(root)
|
||||
this.number= root.findViewByTag("tvNumber")!
|
||||
this.counter= root.findViewByTag("tvCounter")!
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +169,12 @@ class View {
|
||||
}
|
||||
return f;
|
||||
}
|
||||
findViewByTag(tag) {
|
||||
if (tag === this.tag) {
|
||||
return this;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/** Anchor start*/
|
||||
get left() {
|
||||
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() {
|
||||
if (super.isDirty()) {
|
||||
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 : {};
|
||||
|
||||
function createCommonjsModule(fn, basedir, module) {
|
||||
return module = {
|
||||
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');
|
||||
function createCommonjsModule(fn, module) {
|
||||
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
||||
}
|
||||
|
||||
/*! *****************************************************************************
|
||||
@ -2855,6 +2845,10 @@ var doric = (function (exports) {
|
||||
|
||||
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;
|
||||
|
||||
|
@ -1628,6 +1628,12 @@ class View {
|
||||
}
|
||||
return f;
|
||||
}
|
||||
findViewByTag(tag) {
|
||||
if (tag === this.tag) {
|
||||
return this;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/** Anchor start*/
|
||||
get left() {
|
||||
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() {
|
||||
if (super.isDirty()) {
|
||||
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;
|
||||
hidden?: boolean;
|
||||
viewId: string;
|
||||
tag?: string;
|
||||
padding?: {
|
||||
left?: number;
|
||||
right?: number;
|
||||
@ -172,6 +173,7 @@ declare module 'doric/lib/src/ui/view' {
|
||||
onClick?: Function;
|
||||
superview?: Superview;
|
||||
callbacks: Map<String, Function>;
|
||||
findViewByTag(tag: string): View | undefined;
|
||||
constructor();
|
||||
/** Anchor start*/
|
||||
get left(): number;
|
||||
@ -246,6 +248,7 @@ declare module 'doric/lib/src/ui/view' {
|
||||
}
|
||||
export abstract class Superview extends View {
|
||||
subviewById(id: string): View | undefined;
|
||||
findViewByTag(tag: string): View | undefined;
|
||||
abstract allSubviews(): Iterable<View>;
|
||||
isDirty(): boolean;
|
||||
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;
|
||||
hidden?: boolean;
|
||||
viewId: string;
|
||||
tag?: string;
|
||||
padding?: {
|
||||
left?: number;
|
||||
right?: number;
|
||||
@ -53,6 +54,7 @@ export declare abstract class View implements Modeling {
|
||||
callbacks: Map<String, Function>;
|
||||
private callback2Id;
|
||||
private id2Callback;
|
||||
findViewByTag(tag: string): View | undefined;
|
||||
constructor();
|
||||
/** Anchor start*/
|
||||
get left(): number;
|
||||
@ -130,6 +132,8 @@ export declare abstract class View implements Modeling {
|
||||
}
|
||||
export declare abstract class Superview extends View {
|
||||
subviewById(id: string): View | undefined;
|
||||
findViewByTag(tag: string): View | undefined;
|
||||
private findViewTraversal;
|
||||
abstract allSubviews(): Iterable<View>;
|
||||
isDirty(): boolean;
|
||||
clean(): void;
|
||||
|
@ -54,6 +54,12 @@ export class View {
|
||||
}
|
||||
return f;
|
||||
}
|
||||
findViewByTag(tag) {
|
||||
if (tag === this.tag) {
|
||||
return this;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/** Anchor start*/
|
||||
get left() {
|
||||
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() {
|
||||
if (super.isDirty()) {
|
||||
return true;
|
||||
|
@ -69,6 +69,8 @@ export abstract class View implements Modeling {
|
||||
|
||||
viewId = uniqueId('ViewId')
|
||||
|
||||
tag?: string
|
||||
|
||||
@Property
|
||||
padding?: {
|
||||
left?: number,
|
||||
@ -101,6 +103,13 @@ export abstract class View implements Modeling {
|
||||
return f
|
||||
}
|
||||
|
||||
findViewByTag(tag: string): View | undefined {
|
||||
if (tag === this.tag) {
|
||||
return this;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
return new Proxy(this, {
|
||||
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>
|
||||
|
||||
isDirty() {
|
||||
|
21
doric-web/dist/index.js
vendored
21
doric-web/dist/index.js
vendored
@ -1686,6 +1686,12 @@ class View {
|
||||
}
|
||||
return f;
|
||||
}
|
||||
findViewByTag(tag) {
|
||||
if (tag === this.tag) {
|
||||
return this;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/** Anchor start*/
|
||||
get left() {
|
||||
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() {
|
||||
if (super.isDirty()) {
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user