feat:adjust the inject timing of panel's initData
This commit is contained in:
parent
08454d53ea
commit
2b62e8bd3b
@ -17,6 +17,7 @@ package pub.doric;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
@ -114,17 +115,24 @@ public class DoricContext {
|
||||
public static DoricContext create(Context context, String script, String source, String extra) {
|
||||
DoricContext doricContext = DoricContextManager.getInstance().createContext(context, script, source, extra);
|
||||
doricContext.script = script;
|
||||
doricContext.extra = extra;
|
||||
doricContext.init(extra);
|
||||
doricContext.callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
return doricContext;
|
||||
}
|
||||
|
||||
public void init(float width, float height) {
|
||||
public void init(String initData) {
|
||||
this.extra = initData;
|
||||
if (!TextUtils.isEmpty(initData)) {
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, initData);
|
||||
}
|
||||
}
|
||||
|
||||
public void build(float width, float height) {
|
||||
this.initParams = new JSONBuilder()
|
||||
.put("width", width)
|
||||
.put("height", height)
|
||||
.toJSONObject();
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams, extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_BUILD, this.initParams);
|
||||
}
|
||||
|
||||
public AsyncResult<JSDecoder> callEntity(String methodName, Object... args) {
|
||||
@ -186,8 +194,9 @@ public class DoricContext {
|
||||
this.script = script;
|
||||
this.mRootNode.setId("");
|
||||
getDriver().createContext(mContextId, script, source);
|
||||
init(this.extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams, extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_BUILD, this.initParams);
|
||||
onShow();
|
||||
}
|
||||
|
||||
|
@ -61,15 +61,15 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
||||
|
||||
public void config(String script, String alias, String extra) {
|
||||
DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra);
|
||||
doricContext.onShow();
|
||||
config(doricContext);
|
||||
doricContext.onShow();
|
||||
}
|
||||
|
||||
public void config(DoricContext doricContext) {
|
||||
mDoricContext = doricContext;
|
||||
mDoricContext.getRootNode().setRootView(this);
|
||||
if (getMeasuredWidth() != 0 && getMeasuredHeight() != 0) {
|
||||
mDoricContext.init(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight()));
|
||||
mDoricContext.build(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
||||
renderedWidth = w;
|
||||
renderedHeight = h;
|
||||
} else {
|
||||
mDoricContext.init(DoricUtils.px2dp(w), DoricUtils.px2dp(h));
|
||||
mDoricContext.build(DoricUtils.px2dp(w), DoricUtils.px2dp(h));
|
||||
renderedWidth = w;
|
||||
renderedHeight = h;
|
||||
}
|
||||
|
@ -70,4 +70,5 @@ public class DoricConstant {
|
||||
public static final String DORIC_ENTITY_DESTROY = "__onDestroy__";
|
||||
public static final String DORIC_ENTITY_SHOW = "__onShow__";
|
||||
public static final String DORIC_ENTITY_HIDDEN = "__onHidden__";
|
||||
public static final String DORIC_ENTITY_BUILD = "__build__";
|
||||
}
|
||||
|
@ -51,7 +51,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray *)args;
|
||||
|
||||
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height;
|
||||
- (void)build:(CGSize)size;
|
||||
|
||||
- (void)init:(NSString *)initData;
|
||||
|
||||
- (void)reload:(NSString *)script;
|
||||
|
||||
|
@ -36,11 +36,11 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source extr
|
||||
_script = script;
|
||||
_source = source;
|
||||
_initialParams = [@{@"width": @(0), @"height": @(0)} mutableCopy];
|
||||
_extra = extra;
|
||||
[[DoricContextManager instance] createContext:self script:script source:source];
|
||||
_headNodes = [NSMutableDictionary new];
|
||||
DoricRootNode *rootNode = [[DoricRootNode alloc] initWithContext:self];
|
||||
_rootNode = rootNode;
|
||||
[self init:extra];
|
||||
[self callEntity:DORIC_ENTITY_CREATE, nil];
|
||||
}
|
||||
return self;
|
||||
@ -80,20 +80,28 @@ - (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray
|
||||
return [self.driver invokeContextEntity:self.contextId method:method argumentsArray:args];
|
||||
}
|
||||
|
||||
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height {
|
||||
- (void)init:(NSString *)initData {
|
||||
self.extra = initData;
|
||||
if (initData) {
|
||||
[self callEntity:DORIC_ENTITY_INIT, initData, nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)build:(CGSize)size {
|
||||
[self.initialParams also:^(NSMutableDictionary *it) {
|
||||
it[@"width"] = @(width);
|
||||
it[@"height"] = @(height);
|
||||
it[@"width"] = @(size.width);
|
||||
it[@"height"] = @(size.height);
|
||||
}];
|
||||
[self callEntity:DORIC_ENTITY_INIT, self.initialParams, self.extra, nil];
|
||||
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
|
||||
}
|
||||
|
||||
- (void)reload:(NSString *)script {
|
||||
self.rootNode.viewId = nil;
|
||||
self.script = script;
|
||||
[self.driver createContext:self.contextId script:script source:self.source];
|
||||
[self init:self.extra];
|
||||
[self callEntity:DORIC_ENTITY_CREATE, nil];
|
||||
[self callEntity:DORIC_ENTITY_INIT, self.initialParams, self.extra, nil];
|
||||
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
|
||||
[self onShow];
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ - (void)viewWillLayoutSubviews {
|
||||
if (self.doricContext && self.renderedWidth != self.view.width && self.renderedHeight != self.view.height) {
|
||||
self.renderedWidth = self.view.width;
|
||||
self.renderedHeight = self.view.height;
|
||||
[self.doricContext initContextWithWidth:self.renderedWidth height:self.renderedHeight];
|
||||
[self.doricContext build:CGSizeMake(self.renderedWidth, self.renderedHeight)];
|
||||
} else {
|
||||
[self.doricContext.rootNode.view also:^(DoricStackView *it) {
|
||||
if (it.width != self.renderedWidth || it.height != self.renderedHeight) {
|
||||
|
@ -63,3 +63,5 @@ extern NSString *const DORIC_ENTITY_DESTROY;
|
||||
extern NSString *const DORIC_ENTITY_SHOW;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_HIDDEN;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_BUILD;
|
||||
|
@ -81,3 +81,5 @@
|
||||
NSString *const DORIC_ENTITY_SHOW = @"__onShow__";
|
||||
|
||||
NSString *const DORIC_ENTITY_HIDDEN = @"__onHidden__";
|
||||
|
||||
NSString *const DORIC_ENTITY_BUILD = @"__build__";
|
||||
|
@ -942,14 +942,10 @@ var Panel = /** @class */ (function () {
|
||||
Panel.prototype.getInitData = function () {
|
||||
return this.__data__;
|
||||
};
|
||||
Panel.prototype.__init__ = function (frame, data) {
|
||||
Panel.prototype.__init__ = function (data) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data);
|
||||
}
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
};
|
||||
Panel.prototype.__onCreate__ = function () {
|
||||
this.onCreate();
|
||||
@ -963,7 +959,10 @@ var Panel = /** @class */ (function () {
|
||||
Panel.prototype.__onHidden__ = function () {
|
||||
this.onHidden();
|
||||
};
|
||||
Panel.prototype.__build__ = function () {
|
||||
Panel.prototype.__build__ = function (frame) {
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
};
|
||||
Panel.prototype.__response__ = function (viewIds, callbackId) {
|
||||
@ -1143,7 +1142,7 @@ var Panel = /** @class */ (function () {
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", [Object, String]),
|
||||
__metadata$2("design:paramtypes", [String]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__init__", null);
|
||||
__decorate$2([
|
||||
@ -1173,7 +1172,7 @@ var Panel = /** @class */ (function () {
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", []),
|
||||
__metadata$2("design:paramtypes", [Object]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__build__", null);
|
||||
__decorate$2([
|
||||
|
@ -713,14 +713,10 @@ class Panel {
|
||||
getInitData() {
|
||||
return this.__data__;
|
||||
}
|
||||
__init__(frame, data) {
|
||||
__init__(data) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data);
|
||||
}
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__onCreate__() {
|
||||
this.onCreate();
|
||||
@ -734,7 +730,10 @@ class Panel {
|
||||
__onHidden__() {
|
||||
this.onHidden();
|
||||
}
|
||||
__build__() {
|
||||
__build__(frame) {
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__response__(viewIds, callbackId) {
|
||||
@ -837,7 +836,7 @@ class Panel {
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", [Object, String]),
|
||||
__metadata$2("design:paramtypes", [String]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__init__", null);
|
||||
__decorate$2([
|
||||
@ -867,7 +866,7 @@ __decorate$2([
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", []),
|
||||
__metadata$2("design:paramtypes", [Object]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__build__", null);
|
||||
__decorate$2([
|
||||
|
@ -2172,14 +2172,10 @@ class Panel {
|
||||
getInitData() {
|
||||
return this.__data__;
|
||||
}
|
||||
__init__(frame, data) {
|
||||
__init__(data) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data);
|
||||
}
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__onCreate__() {
|
||||
this.onCreate();
|
||||
@ -2193,7 +2189,10 @@ class Panel {
|
||||
__onHidden__() {
|
||||
this.onHidden();
|
||||
}
|
||||
__build__() {
|
||||
__build__(frame) {
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__response__(viewIds, callbackId) {
|
||||
@ -2296,7 +2295,7 @@ class Panel {
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", [Object, String]),
|
||||
__metadata$2("design:paramtypes", [String]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__init__", null);
|
||||
__decorate$2([
|
||||
@ -2326,7 +2325,7 @@ __decorate$2([
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", []),
|
||||
__metadata$2("design:paramtypes", [Object]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__build__", null);
|
||||
__decorate$2([
|
||||
|
2
doric-js/index.d.ts
vendored
2
doric-js/index.d.ts
vendored
@ -446,7 +446,7 @@ declare module 'doric/lib/src/widget/layouts' {
|
||||
space?: number;
|
||||
gravity?: Gravity;
|
||||
}
|
||||
export class VLayout extends LinearLayout implements VLayout {
|
||||
export class VLayout extends LinearLayout implements IVLayout {
|
||||
}
|
||||
export interface IHLayout extends IView {
|
||||
space?: number;
|
||||
|
@ -81,14 +81,10 @@ export class Panel {
|
||||
getInitData() {
|
||||
return this.__data__;
|
||||
}
|
||||
__init__(frame, data) {
|
||||
__init__(data) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data);
|
||||
}
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__onCreate__() {
|
||||
this.onCreate();
|
||||
@ -102,7 +98,10 @@ export class Panel {
|
||||
__onHidden__() {
|
||||
this.onHidden();
|
||||
}
|
||||
__build__() {
|
||||
__build__(frame) {
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__response__(viewIds, callbackId) {
|
||||
@ -205,7 +204,7 @@ export class Panel {
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, String]),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__init__", null);
|
||||
__decorate([
|
||||
@ -235,7 +234,7 @@ __decorate([
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__build__", null);
|
||||
__decorate([
|
||||
|
2
doric-js/lib/src/widget/layouts.d.ts
vendored
2
doric-js/lib/src/widget/layouts.d.ts
vendored
@ -14,7 +14,7 @@ export interface IVLayout extends IView {
|
||||
space?: number;
|
||||
gravity?: Gravity;
|
||||
}
|
||||
export declare class VLayout extends LinearLayout implements VLayout {
|
||||
export declare class VLayout extends LinearLayout implements IVLayout {
|
||||
}
|
||||
export interface IHLayout extends IView {
|
||||
space?: number;
|
||||
|
@ -88,14 +88,10 @@ export abstract class Panel {
|
||||
}
|
||||
|
||||
@NativeCall
|
||||
private __init__(frame: Frame, data?: string) {
|
||||
private __init__(data?: string) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data)
|
||||
}
|
||||
this.__root__.width = frame.width
|
||||
this.__root__.height = frame.height
|
||||
this.__root__.children.length = 0
|
||||
this.build(this.__root__)
|
||||
}
|
||||
|
||||
@NativeCall
|
||||
@ -119,7 +115,10 @@ export abstract class Panel {
|
||||
}
|
||||
|
||||
@NativeCall
|
||||
private __build__() {
|
||||
private __build__(frame: Frame) {
|
||||
this.__root__.width = frame.width
|
||||
this.__root__.height = frame.height
|
||||
this.__root__.children.length = 0
|
||||
this.build(this.__root__)
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ export interface IVLayout extends IView {
|
||||
gravity?: Gravity
|
||||
}
|
||||
|
||||
export class VLayout extends LinearLayout implements VLayout {
|
||||
export class VLayout extends LinearLayout implements IVLayout {
|
||||
}
|
||||
|
||||
|
||||
|
15
doric-web/dist/index.js
vendored
15
doric-web/dist/index.js
vendored
@ -2230,14 +2230,10 @@ class Panel {
|
||||
getInitData() {
|
||||
return this.__data__;
|
||||
}
|
||||
__init__(frame, data) {
|
||||
__init__(data) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data);
|
||||
}
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__onCreate__() {
|
||||
this.onCreate();
|
||||
@ -2251,7 +2247,10 @@ class Panel {
|
||||
__onHidden__() {
|
||||
this.onHidden();
|
||||
}
|
||||
__build__() {
|
||||
__build__(frame) {
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__response__(viewIds, callbackId) {
|
||||
@ -2354,7 +2353,7 @@ class Panel {
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", [Object, String]),
|
||||
__metadata$2("design:paramtypes", [String]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__init__", null);
|
||||
__decorate$2([
|
||||
@ -2384,7 +2383,7 @@ __decorate$2([
|
||||
__decorate$2([
|
||||
NativeCall,
|
||||
__metadata$2("design:type", Function),
|
||||
__metadata$2("design:paramtypes", []),
|
||||
__metadata$2("design:paramtypes", [Object]),
|
||||
__metadata$2("design:returntype", void 0)
|
||||
], Panel.prototype, "__build__", null);
|
||||
__decorate$2([
|
||||
|
6
doric-web/dist/index.js.map
vendored
6
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user