Merge pull request #1229 from NativeScript/issue-1223

Resolved Issue #1223: Android views which have complex backgrounds (i…
This commit is contained in:
Rossen Hristov
2015-12-10 15:32:59 +02:00
11 changed files with 169 additions and 10 deletions

View File

@@ -159,11 +159,18 @@ export class Animation extends common.Animation implements definition.Animation
case common.Properties.opacity:
originalValue1 = nativeView.getAlpha();
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
nativeArray[0] = propertyAnimation.value;
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.opacity = propertyAnimation.value }));
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setAlpha(originalValue1); }));
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "alpha", nativeArray));
nativeArray = java.lang.reflect.Array.newInstance(floatType, 2);
nativeArray[0] = originalValue1;
nativeArray[1] = propertyAnimation.value;
animator = android.animation.ValueAnimator.ofFloat(nativeArray);
animator.addUpdateListener(new android.animation.ValueAnimator.AnimatorUpdateListener({
onAnimationUpdate(animator: android.animation.ValueAnimator) {
propertyAnimation.target.opacity = (<java.lang.Float>animator.getAnimatedValue()).floatValue();
}
}));
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.opacity = propertyAnimation.value; }));
propertyResetCallbacks.push(checkAnimation(() => { propertyAnimation.target.opacity = originalValue1; }));
animators.push(animator);
break;
case common.Properties.backgroundColor:

View File

@@ -341,6 +341,25 @@ export class ImageStyler implements definition.stylers.Styler {
onBackgroundOrBorderPropertyChanged(view);
}
//Opacity methods
private static setOpacityProperty(view: view.View, newValue: any) {
ImageStyler._setOpacity(view, newValue);
}
private static resetOpacityProperty(view: view.View, nativeValue: any) {
ImageStyler._setOpacity(view, 1.0);
}
private static _setOpacity(view: view.View, value: any) {
let opacity = float(value);
let nativeView = <android.view.View>view._nativeView;
nativeView.setAlpha(opacity);
let background = nativeView.getBackground();
if (background) {
background.setAlpha(opacity);
}
}
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
@@ -352,6 +371,10 @@ export class ImageStyler implements definition.stylers.Styler {
style.registerHandler(style.borderWidthProperty, new stylersCommon.StylePropertyChangedHandler(
ImageStyler.setBorderWidthProperty,
ImageStyler.resetBorderWidthProperty), "Image");
style.registerHandler(style.opacityProperty, new stylersCommon.StylePropertyChangedHandler(
ImageStyler.setOpacityProperty,
ImageStyler.resetOpacityProperty), "Image");
}
}