Skip to content

Commit

Permalink
Add null type for initial fragment transition animation
Browse files Browse the repository at this point in the history
  • Loading branch information
selimtoksal committed Nov 10, 2019
1 parent a22da38 commit cdac38e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/com/trendyol/medusa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class MainActivity : AppCompatActivity(), Navigator.NavigatorListener {
R.id.fragmentContainer,
rootFragmentProvider,
navigatorListener = this,
navigatorConfiguration = NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE),
transitionAnimationType = TransitionAnimationType.BOTTOM_TO_TOP)
navigatorConfiguration = NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE))

private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/trendyol/medusa/MainActivity2.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
rootsFragmentProvider,
this,
new NavigatorConfiguration(1, true, NavigatorTransaction.SHOW_HIDE),
TransitionAnimationType.BOTTOM_TO_TOP);
null);

multipleStackNavigator.initialize(savedInstanceState);
final SwitchCompat restartRootFragmentCheckBox = findViewById(R.id.restartSwitch);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/trendyol/medusa/SampleFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import com.trendyol.medusalib.navigator.transitionanimation.TransitionAnimationType
import kotlin.random.Random

class SampleFragment : BaseFragment() {
Expand All @@ -19,7 +20,7 @@ class SampleFragment : BaseFragment() {
view.findViewById<LinearLayout>(R.id.root).setBackgroundColor(Color.argb(255, Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)))

view.findViewById<Button>(R.id.button).setOnClickListener {
multipleStackNavigator!!.start(FragmentGenerator.generateNewFragment())
multipleStackNavigator!!.start(FragmentGenerator.generateNewFragment(), TransitionAnimationType.RIGHT_TO_LEFT)
}
return view
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open class MultipleStackNavigator(
private val rootFragmentProvider: List<() -> Fragment>,
private var navigatorListener: Navigator.NavigatorListener? = null,
private val navigatorConfiguration: NavigatorConfiguration = NavigatorConfiguration(),
private val transitionAnimationType: TransitionAnimationType
private val transitionAnimationType: TransitionAnimationType? = null
) : Navigator {

private val tagCreator: TagCreator = UniqueTagCreator()
Expand Down Expand Up @@ -52,7 +52,7 @@ open class MultipleStackNavigator(
start(fragment, DEFAULT_GROUP_NAME, transitionAnimation)
}

override fun start(fragment: Fragment, fragmentGroupName: String, transitionAnimation: TransitionAnimationType) {
override fun start(fragment: Fragment, fragmentGroupName: String, transitionAnimation: TransitionAnimationType?) {

val createdTag = tagCreator.create(fragment)
val currentTabIndex = fragmentStackState.getSelectedTabIndex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface Navigator {
* @param transitionAnimation will be used start and remove fragment transition animation
* all fragments which has the same group name.
*/
fun start(fragment: Fragment, fragmentGroupName: String, transitionAnimation: TransitionAnimationType)
fun start(fragment: Fragment, fragmentGroupName: String, transitionAnimation: TransitionAnimationType?)

/**
* Adds new fragment to the fragment stack with given tab index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class FragmentManagerController(private val fragmentManager: FragmentManager,
TransitionAnimationType.BOTTOM_TO_TOP -> setCustomAnimations(R.anim.empty_animation, R.anim.exit_to_bottom)
TransitionAnimationType.TOP_TO_BOTTOM -> setCustomAnimations(R.anim.empty_animation, R.anim.exit_to_top)
TransitionAnimationType.FADE_IN_OUT -> setCustomAnimations(R.anim.empty_animation, R.anim.fade_out)
else -> setCustomAnimations(R.anim.empty_animation, R.anim.exit_to_right)
}

currentTransaction?.remove(getFragment(fragmentTag))
Expand Down Expand Up @@ -88,7 +87,6 @@ class FragmentManagerController(private val fragmentManager: FragmentManager,
TransitionAnimationType.BOTTOM_TO_TOP -> setCustomAnimations(R.anim.enter_from_bottom, R.anim.empty_animation)
TransitionAnimationType.TOP_TO_BOTTOM -> setCustomAnimations(R.anim.enter_from_top, R.anim.empty_animation)
TransitionAnimationType.FADE_IN_OUT -> setCustomAnimations(R.anim.fade_in, R.anim.empty_animation)
else -> setCustomAnimations(R.anim.enter_from_left, R.anim.empty_animation)
}
currentTransaction?.add(containerId, fragmentData.fragment, fragmentData.fragmentTag)
}
Expand Down

0 comments on commit cdac38e

Please sign in to comment.