11/**
2- * Copyright 2004-present Facebook. All Rights Reserved.
2+ * The examples provided by Facebook are for non-commercial testing and
3+ * evaluation purposes only.
34 *
4- * @providesModule TransformExample
5+ * Facebook reserves all rights not expressly granted.
6+ *
7+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
8+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9+ * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
10+ * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
11+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
12+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
513 */
614'use strict' ;
715
8- var React = require ( 'React ' ) ;
16+ var React = require ( 'react-native ' ) ;
917var {
18+ Animated,
1019 StyleSheet,
20+ Text,
1121 View,
1222} = React ;
1323
14- var TimerMixin = require ( 'react-timer-mixin' ) ;
15- var UIExplorerBlock = require ( './UIExplorerBlock' ) ;
16- var UIExplorerPage = require ( './UIExplorerPage' ) ;
17-
18- var TransformExample = React . createClass ( {
19-
20- mixins : [ TimerMixin ] ,
21-
24+ var Flip = React . createClass ( {
2225 getInitialState ( ) {
2326 return {
24- interval : this . setInterval ( this . _update , 800 ) ,
25- pulse : false ,
27+ theta : new Animated . Value ( 45 ) ,
2628 } ;
2729 } ,
2830
29- render ( ) {
30- return (
31- < UIExplorerPage title = "Transforms" >
32- < UIExplorerBlock title = "foo bar" >
33- < View style = { { height : 500 } } >
34- < View style = { styles . box1 } />
35- < View style = { styles . box2 } />
36- < View style = { styles . box3step1 } />
37- < View style = { styles . box3step2 } />
38- < View style = { styles . box3step3 } />
39- < View style = { styles . box4 } />
40- < View style = { [
41- styles . box5 ,
42- this . state . pulse ? styles . box5Transform : null
43- ] } />
44- </ View >
45- </ UIExplorerBlock >
46- </ UIExplorerPage >
47- ) ;
31+ componentDidMount ( ) {
32+ this . _animate ( ) ;
4833 } ,
4934
50- _update ( ) {
51- this . setState ( {
52- pulse : ! this . state . pulse ,
53- } ) ;
35+ _animate ( ) {
36+ this . state . theta . setValue ( 0 ) ;
37+ Animated . timing ( this . state . theta , {
38+ toValue : 360 ,
39+ duration : 5000 ,
40+ } ) . start ( this . _animate ) ;
5441 } ,
5542
43+ render ( ) {
44+ return (
45+ < View style = { styles . flipCardContainer } >
46+ < Animated . View style = { [
47+ styles . flipCard ,
48+ { transform : [
49+ { perspective : 850 } ,
50+ { rotateX : this . state . theta . interpolate ( {
51+ inputRange : [ 0 , 180 ] ,
52+ outputRange : [ '0deg' , '180deg' ]
53+ } ) } ,
54+ ] } ] } >
55+ < Text style = { styles . flipText } >
56+ This text is flipping great.
57+ </ Text >
58+ </ Animated . View >
59+ < Animated . View style = { [ styles . flipCard , {
60+ position : 'absolute' ,
61+ top : 0 ,
62+ backgroundColor : 'red' ,
63+ transform : [
64+ { perspective : 850 } ,
65+ { rotateX : this . state . theta . interpolate ( {
66+ inputRange : [ 0 , 180 ] ,
67+ outputRange : [ '180deg' , '360deg' ]
68+ } ) } ,
69+ ] } ] } >
70+ < Text style = { styles . flipText } >
71+ On the flip side...
72+ </ Text >
73+ </ Animated . View >
74+ </ View >
75+ ) ;
76+ }
5677} ) ;
5778
5879var styles = StyleSheet . create ( {
80+ container : {
81+ height : 500 ,
82+ } ,
5983 box1 : {
6084 left : 0 ,
6185 backgroundColor : 'green' ,
@@ -88,7 +112,7 @@ var styles = StyleSheet.create({
88112 } ,
89113 box3step1 : {
90114 left : 0 ,
91- backgroundColor : '#ffb6c1' , // lightpink
115+ backgroundColor : 'lightpink' ,
92116 height : 50 ,
93117 position : 'absolute' ,
94118 top : 0 ,
@@ -99,7 +123,7 @@ var styles = StyleSheet.create({
99123 } ,
100124 box3step2 : {
101125 left : 0 ,
102- backgroundColor : '#ff69b4' , //hotpink
126+ backgroundColor : 'hotpink' ,
103127 height : 50 ,
104128 opacity : 0.5 ,
105129 position : 'absolute' ,
@@ -113,7 +137,7 @@ var styles = StyleSheet.create({
113137 } ,
114138 box3step3 : {
115139 left : 0 ,
116- backgroundColor : '#ff1493' , // deeppink
140+ backgroundColor : 'deeppink' ,
117141 height : 50 ,
118142 opacity : 0.5 ,
119143 position : 'absolute' ,
@@ -129,7 +153,7 @@ var styles = StyleSheet.create({
129153 } ,
130154 box4 : {
131155 left : 0 ,
132- backgroundColor : '#ff8c00' , // darkorange
156+ backgroundColor : 'darkorange' ,
133157 height : 50 ,
134158 position : 'absolute' ,
135159 top : 0 ,
@@ -141,7 +165,7 @@ var styles = StyleSheet.create({
141165 width : 100 ,
142166 } ,
143167 box5 : {
144- backgroundColor : '#800000' , // maroon
168+ backgroundColor : 'maroon' ,
145169 height : 50 ,
146170 position : 'absolute' ,
147171 right : 0 ,
@@ -155,7 +179,110 @@ var styles = StyleSheet.create({
155179 { scale : 2 } ,
156180 ] ,
157181 } ,
182+ flipCardContainer : {
183+ marginVertical : 40 ,
184+ flex : 1 ,
185+ alignSelf : 'center' ,
186+ } ,
187+ flipCard : {
188+ width : 200 ,
189+ height : 200 ,
190+ alignItems : 'center' ,
191+ justifyContent : 'center' ,
192+ backgroundColor : 'blue' ,
193+ backfaceVisibility : 'hidden' ,
194+ } ,
195+ flipText : {
196+ width : 90 ,
197+ fontSize : 20 ,
198+ color : 'white' ,
199+ fontWeight : 'bold' ,
200+ }
158201} ) ;
159202
160-
161- module . exports = TransformExample ;
203+ exports . title = 'Transforms' ;
204+ exports . description = 'View transforms' ;
205+ exports . examples = [
206+ {
207+ title : 'Perspective' ,
208+ description : 'perspective: 850, rotateX: Animated.timing(0 -> 360)' ,
209+ render ( ) : ReactElement { return < Flip /> ; }
210+ } ,
211+ {
212+ title : 'Translate, Rotate, Scale' ,
213+ description : "translateX: 100, translateY: 50, rotate: '30deg', scaleX: 2, scaleY: 2" ,
214+ render ( ) {
215+ return (
216+ < View style = { styles . container } >
217+ < View style = { styles . box1 } />
218+ </ View >
219+ ) ;
220+ }
221+ } ,
222+ {
223+ title : 'Scale, Translate, Rotate, ' ,
224+ description : "scaleX: 2, scaleY: 2, translateX: 100, translateY: 50, rotate: '30deg'" ,
225+ render ( ) {
226+ return (
227+ < View style = { styles . container } >
228+ < View style = { styles . box2 } />
229+ </ View >
230+ ) ;
231+ }
232+ } ,
233+ {
234+ title : 'Rotate' ,
235+ description : "rotate: '30deg'" ,
236+ render ( ) {
237+ return (
238+ < View style = { styles . container } >
239+ < View style = { styles . box3step1 } />
240+ </ View >
241+ ) ;
242+ }
243+ } ,
244+ {
245+ title : 'Rotate, Scale' ,
246+ description : "rotate: '30deg', scaleX: 2, scaleY: 2" ,
247+ render ( ) {
248+ return (
249+ < View style = { styles . container } >
250+ < View style = { styles . box3step2 } />
251+ </ View >
252+ ) ;
253+ }
254+ } ,
255+ {
256+ title : 'Rotate, Scale, Translate ' ,
257+ description : "rotate: '30deg', scaleX: 2, scaleY: 2, translateX: 100, translateY: 50" ,
258+ render ( ) {
259+ return (
260+ < View style = { styles . container } >
261+ < View style = { styles . box3step3 } />
262+ </ View >
263+ ) ;
264+ }
265+ } ,
266+ {
267+ title : 'Translate, Scale, Rotate' ,
268+ description : "translate: [200, 350], scale: 2.5, rotate: '-0.2rad'" ,
269+ render ( ) {
270+ return (
271+ < View style = { styles . container } >
272+ < View style = { styles . box4 } />
273+ </ View >
274+ ) ;
275+ }
276+ } ,
277+ {
278+ title : 'Translate, Rotate, Scale' ,
279+ description : "translate: [-50, 35], rotate: '50deg', scale: 2" ,
280+ render ( ) {
281+ return (
282+ < View style = { styles . container } >
283+ < View style = { [ styles . box5 , styles . box5Transform ] } />
284+ </ View >
285+ ) ;
286+ }
287+ }
288+ ] ;
0 commit comments