项目中有个需求是进入到页面,有个view 是需要从底部滑出,滑倒一定高度,当点击button 是再滑回原来的地方。研究了半天,React Native 的动画,写了一个简单的Demo:
(1)在componentDidMount()方法里从底部滑出view;
(2)点击页面的空白处,view 滑下去。
import React, { Component } from 'react';
import {
AppRegistry,
View,
Animated,
Dimensions,
TouchableOpacity
} from 'react-native';
import FadeInView from './FadeInView';
const { width, height } = Dimensions.get("window");
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
securetyTipViewY: new Animated.Value(height),
}
}
componentDidMount() {
this._showTipView()
}
//展示View
_showTipView = () => {
Animated.timing(
this.state.securetyTipViewY,
{
toValue: height - 254 - 64,
duration: 300, //动画时长300毫秒
}
).start();
}
//隐藏view
_hiddenTipView = () => {
Animated.timing(
this.state.securetyTipViewY,
{