Files
react-native/packages/rn-tester/js/examples/Animated/RotatingImagesExample.js
T
Daniel Sainati 974f0a3281 pre-suppress this typing errors ahead of 154
Summary:
This pre-suppresses the 154 error diff ahead of its release, since it is large.

Changelog: [Internal]

Reviewed By: samwgoldman

Differential Revision: D29065246

fbshipit-source-id: f418041305a46df410dcbe3d9a4db81a61ac7014
2021-06-11 14:31:41 -07:00

92 lines
2.3 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
import * as React from 'react';
import RNTesterButton from '../../components/RNTesterButton';
import {Animated, View, StyleSheet} from 'react-native';
import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes';
const styles = StyleSheet.create({
rotatingImage: {
width: 70,
height: 70,
},
});
function RotatingImagesExample(): React.Node {
// $FlowFixMe[incompatible-use]
// $FlowFixMe[incompatible-type]
this.anim = this.anim || new Animated.Value(0);
return (
<View>
<RNTesterButton
onPress={() => {
// $FlowFixMe[incompatible-use]
Animated.spring(this.anim, {
// Returns to the start
toValue: 0,
// Velocity makes it move
velocity: 3,
// Slow
tension: -10,
// Oscillate a lot
friction: 1,
useNativeDriver: false,
}).start();
}}>
Press to Spin it!
</RNTesterButton>
<Animated.Image
source={require('../../assets/bunny.png')}
style={[
styles.rotatingImage,
{
transform: [
{
scale: this.anim.interpolate({
inputRange: [0, 1],
outputRange: [1, 10],
}),
},
{
// $FlowFixMe[incompatible-use]
translateX: this.anim.interpolate({
inputRange: [0, 1],
outputRange: [0, 100],
}),
},
{
// $FlowFixMe[incompatible-use]
rotate: this.anim.interpolate({
inputRange: [0, 1],
outputRange: [
'0deg',
'360deg', // 'deg' or 'rad'
],
}),
},
],
},
]}
/>
</View>
);
}
export default ({
title: 'Rotating Images',
description: 'Simple Animated.Image rotation.',
render: RotatingImagesExample,
}: RNTesterExampleModuleItem);