如何在屏幕之间共享React本机组件

时间:2019-08-05 15:33:11

标签: android ios react-native

我试图在两个屏幕之间共享React本机组件,就像您可以使用ios中的hero库一样。我希望组件在两个屏幕之间进行动画处理。

我尝试了流体转换库,但无法正常工作。

即。

1 个答案:

答案 0 :(得分:0)

为了制作这样的动画,您可以使用TransitionManager,我个人通常将其与ConstraintLayouts一起使用。

要执行此操作,您需要的是2个ConstraintLayouts(两者都需要具有将出现在屏幕上的所有元素,并且在布局之间更改的属性应该仅是约束条件本身。)

使用2种布局,您可以像这样从一个到另一个制作动画:

final ConstraintSet constraint1 = new ConstraintSet();
constraint1.clone(getApplicationContext(), R.layout.layout_shrunk);

final ConstraintSet constraint2 = new ConstraintSet();
constraint2.clone(getApplicationContext(), R.layout.layout_expanded);

//The view you pass as an argument to both methods should be the layout's root.
TransitionManager.beginDelayedTransition((ConstraintLayout)findViewById(R.id.layout_root));
constraint2.applyTo((ConstraintLayout) findViewById(R.id.layout_root));

结果:

enter image description here

但是也可以通过其他方式制作这种动画,请查阅官方文档以供参考:https://developer.android.com/training/transitions

注意:也要获得反向动画,只需应用其他约束集即可。

相关问题