feat:add RefreshableDemo for Android

This commit is contained in:
pengfei.zhou
2019-11-26 10:31:17 +08:00
parent c766e57c83
commit 362ec833c9
9 changed files with 318 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ 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/util/color"
export * from './src/util/log'
export * from './src/util/types'

View File

@@ -0,0 +1,60 @@
import { View, Property, Superview, IView } from "./view";
import { List } from "./list";
import { Scroller } from "./scroller";
import { BridgeContext } from "../runtime/global";
import { layoutConfig } from "./declarative";
export interface IRefreshable extends IView {
content: List | Scroller
header?: View
onRefresh?: () => void
}
export class Refreshable extends Superview implements IRefreshable {
content!: List | Scroller
header?: View
@Property
onRefresh?: () => void
allSubviews() {
const ret: View[] = [this.content]
if (this.header) {
ret.push(this.header)
}
return ret
}
setRefreshable(context: BridgeContext, refreshable: boolean) {
return this.nativeChannel(context, 'setRefreshable')(refreshable)
}
setRefreshing(context: BridgeContext, refreshing: boolean) {
return this.nativeChannel(context, 'setRefreshing')(refreshing)
}
isRefreshable(context: BridgeContext) {
return this.nativeChannel(context, 'isRefreshable')() as Promise<boolean>
}
isRefreshing(context: BridgeContext) {
return this.nativeChannel(context, 'isRefreshing')() as Promise<boolean>
}
toModel() {
this.dirtyProps.content = this.content.viewId
this.dirtyProps.header = (this.header || {}).viewId
return super.toModel()
}
}
export function refreshable(config: IRefreshable) {
const ret = new Refreshable
ret.layoutConfig = layoutConfig().wrap()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
}

View File

@@ -266,7 +266,7 @@ export abstract class View implements Modeling, IView {
nativeChannel(context: any, name: string) {
let thisView: View | undefined = this
return function (...args: any) {
return function (args: any = undefined) {
const func = context.shader.command
const viewIds = []
while (thisView != undefined) {