Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fluent] Add TabView. #66

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

[fluent] Add TabView. #66

wants to merge 1 commit into from

Conversation

Sanlorng
Copy link
Collaborator

@Sanlorng Sanlorng commented Jun 24, 2024

Components

  1. TabRow
  2. TabItem
    Style: 1. InContentArea(default) 2. InTitleBar

Screenshot

image
image

Basic Usage

val selectedKey = remember { mutableIntStateOf(0) }
val items = remember { mutableStateListOf(*Array(10) { it }) }
val state = rememberLazyListState()
val endDividerController = rememberTabItemEndDividerController(
    selectedKey = { selectedKey.value },
    state = state
)
TabRow(
    state = state,
    selectedKey = { selectedKey.value },
    modifier = Modifier.fillMaxWidth()
) {

    itemsIndexed(items, key = { _, item -> item }) { index, item ->
        val interactionSource = remember { MutableInteractionSource() }
        TabItem(
            selected = item == selectedKey.value,
            onSelectedChanged = { selectedKey.value = item },
            endDividerVisible = endDividerController.attach(item, interactionSource),
            interactionSource = interactionSource,
            text = {Text("Item ${item + 1}")},
            trailing = {
                val isHovered = interactionSource.collectIsHoveredAsState()
                if (isHovered.value) {
                    TabViewDefaults.TabCloseButton(
                        onClick = {
                            val isSelected = selectedKey.value == item
                            items.remove(item)
                            if (isSelected) {
                                selectedKey.value = items.getOrNull(index) ?: items.getOrNull(index - 1) ?: 0
                            }
                        }
                    )
                }
            },
            modifier = Modifier.widthIn(160.dp).animateItemPlacement(),
        )
    }

    item {
        TabViewDefaults.TabAddButton(
            onClick = {
                items.add(items.lastOrNull()?.plus(1) ?: 0)
            }
        )
    }
}

@Sanlorng Sanlorng changed the title [fluent] add TabView. [fluent] Add TabView. Jun 24, 2024
@yaroslavkulinich
Copy link

Where to put my like or star to make all your Pull Requests accepted?=)

@Sanlorng
Copy link
Collaborator Author

Sanlorng commented Jul 2, 2024

Where to put my like or star to make all your Pull Requests accepted?=)

Subscribe the PR that you want to observe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants