Skip to content

Commit

Permalink
improved duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamidreza Etebarian committed Feb 26, 2019
1 parent 1f8b5cb commit fca7e01
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Expand Up @@ -47,7 +47,7 @@ class MeowBottomNavigation : FrameLayout {
private lateinit var bezierView: BezierView

init {
heightCell = dip(context, 68)
heightCell = dip(context, 72)
}

constructor(context: Context) : super(context) {
Expand Down Expand Up @@ -163,7 +163,14 @@ class MeowBottomNavigation : FrameLayout {
private fun anim(cell: MeowBottomNavigationCell, id: Int, enableAnimation: Boolean = true) {
isAnimating = true

val animDuration = if (enableAnimation) 750L else 1L
val pos = getModelPosition(id)
val nowPos = getModelPosition(selectedId)

val nPos = if (nowPos < 0) 0 else nowPos
val dif = Math.abs(pos - nPos)
val d = (dif) * 100L + 150L

val animDuration = if (enableAnimation) d else 1L
val animInterpolator = FastOutSlowInInterpolator()

val anim = ValueAnimator.ofFloat(0f, 1f)
Expand All @@ -184,8 +191,6 @@ class MeowBottomNavigation : FrameLayout {
start()
}

val pos = getModelPosition(id)
val nowPos = getModelPosition(selectedId)
if (Math.abs(pos - nowPos) > 1) {
val progressAnim = ValueAnimator.ofFloat(0f, 1f)
progressAnim.apply {
Expand All @@ -200,6 +205,9 @@ class MeowBottomNavigation : FrameLayout {
}

cell.isFromLeft = pos > nowPos
cells.forEach {
it.duration = d
}
}

fun isShowing(id: Int): Boolean {
Expand Down
Expand Up @@ -103,6 +103,7 @@ class MeowBottomNavigationCell : RelativeLayout, LayoutContainer {
}

var isFromLeft = false
var duration = 0L
private var progress = 0f
set(value) {
field = value
Expand Down Expand Up @@ -201,10 +202,11 @@ class MeowBottomNavigationCell : RelativeLayout, LayoutContainer {
}

private fun animateProgress(enableCell: Boolean, isAnimate: Boolean = true) {
val d = if (enableCell) duration else 250
val anim = ValueAnimator.ofFloat(0f, 1f)
anim.apply {
startDelay = if (enableCell) 250L else 0L
duration = if (isAnimate) 500L else 1L
startDelay = if (enableCell) d / 4 else 0L
duration = if (isAnimate) d else 1L
interpolator = FastOutSlowInInterpolator()
addUpdateListener {
val f = it.animatedFraction
Expand Down
Expand Up @@ -41,5 +41,17 @@ class MainActivity : AppCompatActivity() {//todo add ic_launcher
}
tv_selected.text = "$name page is selected"
}

bottomNavigation.setOnClickMenuListener {
val name = when (it.id) {
ID_HOME -> "HOME"
ID_EXPLORE -> "EXPLORE"
ID_MESSAGE -> "MESSAGE"
ID_NOTIFICATION -> "NOTIFICATION"
ID_ACCOUNT -> "ACCOUNT"
else -> ""
}
// Toast.makeText(this, "$name is clicked", Toast.LENGTH_SHORT).show()
}
}
}
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/activity_main.xml
Expand Up @@ -38,7 +38,7 @@
app:mbn_countTextColor="#ffffff"
app:mbn_countTypeface="fonts/SourceSansPro-Regular.ttf"
app:mbn_defaultIconColor="#90a4ae"
app:mbn_rippleColor="#ffffff"
app:mbn_rippleColor="#2f424242"
app:mbn_selectedIconColor="#3c415e"
app:mbn_shadowColor="#1f212121" />

Expand Down

0 comments on commit fca7e01

Please sign in to comment.