add status bar js api

This commit is contained in:
王劲鹏 2020-01-14 10:59:42 +08:00 committed by osborn
parent e6db23d77c
commit c63454869c
10 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,83 @@
import { Group, Panel, gravity, Color, LayoutSpec, vlayout, scroller, layoutConfig, IVLayout, IText, statusbar, StatusBarMode } from "doric";
import { title, label, colors } from "./utils";
@Entry
class StatusBarDemo extends Panel {
build(rootView: Group): void {
scroller(vlayout([
title("StatusBar Demo"),
label('show').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
statusbar(context).setHidden(false)
}
} as IText),
label('hide').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
statusbar(context).setHidden(true)
}
} as IText),
label('light').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just().configMargin({top: 30}),
onClick: () => {
statusbar(context).setMode(StatusBarMode.LIGHT)
}
} as IText),
label('dark').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
statusbar(context).setMode(StatusBarMode.DARK)
}
} as IText),
label('white').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just().configMargin({top: 30}),
onClick: () => {
statusbar(context).setColor(Color.parse("#ffffff"))
}
} as IText),
label('black').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just(),
onClick: () => {
statusbar(context).setColor(Color.parse("#000000"))
}
} as IText),
]).apply({
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
gravity: gravity().center(),
space: 10,
} as IVLayout)).apply({
layoutConfig: layoutConfig().most(),
}).in(rootView)
}
}

View File

@ -2146,6 +2146,24 @@ function notification(context) {
};
}
(function (StatusBarMode) {
StatusBarMode[StatusBarMode["LIGHT"] = 0] = "LIGHT";
StatusBarMode[StatusBarMode["DARK"] = 1] = "DARK";
})(exports.StatusBarMode || (exports.StatusBarMode = {}));
function statusbar(context) {
return {
setHidden: (hidden) => {
return context.statusbar.setHidden({ hidden });
},
setMode: (mode) => {
return context.statusbar.setMode({ mode });
},
setColor: (color) => {
return context.statusbar.setColor({ color: color.toModel() });
},
};
}
class Observable {
constructor(provider, clz) {
this.observers = new Set;
@ -2299,6 +2317,7 @@ exports.scroller = scroller;
exports.slideItem = slideItem;
exports.slider = slider;
exports.stack = stack;
exports.statusbar = statusbar;
exports.storage = storage;
exports.take = take;
exports.takeAlso = takeAlso;

View File

@ -3605,6 +3605,24 @@ function notification(context) {
};
}
(function (StatusBarMode) {
StatusBarMode[StatusBarMode["LIGHT"] = 0] = "LIGHT";
StatusBarMode[StatusBarMode["DARK"] = 1] = "DARK";
})(exports.StatusBarMode || (exports.StatusBarMode = {}));
function statusbar(context) {
return {
setHidden: (hidden) => {
return context.statusbar.setHidden({ hidden });
},
setMode: (mode) => {
return context.statusbar.setMode({ mode });
},
setColor: (color) => {
return context.statusbar.setColor({ color: color.toModel() });
},
};
}
class Observable {
constructor(provider, clz) {
this.observers = new Set;
@ -3864,6 +3882,7 @@ exports.scroller = scroller;
exports.slideItem = slideItem;
exports.slider = slider;
exports.stack = stack;
exports.statusbar = statusbar;
exports.storage = storage;
exports.take = take;
exports.takeAlso = takeAlso;

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

@ -66,6 +66,7 @@ declare module 'doric/lib/src/native/index.native' {
export * from 'doric/lib/src/native/popover';
export * from 'doric/lib/src/native/animate';
export * from 'doric/lib/src/native/notification';
export * from 'doric/lib/src/native/statusbar';
}
declare module 'doric/lib/src/util/index.util' {
@ -816,6 +817,20 @@ declare module 'doric/lib/src/native/notification' {
};
}
declare module 'doric/lib/src/native/statusbar' {
import { BridgeContext } from "doric/lib/src/runtime/global";
import { Color } from "doric/lib/src/util/color";
export enum StatusBarMode {
LIGHT = 0,
DARK = 1
}
export function statusbar(context: BridgeContext): {
setHidden: (hidden: boolean) => Promise<any>;
setMode: (mode: StatusBarMode) => Promise<any>;
setColor: (color: Color) => Promise<any>;
};
}
declare module 'doric/lib/src/util/color' {
import { Modeling } from "doric/lib/src/util/types";
/**

View File

@ -6,3 +6,4 @@ export * from './storage';
export * from './popover';
export * from './animate';
export * from './notification';
export * from './statusbar';

View File

@ -21,3 +21,4 @@ export * from './storage';
export * from './popover';
export * from './animate';
export * from './notification';
export * from './statusbar';

11
doric-js/lib/src/native/statusbar.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
import { BridgeContext } from "../runtime/global";
import { Color } from "../util/color";
export declare enum StatusBarMode {
LIGHT = 0,
DARK = 1
}
export declare function statusbar(context: BridgeContext): {
setHidden: (hidden: boolean) => Promise<any>;
setMode: (mode: StatusBarMode) => Promise<any>;
setColor: (color: Color) => Promise<any>;
};

View File

@ -0,0 +1,18 @@
export var StatusBarMode;
(function (StatusBarMode) {
StatusBarMode[StatusBarMode["LIGHT"] = 0] = "LIGHT";
StatusBarMode[StatusBarMode["DARK"] = 1] = "DARK";
})(StatusBarMode || (StatusBarMode = {}));
export function statusbar(context) {
return {
setHidden: (hidden) => {
return context.statusbar.setHidden({ hidden });
},
setMode: (mode) => {
return context.statusbar.setMode({ mode });
},
setColor: (color) => {
return context.statusbar.setColor({ color: color.toModel() });
},
};
}

View File

@ -21,3 +21,4 @@ export * from './storage'
export * from './popover'
export * from './animate'
export * from './notification'
export * from './statusbar'

View File

@ -0,0 +1,33 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BridgeContext } from "../runtime/global"
import { Color } from "../util/color"
export enum StatusBarMode { LIGHT, DARK }
export function statusbar(context: BridgeContext) {
return {
setHidden: (hidden: boolean) => {
return context.statusbar.setHidden({hidden})
},
setMode: (mode: StatusBarMode) => {
return context.statusbar.setMode({mode})
},
setColor: (color: Color) => {
return context.statusbar.setColor({color: color.toModel()})
},
}
}