Skip to content

Commit 87e82bd

Browse files
committed
master: fixed changing props while viewcompat is being laid out
1 parent d360761 commit 87e82bd

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,13 @@ implementation 'com.params.stepview:stepview:1.0.0'
9494

9595
* The view can be scrolled if the content exceeds the available width.
9696
* You can also scroll to a particular step by calling ```statusViewScroller.scrollToStep(stepCount)```
97+
98+
### Changing properties at runtime
99+
100+
* You can also easily change any property at runtime as described below.
101+
```
102+
statusViewScroller.statusView.run {
103+
currentCount = 2
104+
circleFillColorCurrent = Color.RED
105+
}
106+
```
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package params.com.statusView
22

3-
import android.support.v7.app.AppCompatActivity
3+
import android.graphics.Color
44
import android.os.Bundle
5+
import android.support.v7.app.AppCompatActivity
56
import kotlinx.android.synthetic.main.activity_main.*
67

78
class MainActivity : AppCompatActivity() {
89

910
override fun onCreate(savedInstanceState: Bundle?) {
1011
super.onCreate(savedInstanceState)
1112
setContentView(R.layout.activity_main)
13+
statusViewScroller.statusView.run {
14+
currentCount = 2
15+
circleFillColorCurrent = Color.RED
16+
}
1217

1318

19+
}
1420

1521

16-
}
1722
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
<params.com.stepview.StatusViewScroller
12+
android:id="@+id/statusViewScroller"
1213
android:layout_width="wrap_content"
1314
android:layout_height="wrap_content"
1415
app:layout_constraintTop_toTopOf="parent"

stepview/src/main/java/params/com/stepview/StatusView.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ class StatusView @JvmOverloads constructor(
409409
//Stores information about every status text and its dimension properties
410410
private class StatusInfo(val text: String, var width: Float = 0.0f, var height: Float = 0.0f, var staticLayout: StaticLayout? = null)
411411

412+
private var propsIntialisedOnce = false
412413

413414
init {
414415

@@ -527,7 +528,7 @@ class StatusView @JvmOverloads constructor(
527528
mTextPaintLabelCurrent.typeface = this
528529
}
529530

530-
531+
propsIntialisedOnce = true
531532
}
532533

533534
private fun initCirclePaints() {
@@ -1092,7 +1093,7 @@ class StatusView @JvmOverloads constructor(
10921093
inner class OnLayoutProp<T>(private var field: T, private inline var func: () -> Unit = {}) {
10931094
operator fun setValue(thisRef: Any?, p: KProperty<*>, v: T) {
10941095
field = v
1095-
if (ViewCompat.isLaidOut(this@StatusView)) {
1096+
if (propsIntialisedOnce) {
10961097
drawingData.clear()
10971098
func()
10981099
requestLayout()
@@ -1113,7 +1114,7 @@ class StatusView @JvmOverloads constructor(
11131114
inner class OnValidateProp<T>(private var field: T, private inline var func: () -> Unit = {}) {
11141115
operator fun setValue(thisRef: Any?, p: KProperty<*>, v: T) {
11151116
field = v
1116-
if (ViewCompat.isLaidOut(this@StatusView)) {
1117+
if (propsIntialisedOnce) {
11171118
func()
11181119
invalidate()
11191120

0 commit comments

Comments
 (0)