Animation 反应本机布局动画滚动视图容器大小
我在ScrollView中包装了一些组件,在某些情况下,最底部的组件不应该渲染。发生这种情况时,我使用LayoutImation将其隐藏。问题是,当组件消失时,ScrollView会直接跳到新的内容高度,而没有任何动画。 我想使用LayoutImation,因为我有内容高度未知的屏幕 如果您查看图像,当按下按钮时,屏幕将立即跳转到蓝色框,而不显示任何动画Animation 反应本机布局动画滚动视图容器大小,animation,react-native,layout-animation,Animation,React Native,Layout Animation,我在ScrollView中包装了一些组件,在某些情况下,最底部的组件不应该渲染。发生这种情况时,我使用LayoutImation将其隐藏。问题是,当组件消失时,ScrollView会直接跳到新的内容高度,而没有任何动画。 我想使用LayoutImation,因为我有内容高度未知的屏幕 如果您查看图像,当按下按钮时,屏幕将立即跳转到蓝色框,而不显示任何动画 state = { showGreenBox: false }; renderBottomBox() { if (this.s
state = { showGreenBox: false };
renderBottomBox() {
if (this.state.showGreenBox) {
return (
<View style={{ height: 300, width: 100, backgroundColor: 'green' }} />
);
}
}
render() {
return (
<ScrollView>
<View style={{ height: 300, width: 100, backgroundColor: 'red' }} />
<View style={{ height: 300, width: 100, backgroundColor: 'blue' }} />
{this.renderBottomBox()}
<TouchableOpacity
onPress={() => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
this.setState({ showGreenBox: !this.state.showGreenBox });
}}
>
<Text>Press to collapse green box</Text>
</TouchableOpacity>
</ScrollView>
);
}
state={showGreenBox:false};
renderBottomBox(){
如果(此.state.showGreenBox){
返回(
);
}
}
render(){
返回(
{this.renderBottomBox()}
{
LayoutImation.configureNext(LayoutImation.Presets.spring);
this.setState({showGreenBox:!this.state.showGreenBox});
}}
>
按下可折叠绿色框
);
}
我复制粘贴您的代码,它为我提供了完美的动画…使用android的“SetLayoutImationEnabledExperimental”try@K.Wu您是否先向下滚动到屏幕的最底部,然后按下按钮,使绿色框消失?你使用的是安卓还是iOS?@PTT我使用的是iOS。应该提到。@Jaros你找到解决办法了吗?