2020-04-16 19:21:24 +08:00
|
|
|
import { View, Property, Superview, NativeViewModel } from "../ui/view";
|
2019-12-04 14:15:05 +08:00
|
|
|
import { List } from "./list";
|
|
|
|
import { Scroller } from "./scroller";
|
|
|
|
import { BridgeContext } from "../runtime/global";
|
|
|
|
import { layoutConfig } from "../util/layoutconfig";
|
|
|
|
|
2020-04-16 19:21:24 +08:00
|
|
|
export class Refreshable extends Superview {
|
2019-12-04 14:15:05 +08:00
|
|
|
|
2020-04-16 19:21:24 +08:00
|
|
|
content!: View
|
2019-12-04 14:15:05 +08:00
|
|
|
|
|
|
|
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>
|
|
|
|
}
|
|
|
|
|
2020-01-03 16:35:04 +08:00
|
|
|
toModel(): NativeViewModel {
|
2019-12-04 14:15:05 +08:00
|
|
|
this.dirtyProps.content = this.content.viewId
|
2020-01-03 13:35:40 +08:00
|
|
|
this.dirtyProps.header = ((this.header || {}) as any).viewId
|
2019-12-04 14:15:05 +08:00
|
|
|
return super.toModel()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 19:21:24 +08:00
|
|
|
export function refreshable(config: Partial<Refreshable>) {
|
2019-12-04 14:15:05 +08:00
|
|
|
const ret = new Refreshable
|
2019-12-14 16:24:58 +08:00
|
|
|
ret.layoutConfig = layoutConfig().fit()
|
2019-12-04 14:15:05 +08:00
|
|
|
for (let key in config) {
|
|
|
|
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IPullable {
|
|
|
|
startAnimation(): void
|
|
|
|
stopAnimation(): void
|
|
|
|
setPullingDistance(distance: number): void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-04 18:14:22 +08:00
|
|
|
export function pullable(v: View, config: IPullable) {
|
2019-12-04 14:15:05 +08:00
|
|
|
Reflect.set(v, 'startAnimation', config.startAnimation)
|
|
|
|
Reflect.set(v, 'stopAnimation', config.stopAnimation)
|
|
|
|
Reflect.set(v, 'setPullingDistance', config.setPullingDistance)
|
|
|
|
return v
|
|
|
|
}
|