Skip to content

Commit

Permalink
run animation when active step or step size change
Browse files Browse the repository at this point in the history
  • Loading branch information
saschoar committed Sep 17, 2020
1 parent f1c19a3 commit a64655f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
11 changes: 6 additions & 5 deletions sequencelayout/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ plugins {
id("com.github.dcendents.android-maven")
}

group="com.github.transferwise"

android {
compileSdkVersion(Versions.SDK)

defaultConfig {
minSdkVersion(Versions.MIN_SDK)
targetSdkVersion(Versions.SDK)
versionCode = 12
versionName = "1.1.0"
setProperty("archivesBaseName", "com.transferwise.sequencelayout-${versionName}")
versionCode = 13
versionName = "1.1.1"
setProperty("archivesBaseName", "com.transferwise.sequencelayout")
}

buildTypes {
Expand All @@ -35,6 +33,9 @@ android {
}
}

group = "com.github.transferwise"
version = android.defaultConfig.versionName.orEmpty()

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.KOTLIN}")
implementation("androidx.appcompat:appcompat:${Versions.ANDROIDX_APPCOMPAT}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import android.widget.FrameLayout
import androidx.annotation.ColorInt
import androidx.annotation.StyleRes
import androidx.core.view.ViewCompat
import androidx.core.view.doOnPreDraw
import kotlinx.android.synthetic.main.sequence_layout.view.*

/**
Expand All @@ -38,7 +37,7 @@ import kotlinx.android.synthetic.main.sequence_layout.view.*
* @see com.transferwise.sequencelayout.SequenceStep
*/
public class SequenceLayout(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
: FrameLayout(context, attrs, defStyleAttr) {
: FrameLayout(context, attrs, defStyleAttr), SequenceStep.OnStepChangedListener {

public constructor(context: Context) : this(context, null)
public constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
Expand Down Expand Up @@ -226,15 +225,17 @@ public class SequenceLayout(context: Context, attrs: AttributeSet?, defStyleAttr
resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_bottom)
)
}
child.onStepChangedListener = this
stepsWrapper.addView(child, params)
child.doOnPreDraw {
setProgressBarHorizontalOffset()
placeDots()
removeCallbacks(animateToActive)
post(animateToActive)
}
return
}
super.addView(child, index, params)
}

override fun onStepChanged() {
setProgressBarHorizontalOffset()
placeDots()
removeCallbacks(animateToActive)
post(animateToActive)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.widget.TextView
import androidx.annotation.Dimension
import androidx.annotation.StringRes
import androidx.annotation.StyleRes
import androidx.core.view.doOnPreDraw
import androidx.core.widget.TextViewCompat
import kotlinx.android.synthetic.main.sequence_step.view.*
import kotlin.math.max
Expand Down Expand Up @@ -50,9 +51,10 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
public constructor(context: Context) : this(context, null)

private var isActive: Boolean = false
internal var onStepChangedListener: OnStepChangedListener? = null

init {
View.inflate(getContext(), R.layout.sequence_step, this)
View.inflate(context, R.layout.sequence_step, this)

clipToPadding = false
clipChildren = false
Expand Down Expand Up @@ -183,10 +185,16 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
*/
public fun setActive(isActive: Boolean) {
this.isActive = isActive
doOnPreDraw { onStepChangedListener?.onStepChanged() }
}

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
doOnPreDraw { onStepChangedListener?.onStepChanged() }
}

fun getDotOffset(): Int =
(max(getViewHeight(anchor), getViewHeight(title)) - 8.toPx()) / 2 //TODO dynamic dot height
(max(getViewHeight(anchor), getViewHeight(title)) - 8.toPx()) / 2 //TODO dynamic dot height

private fun setupAnchor(attributes: TypedArray) {
if (!attributes.hasValue(R.styleable.SequenceStep_anchor)) {
Expand Down Expand Up @@ -255,4 +263,8 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
} else {
view.measuredHeight
}

internal interface OnStepChangedListener {
fun onStepChanged()
}
}

0 comments on commit a64655f

Please sign in to comment.