这是我的代码
import React, { PureComponent } from 'react';
import { View, Text, Animated, ImageStyle, StyleProp } from 'react-native';
import { StyleSheet } from 'react-native';
import { createStyleSheet, EmFastImage, getCurrentTheme, rpx } from '@emcd/react-native-treasure-box';
export interface PageBannerFrame1Props {
active?: boolean;
}
interface PageBannerFrame1State {}
/**
* 组件名称
*/
export class PageBannerFrame1 extends PureComponent<PageBannerFrame1Props, PageBannerFrame1State> {
animate1 = new Animated.Value(0);
animate11 = new Animated.Value(0);
animate12 = new Animated.Value(0);
animate13 = new Animated.Value(0);
animate14 = new Animated.Value(0);
constructor(props: PageBannerFrame1Props) {
super(props);
this.state = {};
}
componentDidMount(): void {
if (this.props.active) {
this.startAnimate();
}
}
componentDidUpdate(
prevProps: Readonly<PageBannerFrame1Props>,
prevState: Readonly<PageBannerFrame1State>,
snapshot?: any
): void {
if (this.props.active && !prevProps.active) {
this.resetAnimate();
this.startAnimate();
}
}
resetAnimate = () => {
this.animate1.setValue(0);
this.animate11.setValue(0);
this.animate12.setValue(0);
this.animate13.setValue(0);
this.animate14.setValue(0);
};
startAnimate = () => {
Animated.parallel([
Animated.timing(this.animate1, {
toValue: 1,
delay: 200,
duration: 300,
useNativeDriver: false,
}),
Animated.timing(this.animate11, {
toValue: 1,
delay: 400,
duration: 400,
useNativeDriver: true,
}),
Animated.timing(this.animate12, {
toValue: 1,
delay: 600,
duration: 400,
useNativeDriver: true,
}),
Animated.timing(this.animate13, {
toValue: 1,
delay: 800,
duration: 400,
useNativeDriver: true,
}),
Animated.timing(this.animate14, {
toValue: 1,
delay: 1000,
duration: 400,
useNativeDriver: true,
}),
]).start();
};
render(): React.ReactNode {
const styles = getStyles();
const style1: Animated.WithAnimatedValue<StyleProp<ImageStyle>> = {
opacity: this.animate1.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
}),
transform: [
{
scaleX: this.animate1.interpolate({
inputRange: [0, 1],
outputRange: [0.5, 1],
}),
},
{
scaleY: this.animate1.interpolate({
inputRange: [0, 1],
outputRange: [0.5, 1],
}),
},
],
};
const style11: Animated.WithAnimatedValue<StyleProp<ImageStyle>> = {
opacity: this.animate11.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
}),
};
const style12: Animated.WithAnimatedValue<StyleProp<ImageStyle>> = {
opacity: this.animate12.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
}),
transform: [
{
translateY: this.animate12.interpolate({
inputRange: [0, 1],
outputRange: [rpx(50), rpx(0)],
}),
},
{
scaleX: this.animate12.interpolate({
inputRange: [0, 1],
outputRange: [0.9, 1],
}),
},
{
scaleY: this.animate12.interpolate({
inputRange: [0, 1],
outputRange: [0.9, 1],
}),
},
],
};
const style13: Animated.WithAnimatedValue<StyleProp<ImageStyle>> = {
opacity: this.animate13.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
}),
transform: [
{
translateY: this.animate13.interpolate({
inputRange: [0, 1],
outputRange: [rpx(50), rpx(0)],
}),
},
{
scaleX: this.animate13.interpolate({
inputRange: [0, 1],
outputRange: [0.9, 1],
}),
},
{
scaleY: this.animate13.interpolate({
inputRange: [0, 1],
outputRange: [0.9, 1],
}),
},
],
};
const style14: Animated.WithAnimatedValue<StyleProp<ImageStyle>> = {
opacity: this.animate14.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
}),
transform: [
{
translateY: this.animate14.interpolate({
inputRange: [0, 1],
outputRange: [rpx(50), rpx(0)],
}),
},
{
scaleX: this.animate14.interpolate({
inputRange: [0, 1],
outputRange: [0.9, 1],
}),
},
{
scaleY: this.animate14.interpolate({
inputRange: [0, 1],
outputRange: [0.9, 1],
}),
},
],
};
return (
<View
style={[
styles.box,
{
opacity: this.props.active ? 1 : 0,
},
]}
>
<Animated.Image fadeDuration={0} source={require('./images/frames/1.png')} style={[styles.main, style1]} />
<Animated.Image fadeDuration={0} source={require('./images/frames/1.1.png')} style={[styles.icon1, style11]} />
<Animated.Image fadeDuration={0} source={require('./images/frames/1.2.png')} style={[styles.icon2, style12]} />
<Animated.Image fadeDuration={0} source={require('./images/frames/1.3.png')} style={[styles.icon3, style13]} />
<Animated.Image fadeDuration={0} source={require('./images/frames/1.4.png')} style={[styles.icon4, style14]} />
</View>
);
}
}
export const getStyles = () => {
const theme = getCurrentTheme();
return createStyleSheet({
box: {
width: 700,
height: 520,
justifyContent: 'flex-end',
},
main: {
width: 328,
height: 441,
alignSelf: 'center',
},
icon1: {
position: 'absolute',
left: 0,
bottom: 130,
width: 163,
height: 130,
},
icon2: {
position: 'absolute',
left: 120,
top: 80,
width: 118,
height: 179,
},
icon3: {
position: 'absolute',
left: 360,
top: 20,
width: 120,
height: 160,
},
icon4: {
position: 'absolute',
right: 75,
top: 120,
width: 119,
height: 182,
},
});
};
最新发布