From 3e8c7263307a35473045bed31d85052049e5f2d2 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 25 Nov 2019 11:53:31 +0800 Subject: [PATCH] feat:add HeadView in panel --- .../java/pub/doric/plugin/ShaderPlugin.java | 1 + .../main/java/pub/doric/shader/ViewNode.java | 2 +- iOS/Pod/Classes/Plugin/DoricShaderPlugin.m | 8 +++-- iOS/Pod/Classes/Shader/DoricViewNode.m | 2 +- js-framework/src/ui/panel.ts | 35 +++++++++++++------ js-framework/src/util/nativeModules.ts | 15 ++++++++ 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java b/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java index 10adc7e7..fb1954ce 100644 --- a/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java +++ b/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java @@ -56,6 +56,7 @@ public class ShaderPlugin extends DoricJavaPlugin { @Override public Object call() throws Exception { RootNode rootNode = getDoricContext().getRootNode(); + rootNode.setId(jsObject.getProperty("id").asString().value()); rootNode.render(jsObject.getProperty("props").asObject()); return null; } diff --git a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java index c62f2f0d..ee394eab 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -187,7 +187,7 @@ public abstract class ViewNode extends DoricContextHolder { do { ids.push(viewNode.mId); viewNode = viewNode.mSuperNode; - } while (viewNode != null && !(viewNode instanceof RootNode)); + } while (viewNode != null); return ids.toArray(new String[0]); } diff --git a/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m b/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m index a5039ef6..32949326 100644 --- a/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m +++ b/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m @@ -23,6 +23,7 @@ #import "DoricShaderPlugin.h" #import "DoricRootNode.h" #import "DoricUtil.h" +#import "Doric.h" #import @@ -31,13 +32,16 @@ @implementation DoricShaderPlugin - (void)render:(NSDictionary *)argument { - if(!argument) { + if (!argument) { return; } __weak typeof(self) _self = self; dispatch_async(dispatch_get_main_queue(), ^{ __strong typeof(_self) self = _self; - [self.doricContext.rootNode render:argument[@"props"]]; + [self.doricContext.rootNode also:^(DoricRootNode *it) { + it.viewId = argument[@"id"]; + [it render:argument[@"props"]]; + }]; }); } diff --git a/iOS/Pod/Classes/Shader/DoricViewNode.m b/iOS/Pod/Classes/Shader/DoricViewNode.m index a978736a..1b948504 100644 --- a/iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/iOS/Pod/Classes/Shader/DoricViewNode.m @@ -192,7 +192,7 @@ - (void)onClick:(UIView *)view { do { [ret addObject:node.viewId]; node = node.superNode; - } while (node && ![node isKindOfClass:[DoricRootNode class]]); + } while (node); return [[ret reverseObjectEnumerator] allObjects]; } diff --git a/js-framework/src/ui/panel.ts b/js-framework/src/ui/panel.ts index abc84bda..a1473451 100644 --- a/js-framework/src/ui/panel.ts +++ b/js-framework/src/ui/panel.ts @@ -42,6 +42,11 @@ export abstract class Panel { private __data__: any private __root__ = new Root + private headviews: Map = new Map + + addHeadView(v: View) { + this.headviews.set(v.viewId, v) + } getRootView() { return this.__root__ @@ -50,6 +55,9 @@ export abstract class Panel { getInitData() { return this.__data__ } + constructor() { + this.addHeadView(this.__root__) + } @NativeCall private __init__(frame: Frame, data: any) { @@ -90,21 +98,26 @@ export abstract class Panel { const v = this.retrospectView(viewIds) if (v === undefined) { loge(`Cannot find view for ${viewIds}`) + } else { + const argumentsList: any = [callbackId] + for (let i = 2; i < arguments.length; i++) { + argumentsList.push(arguments[i]) + } + return Reflect.apply(v.responseCallback, v, argumentsList) } - const argumentsList: any = [callbackId] - for (let i = 2; i < arguments.length; i++) { - argumentsList.push(arguments[i]) - } - return Reflect.apply(v.responseCallback, v, argumentsList) } - private retrospectView(ids: string[]): View { - return ids.reduce((acc: View, cur) => { - if (Reflect.has(acc, "subviewById")) { - return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur]) + private retrospectView(ids: string[]): View | undefined { + return ids.reduce((acc: View | undefined, cur) => { + if (acc === undefined) { + return this.headviews.get(cur) + } else { + if (Reflect.has(acc, "subviewById")) { + return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur]) + } + return acc } - return acc - }, this.__root__) + }, undefined) } private nativeRender(model: Model) { diff --git a/js-framework/src/util/nativeModules.ts b/js-framework/src/util/nativeModules.ts index 1dd8f850..8e9a5f6e 100644 --- a/js-framework/src/util/nativeModules.ts +++ b/js-framework/src/util/nativeModules.ts @@ -179,4 +179,19 @@ export function navigator(context: BridgeContext) { return context.navigator.pop({ animated }) }, } +} + +export function navbar(context: BridgeContext) { + return { + setHidden: (hidden: boolean) => { + return context.navbar.push({ + hidden, + }) + }, + setTitle: (title: string) => { + return context.navbar.push({ + title, + }) + }, + } } \ No newline at end of file