add navbar custom left & right view api

This commit is contained in:
王劲鹏 2020-01-10 15:55:47 +08:00 committed by osborn
parent 54b79e7f1e
commit 848b7005b7
9 changed files with 150 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -752,7 +752,12 @@ class Panel {
if (cur === this.__root__.viewId) { if (cur === this.__root__.viewId) {
return this.__root__; return this.__root__;
} }
return this.headviews.get(cur); for (let map of this.headviews.values()) {
if (map.has(cur)) {
return map.get(cur);
}
}
return undefined;
} }
else { else {
if (Reflect.has(acc, "subviewById")) { if (Reflect.has(acc, "subviewById")) {
@ -1837,6 +1842,10 @@ function modal(context) {
function navbar(context) { function navbar(context) {
const entity = context.entity; const entity = context.entity;
let panel = undefined;
if (entity instanceof Panel) {
panel = entity;
}
return { return {
isHidden: () => { isHidden: () => {
return context.navbar.isHidden(); return context.navbar.isHidden();
@ -1856,6 +1865,20 @@ function navbar(context) {
color: color.toModel(), color: color.toModel(),
}); });
}, },
setLeft: (view) => {
if (panel) {
panel.clearHeadViews("navbar_left");
panel.addHeadView("navbar_left", view);
}
return context.navbar.setLeft(view.toModel());
},
setRight: (view) => {
if (panel) {
panel.clearHeadViews("navbar_right");
panel.addHeadView("navbar_right", view);
}
return context.navbar.setRight(view.toModel());
}
}; };
} }

View File

@ -2211,7 +2211,12 @@ class Panel {
if (cur === this.__root__.viewId) { if (cur === this.__root__.viewId) {
return this.__root__; return this.__root__;
} }
return this.headviews.get(cur); for (let map of this.headviews.values()) {
if (map.has(cur)) {
return map.get(cur);
}
}
return undefined;
} }
else { else {
if (Reflect.has(acc, "subviewById")) { if (Reflect.has(acc, "subviewById")) {
@ -3296,6 +3301,10 @@ function modal(context) {
function navbar(context) { function navbar(context) {
const entity = context.entity; const entity = context.entity;
let panel = undefined;
if (entity instanceof Panel) {
panel = entity;
}
return { return {
isHidden: () => { isHidden: () => {
return context.navbar.isHidden(); return context.navbar.isHidden();
@ -3315,6 +3324,20 @@ function navbar(context) {
color: color.toModel(), color: color.toModel(),
}); });
}, },
setLeft: (view) => {
if (panel) {
panel.clearHeadViews("navbar_left");
panel.addHeadView("navbar_left", view);
}
return context.navbar.setLeft(view.toModel());
},
setRight: (view) => {
if (panel) {
panel.clearHeadViews("navbar_right");
panel.addHeadView("navbar_right", view);
}
return context.navbar.setRight(view.toModel());
}
}; };
} }

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

@ -713,11 +713,14 @@ declare module 'doric/lib/src/native/modal' {
declare module 'doric/lib/src/native/navbar' { declare module 'doric/lib/src/native/navbar' {
import { BridgeContext } from "doric/lib/src/runtime/global"; import { BridgeContext } from "doric/lib/src/runtime/global";
import { Color } from "doric/lib/src/util/color"; import { Color } from "doric/lib/src/util/color";
import { View } from "doric/lib/src/ui/view";
export function navbar(context: BridgeContext): { export function navbar(context: BridgeContext): {
isHidden: () => Promise<boolean>; isHidden: () => Promise<boolean>;
setHidden: (hidden: boolean) => Promise<any>; setHidden: (hidden: boolean) => Promise<any>;
setTitle: (title: string) => Promise<any>; setTitle: (title: string) => Promise<any>;
setBgColor: (color: Color) => Promise<any>; setBgColor: (color: Color) => Promise<any>;
setLeft: (view: View) => Promise<any>;
setRight: (view: View) => Promise<any>;
}; };
} }

View File

@ -1,8 +1,11 @@
import { BridgeContext } from "../runtime/global"; import { BridgeContext } from "../runtime/global";
import { Color } from "../util/color"; import { Color } from "../util/color";
import { View } from "../ui/view";
export declare function navbar(context: BridgeContext): { export declare function navbar(context: BridgeContext): {
isHidden: () => Promise<boolean>; isHidden: () => Promise<boolean>;
setHidden: (hidden: boolean) => Promise<any>; setHidden: (hidden: boolean) => Promise<any>;
setTitle: (title: string) => Promise<any>; setTitle: (title: string) => Promise<any>;
setBgColor: (color: Color) => Promise<any>; setBgColor: (color: Color) => Promise<any>;
setLeft: (view: View) => Promise<any>;
setRight: (view: View) => Promise<any>;
}; };

View File

@ -24,5 +24,19 @@ export function navbar(context) {
color: color.toModel(), color: color.toModel(),
}); });
}, },
setLeft: (view) => {
if (panel) {
panel.clearHeadViews("navbar_left");
panel.addHeadView("navbar_left", view);
}
return context.navbar.setLeft(view.toModel());
},
setRight: (view) => {
if (panel) {
panel.clearHeadViews("navbar_right");
panel.addHeadView("navbar_right", view);
}
return context.navbar.setRight(view.toModel());
}
}; };
} }

View File

@ -123,7 +123,12 @@ export class Panel {
if (cur === this.__root__.viewId) { if (cur === this.__root__.viewId) {
return this.__root__; return this.__root__;
} }
return this.headviews.get(cur); for (let map of this.headviews.values()) {
if (map.has(cur)) {
return map.get(cur);
}
}
return undefined;
} }
else { else {
if (Reflect.has(acc, "subviewById")) { if (Reflect.has(acc, "subviewById")) {

View File

@ -16,6 +16,7 @@
import { BridgeContext } from "../runtime/global" import { BridgeContext } from "../runtime/global"
import { Panel } from "../ui/panel" import { Panel } from "../ui/panel"
import { Color } from "../util/color" import { Color } from "../util/color"
import { View } from "../ui/view"
export function navbar(context: BridgeContext) { export function navbar(context: BridgeContext) {
const entity = context.entity const entity = context.entity
@ -43,5 +44,19 @@ export function navbar(context: BridgeContext) {
color: color.toModel(), color: color.toModel(),
}) })
}, },
setLeft: (view: View) => {
if (panel) {
panel.clearHeadViews("navbar_left")
panel.addHeadView("navbar_left", view)
}
return context.navbar.setLeft(view.toModel())
},
setRight: (view: View) => {
if (panel) {
panel.clearHeadViews("navbar_right")
panel.addHeadView("navbar_right", view)
}
return context.navbar.setRight(view.toModel())
}
} }
} }

View File

@ -141,7 +141,12 @@ export abstract class Panel {
if (cur === this.__root__.viewId) { if (cur === this.__root__.viewId) {
return this.__root__ return this.__root__
} }
return this.headviews.get(cur) for (let map of this.headviews.values()) {
if (map.has(cur)) {
return map.get(cur)
}
}
return undefined
} else { } else {
if (Reflect.has(acc, "subviewById")) { if (Reflect.has(acc, "subviewById")) {
return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur]) return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur])