public class SurfaceBox

  1. Object
  2. SurfaceNode
  3. SurfaceContainer
  4. SurfaceBox
A container that stacks its children on top of each other. Each child positions itself within the box via its own setAlignment(...). Maps to a SwiftUI ZStack, an Android FrameLayout and a layered box on desktop surfaces.

Constructors

public SurfaceBox()

Methods

public SurfaceBox add(SurfaceNode child)Adds a child node.
public SurfaceBox setPadding(int all)Sets the same padding on all four sides.
public SurfaceBox setPadding(int top, int right, int bottom, int left)Sets the padding of each side individually.
public SurfaceBox setBackground(SurfaceColor color)Sets the background color of this node.
public SurfaceBox setCornerRadius(int radius)Sets the corner radius applied to the node’s background.
public SurfaceBox setAlignment(SurfaceAlignment alignment)Sets this node’s alignment within its parent.
public SurfaceBox setWeight(int weight)Sets the flexible-space weight of this node within a row or column.
public SurfaceBox setSize(int widthDips, int heightDips)Sets a fixed size for this node.
public SurfaceBox setAction(String actionId)Assigns a tap action to this node.
public SurfaceBox setAction(String actionId, Map<String, Object> params)Assigns a tap action with parameters to this node.

Inherited methods

Constructor details

SurfaceBox

public SurfaceBox()

Method details

add

public SurfaceBox add(SurfaceNode child)
Adds a child node.

Parameters

child SurfaceNode
the node to append

Returns

this container, for chaining

setPadding

public SurfaceBox setPadding(int all)
Sets the same padding on all four sides.

Parameters

all int
padding in dips

Returns

this node, for chaining

setPadding

public SurfaceBox setPadding(int top, int right, int bottom, int left)
Sets the padding of each side individually.

Parameters

top int
top padding in dips
right int
right padding in dips
bottom int
bottom padding in dips
left int
left padding in dips

Returns

this node, for chaining

setBackground

public SurfaceBox setBackground(SurfaceColor color)
Sets the background color of this node.

Parameters

color SurfaceColor
the background color

Returns

this node, for chaining

setCornerRadius

public SurfaceBox setCornerRadius(int radius)
Sets the corner radius applied to the node’s background. May render square on Android versions below 12.

Parameters

radius int
the corner radius in dips

Returns

this node, for chaining

setAlignment

public SurfaceBox setAlignment(SurfaceAlignment alignment)
Sets this node’s alignment within its parent. In a SurfaceBox all nine positions apply; in rows and columns only the cross-axis component is used.

Parameters

alignment SurfaceAlignment
the alignment

Returns

this node, for chaining

setWeight

public SurfaceBox setWeight(int weight)
Sets the flexible-space weight of this node within a row or column. Nodes with a weight share the leftover space of the parent proportionally; a weight of 0 (the default) sizes the node to its natural size.

Parameters

weight int
the relative weight, 0 for natural sizing

Returns

this node, for chaining

setSize

public SurfaceBox setSize(int widthDips, int heightDips)
Sets a fixed size for this node. A value of 0 (the default) keeps the natural size of the respective axis.

Parameters

widthDips int
fixed width in dips, 0 for natural width
heightDips int
fixed height in dips, 0 for natural height

Returns

this node, for chaining

setAction

public SurfaceBox setAction(String actionId)
Assigns a tap action to this node. Tapping the node opens (or foregrounds) the app and delivers the action id to the handler registered with Surfaces.setActionHandler(...). Note that small iOS home-screen widgets only honor the action of the root node.

Parameters

actionId String
the app-defined action identifier

Returns

this node, for chaining

setAction

public SurfaceBox setAction(String actionId, Map<String, Object> params)
Assigns a tap action with parameters to this node. The parameter map may contain String, Number and Boolean values and is delivered verbatim with the SurfaceActionEvent.

Parameters

actionId String
the app-defined action identifier
params Map<String, Object>
parameters delivered with the action, may be null

Returns

this node, for chaining