From 8fda806625765aee533d6cdea1ab4fff64c1d352 Mon Sep 17 00:00:00 2001 From: "selim.toksal" Date: Tue, 26 Nov 2019 16:39:23 +0300 Subject: [PATCH 1/2] Add transitionAnimationType from main activities Create SharedElementSampleSecondFragment with image view Add image view to SampleFragment for shared element Add and create SharedElement class to FragmentData Add hasSharedElement control FragmentManagerController Implement shared element transition Add new start method for shared element data --- .../java/com/trendyol/medusa/MainActivity.kt | 3 +- .../com/trendyol/medusa/MainActivity2.java | 2 +- .../com/trendyol/medusa/SampleFragment.kt | 11 +++++- .../SharedElementSampleSecondFragment.kt | 23 +++++++++++ app/src/main/res/layout/fragment_sample.xml | 8 ++++ app/src/main/res/layout/fragment_second.xml | 17 +++++++++ .../navigator/MultipleStackNavigator.kt | 31 +++++++++++++-- .../trendyol/medusalib/navigator/Navigator.kt | 11 ++++++ .../controller/FragmentManagerController.kt | 38 +++++++++++++++---- .../medusalib/navigator/data/FragmentData.kt | 4 +- .../transitionanimation/SharedElement.kt | 5 +++ 11 files changed, 138 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/trendyol/medusa/SharedElementSampleSecondFragment.kt create mode 100644 app/src/main/res/layout/fragment_second.xml create mode 100644 medusalib/src/main/java/com/trendyol/medusalib/navigator/transitionanimation/SharedElement.kt diff --git a/app/src/main/java/com/trendyol/medusa/MainActivity.kt b/app/src/main/java/com/trendyol/medusa/MainActivity.kt index e988e38..b51ef91 100644 --- a/app/src/main/java/com/trendyol/medusa/MainActivity.kt +++ b/app/src/main/java/com/trendyol/medusa/MainActivity.kt @@ -33,7 +33,8 @@ class MainActivity : AppCompatActivity(), Navigator.NavigatorListener { R.id.fragmentContainer, rootFragmentProvider, navigatorListener = this, - navigatorConfiguration = NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE)) + navigatorConfiguration = NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE), + transitionAnimationType = TransitionAnimationType.RIGHT_TO_LEFT) private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> when (item.itemId) { diff --git a/app/src/main/java/com/trendyol/medusa/MainActivity2.java b/app/src/main/java/com/trendyol/medusa/MainActivity2.java index 21ba623..4ae133f 100644 --- a/app/src/main/java/com/trendyol/medusa/MainActivity2.java +++ b/app/src/main/java/com/trendyol/medusa/MainActivity2.java @@ -81,7 +81,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { rootsFragmentProvider, this, new NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE), - null); + TransitionAnimationType.RIGHT_TO_LEFT); multipleStackNavigator.initialize(savedInstanceState); final SwitchCompat restartRootFragmentCheckBox = findViewById(R.id.restartSwitch); diff --git a/app/src/main/java/com/trendyol/medusa/SampleFragment.kt b/app/src/main/java/com/trendyol/medusa/SampleFragment.kt index 61ed00e..a989855 100644 --- a/app/src/main/java/com/trendyol/medusa/SampleFragment.kt +++ b/app/src/main/java/com/trendyol/medusa/SampleFragment.kt @@ -6,8 +6,10 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button +import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView +import com.trendyol.medusalib.navigator.transitionanimation.SharedElement import com.trendyol.medusalib.navigator.transitionanimation.TransitionAnimationType import kotlin.random.Random @@ -19,9 +21,16 @@ class SampleFragment : BaseFragment() { view.findViewById(R.id.root).setBackgroundColor(Color.argb(255, Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))) + //Using for shared element transition + val image = view.findViewById(R.id.ic_android) view.findViewById