11/*
2- * Tests the functionality of a GestureView component
2+ * Tests the functionality of a GestureView component
33* through user interaction.
44*/
55
@@ -38,10 +38,12 @@ const _styles = {
3838} ;
3939
4040const _colors = [ 'red' , 'green' , 'blue' ] ;
41+ const _shades = [ '#000' , '#333' , '#666' , '#999' , '#CCC' , '#FFF' ] ;
4142
4243interface GestureViewState {
4344 test1ColorIndex ?: number ;
4445 test2ColorIndex ?: number ;
46+ test4ColorIndex ?: number ;
4547}
4648
4749class GestureViewView extends RX . Component < RX . CommonProps , GestureViewState > {
@@ -51,7 +53,7 @@ class GestureViewView extends RX.Component<RX.CommonProps, GestureViewState> {
5153 private _test1AnimatedStyle = RX . Styles . createAnimatedViewStyle ( {
5254 transform : [ {
5355 scale : this . _test1ScaleValue
54- } , {
56+ } , {
5557 rotate : this . _test1RotateValue . interpolate ( {
5658 inputRange : [ 0 , 360 ] ,
5759 outputRange : [ '0deg' , '360deg' ]
@@ -79,12 +81,23 @@ class GestureViewView extends RX.Component<RX.CommonProps, GestureViewState> {
7981 } ]
8082 } ) ;
8183
84+ private _test4HorizontalOffset = new RX . Animated . Value ( 0 ) ;
85+ private _test4VerticalOffset = new RX . Animated . Value ( 0 ) ;
86+ private _test4AnimatedStyle = RX . Styles . createAnimatedViewStyle ( {
87+ transform : [ {
88+ translateX : this . _test4HorizontalOffset
89+ } , {
90+ translateY : this . _test4VerticalOffset
91+ } ]
92+ } ) ;
93+
8294 constructor ( props : RX . CommonProps ) {
8395 super ( props ) ;
8496
8597 this . state = {
8698 test1ColorIndex : 0 ,
87- test2ColorIndex : 1
99+ test2ColorIndex : 1 ,
100+ test4ColorIndex : 2
88101 } ;
89102 }
90103
@@ -98,6 +111,10 @@ class GestureViewView extends RX.Component<RX.CommonProps, GestureViewState> {
98111 backgroundColor : _colors [ this . state . test2ColorIndex ]
99112 } , false ) ;
100113
114+ let test4ColorStyle = RX . Styles . createViewStyle ( {
115+ backgroundColor : _shades [ this . state . test4ColorIndex ]
116+ } , false ) ;
117+
101118 return (
102119 < RX . View style = { _styles . container } >
103120 < RX . View style = { _styles . explainTextContainer } key = { 'explanation1' } >
@@ -154,6 +171,23 @@ class GestureViewView extends RX.Component<RX.CommonProps, GestureViewState> {
154171 style = { [ _styles . smallBox , this . _test3AnimatedStyle ] }
155172 />
156173 </ RX . GestureView >
174+
175+ < RX . View style = { _styles . explainTextContainer } key = { 'explanation4' } >
176+ < RX . Text style = { _styles . explainText } >
177+ { 'Desktop platforms: Left click will make the box lighter. ' +
178+ 'Right click (context menu) will make the box darker.' }
179+ </ RX . Text >
180+ </ RX . View >
181+ < RX . GestureView
182+ style = { _styles . gestureView }
183+ onTap = { state => this . _onTapTest4 ( state ) }
184+ onContextMenu = { e => this . _onContextMenu4 ( e ) }
185+ mouseOverCursor = { RX . Types . GestureMouseCursor . Pointer }
186+ >
187+ < RX . Animated . View
188+ style = { [ _styles . smallBox , test4ColorStyle , this . _test4AnimatedStyle ] }
189+ />
190+ </ RX . GestureView >
157191 </ RX . View >
158192 ) ;
159193 }
@@ -222,6 +256,19 @@ class GestureViewView extends RX.Component<RX.CommonProps, GestureViewState> {
222256 this . _test3VerticalOffset . setValue ( state . pageY - state . initialPageY ) ;
223257 }
224258 }
259+
260+ private _onTapTest4 ( gestureState : RX . Types . TapGestureState ) {
261+ // Change the color.
262+ this . setState ( {
263+ test4ColorIndex : Math . min ( this . state . test4ColorIndex + 1 , _shades . length - 1 )
264+ } ) ;
265+ }
266+
267+ private _onContextMenu4 ( gestureState : RX . Types . TapGestureState ) {
268+ this . setState ( {
269+ test4ColorIndex : Math . max ( this . state . test4ColorIndex - 1 , 0 )
270+ } ) ;
271+ }
225272}
226273
227274class GestureViewTest implements Test {
@@ -230,7 +277,7 @@ class GestureViewTest implements Test {
230277 getPath ( ) : string {
231278 return 'Components/GestureView' ;
232279 }
233-
280+
234281 getTestType ( ) : TestType {
235282 return TestType . Interactive ;
236283 }
0 commit comments