From af7f811d9bd8f4b52923a59e668e0e4efce82c41 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 18 Aug 2015 10:18:12 +0300 Subject: [PATCH] Image rounded coreners clip --- org.nativescript.widgets.d.ts | 5 ++++ ui/styling/stylers.android.ts | 53 +++++++++++++++++++++++++++++++++++ ui/styling/styling.d.ts | 15 ++++++++++ 3 files changed, 73 insertions(+) diff --git a/org.nativescript.widgets.d.ts b/org.nativescript.widgets.d.ts index 9a4e16637..fbd756c59 100644 --- a/org.nativescript.widgets.d.ts +++ b/org.nativescript.widgets.d.ts @@ -136,6 +136,11 @@ export class ImageView extends android.widget.ImageView { constructor(context: android.content.Context); + getCornerRadius(): number; + setCornerRadius(radius: number): void; + + getBorderWidth(): number; + setBorderWidth(width: number): void; } } } diff --git a/ui/styling/stylers.android.ts b/ui/styling/stylers.android.ts index 842e4ff19..cdd3d2176 100644 --- a/ui/styling/stylers.android.ts +++ b/ui/styling/stylers.android.ts @@ -270,6 +270,58 @@ export class DefaultStyler implements definition.stylers.Styler { } } +export class ImageStyler implements definition.stylers.Styler { + // Corner radius + private static setBorderRadiusProperty(view: view.View, newValue: any, defaultValue: any) { + if (!view._nativeView) { + return; + } + var val = newValue * utils.layout.getDisplayDensity(); + (view._nativeView).setCornerRadius(val); + onBackgroundOrBorderPropertyChanged(view); + } + + private static resetBorderRadiusProperty(view: view.View, nativeValue: any) { + if (!view._nativeView) { + return; + } + (view._nativeView).setCornerRadius(0); + onBackgroundOrBorderPropertyChanged(view); + } + + // Border width + private static setBorderWidthProperty(view: view.View, newValue: any, defaultValue: any) { + if (!view._nativeView) { + return; + } + + var val = newValue * utils.layout.getDisplayDensity(); + (view._nativeView).setBorderWidth(val); + onBackgroundOrBorderPropertyChanged(view); + } + + private static resetBorderWidthProperty(view: view.View, nativeValue: any) { + if (!view._nativeView) { + return; + } + (view._nativeView).setBorderWidth(0); + onBackgroundOrBorderPropertyChanged(view); + } + + public static registerHandlers() { + // Use the same handler for all background/border properties + // Note: There is no default value getter - the default value is handled in onBackgroundOrBorderPropertyChanged + + style.registerHandler(style.borderRadiusProperty, new stylersCommon.StylePropertyChangedHandler( + ImageStyler.setBorderRadiusProperty, + ImageStyler.resetBorderRadiusProperty), "Image"); + + style.registerHandler(style.borderWidthProperty, new stylersCommon.StylePropertyChangedHandler( + ImageStyler.setBorderWidthProperty, + ImageStyler.resetBorderWidthProperty), "Image"); + } +} + export class TextViewStyler implements definition.stylers.Styler { // color private static setColorProperty(view: view.View, newValue: any) { @@ -556,6 +608,7 @@ export class SearchBarStyler implements definition.stylers.Styler { export function _registerDefaultStylers() { style.registerNoStylingClass("Frame"); DefaultStyler.registerHandlers(); + ImageStyler.registerHandlers(); TextViewStyler.registerHandlers(); ActivityIndicatorStyler.registerHandlers(); SegmentedBarStyler.registerHandlers(); diff --git a/ui/styling/styling.d.ts b/ui/styling/styling.d.ts index 31509d357..ede2671a4 100644 --- a/ui/styling/styling.d.ts +++ b/ui/styling/styling.d.ts @@ -68,6 +68,21 @@ */ backgroundRepeat: string; + /** + * Gets or sets the border-color style property. + */ + borderColor: color.Color + + /** + * Gets or sets the border-width style property. + */ + borderWidth: number + + /** + * Gets or sets the border-radius style property. + */ + borderRadius: number; + /** * Gets or sets font-size style property. */