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>