@@ -7,6 +7,7 @@ import utils = require("utils/utils");
77import enums = require( "ui/enums" ) ;
88import dependencyObservable = require( "ui/core/dependency-observable" ) ;
99import styleScope = require( "../styling/style-scope" ) ;
10+ import { Property } from "ui/core/dependency-observable" ;
1011
1112class TapHandlerImpl extends NSObject {
1213 private _owner : WeakRef < Button > ;
@@ -50,20 +51,21 @@ export class Button extends common.Button {
5051
5152 public onLoaded ( ) {
5253 super . onLoaded ( ) ;
53- if ( this . parent !== null && this . page !== null ) {
54- let rootPage = this . page ;
55- let scope : styleScope . StyleScope = ( < any > rootPage ) . _getStyleScope ( ) ;
56- if ( scope . getVisualStates ( this ) !== undefined ) {
57- this . _stateChangedHandler . start ( ) ;
58- }
59- }
54+ this . _updateHandler ( ) ;
6055 }
6156
6257 public onUnloaded ( ) {
6358 super . onUnloaded ( ) ;
6459 this . _stateChangedHandler . stop ( ) ;
6560 }
6661
62+ public _onPropertyChanged ( property : Property , oldValue : any , newValue : any ) {
63+ super . _onPropertyChanged ( property , oldValue , newValue ) ;
64+ if ( property . metadata . affectsStyle ) {
65+ this . _updateHandler ( ) ;
66+ }
67+ }
68+
6769 get ios ( ) : UIButton {
6870 return this . _ios ;
6971 }
@@ -81,10 +83,23 @@ export class Button extends common.Button {
8183 // the UIControlStateNormal value. If the value for UIControlStateNormal is not set,
8284 // then the property defaults to a system value. Therefore, at a minimum, you should
8385 // set the value for the normal state.
84- var newText = value ? value . _formattedText : null ;
86+ let newText = value ? value . _formattedText : null ;
8587 this . ios . setAttributedTitleForState ( newText , UIControlState . UIControlStateNormal ) ;
8688 this . style . _updateTextDecoration ( ) ;
8789 }
90+
91+ private _updateHandler ( ) {
92+ if ( this . parent !== null && this . page !== null ) {
93+ let rootPage = this . page ;
94+ let scope : styleScope . StyleScope = ( < any > rootPage ) . _getStyleScope ( ) ;
95+ if ( scope . getVisualStates ( this ) !== undefined ) {
96+ this . _stateChangedHandler . start ( ) ;
97+ }
98+ else {
99+ this . _stateChangedHandler . stop ( ) ;
100+ }
101+ }
102+ }
88103}
89104
90105export class ButtonStyler implements style . Styler {
0 commit comments