> For the complete documentation index, see [llms.txt](https://docs.verygoodsecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/android-sdk/compose.md). Agents can also search and read this documentation through its [MCP server](https://docs.verygoodsecurity.com/~gitbook/mcp).

# Jetpack Compose

VGS Collect Android SDK provide support for integration with apps that use Jetpack Compose UI building toolkit by providing composable wrappers for all VGS custom view. VGS Collect composable wrappers are designed to make integration easier and more straight forward by taking care of all needed state and lifecycle events.

## Integration

Update VGS Collect Android SDK version to >1.9.

```gradle
dependencies {
    implementation 'com.verygoodsecurity:vgscollect:1.9.+'
}
```

Select composable wrapper which meet your needs:

* **VGSEditTextWrapper**
* **PersonNameEditTextWrapper**
* **VGSCardNumberEditTextWrapper**
* **CardVerificationCodeEditTextWrapper**
* **SSNEditTextWrapper**
* **ExpirationDateEditTextWrapper**
* **RangeDateEditTextWrapper**

Add composable wrapper:

```kotlin
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.verygoodsecurity.vgscollect.core.VGSCollect
import com.verygoodsecurity.vgscollect.core.VgsCollectResponseListener
import com.verygoodsecurity.vgscollect.core.model.network.VGSResponse
import com.verygoodsecurity.vgscollect.widget.compose.VGSCardNumberEditTextWrapper

class ComposeActivity : AppCompatActivity(), VgsCollectResponseListener {

    private val collect: VGSCollect by lazy {
        VGSCollect(
            this,
            "<VAULT_ID>"",
            "<ENVIRONMENT>"
        ).also {
            it.addOnResponseListeners(this)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                Content(collect = collect)
            }
        }
    }

    override fun onResponse(response: VGSResponse?) {
        // Handle response
    }

    @Composable
    private fun Content(collect: VGSCollect?) {
        Column {
            VGSCardNumberEditTextWrapper(
                collect = collect,
                fieldName = "<FIELD_NAME>",
                modifier = Modifier.fillMaxWidth(),
                onViewCreate = { layout, input -> },
                onViewUpdate = { layout, input -> }
            )
        }
    }
}
```

All composable wrappers share same public interface:

* **collect** - `VGSCollect` instance.
* **fieldName** - field-name in JSON path in inbound route filters.
* **modifier** - modifier which applied to `AndroidView` wrapper.
* **onViewCreate** - a callback to be invoked when `VGSTextInputLayout` and VGS custom edit text view is created.
* **onViewUpdate** - a callback to be invoked after the view is inflated and upon recomposition to update the information and state of the view.

Best place to customize composable wrapper is `onViewCreate`:

```kotlin
@Composable
private fun Content(collect: VGSCollect?) {
    Column {
        VGSCardNumberEditTextWrapper(
            collect = collect,
            fieldName = "<FIELD_NAME>",
            modifier = Modifier.fillMaxWidth(),
            onViewCreate = { layout, input ->
                // Customise layout
                layout.setHint(hint)

                // Customise input
                input.setDivider(' ')
                input.setCardBrandIconGravity(Gravity.END)
            },
            onViewUpdate = { layout, input -> }
        )
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/android-sdk/compose.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
