How to exclude some views when animating with Shared Element

19 views Asked by At

FAB and AdMob's banner ad view is not fading immediately during transition of views that has shared element.

I have the below setup and this is how it currently looks like.

RecyclerView ItemView

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingHorizontal="@dimen/space_16"
    android:paddingTop="@dimen/space_4">

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/postImage"
        android:layout_width="match_parent"
        android:layout_height="225dp"
        android:adjustViewBounds="true"
        android:transitionName="featured_image"
        android:background="@color/colorPrimaryDark_Primary"
        android:src="@drawable/ic_launcher_colored" />

    <com.google.android.material.textview.MaterialTextView
        android:id="@+id/postTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="2"
        android:paddingVertical="@dimen/space_12"
        android:textSize="@dimen/textSize16"
        android:textStyle="bold"
        tools:text="@tools:sample/cities" />

    <com.google.android.material.textview.MaterialTextView
        android:id="@+id/postTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableStart="@drawable/ic_calendar"
        android:drawablePadding="@dimen/space_8"
        android:gravity="center_vertical"
        android:paddingBottom="@dimen/space_12"
        android:textAllCaps="true"
        tools:text="@tools:sample/date/mmddyy" />

    <com.google.android.material.divider.MaterialDivider
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <com.google.android.material.textview.MaterialTextView
        android:id="@+id/labelHead"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/space_16"
        android:paddingBottom="@dimen/space_4"
        android:text="@string/related_content"
        android:textAllCaps="true"
        android:textSize="@dimen/textSize12"
        android:textStyle="bold" />

</androidx.appcompat.widget.LinearLayoutCompat>

Second Activity

<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".presentation.BlogViewActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:liftOnScroll="false"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/collapsingToolbarLayoutLargeSize"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|snap|enterAlways|enterAlwaysCollapsed"
            app:maxLines="3">

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/featuredImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:fitsSystemWindows="true"
                android:transitionName="featured_image"
                android:background="@color/colorWhite_PrimaryDark"
                android:src="@drawable/placeholder"
                app:layout_collapseMode="parallax" />

            <com.google.android.material.appbar.MaterialToolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:navigationIcon="?attr/homeAsUpIndicator"
                app:navigationContentDescription="@string/abc_action_bar_up_description"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|snap|enterAlways|enterAlwaysCollapsed"
                app:title="@string/vwap" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.appcompat.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <org.sufficientlysecure.htmltextview.HtmlTextView
                android:id="@+id/description_html_txt_v"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingHorizontal="@dimen/space_12"
                android:paddingTop="@dimen/space_48"
                android:paddingBottom="@dimen/space_12"
                android:text="@tools:sample/lorem/random"
                android:textSize="@dimen/textSize14" />

            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingVertical="@dimen/space_16"
                android:visibility="visible">

                <com.google.android.material.textview.MaterialTextView
                    android:id="@+id/labelTxt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingHorizontal="@dimen/space_12"
                    android:paddingBottom="@dimen/space_8"
                    android:text="@string/related_content"
                    android:textAllCaps="true"
                    android:textColor="@color/colorPrimaryDark_Accent"
                    android:textSize="@dimen/textSize24" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/feedRecycler"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clipToPadding="false"
                    android:nestedScrollingEnabled="false"
                    android:paddingHorizontal="@dimen/space_12" />

            </androidx.appcompat.widget.LinearLayoutCompat>

        </androidx.appcompat.widget.LinearLayoutCompat>

    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/visitWeb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/space_12"
        android:contentDescription="@string/news"
        android:src="@drawable/ic_open_tab"
        app:layout_anchor="@id/appBar"
        app:layout_anchorGravity="bottom|end" />

    <FrameLayout
        android:id="@+id/ad_frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Inside a fragment class

val optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(
                    requireActivity(),
                    featuredImage,
                    featuredImage.transitionName
                )

startActivity(Intent(this@with, BlogViewActivity::class.java).apply {
                    putExtra(BlogViewActivity.INTENT_NEWS, domain)
                }, optionsCompat.toBundle())

There is also noticeable glitch with BottomNavigationView. Is there a way to immediately hide some views when the activity of target view is exiting?

0

There are 0 answers