There is a Box,some buttons are in box content,how...
# compose
w
There is a Box,some buttons are in box content,how can I disable these buttons ,make clickable disabled
k
Don’t add the clickable modifier, or mark the buttons as
enabled=false
Whatever your condition is, express it in code and don’t make the buttons clickable
w
Box can hold any content, I can't change the components in it
In other words, a component DisableClickable is needed to make all incoming content unclickable
k
Do you want to prevent any user interaction with those components, including focus traversal, using keyboard to activate, accessibility helpers, low level custom application event handlers etc?
At this point it sounds like a classic XY problem where you’re asking questions about your chosen solution instead of the original problem you need to solve
w
You are right, so what should I do to block these events in compose
k
What is the larger context for your question
w
One area can switch all touch events, and there are many interactive components in the area
k
Interaction is not just touch based. There’s plenty of ways to interact with components in Compose across different form factors
w
What if only clicks are disabled?
k
You still need to step back away from the specific solution and give some details about the problem. Is this a single code base? Who owns these components? Where do they come from?
w
Copy code
@Composable
fun EnableClick(
    enable: Boolean,
    content: @Composable () -> Unit
) {
}

@Composable
fun EnableClickExample() {
    //
    var enable by remember { mutableStateOf(true) }
    Column {
        Button(onClick = { enable = !enable }){
            Text("Change")
        }
        EnableClick(enable) {
            // Any component can be passed in here
            Button(onClick = {}) {
                Text("Button")
            }
        }
    }
}
is a component,If enable is false, I want all content in the content of EnableClick to be unclickable.
k
Where is the content coming from? Who owns it?
w
content Content is not sure. It could be anything.
w
it works thanks