android - 如何在屏幕之间共享反应原生组件
问题描述
我正在尝试在两个屏幕之间共享 react native 组件,就像你可以在 ios 中使用hero库一样。我希望组件在两个屏幕之间进行动画处理。
我已经尝试过流体转换库,但我无法让它工作。
IE。
解决方案
为了制作这样的动画,您可以使用 TransitionManager,我个人通常将它与 constraintLayouts 一起使用。
为此,您需要 2 个约束布局(两者都需要具有将出现在屏幕上的所有元素,并且在布局之间更改的属性应该只是约束本身。)
使用 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));
结果:
但是这种动画也可以通过其他方式制作,请查看官方文档以供参考:https ://developer.android.com/training/transitions
注意:要获得反向动画也只需应用其他约束集。
推荐阅读
- registry - 是否可以从注册表值发送 shell 命令
- ocaml - 在绑定线程链中将 ref 设置为 Lwt_io.read_line 的结果
- c++ - 为什么我不能在用新对象替换对象之前删除它?
- mongodb - 类注册模式推荐
- javascript - jQuery:IF 语句中的 addClass 不切换
- haskell - 为自定义 NestedList 类型实例化 Show typeclass
- java - 如何修复 java.util.NoSuchElementException
- python - PYTHON - 检查单元格是否包含来自另一个单元格的字符串
- javascript - 无法通过 AJAX (Cordova) 调用 PHP 文件
- java - 有没有办法简单地监听对象的更改,而不是进行了哪些更改?