mirror of
https://github.com/zhigang1992/react-native-reanimated.git
synced 2026-06-11 00:08:58 +08:00
98 lines
1.9 KiB
JavaScript
98 lines
1.9 KiB
JavaScript
import React, { Component } from 'react';
|
|
import { StyleSheet, Text, View } from 'react-native';
|
|
|
|
import Animated, { Easing } from 'react-native-reanimated';
|
|
|
|
const {
|
|
set,
|
|
cond,
|
|
startClock,
|
|
stopClock,
|
|
clockRunning,
|
|
block,
|
|
timing,
|
|
debug,
|
|
Value,
|
|
Clock,
|
|
divide,
|
|
concat,
|
|
} = Animated;
|
|
|
|
function runTiming(clock, value, dest) {
|
|
const state = {
|
|
finished: new Value(0),
|
|
position: new Value(0),
|
|
time: new Value(0),
|
|
frameTime: new Value(0),
|
|
};
|
|
|
|
const config = {
|
|
duration: 5000,
|
|
toValue: new Value(0),
|
|
easing: Easing.inOut(Easing.ease),
|
|
};
|
|
|
|
return block([
|
|
cond(clockRunning(clock), 0, [
|
|
set(state.finished, 0),
|
|
set(state.time, 0),
|
|
set(state.position, value),
|
|
set(state.frameTime, 0),
|
|
set(config.toValue, dest),
|
|
startClock(clock),
|
|
]),
|
|
timing(clock, state, config),
|
|
cond(state.finished, debug('stop clock', stopClock(clock))),
|
|
state.position,
|
|
]);
|
|
}
|
|
|
|
export default class Example extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.trans = runTiming(new Clock(), 0, 360);
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<View style={styles.container}>
|
|
<Animated.View
|
|
style={[
|
|
styles.box,
|
|
{ transform: [{ rotate: concat(this.trans, 'deg') }] },
|
|
]}
|
|
/>
|
|
<Animated.View
|
|
style={[
|
|
styles.box,
|
|
{
|
|
transform: [
|
|
{ rotate: concat(divide(this.trans, 57.2957795786), 'rad') },
|
|
],
|
|
},
|
|
]}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
const BOX_SIZE = 100;
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
backgroundColor: '#F5FCFF',
|
|
},
|
|
box: {
|
|
width: BOX_SIZE,
|
|
height: BOX_SIZE,
|
|
borderColor: '#F5FCFF',
|
|
alignSelf: 'center',
|
|
backgroundColor: 'plum',
|
|
margin: BOX_SIZE / 2,
|
|
},
|
|
});
|