feat:split views to widgets
This commit is contained in:
parent
84f12bd964
commit
0c5cdbc776
@ -13,20 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export * from "./src/ui/view"
|
||||
export * from "./src/ui/layout"
|
||||
export * from "./src/ui/list"
|
||||
export * from "./src/ui/slider"
|
||||
export * from "./src/ui/scroller"
|
||||
export * from "./src/ui/widgets"
|
||||
export * from "./src/ui/panel"
|
||||
export * from "./src/ui/declarative"
|
||||
export * from "./src/ui/refreshable"
|
||||
export * from './src/runtime/global'
|
||||
export * from './src/native/index.native'
|
||||
export * from "./src/widget/index.widget"
|
||||
export * from "./src/panel/panel"
|
||||
export * from "./src/util/color"
|
||||
export * from './src/util/log'
|
||||
export * from './src/util/types'
|
||||
export * from './src/util/gravity'
|
||||
export * from './src/util/candies'
|
||||
export * from './src/vm/mvvm'
|
||||
export * from './src/runtime/global'
|
||||
export * from './src/native/index.native'
|
||||
export * from './src/util/layoutconfig'
|
||||
export * from './src/panel/mvvm'
|
||||
|
@ -13,8 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Panel } from '../ui/panel'
|
||||
import { View } from '../ui/view'
|
||||
import { Panel } from '../panel/panel'
|
||||
import { View } from '../widget/view'
|
||||
|
||||
export interface Driver {
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
import { Panel } from "../ui/panel"
|
||||
import { Panel } from "../panel/panel"
|
||||
import { Color } from "../util/color"
|
||||
|
||||
export function navbar(context: BridgeContext) {
|
||||
|
@ -13,8 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Group } from "../ui/view";
|
||||
import { Panel } from "../ui/panel";
|
||||
import { Group } from "../widget/view";
|
||||
import { Panel } from "./panel";
|
||||
|
||||
export abstract class ViewHolder<M>{
|
||||
abstract build(root: Group): void
|
@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import './../runtime/global'
|
||||
import { View, Group } from "./view";
|
||||
import '../runtime/global'
|
||||
import { View, Group } from "../widget/view";
|
||||
import { loge, log } from '../util/log';
|
||||
import { Model } from '../util/types';
|
||||
import { Root } from './layout';
|
||||
import { Root } from '../widget/layouts';
|
||||
|
||||
|
||||
export function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor) {
|
@ -36,7 +36,7 @@ import "reflect-metadata"
|
||||
* Reflect.apply(function(__module){
|
||||
* (function(module,exports,require){
|
||||
* //module content
|
||||
* })(__module,__module.exports,hego.__require__);
|
||||
* })(__module,__module.exports,doric.__require__);
|
||||
* return __module.exports
|
||||
* },this,[{exports:{}}])
|
||||
* ])
|
||||
|
@ -13,73 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { View, LayoutSpec, LayoutConfig } from './view'
|
||||
import { Stack, HLayout, VLayout } from './layout'
|
||||
import { IText, IImage, Text, Image } from './widgets'
|
||||
import { IList, List } from './list'
|
||||
import { ISlider, Slider } from './slider'
|
||||
import { Gravity } from '../util/gravity'
|
||||
import { Modeling } from '../util/types'
|
||||
import { Gravity } from "./gravity";
|
||||
import { Modeling } from "./types";
|
||||
|
||||
export function text(config: IText) {
|
||||
const ret = new Text
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
}
|
||||
return ret
|
||||
export enum LayoutSpec {
|
||||
EXACTLY = 0,
|
||||
WRAP_CONTENT = 1,
|
||||
AT_MOST = 2,
|
||||
}
|
||||
|
||||
export function image(config: IImage) {
|
||||
const ret = new Image
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
export interface LayoutConfig {
|
||||
widthSpec?: LayoutSpec
|
||||
heightSpec?: LayoutSpec
|
||||
margin?: {
|
||||
left?: number,
|
||||
right?: number,
|
||||
top?: number,
|
||||
bottom?: number,
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function stack(views: View[]) {
|
||||
const ret = new Stack
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let v of views) {
|
||||
ret.addChild(v)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function hlayout(views: View[]) {
|
||||
const ret = new HLayout
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let v of views) {
|
||||
ret.addChild(v)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function vlayout(views: View[]) {
|
||||
const ret = new VLayout
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let v of views) {
|
||||
ret.addChild(v)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function list(config: IList) {
|
||||
const ret = new List
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function slider(config: ISlider) {
|
||||
const ret = new Slider
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
}
|
||||
return ret
|
||||
alignment?: Gravity
|
||||
//Only affective in VLayout or HLayout
|
||||
weight?: number
|
||||
}
|
||||
|
||||
export class LayoutConfigImpl implements LayoutConfig, Modeling {
|
||||
@ -156,4 +110,4 @@ export class LayoutConfigImpl implements LayoutConfig, Modeling {
|
||||
|
||||
export function layoutConfig() {
|
||||
return new LayoutConfigImpl
|
||||
}
|
||||
}
|
@ -14,33 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IView, View, Property } from "./view"
|
||||
import { Color } from "../util/color"
|
||||
import { Gravity } from "../util/gravity"
|
||||
|
||||
export interface IText extends IView {
|
||||
text?: string
|
||||
textColor?: Color
|
||||
textSize?: number
|
||||
maxLines?: number
|
||||
textAlignment?: Gravity
|
||||
}
|
||||
|
||||
export class Text extends View implements IText {
|
||||
@Property
|
||||
text?: string
|
||||
|
||||
@Property
|
||||
textColor?: Color
|
||||
|
||||
@Property
|
||||
textSize?: number
|
||||
|
||||
@Property
|
||||
maxLines?: number
|
||||
|
||||
@Property
|
||||
textAlignment?: Gravity
|
||||
}
|
||||
import { layoutConfig } from "../util/layoutconfig"
|
||||
|
||||
export enum ScaleType {
|
||||
ScaleToFill = 0,
|
||||
@ -65,4 +39,13 @@ export class Image extends View implements IImage {
|
||||
|
||||
@Property
|
||||
loadCallback?: (image: { width: number; height: number } | undefined) => void
|
||||
}
|
||||
|
||||
export function image(config: IImage) {
|
||||
const ret = new Image
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
}
|
||||
return ret
|
||||
}
|
23
js-framework/src/widget/index.widget.ts
Normal file
23
js-framework/src/widget/index.widget.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
export * from './view'
|
||||
export * from './layouts'
|
||||
export * from './text'
|
||||
export * from './image'
|
||||
export * from './list'
|
||||
export * from './slider'
|
||||
export * from './scroller'
|
||||
export * from './refreshable'
|
@ -13,8 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Group, Property, IView } from "./view";
|
||||
import { Group, Property, IView, View } from "./view";
|
||||
import { Gravity } from "../util/gravity";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
export interface IStack extends IView {
|
||||
}
|
||||
@ -49,3 +50,30 @@ export interface IHLayout extends IView {
|
||||
|
||||
export class HLayout extends LinearLayout implements IHLayout {
|
||||
}
|
||||
|
||||
export function stack(views: View[]) {
|
||||
const ret = new Stack
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let v of views) {
|
||||
ret.addChild(v)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function hlayout(views: View[]) {
|
||||
const ret = new HLayout
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let v of views) {
|
||||
ret.addChild(v)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function vlayout(views: View[]) {
|
||||
const ret = new VLayout
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let v of views) {
|
||||
ret.addChild(v)
|
||||
}
|
||||
return ret
|
||||
}
|
@ -14,18 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { View, Property, LayoutSpec, Superview, IView } from "./view";
|
||||
import { Stack } from "./layout";
|
||||
|
||||
export function listItem(item: View) {
|
||||
return (new ListItem).also((it) => {
|
||||
it.layoutConfig = {
|
||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
}
|
||||
it.addChild(item)
|
||||
})
|
||||
}
|
||||
import { View, Property, Superview, IView } from "./view";
|
||||
import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
export class ListItem extends Stack {
|
||||
/**
|
||||
@ -87,4 +78,19 @@ export class List extends Superview implements IList {
|
||||
return listItem.toModel()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function list(config: IList) {
|
||||
const ret = new List
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function listItem(item: View) {
|
||||
return (new ListItem).also((it) => {
|
||||
it.layoutConfig = layoutConfig().wrap()
|
||||
it.addChild(item)
|
||||
})
|
||||
}
|
@ -2,7 +2,7 @@ import { View, Property, Superview, IView } from "./view";
|
||||
import { List } from "./list";
|
||||
import { Scroller } from "./scroller";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { layoutConfig } from "./declarative";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
export interface IRefreshable extends IView {
|
||||
content: View
|
@ -13,14 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Superview, View, Property, IView, LayoutSpec } from './view'
|
||||
import { Superview, View, IView } from './view'
|
||||
import { layoutConfig } from '../util/layoutconfig'
|
||||
|
||||
export function scroller(content: View) {
|
||||
return (new Scroller).also(v => {
|
||||
v.layoutConfig = {
|
||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
}
|
||||
v.layoutConfig = layoutConfig().wrap()
|
||||
v.content = content
|
||||
})
|
||||
}
|
@ -1,15 +1,6 @@
|
||||
import { Superview, View, LayoutSpec, Property, IView } from "./view";
|
||||
import { Stack } from "./layout";
|
||||
|
||||
export function slideItem(item: View) {
|
||||
return (new SlideItem).also((it) => {
|
||||
it.layoutConfig = {
|
||||
widthSpec: LayoutSpec.AT_MOST,
|
||||
heightSpec: LayoutSpec.AT_MOST,
|
||||
}
|
||||
it.addChild(item)
|
||||
})
|
||||
}
|
||||
import { Superview, View, Property, IView } from "./view";
|
||||
import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
|
||||
export class SlideItem extends Stack {
|
||||
/**
|
||||
@ -69,4 +60,19 @@ export class Slider extends Superview implements ISlider {
|
||||
return slideItem.toModel()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function slideItem(item: View) {
|
||||
return (new SlideItem).also((it) => {
|
||||
it.layoutConfig = layoutConfig().wrap()
|
||||
it.addChild(item)
|
||||
})
|
||||
}
|
||||
|
||||
export function slider(config: ISlider) {
|
||||
const ret = new Slider
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
}
|
||||
return ret
|
||||
}
|
53
js-framework/src/widget/text.ts
Normal file
53
js-framework/src/widget/text.ts
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 { IView, View, Property } from "./view"
|
||||
import { Color } from "../util/color"
|
||||
import { Gravity } from "../util/gravity"
|
||||
import { layoutConfig } from "../util/layoutconfig"
|
||||
|
||||
export interface IText extends IView {
|
||||
text?: string
|
||||
textColor?: Color
|
||||
textSize?: number
|
||||
maxLines?: number
|
||||
textAlignment?: Gravity
|
||||
}
|
||||
|
||||
export class Text extends View implements IText {
|
||||
@Property
|
||||
text?: string
|
||||
|
||||
@Property
|
||||
textColor?: Color
|
||||
|
||||
@Property
|
||||
textSize?: number
|
||||
|
||||
@Property
|
||||
maxLines?: number
|
||||
|
||||
@Property
|
||||
textAlignment?: Gravity
|
||||
}
|
||||
|
||||
export function text(config: IText) {
|
||||
const ret = new Text
|
||||
ret.layoutConfig = layoutConfig().wrap()
|
||||
for (let key in config) {
|
||||
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
||||
}
|
||||
return ret
|
||||
}
|
@ -16,29 +16,9 @@
|
||||
import { Color, GradientColor } from "../util/color"
|
||||
import { Modeling, Model, obj2Model } from "../util/types";
|
||||
import { uniqueId } from "../util/uniqueId";
|
||||
import { Gravity } from "../util/gravity";
|
||||
import { loge } from "../util/log";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
|
||||
export enum LayoutSpec {
|
||||
EXACTLY = 0,
|
||||
WRAP_CONTENT = 1,
|
||||
AT_MOST = 2,
|
||||
}
|
||||
|
||||
export interface LayoutConfig {
|
||||
widthSpec?: LayoutSpec
|
||||
heightSpec?: LayoutSpec
|
||||
margin?: {
|
||||
left?: number,
|
||||
right?: number,
|
||||
top?: number,
|
||||
bottom?: number,
|
||||
}
|
||||
alignment?: Gravity
|
||||
//Only affective in VLayout or HLayout
|
||||
weight?: number
|
||||
}
|
||||
import { LayoutConfig } from '../util/layoutconfig'
|
||||
|
||||
export function Property(target: Object, propKey: string) {
|
||||
Reflect.defineMetadata(propKey, true, target)
|
Reference in New Issue
Block a user