Merge pull request #1913 from NativeScript/button-css

Style properties are now applied on Buttons
This commit is contained in:
Rossen Hristov
2016-04-08 14:56:17 +03:00
2 changed files with 51 additions and 33 deletions

View File

@ -1,6 +1,8 @@
import common = require("./button-common");
import utils = require("utils/utils")
import dependencyObservable = require("ui/core/dependency-observable");
import style = require("ui/styling/style");
import { TextBaseStyler as TBS } from "ui/text-base/text-base-styler";
global.moduleMerge(common, exports);
@ -81,3 +83,48 @@ export class Button extends common.Button {
}
}
}
export class ButtonStyler implements style.Styler {
public static registerHandlers() {
// !!! IMPORTANT !!! This was moved here because of the following bug: https://github.com/NativeScript/NativeScript/issues/1902
// If there is no TextBase on the Page, the TextBaseStyler.registerHandlers
// method was never called because the file it is called from was never required.
// Register the same stylers for Button.
// It also derives from TextView but is not under TextBase in our View hierarchy.
var TextBaseStyler = <any>TBS;
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setColorProperty,
TextBaseStyler.resetColorProperty,
TextBaseStyler.getNativeColorValue), "Button");
style.registerHandler(style.fontInternalProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setFontInternalProperty,
TextBaseStyler.resetFontInternalProperty,
TextBaseStyler.getNativeFontInternalValue), "Button");
style.registerHandler(style.textAlignmentProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextAlignmentProperty,
TextBaseStyler.resetTextAlignmentProperty,
TextBaseStyler.getNativeTextAlignmentValue), "Button");
style.registerHandler(style.textDecorationProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextDecorationProperty,
TextBaseStyler.resetTextDecorationProperty), "Button");
style.registerHandler(style.textTransformProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextTransformProperty,
TextBaseStyler.resetTextTransformProperty), "Button");
style.registerHandler(style.whiteSpaceProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setWhiteSpaceProperty,
TextBaseStyler.resetWhiteSpaceProperty), "Button");
style.registerHandler(style.letterSpacingProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setLetterSpacingProperty,
TextBaseStyler.resetLetterSpacingProperty,
TextBaseStyler.getLetterSpacingProperty), "Button");
}
}
ButtonStyler.registerHandlers();

View File

@ -158,38 +158,9 @@ export class TextBaseStyler implements style.Styler {
TextBaseStyler.resetLetterSpacingProperty,
TextBaseStyler.getLetterSpacingProperty), "TextBase");
// Register the same stylers for Button.
// It also derives from TextView but is not under TextBase in our View hierarchy.
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setColorProperty,
TextBaseStyler.resetColorProperty,
TextBaseStyler.getNativeColorValue), "Button");
style.registerHandler(style.fontInternalProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setFontInternalProperty,
TextBaseStyler.resetFontInternalProperty,
TextBaseStyler.getNativeFontInternalValue), "Button");
style.registerHandler(style.textAlignmentProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextAlignmentProperty,
TextBaseStyler.resetTextAlignmentProperty,
TextBaseStyler.getNativeTextAlignmentValue), "Button");
style.registerHandler(style.textDecorationProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextDecorationProperty,
TextBaseStyler.resetTextDecorationProperty), "Button");
style.registerHandler(style.textTransformProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setTextTransformProperty,
TextBaseStyler.resetTextTransformProperty), "Button");
style.registerHandler(style.whiteSpaceProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setWhiteSpaceProperty,
TextBaseStyler.resetWhiteSpaceProperty), "Button");
style.registerHandler(style.letterSpacingProperty, new style.StylePropertyChangedHandler(
TextBaseStyler.setLetterSpacingProperty,
TextBaseStyler.resetLetterSpacingProperty,
TextBaseStyler.getLetterSpacingProperty), "Button");
// !!! IMPORTANT !!! Button registrations were moved to button.android.ts to make sure they
// are executed when there is a Button on the page: https://github.com/NativeScript/NativeScript/issues/1902
// If there is no TextBase on the Page, the TextBaseStyler.registerHandlers
// method was never called because the file it is called from was never required.
}
}