1
1
/**
2
- * Copyright 2004-present Facebook. All Rights Reserved.
2
+ * The examples provided by Facebook are for non-commercial testing and
3
+ * evaluation purposes only.
3
4
*
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.
5
13
*/
6
14
'use strict' ;
7
15
8
- var React = require ( 'React ' ) ;
16
+ var React = require ( 'react-native ' ) ;
9
17
var {
18
+ Animated,
10
19
StyleSheet,
20
+ Text,
11
21
View,
12
22
} = React ;
13
23
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 ( {
22
25
getInitialState ( ) {
23
26
return {
24
- interval : this . setInterval ( this . _update , 800 ) ,
25
- pulse : false ,
27
+ theta : new Animated . Value ( 45 ) ,
26
28
} ;
27
29
} ,
28
30
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 ( ) ;
48
33
} ,
49
34
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 ) ;
54
41
} ,
55
42
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
+ }
56
77
} ) ;
57
78
58
79
var styles = StyleSheet . create ( {
80
+ container : {
81
+ height : 500 ,
82
+ } ,
59
83
box1 : {
60
84
left : 0 ,
61
85
backgroundColor : 'green' ,
@@ -88,7 +112,7 @@ var styles = StyleSheet.create({
88
112
} ,
89
113
box3step1 : {
90
114
left : 0 ,
91
- backgroundColor : '#ffb6c1' , // lightpink
115
+ backgroundColor : 'lightpink' ,
92
116
height : 50 ,
93
117
position : 'absolute' ,
94
118
top : 0 ,
@@ -99,7 +123,7 @@ var styles = StyleSheet.create({
99
123
} ,
100
124
box3step2 : {
101
125
left : 0 ,
102
- backgroundColor : '#ff69b4' , //hotpink
126
+ backgroundColor : 'hotpink' ,
103
127
height : 50 ,
104
128
opacity : 0.5 ,
105
129
position : 'absolute' ,
@@ -113,7 +137,7 @@ var styles = StyleSheet.create({
113
137
} ,
114
138
box3step3 : {
115
139
left : 0 ,
116
- backgroundColor : '#ff1493' , // deeppink
140
+ backgroundColor : 'deeppink' ,
117
141
height : 50 ,
118
142
opacity : 0.5 ,
119
143
position : 'absolute' ,
@@ -129,7 +153,7 @@ var styles = StyleSheet.create({
129
153
} ,
130
154
box4 : {
131
155
left : 0 ,
132
- backgroundColor : '#ff8c00' , // darkorange
156
+ backgroundColor : 'darkorange' ,
133
157
height : 50 ,
134
158
position : 'absolute' ,
135
159
top : 0 ,
@@ -141,7 +165,7 @@ var styles = StyleSheet.create({
141
165
width : 100 ,
142
166
} ,
143
167
box5 : {
144
- backgroundColor : '#800000' , // maroon
168
+ backgroundColor : 'maroon' ,
145
169
height : 50 ,
146
170
position : 'absolute' ,
147
171
right : 0 ,
@@ -155,7 +179,110 @@ var styles = StyleSheet.create({
155
179
{ scale : 2 } ,
156
180
] ,
157
181
} ,
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
+ }
158
201
} ) ;
159
202
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