mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Resolved Issue #754: The backgroundColor of a Label is not animatable in iOS.
This commit is contained in:
@@ -7,60 +7,66 @@ global.moduleMerge(common, exports);
|
||||
export module ios {
|
||||
export function createBackgroundUIColor(view: viewModule.View): UIColor {
|
||||
if(!view._nativeView){
|
||||
return null;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var background = <common.Background> view.style._getValue(style.backgroundInternalProperty);
|
||||
|
||||
if (!background || background.isEmpty()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!background.image) {
|
||||
return background.color.ios;
|
||||
}
|
||||
|
||||
// We have an image for a background
|
||||
var frame = (<UIView>view._nativeView).frame;
|
||||
var boundsWidth = frame.size.width;
|
||||
var boundsHeight = frame.size.height;
|
||||
var result: UIColor;
|
||||
|
||||
if (background && !background.isEmpty() && boundsWidth > 0 && boundsHeight) {
|
||||
if (!background.image) {
|
||||
result = background.color.ios;
|
||||
}
|
||||
else {
|
||||
var img = <UIImage>background.image.ios;
|
||||
var params = background.getDrawParams(boundsWidth, boundsHeight);
|
||||
|
||||
if (params.sizeX > 0 && params.sizeY > 0) {
|
||||
var resizeRect = CGRectMake(0, 0, params.sizeX, params.sizeY);
|
||||
UIGraphicsBeginImageContext(resizeRect.size);
|
||||
img.drawInRect(resizeRect);
|
||||
img = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
}
|
||||
|
||||
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0.0);
|
||||
var context = UIGraphicsGetCurrentContext();
|
||||
|
||||
if (background.color && background.color.ios) {
|
||||
CGContextSetFillColorWithColor(context, background.color.ios.CGColor);
|
||||
CGContextFillRect(context, CGRectMake(0, 0, boundsWidth, boundsHeight));
|
||||
}
|
||||
|
||||
if (!params.repeatX && !params.repeatY) {
|
||||
img.drawAtPoint(CGPointMake(params.posX, params.posY));
|
||||
}
|
||||
else {
|
||||
var w = params.repeatX ? boundsWidth : img.size.width;
|
||||
var h = params.repeatY ? boundsHeight : img.size.height;
|
||||
|
||||
CGContextSetPatternPhase(context, CGSizeMake(params.posX, params.posY));
|
||||
|
||||
params.posX = params.repeatX ? 0 : params.posX;
|
||||
params.posY = params.repeatY ? 0 : params.posY;
|
||||
|
||||
var patternRect = CGRectMake(params.posX, params.posY, w, h);
|
||||
|
||||
img.drawAsPatternInRect(patternRect);
|
||||
}
|
||||
var bkgImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
result = UIColor.alloc().initWithPatternImage(bkgImage);
|
||||
}
|
||||
return result;
|
||||
if (!boundsWidth || !boundsHeight) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var img = <UIImage>background.image.ios;
|
||||
var params = background.getDrawParams(boundsWidth, boundsHeight);
|
||||
|
||||
if (params.sizeX > 0 && params.sizeY > 0) {
|
||||
var resizeRect = CGRectMake(0, 0, params.sizeX, params.sizeY);
|
||||
UIGraphicsBeginImageContext(resizeRect.size);
|
||||
img.drawInRect(resizeRect);
|
||||
img = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
}
|
||||
|
||||
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0.0);
|
||||
var context = UIGraphicsGetCurrentContext();
|
||||
|
||||
if (background.color && background.color.ios) {
|
||||
CGContextSetFillColorWithColor(context, background.color.ios.CGColor);
|
||||
CGContextFillRect(context, CGRectMake(0, 0, boundsWidth, boundsHeight));
|
||||
}
|
||||
|
||||
if (!params.repeatX && !params.repeatY) {
|
||||
img.drawAtPoint(CGPointMake(params.posX, params.posY));
|
||||
}
|
||||
else {
|
||||
var w = params.repeatX ? boundsWidth : img.size.width;
|
||||
var h = params.repeatY ? boundsHeight : img.size.height;
|
||||
|
||||
CGContextSetPatternPhase(context, CGSizeMake(params.posX, params.posY));
|
||||
|
||||
params.posX = params.repeatX ? 0 : params.posX;
|
||||
params.posY = params.repeatY ? 0 : params.posY;
|
||||
|
||||
var patternRect = CGRectMake(params.posX, params.posY, w, h);
|
||||
|
||||
img.drawAsPatternInRect(patternRect);
|
||||
}
|
||||
var bkgImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
return UIColor.alloc().initWithPatternImage(bkgImage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,6 +318,47 @@ export class ButtonStyler implements definition.stylers.Styler {
|
||||
}
|
||||
}
|
||||
|
||||
export class LabelStyler implements definition.stylers.Styler {
|
||||
//Background methods
|
||||
private static setBackgroundInternalProperty(view: view.View, newValue: any) {
|
||||
var uiLabel: UILabel = <UILabel>view._nativeView;
|
||||
if (uiLabel && uiLabel.layer) {
|
||||
var uiColor = <UIColor>background.ios.createBackgroundUIColor(view);
|
||||
var cgColor = uiColor ? uiColor.CGColor : null;
|
||||
uiLabel.layer.backgroundColor = cgColor;
|
||||
}
|
||||
}
|
||||
|
||||
private static resetBackgroundInternalProperty(view: view.View, nativeValue: any) {
|
||||
var uiLabel: UILabel = <UILabel>view._nativeView;
|
||||
if (uiLabel && uiLabel.layer) {
|
||||
var uiColor = <UIColor>nativeValue;
|
||||
var cgColor = uiColor ? uiColor.CGColor : null;
|
||||
uiLabel.layer.backgroundColor = cgColor;
|
||||
}
|
||||
}
|
||||
|
||||
private static getNativeBackgroundInternalValue(view: view.View): any {
|
||||
var uiLabel: UILabel = <UILabel>view._nativeView;
|
||||
if (uiLabel && uiLabel.layer) {
|
||||
var cgColor = uiLabel.layer.backgroundColor;
|
||||
if (cgColor) {
|
||||
return UIColor.colorWithCGColor(cgColor);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public static registerHandlers() {
|
||||
style.registerHandler(style.backgroundInternalProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||
LabelStyler.setBackgroundInternalProperty,
|
||||
LabelStyler.resetBackgroundInternalProperty,
|
||||
LabelStyler.getNativeBackgroundInternalValue), "Label");
|
||||
}
|
||||
}
|
||||
|
||||
export class TextBaseStyler implements definition.stylers.Styler {
|
||||
// font
|
||||
private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) {
|
||||
@@ -1100,6 +1141,7 @@ export function _registerDefaultStylers() {
|
||||
DefaultStyler.registerHandlers();
|
||||
TextBaseStyler.registerHandlers();
|
||||
ButtonStyler.registerHandlers();
|
||||
LabelStyler.registerHandlers();
|
||||
TextViewStyler.registerHandlers();
|
||||
SegmentedBarStyler.registerHandlers();
|
||||
SearchBarStyler.registerHandlers();
|
||||
|
||||
Reference in New Issue
Block a user