@@ -128,8 +128,8 @@ export type ButtonOptions = ViewsInput & {
128128 */
129129export class FancyButton extends ButtonContainer
130130{
131- protected animations : StateAnimations = { } ;
132- protected originalInnerViewState : AnimationData = { } ;
131+ protected animations ! : StateAnimations ;
132+ protected originalInnerViewState ! : AnimationData ;
133133 protected defaultDuration = 100 ;
134134
135135 /** FancyButton options. */
@@ -253,6 +253,7 @@ export class FancyButton extends ButtonContainer
253253 if ( animations )
254254 {
255255 this . animations = animations ;
256+ this . setOriginalInnerViewState ( ) ;
256257 Ticker . shared . add ( ( ) => Group . shared . update ( ) ) ;
257258 }
258259
@@ -831,40 +832,6 @@ export class FancyButton extends ButtonContainer
831832 {
832833 if ( ! this . animations ) return ;
833834
834- if ( state === 'default' && ! this . originalInnerViewState )
835- {
836- this . originalInnerViewState = {
837- x : this . innerView . x ,
838- y : this . innerView . y ,
839- width : this . innerView . width ,
840- height : this . innerView . height ,
841- scale : {
842- x : this . innerView . scale . x ,
843- y : this . innerView . scale . y ,
844- } ,
845- } ;
846-
847- // first animation state is default, so we don't need to animate it
848- // this part will run only once, during initialization
849- const defaultStateAnimation = this . animations ?. default ;
850-
851- if ( defaultStateAnimation )
852- {
853- this . innerView . x = defaultStateAnimation . props . x ?? this . originalInnerViewState . x ?? 0 ;
854- this . innerView . y = defaultStateAnimation . props . y ?? this . originalInnerViewState . y ?? 0 ;
855- this . innerView . width
856- = defaultStateAnimation . props . width ?? this . originalInnerViewState . width ?? 0 ;
857- this . innerView . height
858- = defaultStateAnimation . props . height ?? this . originalInnerViewState . height ?? 0 ;
859- this . innerView . scale . x
860- = defaultStateAnimation . props . scale ?. x ?? this . originalInnerViewState . scale ?. x ?? 1 ;
861- this . innerView . scale . y
862- = defaultStateAnimation . props . scale ?. y ?? this . originalInnerViewState . scale ?. y ?? 1 ;
863-
864- return ;
865- }
866- }
867-
868835 const stateAnimation = this . animations [ state ] ?? this . animations . default ;
869836
870837 if ( stateAnimation )
@@ -882,6 +849,38 @@ export class FancyButton extends ButtonContainer
882849 new Tween ( this . innerView ) . to ( this . originalInnerViewState , this . defaultDuration ) . start ( ) ;
883850 }
884851
852+ protected setOriginalInnerViewState ( )
853+ {
854+ this . originalInnerViewState = {
855+ x : this . innerView . x ,
856+ y : this . innerView . y ,
857+ width : this . innerView . width ,
858+ height : this . innerView . height ,
859+ scale : {
860+ x : this . innerView . scale . x ,
861+ y : this . innerView . scale . y ,
862+ } ,
863+ } ;
864+
865+ // first animation state is default, so we don't need to animate it
866+ // this part will run only once, during initialization
867+ const defaultStateAnimation = this . animations ?. default ;
868+
869+ if ( defaultStateAnimation )
870+ {
871+ this . innerView . x = defaultStateAnimation . props . x ?? this . originalInnerViewState . x ?? 0 ;
872+ this . innerView . y = defaultStateAnimation . props . y ?? this . originalInnerViewState . y ?? 0 ;
873+ this . innerView . width
874+ = defaultStateAnimation . props . width ?? this . originalInnerViewState . width ?? 0 ;
875+ this . innerView . height
876+ = defaultStateAnimation . props . height ?? this . originalInnerViewState . height ?? 0 ;
877+ this . innerView . scale . x
878+ = defaultStateAnimation . props . scale ?. x ?? this . originalInnerViewState . scale ?. x ?? 1 ;
879+ this . innerView . scale . y
880+ = defaultStateAnimation . props . scale ?. y ?? this . originalInnerViewState . scale ?. y ?? 1 ;
881+ }
882+ }
883+
885884 protected initStateControl ( )
886885 {
887886 this . onDown . connect ( ( ) =>
@@ -891,7 +890,7 @@ export class FancyButton extends ButtonContainer
891890
892891 this . onUp . connect ( ( ) =>
893892 {
894- isMobile . any ? this . setState ( 'default' ) : this . setState ( 'hover' ) ;
893+ this . setState ( isMobile . any ? 'default' : 'hover' ) ;
895894 } ) ;
896895
897896 this . onUpOut . connect ( ( ) =>
@@ -909,14 +908,14 @@ export class FancyButton extends ButtonContainer
909908
910909 this . onPress . connect ( ( ) =>
911910 {
912- isMobile . any ? this . setState ( 'default' ) : this . setState ( 'hover' ) ;
911+ this . setState ( isMobile . any ? 'default' : 'hover' ) ;
913912 } ) ;
914913
915914 this . onHover . connect ( ( ) =>
916915 {
917916 if ( ! this . button . isDown )
918917 {
919- isMobile . any ? this . setState ( 'default' ) : this . setState ( 'hover' ) ;
918+ this . setState ( isMobile . any ? 'default' : 'hover' ) ;
920919 }
921920 } ) ;
922921 }
0 commit comments