add flexscroller

This commit is contained in:
pengfei.zhou
2020-04-11 11:02:51 +08:00
committed by osborn
parent 6bcc6d014c
commit 4e537eed47
20 changed files with 685 additions and 24 deletions

View File

@@ -0,0 +1,56 @@
/*
* 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 { View, IView, Property, Group } from '../ui/view'
import { layoutConfig } from '../util/layoutconfig'
import { BridgeContext } from '../runtime/global'
export function flexScroller(views: View[], config?: IFlexScroller) {
const ret = new FlexScroller
ret.layoutConfig = layoutConfig().fit()
for (let v of views) {
ret.addChild(v)
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
}
return ret
}
export interface IFlexScroller extends IView {
contentOffset?: { x: number, y: number }
}
export class FlexScroller extends Group implements IFlexScroller {
@Property
contentOffset?: { x: number, y: number }
@Property
onScroll?: (offset: { x: number, y: number }) => void
@Property
onScrollEnd?: (offset: { x: number, y: number }) => void
scrollTo(context: BridgeContext, offset: { x: number, y: number }, animated?: boolean) {
return this.nativeChannel(context, "scrollTo")({ offset, animated })
}
scrollBy(context: BridgeContext, offset: { x: number, y: number }, animated?: boolean) {
return this.nativeChannel(context, "scrollBy")({ offset, animated })
}
}

View File

@@ -24,4 +24,5 @@ export * from './flowlayout'
export * from './input'
export * from './nestedSlider'
export * from './draggable'
export * from './switch'
export * from './switch'
export * from './flexScroller'

View File

@@ -98,7 +98,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?: IView) {
const ret = new FlexLayout
ret.layoutConfig = layoutConfig().fit()
for (let v of views) {