Skip to content

Commit 8e0823f

Browse files
authored
Merge pull request #108 from afollestad/main
Override setBackground() like we do setVisibility() in WorkflowViewStub.
2 parents 7069dc0 + 86f6dcb commit 8e0823f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

workflow-ui/core-android/api/core-android.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public final class com/squareup/workflow1/ui/WorkflowViewStub : android/view/Vie
180180
public final fun getActual ()Landroid/view/View;
181181
public final fun getInflatedId ()I
182182
public final fun getReplaceOldViewInParent ()Lkotlin/jvm/functions/Function2;
183+
public fun setBackground (Landroid/graphics/drawable/Drawable;)V
183184
public final fun setInflatedId (I)V
184185
public final fun setReplaceOldViewInParent (Lkotlin/jvm/functions/Function2;)V
185186
public fun setVisibility (I)V

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowViewStub.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.squareup.workflow1.ui
1717

1818
import android.content.Context
19+
import android.graphics.drawable.Drawable
1920
import android.util.AttributeSet
2021
import android.view.View
2122
import android.view.ViewGroup
@@ -121,6 +122,23 @@ class WorkflowViewStub @JvmOverloads constructor(
121122
if (actual != this) actual.visibility = visibility
122123
}
123124

125+
/**
126+
* Sets the background of this stub as usual, and also that of [actual].
127+
* Any new views created by [update] will be assigned this background.
128+
*
129+
* If the provided [background] is null, the background of [actual] will be left alone rather
130+
* than being nullified.
131+
*/
132+
override fun setBackground(background: Drawable?) {
133+
super.setBackground(background)
134+
// `actual` can be null here when setBackground() is called from the constructor, before
135+
// `actual` is really assigned to `this`. Thanks, Android!
136+
@Suppress("SENSELESS_COMPARISON")
137+
if (actual != this && actual != null && background != null) {
138+
actual.background = background
139+
}
140+
}
141+
124142
/**
125143
* Replaces this view with one that can display [rendering]. If the receiver
126144
* has already been replaced, updates the replacement if it [canShowRendering].
@@ -160,6 +178,7 @@ class WorkflowViewStub @JvmOverloads constructor(
160178
.also { newView ->
161179
if (inflatedId != NO_ID) newView.id = inflatedId
162180
newView.visibility = visibility
181+
background?.let { newView.background = it }
163182
replaceOldViewInParent(parent, newView)
164183
actual = newView
165184
}

0 commit comments

Comments
 (0)