Skip to content

[Previewer] Inline function will cause the preview to fail #357

Description

@zhangz1han

Create the following function:

import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.DefaultGroupName
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

inline fun buildImageVector(
    name: String = DefaultGroupName,
    defaultWidth: Dp,
    defaultHeight: Dp,
    viewportWidth: Float,
    viewportHeight: Float,
    tintColor: Color = Color.Unspecified,
    tintBlendMode: BlendMode = BlendMode.SrcIn,
    autoMirror: Boolean = false,
    builderAction: ImageVector.Builder.() -> Unit
): ImageVector {
    contract { callsInPlace(builderAction, InvocationKind.EXACTLY_ONCE) }
    return ImageVector.Builder(
        name, defaultWidth, defaultHeight,
        viewportWidth, viewportHeight,
        tintColor, tintBlendMode, autoMirror
    ).apply(builderAction).build()
}

Using this function in ImageVector will cause the preview to fail:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions