update js defination,use Partical insted of IView

This commit is contained in:
pengfei.zhou
2020-04-16 19:21:24 +08:00
committed by osborn
parent b2241fe343
commit 2598d0f266
57 changed files with 633 additions and 972 deletions

View File

@@ -14,19 +14,15 @@
* limitations under the License.
*/
import { Property, View } from "../ui/view"
import { IStack, Stack } from "../widget/layouts"
import { Stack } from "../widget/layouts"
import { layoutConfig } from "../util/layoutconfig"
export interface IDraggable extends IStack {
onDrag?: (x: number, y: number) => void
}
export class Draggable extends Stack implements IDraggable {
export class Draggable extends Stack {
@Property
onDrag?: (x: number, y: number) => void
}
export function draggable(views: View | View[], config?: IDraggable) {
export function draggable(views: View | View[], config?: Partial<Draggable>) {
const ret = new Draggable
ret.layoutConfig = layoutConfig().fit()
if (views instanceof View) {

View File

@@ -13,15 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Stack, IStack } from './layouts'
import { Property, IView, Superview, View, NativeViewModel } from '../ui/view'
import { Stack } from './layouts'
import { Property, Superview, View, NativeViewModel } from '../ui/view'
import { layoutConfig } from '../util/index.util'
export interface IFlowLayoutItem extends IStack {
identifier?: string
}
export class FlowLayoutItem extends Stack implements IFlowLayoutItem {
export class FlowLayoutItem extends Stack {
/**
* Set to reuse native view
*/
@@ -29,32 +25,7 @@ export class FlowLayoutItem extends Stack implements IFlowLayoutItem {
identifier?: string
}
export interface IFlowLayout extends IView {
renderItem: (index: number) => FlowLayoutItem
itemCount: number
batchCount?: number
columnCount?: number
columnSpace?: number
rowSpace?: number
loadMore?: boolean
onLoadMore?: () => void
loadMoreView?: FlowLayoutItem
onScroll?: (offset: { x: number, y: number }) => void
onScrollEnd?: (offset: { x: number, y: number }) => void
}
export class FlowLayout extends Superview implements IFlowLayout {
export class FlowLayout extends Superview {
private cachedViews: Map<string, FlowLayoutItem> = new Map
private ignoreDirtyCallOnce = false
@@ -135,7 +106,7 @@ export class FlowLayout extends Superview implements IFlowLayout {
}
}
export function flowlayout(config: IFlowLayout) {
export function flowlayout(config: Partial<FlowLayout>) {
const ret = new FlowLayout
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
@@ -143,7 +114,7 @@ export function flowlayout(config: IFlowLayout) {
return ret
}
export function flowItem(item: View | View[], config?: IFlowLayoutItem) {
export function flowItem(item: View | View[], config?: Partial<FlowLayoutItem>) {
return (new FlowLayoutItem).also((it) => {
it.layoutConfig = layoutConfig().fit()
if (item instanceof View) {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { IView, View, Property } from "../ui/view"
import { View, Property } from "../ui/view"
import { layoutConfig } from "../util/layoutconfig"
import { Color } from "../util/color"
@@ -23,13 +23,16 @@ export enum ScaleType {
ScaleAspectFill,
}
export interface IImage extends IView {
export class Image extends View {
@Property
imageUrl?: string
/**
* Read image from local path
* For android,it based on assets dir.
* For iOS,it based on main bundle dir.
*/
@Property
imagePath?: string
/**
@@ -37,67 +40,41 @@ export interface IImage extends IView {
* For android,it will try to read from drawable.
* For iOS,it will try to read from Image.Assets.
*/
@Property
imageRes?: string
@Property
imageBase64?: string
@Property
scaleType?: ScaleType
@Property
isBlur?: boolean
/**
* Display while image is loading
* Local file name
*/
@Property
placeHolderImage?: string
/**
* Display while image is loading
* Color
* This priority is lower than placeHolderImage
*/
@Property
placeHolderColor?: Color
/**
* Display while image is failed to load
* It can be file name in local path
*/
@Property
errorImage?: string
/**
* Display while image is failed to load
* Color
* This priority is lower than errorImage
*/
errorColor?: Color
loadCallback?: (image: { width: number; height: number } | undefined) => void
}
export class Image extends View implements IImage {
@Property
imageUrl?: string
@Property
imagePath?: string
@Property
imageRes?: string
@Property
imageBase64?: string
@Property
scaleType?: ScaleType
@Property
isBlur?: boolean
@Property
placeHolderImage?: string
@Property
placeHolderColor?: Color
@Property
errorImage?: string
@Property
errorColor?: Color
@@ -105,7 +82,7 @@ export class Image extends View implements IImage {
loadCallback?: (image: { width: number; height: number } | undefined) => void
}
export function image(config: IImage) {
export function image(config: Partial<Image>) {
const ret = new Image
ret.layoutConfig = layoutConfig().fit()
for (let key in config) {

View File

@@ -13,25 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { View, IView, Property } from "../ui/view";
import { View, Property } from "../ui/view";
import { Color } from "../util/color";
import { Gravity } from "../util/gravity";
import { BridgeContext } from "../runtime/global";
import { layoutConfig } from "../util/index.util";
export interface IInput extends IView {
text?: string
textColor?: Color
textSize?: number
hintText?: string
hintTextColor?: Color
multilines?: boolean
textAlignment?: Gravity
onTextChange?: (text: string) => void
onFocusChange?: (focused: boolean) => void
}
export class Input extends View implements IInput {
export class Input extends View {
@Property
text?: string
@@ -80,7 +68,7 @@ export class Input extends View implements IInput {
}
}
export function input(config: IInput) {
export function input(config: Partial<Input>) {
const ret = new Input
ret.layoutConfig = layoutConfig().just()
for (let key in config) {

View File

@@ -13,14 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Group, Property, IView, View } from "../ui/view";
import { Group, Property, View } from "../ui/view";
import { Gravity } from "../util/gravity";
import { layoutConfig } from "../util/layoutconfig";
export interface IStack extends IView {
}
export class Stack extends Group implements IStack {
export class Stack extends Group {
}
export class Root extends Stack {
@@ -34,24 +31,13 @@ class LinearLayout extends Group {
gravity?: Gravity
}
export interface IVLayout extends IView {
space?: number
gravity?: Gravity
export class VLayout extends LinearLayout {
}
export class VLayout extends LinearLayout implements IVLayout {
export class HLayout extends LinearLayout {
}
export interface IHLayout extends IView {
space?: number
gravity?: Gravity
}
export class HLayout extends LinearLayout implements IHLayout {
}
export function stack(views: View[], config?: IStack) {
export function stack(views: View[], config?: Partial<Stack>) {
const ret = new Stack
ret.layoutConfig = layoutConfig().fit()
for (let v of views) {
@@ -65,7 +51,7 @@ export function stack(views: View[], config?: IStack) {
return ret
}
export function hlayout(views: View[], config?: IHLayout) {
export function hlayout(views: View[], config?: Partial<HLayout>) {
const ret = new HLayout
ret.layoutConfig = layoutConfig().fit()
for (let v of views) {
@@ -79,7 +65,7 @@ export function hlayout(views: View[], config?: IHLayout) {
return ret
}
export function vlayout(views: View[], config?: IVLayout) {
export function vlayout(views: View[], config?: Partial<VLayout>) {
const ret = new VLayout
ret.layoutConfig = layoutConfig().fit()
for (let v of views) {
@@ -98,7 +84,7 @@ export function vlayout(views: View[], config?: IVLayout) {
export class FlexLayout extends Group {
}
export function flexlayout(views: View[], config?: IView) {
export function flexlayout(views: View[], config?: Partial<FlexLayout>) {
const ret = new FlexLayout
ret.layoutConfig = layoutConfig().fit()
for (let v of views) {

View File

@@ -14,15 +14,12 @@
* limitations under the License.
*/
import { View, Property, Superview, IView, NativeViewModel } from "../ui/view";
import { Stack, IStack } from "./layouts";
import { layoutConfig, LayoutSpec } from "../util/layoutconfig";
import { View, Property, Superview, NativeViewModel } from "../ui/view";
import { Stack } from "./layouts";
import { layoutConfig } from "../util/layoutconfig";
export interface IListItem extends IStack {
identifier?: string
}
export class ListItem extends Stack implements IListItem {
export class ListItem extends Stack {
/**
* Set to reuse native view
*/
@@ -30,25 +27,7 @@ export class ListItem extends Stack implements IListItem {
identifier?: string
}
export interface IList extends IView {
renderItem: (index: number) => ListItem
itemCount: number
batchCount?: number
onLoadMore?: () => void
loadMore?: boolean
loadMoreView?: ListItem
onScroll?: (offset: { x: number, y: number }) => void
onScrollEnd?: (offset: { x: number, y: number }) => void
}
export class List extends Superview implements IList {
export class List extends Superview {
private cachedViews: Map<string, ListItem> = new Map
private ignoreDirtyCallOnce = false
@@ -120,7 +99,7 @@ export class List extends Superview implements IList {
}
}
export function list(config: IList) {
export function list(config: Partial<List>) {
const ret = new List
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
@@ -128,7 +107,7 @@ export function list(config: IList) {
return ret
}
export function listItem(item: View | View[], config?: IListItem) {
export function listItem(item: View | View[], config?: Partial<ListItem>) {
return (new ListItem).also((it) => {
it.layoutConfig = layoutConfig().fit()
if (item instanceof View) {

View File

@@ -1,18 +1,12 @@
import { View, Property, Superview, IView, NativeViewModel } from "../ui/view";
import { View, Property, Superview, NativeViewModel } from "../ui/view";
import { List } from "./list";
import { Scroller } from "./scroller";
import { BridgeContext } from "../runtime/global";
import { layoutConfig } from "../util/layoutconfig";
export interface IRefreshable extends IView {
content: View
header?: View
onRefresh?: () => void
}
export class Refreshable extends Superview {
export class Refreshable extends Superview implements IRefreshable {
content!: List | Scroller
content!: View
header?: View
@@ -50,7 +44,7 @@ export class Refreshable extends Superview implements IRefreshable {
}
}
export function refreshable(config: IRefreshable) {
export function refreshable(config: Partial<Refreshable>) {
const ret = new Refreshable
ret.layoutConfig = layoutConfig().fit()
for (let key in config) {

View File

@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Superview, View, IView, NativeViewModel, Property } from '../ui/view'
import { Superview, View, NativeViewModel, Property } from '../ui/view'
import { layoutConfig } from '../util/layoutconfig'
import { BridgeContext } from '../runtime/global'
export function scroller(content: View, config?: IScroller) {
export function scroller(content: View, config?: Partial<Scroller>) {
return (new Scroller).also(v => {
v.layoutConfig = layoutConfig().fit()
if (config) {
@@ -29,12 +29,8 @@ export function scroller(content: View, config?: IScroller) {
})
}
export interface IScroller extends IView {
content?: View
contentOffset?: { x: number, y: number }
}
export class Scroller extends Superview implements IScroller {
export class Scroller extends Superview {
content!: View
@Property

View File

@@ -13,17 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Superview, View, Property, IView } from "../ui/view";
import { Stack, IStack } from "./layouts";
import { Superview, View, Property } from "../ui/view";
import { Stack } from "./layouts";
import { layoutConfig } from "../util/layoutconfig";
import { BridgeContext } from "../runtime/global";
export interface ISlideItem extends IStack {
identifier?: string
}
export class SlideItem extends Stack implements ISlideItem {
export class SlideItem extends Stack {
/**
* Set to reuse native view
*/
@@ -31,15 +28,7 @@ export class SlideItem extends Stack implements ISlideItem {
identifier?: string
}
export interface ISlider extends IView {
renderPage: (index: number) => SlideItem
itemCount: number
batchCount?: number
onPageSlided?: (index: number) => void
loop?: boolean
}
export class Slider extends Superview implements ISlider {
export class Slider extends Superview {
private cachedViews: Map<string, SlideItem> = new Map
private ignoreDirtyCallOnce = false
@@ -96,7 +85,7 @@ export class Slider extends Superview implements ISlider {
}
export function slider(config: ISlider) {
export function slider(config: Partial<Slider>) {
const ret = new Slider
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
@@ -104,7 +93,7 @@ export function slider(config: ISlider) {
return ret
}
export function slideItem(item: View | View[], config?: ISlideItem) {
export function slideItem(item: View | View[], config?: Partial<SlideItem>) {
return (new SlideItem).also((it) => {
it.layoutConfig = layoutConfig().most()
if (item instanceof View) {

View File

@@ -13,35 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { View, Property, IView } from "../ui/view";
import { View, Property } from "../ui/view";
import { Color } from "../util/color";
import { layoutConfig } from "../util/index.util";
export interface ISwitch extends IView {
/**
* True is on ,false is off,defalut is off.
*/
state?: boolean
/**
* Switch change callback
*/
onSwitch?: (state: boolean) => void
onTintColor?: Color
offTintColor?: Color
thumbTintColor?: Color
}
export class Switch extends View {
/**
* True is on ,false is off,defalut is off.
*/
@Property
state?: boolean
/**
* Switch change callback
*/
@Property
onSwitch?: (state: boolean) => void
@@ -55,7 +39,7 @@ export class Switch extends View {
thumbTintColor?: Color
}
export function switchView(config: ISwitch) {
export function switchView(config: Partial<Switch>) {
const ret = new Switch
ret.layoutConfig = layoutConfig().just()
ret.width = 50

View File

@@ -13,28 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { IView, View, Property } from "../ui/view"
import { View, Property } from "../ui/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
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"
font?: string
maxWidth?: number
maxHeight?: number
lineSpacing?: number
strikethrough?: boolean
underline?: boolean
htmlText?: string
}
export class Text extends View implements IText {
export class Text extends View {
@Property
text?: string
@@ -75,7 +59,7 @@ export class Text extends View implements IText {
htmlText?: string
}
export function text(config: IText) {
export function text(config: Partial<Text>) {
const ret = new Text
ret.layoutConfig = layoutConfig().fit()
for (let key in config) {