All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.androidx.compose.material3.internal.AccessibilityUtil.kt Maven / Gradle / Ivy

/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.compose.material3.internal

import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.layout.padding
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.layout
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.offset

@VisibleForTesting internal val HorizontalSemanticsBoundsPadding: Dp = 10.dp

internal val IncreaseHorizontalSemanticsBounds: Modifier =
    Modifier.layout { measurable, constraints ->
            val paddingPx = HorizontalSemanticsBoundsPadding.roundToPx()
            // We need to add horizontal padding to the semantics bounds in order to meet
            // screenreader green box minimum size, but we also want to
            // preserve a visual appearance and layout size below that minimum
            // in order to maintain backwards compatibility. This custom
            // layout effectively implements "negative padding".
            val newConstraint = constraints.offset(paddingPx * 2, 0)
            val placeable = measurable.measure(newConstraint)

            // But when actually placing the placeable, create the layout without additional
            // space. Place the placeable where it would've been without any extra padding.
            val height = placeable.height
            val width = placeable.width - paddingPx * 2
            layout(width, height) { placeable.place(-paddingPx, 0) }
        }
        .semantics(mergeDescendants = true) {}
        .padding(horizontal = HorizontalSemanticsBoundsPadding)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy