Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions workflow-ui/core-android/api/core-android.api
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public final class com/squareup/workflow1/ui/WorkflowViewStub : android/view/Vie
public final fun getActual ()Landroid/view/View;
public final fun getInflatedId ()I
public final fun getReplaceOldViewInParent ()Lkotlin/jvm/functions/Function2;
public fun setBackground (Landroid/graphics/drawable/Drawable;)V
public final fun setInflatedId (I)V
public final fun setReplaceOldViewInParent (Lkotlin/jvm/functions/Function2;)V
public fun setVisibility (I)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.squareup.workflow1.ui

import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -121,6 +122,23 @@ class WorkflowViewStub @JvmOverloads constructor(
if (actual != this) actual.visibility = visibility
}

/**
* Sets the background of this stub as usual, and also that of [actual].
* Any new views created by [update] will be assigned this background.
*
* If the provided [background] is null, the background of [actual] will be left alone rather
* than being nullified.
*/
override fun setBackground(background: Drawable?) {
super.setBackground(background)
// `actual` can be null here when setBackground() is called from the constructor, before
// `actual` is really assigned to `this`. Thanks, Android!
@Suppress("SENSELESS_COMPARISON")
if (actual != this && actual != null && background != null) {
actual.background = background
}
}

/**
* Replaces this view with one that can display [rendering]. If the receiver
* has already been replaced, updates the replacement if it [canShowRendering].
Expand Down Expand Up @@ -160,6 +178,7 @@ class WorkflowViewStub @JvmOverloads constructor(
.also { newView ->
if (inflatedId != NO_ID) newView.id = inflatedId
newView.visibility = visibility
background?.let { newView.background = it }
replaceOldViewInParent(parent, newView)
actual = newView
}
Expand Down