Skip to content

Commit

Permalink
Fix the sample app about shared elements between fragments for animat…
Browse files Browse the repository at this point in the history
…ions

Summary: Fix the sample app about shared elements between fragments for animations

Differential Revision: D55199237

fbshipit-source-id: df3a44a4463fca589a9e04c54bf5f22bf1741e99
  • Loading branch information
jettbow authored and facebook-github-bot committed Mar 22, 2024
1 parent 760ff2f commit 047d69d
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static class FirstFragment extends Fragment {
LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
postponeEnterTransition();

Activity activity = getActivity();
if (activity == null) {
Expand Down Expand Up @@ -110,6 +111,14 @@ public void onClick(View v) {
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layout.addView(boxInLithoView);
LithoView.OnDirtyMountListener dirtyMountListener =
new LithoView.OnDirtyMountListener() {
@Override
public void onDirtyMount(LithoView view) {
startPostponedEnterTransition();
}
};
boxInLithoView.setOnDirtyMountListener(dirtyMountListener);

layout.addView(new View(activity), 200, 200);
TextView componentHostTitle = new TextView(activity);
Expand All @@ -123,8 +132,8 @@ public void onClick(View v) {
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layout.addView(boxInComponentHost);

layout.setClipChildren(false);
boxInComponentHost.setOnDirtyMountListener(dirtyMountListener);

return layout;
}
Expand Down Expand Up @@ -156,6 +165,7 @@ public void nextFragment(View view, int color) {
.beginTransaction()
.addSharedElement(view, transitionName)
.replace(CONTENT_VIEW_ID, fragment)
.setReorderingAllowed(true)
.addToBackStack(null)
.commit();
}
Expand Down Expand Up @@ -209,8 +219,13 @@ public void onDirtyMount(LithoView view) {
}
};
lithoView.setOnDirtyMountListener(dirtyMountListener);

return lithoView;
// We can not set LithoView as the root view of Fragment because the enforement of alpha
// value here https://fburl.com/code/2ilg549t causes the transition to fail. A workaround is
// to wrap the LithoView in a FrameLayout.
// TODO: T183183765
final FrameLayout frameLayout = new FrameLayout(activity);
frameLayout.addView(lithoView);
return frameLayout;
}
}
}

0 comments on commit 047d69d

Please sign in to comment.