From f6ec51920257c7a1488e2f3b7ae7022c32a7540d Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 7 Dec 2019 15:51:00 +0800 Subject: [PATCH] feat:add nested slider for complex nested situation --- src/widget/flowlayout.ts | 9 +++------ src/widget/index.widget.ts | 3 ++- src/widget/nestedSlider.ts | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/widget/nestedSlider.ts diff --git a/src/widget/flowlayout.ts b/src/widget/flowlayout.ts index fe0655a5..5b8033d3 100644 --- a/src/widget/flowlayout.ts +++ b/src/widget/flowlayout.ts @@ -69,12 +69,9 @@ export class FlowLayout extends Superview implements IFlowLayout { this.itemCount = 0 } private getItem(itemIdx: number) { - let view = this.cachedViews.get(`${itemIdx}`) - if (view === undefined) { - view = this.renderItem(itemIdx) - view.superview = this - this.cachedViews.set(`${itemIdx}`, view) - } + let view = this.renderItem(itemIdx) + view.superview = this + this.cachedViews.set(`${itemIdx}`, view) return view } diff --git a/src/widget/index.widget.ts b/src/widget/index.widget.ts index 26428538..11f5bd97 100644 --- a/src/widget/index.widget.ts +++ b/src/widget/index.widget.ts @@ -21,4 +21,5 @@ export * from './slider' export * from './scroller' export * from './refreshable' export * from './flowlayout' -export * from './input' \ No newline at end of file +export * from './input' +export * from './nestedSlider' \ No newline at end of file diff --git a/src/widget/nestedSlider.ts b/src/widget/nestedSlider.ts new file mode 100644 index 00000000..dab3f755 --- /dev/null +++ b/src/widget/nestedSlider.ts @@ -0,0 +1,35 @@ +/* + * 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 { Group, View, Property } from '../ui/view' +import { BridgeContext } from '../runtime/global' + + +export class NestedSlider extends Group { + @Property + onPageSlided?: (index: number) => void + + addSlideItem(view: View) { + this.addChild(view) + } + + slidePage(context: BridgeContext, page: number, smooth = false) { + return this.nativeChannel(context, "slidePage")({ page, smooth }) + } + + getSlidedPage(context: BridgeContext) { + return this.nativeChannel(context, "getSlidedPage")() as Promise + } +} \ No newline at end of file