My app used to have a shared element transition from a fragment to an activity. I am not sure exactly when it stopped working. I have made minor code changes, but nothing that affects the code around the transitions. The biggest thing I have done is update my support libraries to v24.2.1 (from v23.3.0). I am wondering if I am just overlooking something silly, or if the support library change did something. Relevant code snippets follow:
The code that starts the shared element transition:
public void PreviewClicked(object sender, EventArgs e)
{
var intent = new Intent(Activity, typeof(RoutineActivity));
intent.PutExtra(RoutineBundleKeys.BLOB_ID, _selectedBlobId.ToString());
intent.PutExtra(RoutineBundleKeys.ROUTINE_TITLE, _selectedTitle);
intent.PutExtra(RoutineBundleKeys.ROUTINE_HTML, ViewModel.Html);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
_selectedPreview.TransitionGroup = true;
ActivityOptionsCompat options = ActivityOptionsCompat.MakeSceneTransitionAnimation(Activity,
_selectedPreview,
"webview_preview_transition");
StartActivity(intent, options.ToBundle());
}
else
{
StartActivity(intent);
}
}
And the XML element that is being shared (_selectedPreview in the snippet above):
<WebView
android:id="@+id/routine_preview"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center_vertical"
android:scrollbars="none"
android:transitionName="webview_preview_transition" />
The OnCreate method in the finishing Activity:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.routine_activity_layout);
_routineTitle = Intent.GetStringExtra(RoutineBundleKeys.ROUTINE_TITLE);
var titleToolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.doc_title_toolbar);
SetSupportActionBar(titleToolbar);
SupportActionBar.Title = _routineTitle;
_htmlString = Intent.GetStringExtra(RoutineBundleKeys.ROUTINE_HTML);
if (_htmlString != null)
{
_routineView = FindViewById<WebView>(Resource.Id.routine_frame);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
_routineView.TransitionGroup = true;
}
_routineView.Settings.BuiltInZoomControls = true;
_routineView.Settings.DisplayZoomControls = false;
string mimeType = "text/html";
string encoding = "UTF-8";
_routineView.LoadDataWithBaseURL("", _htmlString, mimeType, encoding, "");
}
else
{
var blobIdString = Intent.GetStringExtra(RoutineBundleKeys.BLOB_ID);
_blobId = new Guid(blobIdString);
RoutineFragment routineFragment = new RoutineFragment(_blobId);
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.routine_frame, routineFragment).Commit();
}
}
And the XML for this Activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nothing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/doc_title_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<WebView
android:id="@+id/routine_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="webview_preview_transition" />
</LinearLayout>
In my base theme, I do have <item name="android:windowContentTransitions">true</item>
I am at a loss what the issue might be. It seems like everything is set up right.
EDIT 02 Feb 2017: Xamarin developers have confirmed that it is a bug.
I was never able to get this working, but I suspect it might be a Xamarin bug. I found this bug on the AndroidSupportComponents issue tracker. Apparently it was found in rc1 of the support library but I do not see any developer response.