Skip to content

Commit a64655f

Browse files
committed
run animation when active step or step size change
1 parent f1c19a3 commit a64655f

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

sequencelayout/build.gradle.kts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ plugins {
55
id("com.github.dcendents.android-maven")
66
}
77

8-
group="com.github.transferwise"
9-
108
android {
119
compileSdkVersion(Versions.SDK)
1210

1311
defaultConfig {
1412
minSdkVersion(Versions.MIN_SDK)
1513
targetSdkVersion(Versions.SDK)
16-
versionCode = 12
17-
versionName = "1.1.0"
18-
setProperty("archivesBaseName", "com.transferwise.sequencelayout-${versionName}")
14+
versionCode = 13
15+
versionName = "1.1.1"
16+
setProperty("archivesBaseName", "com.transferwise.sequencelayout")
1917
}
2018

2119
buildTypes {
@@ -35,6 +33,9 @@ android {
3533
}
3634
}
3735

36+
group = "com.github.transferwise"
37+
version = android.defaultConfig.versionName.orEmpty()
38+
3839
dependencies {
3940
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.KOTLIN}")
4041
implementation("androidx.appcompat:appcompat:${Versions.ANDROIDX_APPCOMPAT}")

sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceLayout.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import android.widget.FrameLayout
1212
import androidx.annotation.ColorInt
1313
import androidx.annotation.StyleRes
1414
import androidx.core.view.ViewCompat
15-
import androidx.core.view.doOnPreDraw
1615
import kotlinx.android.synthetic.main.sequence_layout.view.*
1716

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

4342
public constructor(context: Context) : this(context, null)
4443
public constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
@@ -226,15 +225,17 @@ public class SequenceLayout(context: Context, attrs: AttributeSet?, defStyleAttr
226225
resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_bottom)
227226
)
228227
}
228+
child.onStepChangedListener = this
229229
stepsWrapper.addView(child, params)
230-
child.doOnPreDraw {
231-
setProgressBarHorizontalOffset()
232-
placeDots()
233-
removeCallbacks(animateToActive)
234-
post(animateToActive)
235-
}
236230
return
237231
}
238232
super.addView(child, index, params)
239233
}
234+
235+
override fun onStepChanged() {
236+
setProgressBarHorizontalOffset()
237+
placeDots()
238+
removeCallbacks(animateToActive)
239+
post(animateToActive)
240+
}
240241
}

sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceStep.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.widget.TextView
99
import androidx.annotation.Dimension
1010
import androidx.annotation.StringRes
1111
import androidx.annotation.StyleRes
12+
import androidx.core.view.doOnPreDraw
1213
import androidx.core.widget.TextViewCompat
1314
import kotlinx.android.synthetic.main.sequence_step.view.*
1415
import kotlin.math.max
@@ -50,9 +51,10 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
5051
public constructor(context: Context) : this(context, null)
5152

5253
private var isActive: Boolean = false
54+
internal var onStepChangedListener: OnStepChangedListener? = null
5355

5456
init {
55-
View.inflate(getContext(), R.layout.sequence_step, this)
57+
View.inflate(context, R.layout.sequence_step, this)
5658

5759
clipToPadding = false
5860
clipChildren = false
@@ -183,10 +185,16 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
183185
*/
184186
public fun setActive(isActive: Boolean) {
185187
this.isActive = isActive
188+
doOnPreDraw { onStepChangedListener?.onStepChanged() }
189+
}
190+
191+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
192+
super.onSizeChanged(w, h, oldw, oldh)
193+
doOnPreDraw { onStepChangedListener?.onStepChanged() }
186194
}
187195

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

191199
private fun setupAnchor(attributes: TypedArray) {
192200
if (!attributes.hasValue(R.styleable.SequenceStep_anchor)) {
@@ -255,4 +263,8 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
255263
} else {
256264
view.measuredHeight
257265
}
266+
267+
internal interface OnStepChangedListener {
268+
fun onStepChanged()
269+
}
258270
}

0 commit comments

Comments
 (0)