UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);//安卓启用
const defaultAnimation = {
duration: 500,
create: {
duration: 300,
type: LayoutAnimation.Types.easeInEaseOut,
property: LayoutAnimation.Properties.opacity
},
update: {
type: LayoutAnimation.Types.spring,//弹跳动画阻尼系数(配合 spring 使用)
springDamping: 200
}
};
type:类型定义在LayoutAnimation.Types中:
spring:弹跳
linear:线性
easeInEaseOut:缓入缓出
easeIn:缓入
easeOut:缓出
property:类型定义在LayoutAnimation.Properties中:
opacity:透明度
scaleXY:缩放
布局发生变化时,自动将视图运动到它们的新位置.调用LayoutAnimation.configureNext(),然后调用setState.
let animationConfig = defaultAnimation;
//用来创建 configureNext 所需的 config 参数的辅助函数。
animationConfig = LayoutAnimation.create(
event.duration,
LayoutAnimation.Types[event.easing],
LayoutAnimation.Properties.opacity,
);
LayoutAnimation.configureNext(animationConfig);
this.setState({
marginTop:JDDevice.height - this.NavHeight - this.textInputHeight - this.keyboardSpace + 1,
})
```'
<Animated.View style = {{marginTop:this.state.marginTop} }>
<View> </View>
</Animated.View>