-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add voice message 'hold to record' tooltip (#1710)
--------- Co-authored-by: ElementBot <[email protected]>
- Loading branch information
1 parent
8cc541b
commit 5080df3
Showing
18 changed files
with
263 additions
and
16 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...in/io/element/android/libraries/designsystem/components/tooltip/ElementTooltipDefaults.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector Ltd | ||
* | ||
* 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 io.element.android.libraries.designsystem.components.tooltip | ||
|
||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.TooltipDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.IntOffset | ||
import androidx.compose.ui.unit.IntRect | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.PopupPositionProvider | ||
|
||
object ElementTooltipDefaults { | ||
/** | ||
* Creates a [PopupPositionProvider] that allows adding padding between the edge of the | ||
* window and the tooltip. | ||
* | ||
* It is a wrapper around [TooltipDefaults.rememberPlainTooltipPositionProvider] and is | ||
* designed for use with a [PlainTooltip]. | ||
* | ||
* @param spacingBetweenTooltipAndAnchor the spacing between the tooltip and the anchor. | ||
* @param windowPadding the padding between the tooltip and the edge of the window. | ||
* | ||
* @return a [PopupPositionProvider]. | ||
*/ | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun rememberPlainTooltipPositionProvider( | ||
spacingBetweenTooltipAndAnchor: Dp = 8.dp, | ||
windowPadding: Dp = 12.dp, | ||
): PopupPositionProvider { | ||
val windowPaddingPx = with(LocalDensity.current) { windowPadding.roundToPx() } | ||
val plainTooltipPositionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider( | ||
spacingBetweenTooltipAndAnchor = spacingBetweenTooltipAndAnchor, | ||
) | ||
return remember(windowPaddingPx, plainTooltipPositionProvider) { | ||
object : PopupPositionProvider { | ||
override fun calculatePosition( | ||
anchorBounds: IntRect, | ||
windowSize: IntSize, | ||
layoutDirection: LayoutDirection, | ||
popupContentSize: IntSize | ||
): IntOffset = plainTooltipPositionProvider | ||
.calculatePosition( | ||
anchorBounds = anchorBounds, | ||
windowSize = windowSize, | ||
layoutDirection = layoutDirection, | ||
popupContentSize = popupContentSize | ||
) | ||
.let { | ||
val maxX = windowSize.width - popupContentSize.width - windowPaddingPx | ||
val maxY = windowSize.height - popupContentSize.height - windowPaddingPx | ||
if (maxX <= windowPaddingPx || maxY <= windowPaddingPx) { | ||
return@let it | ||
} | ||
IntOffset( | ||
x = it.x.coerceIn( | ||
minimumValue = windowPaddingPx, | ||
maximumValue = maxX, | ||
), | ||
y = it.y.coerceIn( | ||
minimumValue = windowPaddingPx, | ||
maximumValue = maxY, | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../main/kotlin/io/element/android/libraries/designsystem/components/tooltip/PlainTooltip.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector Ltd | ||
* | ||
* 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 io.element.android.libraries.designsystem.components.tooltip | ||
|
||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.TooltipDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.Shape | ||
import io.element.android.libraries.theme.ElementTheme | ||
import androidx.compose.material3.PlainTooltip as M3PlainTooltip | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun PlainTooltip( | ||
modifier: Modifier = Modifier, | ||
contentColor: Color = ElementTheme.colors.textOnSolidPrimary, | ||
containerColor: Color = ElementTheme.colors.bgActionPrimaryRest, | ||
shape: Shape = TooltipDefaults.plainTooltipContainerShape, | ||
content: @Composable () -> Unit, | ||
) = M3PlainTooltip( | ||
modifier = modifier, | ||
contentColor = contentColor, | ||
containerColor = containerColor, | ||
shape = shape, | ||
content = content, | ||
) |
42 changes: 42 additions & 0 deletions
42
...rc/main/kotlin/io/element/android/libraries/designsystem/components/tooltip/TooltipBox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector Ltd | ||
* | ||
* 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 io.element.android.libraries.designsystem.components.tooltip | ||
|
||
import androidx.compose.material3.TooltipState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.window.PopupPositionProvider | ||
import androidx.compose.material3.TooltipBox as M3TooltipBox | ||
|
||
@Composable | ||
fun TooltipBox( | ||
positionProvider: PopupPositionProvider, | ||
tooltip: @Composable () -> Unit, | ||
state: TooltipState, | ||
modifier: Modifier = Modifier, | ||
focusable: Boolean = true, | ||
enableUserInput: Boolean = true, | ||
content: @Composable () -> Unit, | ||
) = M3TooltipBox( | ||
positionProvider = positionProvider, | ||
tooltip = tooltip, | ||
state = state, | ||
modifier = modifier, | ||
focusable = focusable, | ||
enableUserInput = enableUserInput, | ||
content = content, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...xtcomposer.components_null_HoldToRecordTooltip-D-13_13_null,NEXUS_5,1.0,en].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...xtcomposer.components_null_HoldToRecordTooltip-N-13_14_null,NEXUS_5,1.0,en].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters