@@ -9,6 +9,7 @@ import android.widget.TextView
99import androidx.annotation.Dimension
1010import androidx.annotation.StringRes
1111import androidx.annotation.StyleRes
12+ import androidx.core.view.doOnPreDraw
1213import androidx.core.widget.TextViewCompat
1314import kotlinx.android.synthetic.main.sequence_step.view.*
1415import 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