diff --git a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java index 135124bb..553b0291 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java @@ -51,8 +51,8 @@ public class SliderNode extends SuperNode { private String renderPageFuncId; private boolean scrollable = true; private String slideStyle = null; - private static final float MIN_SCALE = 0.5f; - private static final float MAX_SCALE = 1; + private float minScale = 0.618f; + private float maxScale = 1; public SliderNode(DoricContext doricContext) { super(doricContext); @@ -133,9 +133,10 @@ public class SliderNode extends SuperNode { if (child.getWidth() == 0) { return; } - float centerX = (child.getLeft() + child.getRight()) / 2.f; - float percent = 1 - Math.abs(recyclerView.getWidth() / 2f - centerX) / recyclerView.getWidth() / 2f; - float scaleFactor = MIN_SCALE + Math.abs(percent) * (MAX_SCALE - MIN_SCALE); + float centerX = recyclerView.getWidth() / 2.f; + float vCenterX = (child.getLeft() + child.getRight()) / 2.f; + float percent = 1 - Math.abs(centerX - vCenterX) / centerX; + float scaleFactor = minScale + Math.abs(percent) * (maxScale - minScale); child.setLayoutParams(lp); child.setScaleY(scaleFactor); child.setScaleX(scaleFactor); @@ -246,6 +247,10 @@ public class SliderNode extends SuperNode { case "slideStyle": if (prop.isString()) { this.slideStyle = prop.asString().value(); + } else if (prop.isObject()) { + this.slideStyle = prop.asObject().getProperty("type").asString().value(); + this.maxScale = prop.asObject().getProperty("maxScale").asNumber().toFloat(); + this.minScale = prop.asObject().getProperty("minScale").asNumber().toFloat(); } break; default: diff --git a/doric-js/bundle/doric-lib.es5.js b/doric-js/bundle/doric-lib.es5.js index f17006f5..8e512eeb 100644 --- a/doric-js/bundle/doric-lib.es5.js +++ b/doric-js/bundle/doric-lib.es5.js @@ -2727,7 +2727,7 @@ var Slider = /** @class */ (function (_super) { ], Slider.prototype, "bounces", void 0); __decorate$9([ Property, - __metadata$9("design:type", String) + __metadata$9("design:type", Object) ], Slider.prototype, "slideStyle", void 0); return Slider; }(Superview)); diff --git a/doric-js/bundle/doric-lib.js b/doric-js/bundle/doric-lib.js index 2ef9f7b4..d0d10af8 100644 --- a/doric-js/bundle/doric-lib.js +++ b/doric-js/bundle/doric-lib.js @@ -2068,7 +2068,7 @@ __decorate$9([ ], Slider.prototype, "bounces", void 0); __decorate$9([ Property, - __metadata$9("design:type", String) + __metadata$9("design:type", Object) ], Slider.prototype, "slideStyle", void 0); function slider(config) { const ret = new Slider; diff --git a/doric-js/bundle/doric-vm.js b/doric-js/bundle/doric-vm.js index 10ed9a09..b65d1cbb 100644 --- a/doric-js/bundle/doric-vm.js +++ b/doric-js/bundle/doric-vm.js @@ -3596,7 +3596,7 @@ __decorate$9([ ], Slider.prototype, "bounces", void 0); __decorate$9([ Property, - __metadata$9("design:type", String) + __metadata$9("design:type", Object) ], Slider.prototype, "slideStyle", void 0); function slider(config) { const ret = new Slider; diff --git a/doric-js/index.d.ts b/doric-js/index.d.ts index e5bf3a5a..6a01c882 100644 --- a/doric-js/index.d.ts +++ b/doric-js/index.d.ts @@ -810,7 +810,15 @@ declare module 'doric/lib/src/widget/slider' { * Take effect only on iOS */ bounces?: boolean; - slideStyle?: "zoomOut"; + /** + * Set the effect when sliding + * ZoomOut is currently supported + */ + slideStyle?: "zoomOut" | { + type: "zoomOut"; + minScale: number; + maxScale: number; + }; slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise; getSlidedPage(context: BridgeContext): Promise; } diff --git a/doric-js/lib/src/widget/slider.d.ts b/doric-js/lib/src/widget/slider.d.ts index df8583ba..dcf8cdcd 100644 --- a/doric-js/lib/src/widget/slider.d.ts +++ b/doric-js/lib/src/widget/slider.d.ts @@ -20,7 +20,15 @@ export declare class Slider extends Superview { * Take effect only on iOS */ bounces?: boolean; - slideStyle?: "zoomOut"; + /** + * Set the effect when sliding + * ZoomOut is currently supported + */ + slideStyle?: "zoomOut" | { + type: "zoomOut"; + minScale: number; + maxScale: number; + }; private getItem; private renderBunchedItems; slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise; diff --git a/doric-js/lib/src/widget/slider.js b/doric-js/lib/src/widget/slider.js index be752d38..808721e5 100644 --- a/doric-js/lib/src/widget/slider.js +++ b/doric-js/lib/src/widget/slider.js @@ -90,7 +90,7 @@ __decorate([ ], Slider.prototype, "bounces", void 0); __decorate([ Property, - __metadata("design:type", String) + __metadata("design:type", Object) ], Slider.prototype, "slideStyle", void 0); export function slider(config) { const ret = new Slider; diff --git a/doric-js/src/widget/slider.ts b/doric-js/src/widget/slider.ts index 68dd77ec..605a07d5 100644 --- a/doric-js/src/widget/slider.ts +++ b/doric-js/src/widget/slider.ts @@ -56,9 +56,12 @@ export class Slider extends Superview { */ @Property bounces?: boolean - + /** + * Set the effect when sliding + * ZoomOut is currently supported + */ @Property - slideStyle?: "zoomOut" + slideStyle?: "zoomOut" | { type: "zoomOut", minScale: number, maxScale: number } private getItem(itemIdx: number) { let view = this.renderPage(itemIdx)