2015-06-02 14:22:19 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-12-22 21:36:37 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule TransformExample
|
2015-06-02 14:22:19 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2015-07-01 01:44:02 +00:00
|
|
|
var {
|
2015-07-15 14:57:25 +00:00
|
|
|
Animated,
|
2015-07-01 01:44:02 +00:00
|
|
|
StyleSheet,
|
2015-07-15 14:57:25 +00:00
|
|
|
Text,
|
2015-07-01 01:44:02 +00:00
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-06-02 14:22:19 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class Flip extends React.Component<{}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
theta: new Animated.Value(45),
|
|
|
|
};
|
2015-06-02 14:22:19 +00:00
|
|
|
|
2015-07-15 14:57:25 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this._animate();
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-06-02 14:22:19 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_animate = () => {
|
2015-07-15 14:57:25 +00:00
|
|
|
this.state.theta.setValue(0);
|
|
|
|
Animated.timing(this.state.theta, {
|
|
|
|
toValue: 360,
|
|
|
|
duration: 5000,
|
|
|
|
}).start(this._animate);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-06-02 14:22:19 +00:00
|
|
|
|
2015-07-15 14:57:25 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.flipCardContainer}>
|
|
|
|
<Animated.View style={[
|
|
|
|
styles.flipCard,
|
|
|
|
{transform: [
|
|
|
|
{perspective: 850},
|
|
|
|
{rotateX: this.state.theta.interpolate({
|
|
|
|
inputRange: [0, 180],
|
|
|
|
outputRange: ['0deg', '180deg']
|
|
|
|
})},
|
|
|
|
]}]}>
|
|
|
|
<Text style={styles.flipText}>
|
|
|
|
This text is flipping great.
|
|
|
|
</Text>
|
|
|
|
</Animated.View>
|
|
|
|
<Animated.View style={[styles.flipCard, {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
backgroundColor: 'red',
|
|
|
|
transform: [
|
|
|
|
{perspective: 850},
|
|
|
|
{rotateX: this.state.theta.interpolate({
|
|
|
|
inputRange: [0, 180],
|
|
|
|
outputRange: ['180deg', '360deg']
|
|
|
|
})},
|
|
|
|
]}]}>
|
|
|
|
<Text style={styles.flipText}>
|
|
|
|
On the flip side...
|
|
|
|
</Text>
|
|
|
|
</Animated.View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-06-02 14:22:19 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
2015-07-15 14:57:25 +00:00
|
|
|
container: {
|
|
|
|
height: 500,
|
|
|
|
},
|
2015-06-02 14:22:19 +00:00
|
|
|
box1: {
|
|
|
|
left: 0,
|
|
|
|
backgroundColor: 'green',
|
|
|
|
height: 50,
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
transform: [
|
|
|
|
{translateX: 100},
|
|
|
|
{translateY: 50},
|
|
|
|
{rotate: '30deg'},
|
|
|
|
{scaleX: 2},
|
|
|
|
{scaleY: 2},
|
|
|
|
],
|
|
|
|
width: 50,
|
|
|
|
},
|
|
|
|
box2: {
|
|
|
|
left: 0,
|
|
|
|
backgroundColor: 'purple',
|
|
|
|
height: 50,
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
transform: [
|
|
|
|
{scaleX: 2},
|
|
|
|
{scaleY: 2},
|
|
|
|
{translateX: 100},
|
|
|
|
{translateY: 50},
|
|
|
|
{rotate: '30deg'},
|
|
|
|
],
|
|
|
|
width: 50,
|
|
|
|
},
|
|
|
|
box3step1: {
|
|
|
|
left: 0,
|
2015-07-15 14:57:25 +00:00
|
|
|
backgroundColor: 'lightpink',
|
2015-06-02 14:22:19 +00:00
|
|
|
height: 50,
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
transform: [
|
|
|
|
{rotate: '30deg'},
|
|
|
|
],
|
|
|
|
width: 50,
|
|
|
|
},
|
|
|
|
box3step2: {
|
|
|
|
left: 0,
|
2015-07-15 14:57:25 +00:00
|
|
|
backgroundColor: 'hotpink',
|
2015-06-02 14:22:19 +00:00
|
|
|
height: 50,
|
|
|
|
opacity: 0.5,
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
transform: [
|
|
|
|
{rotate: '30deg'},
|
|
|
|
{scaleX: 2},
|
|
|
|
{scaleY: 2},
|
|
|
|
],
|
|
|
|
width: 50,
|
|
|
|
},
|
|
|
|
box3step3: {
|
|
|
|
left: 0,
|
2015-07-15 14:57:25 +00:00
|
|
|
backgroundColor: 'deeppink',
|
2015-06-02 14:22:19 +00:00
|
|
|
height: 50,
|
|
|
|
opacity: 0.5,
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
transform: [
|
|
|
|
{rotate: '30deg'},
|
|
|
|
{scaleX: 2},
|
|
|
|
{scaleY: 2},
|
|
|
|
{translateX: 100},
|
|
|
|
{translateY: 50},
|
|
|
|
],
|
|
|
|
width: 50,
|
|
|
|
},
|
|
|
|
box4: {
|
|
|
|
left: 0,
|
2015-07-15 14:57:25 +00:00
|
|
|
backgroundColor: 'darkorange',
|
2015-06-02 14:22:19 +00:00
|
|
|
height: 50,
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
transform: [
|
|
|
|
{translate: [200, 350]},
|
|
|
|
{scale: 2.5},
|
|
|
|
{rotate: '-0.2rad'},
|
|
|
|
],
|
|
|
|
width: 100,
|
|
|
|
},
|
|
|
|
box5: {
|
2015-07-15 14:57:25 +00:00
|
|
|
backgroundColor: 'maroon',
|
2015-06-02 14:22:19 +00:00
|
|
|
height: 50,
|
|
|
|
position: 'absolute',
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
width: 50,
|
|
|
|
},
|
|
|
|
box5Transform: {
|
|
|
|
transform: [
|
|
|
|
{translate: [-50, 35]},
|
|
|
|
{rotate: '50deg'},
|
|
|
|
{scale: 2},
|
|
|
|
],
|
|
|
|
},
|
2015-07-15 14:57:25 +00:00
|
|
|
flipCardContainer: {
|
|
|
|
marginVertical: 40,
|
|
|
|
flex: 1,
|
|
|
|
alignSelf: 'center',
|
|
|
|
},
|
|
|
|
flipCard: {
|
|
|
|
width: 200,
|
|
|
|
height: 200,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: 'blue',
|
|
|
|
backfaceVisibility: 'hidden',
|
|
|
|
},
|
|
|
|
flipText: {
|
|
|
|
width: 90,
|
|
|
|
fontSize: 20,
|
|
|
|
color: 'white',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
}
|
2015-06-02 14:22:19 +00:00
|
|
|
});
|
|
|
|
|
2015-07-15 14:57:25 +00:00
|
|
|
exports.title = 'Transforms';
|
|
|
|
exports.description = 'View transforms';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
2017-02-04 19:05:37 +00:00
|
|
|
title: 'Perspective, Rotate, Animation',
|
2015-07-15 14:57:25 +00:00
|
|
|
description: 'perspective: 850, rotateX: Animated.timing(0 -> 360)',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> { return <Flip />; }
|
2015-07-15 14:57:25 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Translate, Rotate, Scale',
|
|
|
|
description: "translateX: 100, translateY: 50, rotate: '30deg', scaleX: 2, scaleY: 2",
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.box1} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Scale, Translate, Rotate, ',
|
|
|
|
description: "scaleX: 2, scaleY: 2, translateX: 100, translateY: 50, rotate: '30deg'",
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.box2} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Rotate',
|
|
|
|
description: "rotate: '30deg'",
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.box3step1} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Rotate, Scale',
|
|
|
|
description: "rotate: '30deg', scaleX: 2, scaleY: 2",
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.box3step2} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Rotate, Scale, Translate ',
|
|
|
|
description: "rotate: '30deg', scaleX: 2, scaleY: 2, translateX: 100, translateY: 50",
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.box3step3} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Translate, Scale, Rotate',
|
|
|
|
description: "translate: [200, 350], scale: 2.5, rotate: '-0.2rad'",
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.box4} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Translate, Rotate, Scale',
|
|
|
|
description: "translate: [-50, 35], rotate: '50deg', scale: 2",
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={[styles.box5, styles.box5Transform]} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|