feat: add apply function on Ref

This commit is contained in:
pengfei.zhou 2021-12-03 15:37:42 +08:00 committed by osborn
parent 1c1ca76782
commit 5aa20dbd6a
11 changed files with 53 additions and 1 deletions

View File

@ -221,6 +221,11 @@ var Ref = /** @class */ (function () {
enumerable: false, enumerable: false,
configurable: true configurable: true
}); });
Ref.prototype.apply = function (config) {
if (this.view) {
this.view.apply(config);
}
};
return Ref; return Ref;
}()); }());
function createRef() { function createRef() {
@ -4044,6 +4049,7 @@ function animate(context) {
var v = _f.value; var v = _f.value;
if (v.isDirty()) { if (v.isDirty()) {
var model_1 = v.toModel(); var model_1 = v.toModel();
model_1.duration = args.duration;
var ret_1 = context.callNative('animate', 'animateRender', model_1); var ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean(); v.clean();
return ret_1; return ret_1;

View File

@ -151,6 +151,11 @@ class Ref {
} }
return this.view; return this.view;
} }
apply(config) {
if (this.view) {
this.view.apply(config);
}
}
} }
function createRef() { function createRef() {
return new Ref; return new Ref;
@ -3093,6 +3098,7 @@ function animate(context) {
for (let v of map.values()) { for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model_1 = v.toModel(); const model_1 = v.toModel();
model_1.duration = args.duration;
const ret_1 = context.callNative('animate', 'animateRender', model_1); const ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean(); v.clean();
return ret_1; return ret_1;

View File

@ -1679,6 +1679,11 @@ class Ref {
} }
return this.view; return this.view;
} }
apply(config) {
if (this.view) {
this.view.apply(config);
}
}
} }
function createRef() { function createRef() {
return new Ref; return new Ref;
@ -4621,6 +4626,7 @@ function animate(context) {
for (let v of map.values()) { for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model_1 = v.toModel(); const model_1 = v.toModel();
model_1.duration = args.duration;
const ret_1 = context.callNative('animate', 'animateRender', model_1); const ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean(); v.clean();
return ret_1; return ret_1;

3
doric-js/index.d.ts vendored
View File

@ -199,9 +199,11 @@ declare module 'doric/lib/src/ui/view' {
[index: string]: Model; [index: string]: Model;
}; };
}; };
type RefType<T> = T extends Ref<infer R> ? R : never;
export class Ref<T extends View> { export class Ref<T extends View> {
set current(v: T); set current(v: T);
get current(): T; get current(): T;
apply(config: Partial<RefType<this>>): void;
} }
export function createRef<T extends View>(): Ref<T>; export function createRef<T extends View>(): Ref<T>;
export abstract class View implements Modeling { export abstract class View implements Modeling {
@ -341,6 +343,7 @@ declare module 'doric/lib/src/ui/view' {
removeAllChildren(): void; removeAllChildren(): void;
set innerElement(e: View | ViewFragment | ViewFragment[] | undefined | null); set innerElement(e: View | ViewFragment | ViewFragment[] | undefined | null);
} }
export {};
} }
declare module 'doric/lib/src/ui/animation' { declare module 'doric/lib/src/ui/animation' {

View File

@ -47,6 +47,7 @@ export function animate(context) {
for (let v of map.values()) { for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model_1 = v.toModel(); const model_1 = v.toModel();
model_1.duration = args.duration;
const ret_1 = context.callNative('animate', 'animateRender', model_1); const ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean(); v.clean();
return ret_1; return ret_1;

View File

@ -14,10 +14,12 @@ export declare type NativeViewModel = {
[index: string]: Model; [index: string]: Model;
}; };
}; };
declare type RefType<T> = T extends Ref<infer R> ? R : never;
export declare class Ref<T extends View> { export declare class Ref<T extends View> {
private view?; private view?;
set current(v: T); set current(v: T);
get current(): T; get current(): T;
apply(config: Partial<RefType<this>>): void;
} }
export declare function createRef<T extends View>(): Ref<T>; export declare function createRef<T extends View>(): Ref<T>;
export declare abstract class View implements Modeling { export declare abstract class View implements Modeling {
@ -164,3 +166,4 @@ export declare abstract class Group extends Superview implements JSX.ElementChil
private addInnerElement; private addInnerElement;
set innerElement(e: View | ViewFragment | ViewFragment[] | undefined | null); set innerElement(e: View | ViewFragment | ViewFragment[] | undefined | null);
} }
export {};

View File

@ -33,6 +33,11 @@ export class Ref {
} }
return this.view; return this.view;
} }
apply(config) {
if (this.view) {
this.view.apply(config);
}
}
} }
export function createRef() { export function createRef() {
return new Ref; return new Ref;

View File

@ -65,6 +65,8 @@ export type NativeViewModel = {
}; };
} }
type RefType<T> = T extends Ref<infer R> ? R : never;
export class Ref<T extends View> { export class Ref<T extends View> {
private view?: T; private view?: T;
@ -78,6 +80,12 @@ export class Ref<T extends View> {
} }
return this.view return this.view
} }
apply(config: Partial<RefType<this>>) {
if (this.view) {
this.view.apply(config)
}
}
} }
export function createRef() { export function createRef() {

View File

@ -47,6 +47,8 @@ export type NativeViewModel = {
}; };
} }
type RefType<T> = T extends Ref<infer R> ? R : never;
export class Ref<T extends View> { export class Ref<T extends View> {
private view?: T; private view?: T;
@ -60,6 +62,12 @@ export class Ref<T extends View> {
} }
return this.view return this.view
} }
apply(config: Partial<RefType<this>>) {
if (this.view) {
this.view.apply(config)
}
}
} }
export function createRef<T extends View>(): Ref<T> { export function createRef<T extends View>(): Ref<T> {

View File

@ -1753,6 +1753,11 @@ class Ref {
} }
return this.view; return this.view;
} }
apply(config) {
if (this.view) {
this.view.apply(config);
}
}
} }
function createRef() { function createRef() {
return new Ref; return new Ref;
@ -4695,6 +4700,7 @@ function animate(context) {
for (let v of map.values()) { for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model_1 = v.toModel(); const model_1 = v.toModel();
model_1.duration = args.duration;
const ret_1 = context.callNative('animate', 'animateRender', model_1); const ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean(); v.clean();
return ret_1; return ret_1;

File diff suppressed because one or more lines are too long