Merge branch 'develop' into feature/bma/sxcludePreviewFromCodeCoverage

This commit is contained in:
Benoit Marty 2024-01-11 16:02:58 +01:00 committed by GitHub
commit 92d8e4f55b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
952 changed files with 1476 additions and 2027 deletions

View file

@ -36,4 +36,3 @@ fun Context.isScreenReaderEnabled(): Boolean {
it.isEnabled && it.isTouchExplorationEnabled
}
}

View file

@ -31,7 +31,6 @@ import javax.inject.Inject
class AndroidClipboardHelper @Inject constructor(
@ApplicationContext private val context: Context,
) : ClipboardHelper {
private val clipboardManager = requireNotNull(context.getSystemService<ClipboardManager>())
override fun copyPlainText(text: String) {

View file

@ -17,7 +17,6 @@
package io.element.android.libraries.androidutils.clipboard
class FakeClipboardHelper : ClipboardHelper {
var clipboardContents: Any? = null
override fun copyPlainText(text: String) {

View file

@ -26,6 +26,6 @@ fun PackageManager.getApplicationInfoCompat(packageName: String, flags: Int): Ap
packageName,
PackageManager.ApplicationInfoFlags.of(flags.toLong())
)
else -> @Suppress("DEPRECATION") getApplicationInfo(packageName, flags)
else -> getApplicationInfo(packageName, flags)
}
}

View file

@ -26,7 +26,6 @@ internal class DefaultDiffCallback<T>(
private val newList: List<T>,
private val areItemsTheSame: (oldItem: T?, newItem: T?) -> Boolean,
) : DiffUtil.Callback() {
override fun getOldListSize(): Int {
return oldList.size
}

View file

@ -40,7 +40,6 @@ interface MutableDiffCache<E> : DiffCache<E> {
*
*/
class MutableListDiffCache<E>(private val mutableList: MutableList<E?> = ArrayList()) : MutableDiffCache<E> {
override fun removeAt(index: Int): E? {
return mutableList.removeAt(index)
}

View file

@ -36,7 +36,6 @@ interface DiffCacheInvalidator<T> {
* It invalidates the cache by setting values to null.
*/
class DefaultDiffCacheInvalidator<T> : DiffCacheInvalidator<T> {
override fun onChanged(position: Int, count: Int, cache: MutableDiffCache<T>) {
for (i in position until position + count) {
// Invalidate cache

View file

@ -36,7 +36,6 @@ class DiffCacheUpdater<ListItem, CachedItem>(
private val cacheInvalidator: DiffCacheInvalidator<CachedItem> = DefaultDiffCacheInvalidator(),
private val areItemsTheSame: (oldItem: ListItem?, newItem: ListItem?) -> Boolean,
) {
private val lock = Object()
private var prevOriginalList: List<ListItem> = emptyList()

View file

@ -26,8 +26,8 @@ fun String.hash() = try {
val digest = MessageDigest.getInstance("SHA-512")
digest.update(toByteArray())
digest.digest()
.joinToString("") { String.format(Locale.ROOT, "%02X", it) }
.lowercase(Locale.ROOT)
.joinToString("") { String.format(Locale.ROOT, "%02X", it) }
.lowercase(Locale.ROOT)
} catch (exc: Exception) {
// Should not happen, but just in case
hashCode().toString()

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.libraries.androidutils.filesize
package io.element.android.libraries.androidutils.filesize
import android.os.Build
import com.google.common.truth.Truth.assertThat

View file

@ -27,7 +27,6 @@ import kotlin.contracts.contract
*/
@Stable
sealed interface AsyncAction<out T> {
/**
* Represents an uninitialized operation (i.e. yet to be run by the user).
*/

View file

@ -27,7 +27,6 @@ import kotlin.contracts.contract
*/
@Stable
sealed interface AsyncData<out T> {
/**
* Represents a failed operation.
*

View file

@ -23,9 +23,8 @@ import io.element.android.libraries.architecture.overlay.operation.Hide
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
class HideOverlayBackPressHandler<NavTarget : Any>
: BaseBackPressHandlerStrategy<NavTarget, BackStack.State>() {
class HideOverlayBackPressHandler<NavTarget : Any> :
BaseBackPressHandlerStrategy<NavTarget, BackStack.State>() {
override val canHandleBackPressFlow: Flow<Boolean> by lazy {
navModel.elements.map(::areThereElements)
}

View file

@ -40,7 +40,6 @@ class Overlay<NavTarget : Any>(
savedStateMap = savedStateMap,
key = key,
) {
override val initialElements: NavElements<NavTarget, BackStack.State>
get() = emptyList()
}

View file

@ -24,7 +24,6 @@ import kotlinx.parcelize.Parcelize
@Parcelize
class Hide<T : Any> : OverlayOperation<T> {
override fun isApplicable(elements: BackStackElements<T>): Boolean =
elements.any { it.targetState == BackStack.State.ACTIVE }

View file

@ -29,7 +29,6 @@ import kotlinx.parcelize.RawValue
data class Show<T : Any>(
private val element: @RawValue T
) : OverlayOperation<T> {
override fun isApplicable(elements: BackStackElements<T>): Boolean =
element != elements.activeElement

View file

@ -84,7 +84,7 @@ class AsyncDataKtTest {
private class TestableMutableState<T>(
value: T
) : MutableState<T> {
@Suppress("ktlint:standard:property-naming")
private val _deque = ArrayDeque<T>(listOf(value))
override var value: T

View file

@ -21,7 +21,6 @@ package io.element.android.libraries.core.cache
* This class is not thread safe.
*/
class CircularCache<T : Any>(cacheSize: Int, factory: (Int) -> Array<T?>) {
companion object {
inline fun <reified T : Any> create(cacheSize: Int) = CircularCache(cacheSize) { Array<T?>(cacheSize) { null } }
}

View file

@ -26,20 +26,6 @@ inline fun <T> T.ooi(block: (T) -> Unit): T = also(block)
*/
fun CharSequence?.orEmpty() = this ?: ""
/**
* Check if a CharSequence is a phone number.
*/
/*
fun CharSequence.isMsisdn(): Boolean {
return try {
PhoneNumberUtil.getInstance().parse(ensurePrefix("+"), null)
true
} catch (e: NumberParseException) {
false
}
}
*/
/**
* Useful to append a String at the end of a filename but before the extension if any
* Ex:

View file

@ -23,7 +23,6 @@ package io.element.android.libraries.core.log.logger
* Timber.tag(loggerTag.value).v("My log message")
*/
open class LoggerTag(name: String, parentTag: LoggerTag? = null) {
object PushLoggerTag : LoggerTag("Push")
object NotificationLoggerTag : LoggerTag("Notification", PushLoggerTag)

View file

@ -19,6 +19,7 @@ package io.element.android.libraries.core.mimetype
import io.element.android.libraries.core.bool.orFalse
// The Android SDK does not provide constant for mime type, add some of them here
@Suppress("ktlint:standard:property-naming")
object MimeTypes {
const val Any: String = "*/*"
const val OctetStream = "application/octet-stream"

View file

@ -20,7 +20,6 @@ import org.junit.Assert.assertEquals
import org.junit.Test
class BasicExtensionsTest {
@Test(expected = IllegalArgumentException::class)
fun `test ellipsize at 0`() {
"1234567890".ellipsize(0)

View file

@ -20,7 +20,6 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Test
class ResultTest {
@Test
fun testFlatMap() {
val initial = Result.success("initial")

View file

@ -31,7 +31,6 @@ import javax.inject.Inject
*/
@ContributesBinding(AppScope::class)
class AESEncryptionDecryptionService @Inject constructor() : EncryptionDecryptionService {
override fun createEncryptionCipher(key: SecretKey): Cipher {
return Cipher.getInstance(AESEncryptionSpecs.CIPHER_TRANSFORMATION).apply {
init(Cipher.ENCRYPT_MODE, key)

View file

@ -27,7 +27,6 @@ internal const val ANDROID_KEYSTORE = "AndroidKeyStore"
@ContributesTo(AppScope::class)
@Module
object CryptographyModule {
@Provides
fun providesAndroidKeyStore(): KeyStore {
return KeyStore.getInstance(ANDROID_KEYSTORE).apply {

View file

@ -38,7 +38,6 @@ import javax.inject.Inject
class KeyStoreSecretKeyRepository @Inject constructor(
private val keyStore: KeyStore,
) : SecretKeyRepository {
// False positive lint issue
@SuppressLint("WrongConstant")
override fun getOrCreateKey(alias: String, requiresUserAuthentication: Boolean): SecretKey {

View file

@ -24,7 +24,6 @@ import java.security.GeneralSecurityException
import javax.crypto.KeyGenerator
class AESEncryptionDecryptionServiceTest {
private val encryptionDecryptionService = AESEncryptionDecryptionService()
@Test
@ -50,5 +49,4 @@ class AESEncryptionDecryptionServiceTest {
encryptionDecryptionService.decrypt(decryptionKey, encryptionResult)
}
}
}

View file

@ -22,7 +22,6 @@ import javax.crypto.KeyGenerator
import javax.crypto.SecretKey
class SimpleSecretKeyRepository : SecretKeyRepository {
private var secretKeyForAlias = HashMap<String, SecretKey>()
override fun getOrCreateKey(alias: String, requiresUserAuthentication: Boolean): SecretKey {

View file

@ -36,7 +36,6 @@ class DateFormatters @Inject constructor(
private val clock: Clock,
private val timeZone: TimeZone,
) {
private val onlyTimeFormatter: DateTimeFormatter by lazy {
val pattern = DateFormat.getBestDateTimePattern(locale, "HH:mm") ?: "HH:mm"
DateTimeFormatter.ofPattern(pattern, locale)

View file

@ -26,7 +26,6 @@ class DefaultDaySeparatorFormatter @Inject constructor(
private val localDateTimeProvider: LocalDateTimeProvider,
private val dateFormatters: DateFormatters,
) : DaySeparatorFormatter {
override fun format(timestamp: Long): String {
val dateToFormat = localDateTimeProvider.providesFromTimestamp(timestamp)
return dateFormatters.formatDateWithYear(dateToFormat)

View file

@ -26,7 +26,6 @@ class DefaultLastMessageTimestampFormatter @Inject constructor(
private val localDateTimeProvider: LocalDateTimeProvider,
private val dateFormatters: DateFormatters,
) : LastMessageTimestampFormatter {
override fun format(timestamp: Long?): String {
if (timestamp == null) return ""
val currentDate = localDateTimeProvider.providesNow()

View file

@ -27,7 +27,6 @@ class LocalDateTimeProvider @Inject constructor(
private val clock: Clock,
private val timezone: TimeZone,
) {
fun providesNow(): LocalDateTime {
val now: Instant = clock.now()
return now.toLocalDateTime(timezone)

View file

@ -22,7 +22,7 @@ import dagger.Provides
import io.element.android.libraries.di.AppScope
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import java.util.*
import java.util.Locale
@Module
@ContributesTo(AppScope::class)

View file

@ -25,7 +25,6 @@ import org.junit.Test
import java.util.Locale
class DefaultLastMessageTimestampFormatterTest {
@Test
fun `test null`() {
val now = "1980-04-06T18:35:24.00Z"

View file

@ -19,7 +19,6 @@ package io.element.android.libraries.dateformatter.test
import io.element.android.libraries.dateformatter.api.DaySeparatorFormatter
class FakeDaySeparatorFormatter : DaySeparatorFormatter {
private var format = ""
fun givenFormat(format: String) {

View file

@ -21,11 +21,11 @@ import io.element.android.libraries.androidutils.system.startSharePlainTextInten
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.permalink.PermalinkBuilder
import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.services.toolbox.api.strings.StringProvider
import timber.log.Timber
import javax.inject.Inject
import io.element.android.libraries.androidutils.R as AndroidUtilsR
import io.element.android.libraries.ui.strings.CommonStrings
class InviteFriendsUseCase @Inject constructor(
private val stringProvider: StringProvider,

View file

@ -23,7 +23,6 @@ import io.element.android.libraries.matrix.test.A_THREAD_ID
import org.junit.Test
class DeepLinkCreatorTest {
@Test
fun room() {
val sut = DeepLinkCreator()

View file

@ -38,8 +38,8 @@ import io.element.android.libraries.designsystem.R
import io.element.android.libraries.designsystem.modifiers.blurCompat
import io.element.android.libraries.designsystem.modifiers.blurredShapeShadow
import io.element.android.libraries.designsystem.modifiers.canUseBlurMaskFilter
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
@Composable
fun ElementLogoAtom(
@ -49,7 +49,6 @@ fun ElementLogoAtom(
darkTheme: Boolean = isSystemInDarkTheme(),
) {
val blur = if (darkTheme) 160.dp else 24.dp
//box-shadow: 0px 6.075949668884277px 24.30379867553711px 0px #1B1D2280;
val shadowColor = if (darkTheme) size.shadowColorDark else size.shadowColorLight
val logoShadowColor = if (darkTheme) size.logoShadowColorDark else size.logoShadowColorLight
val backgroundColor = if (darkTheme) Color.White.copy(alpha = 0.2f) else Color.White.copy(alpha = 0.4f)

View file

@ -26,10 +26,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.theme.placeholderBackground
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.placeholderBackground
@Composable
fun PlaceholderAtom(

View file

@ -28,9 +28,9 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.compound.theme.ElementTheme
@Composable
fun RedIndicatorAtom(

View file

@ -32,11 +32,11 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.temporaryColorBgSpecial
import io.element.android.compound.theme.ElementTheme
/**
* RoundedIconAtom is an atom which displays an icon inside a rounded container.

View file

@ -26,10 +26,10 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.theme.unreadIndicator
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.unreadIndicator
@Composable
fun UnreadIndicatorAtom(

View file

@ -24,8 +24,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.OutlinedButton
import io.element.android.libraries.designsystem.theme.components.TextButton

View file

@ -22,8 +22,8 @@ import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.TextButton
@Composable

View file

@ -29,13 +29,13 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.atomic.molecules.InfoListItemMolecule
import io.element.android.libraries.designsystem.atomic.molecules.InfoListItemPosition
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.compound.theme.ElementTheme
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf

View file

@ -26,11 +26,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Scaffold
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.compound.theme.ElementTheme
/**
* @param modifier Classical modifier.

View file

@ -29,11 +29,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.R
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.R
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Text
/**
* Page for onboarding screens, with content and optional footer.

View file

@ -22,4 +22,3 @@ data class AvatarColors(
val background: Color,
val foreground: Color,
)

View file

@ -25,11 +25,11 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.OutlinedTextField
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.compound.theme.ElementTheme
@Composable
fun LabelledOutlinedTextField(
@ -83,4 +83,3 @@ internal fun LabelledOutlinedTextFieldPreview() = ElementPreview {
)
}
}

View file

@ -25,11 +25,11 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.TextField
import io.element.android.compound.theme.ElementTheme
@Composable
fun LabelledTextField(

View file

@ -24,11 +24,11 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.R
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.R
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Icon
@Composable
fun PinIcon(

View file

@ -35,10 +35,10 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import io.element.android.libraries.designsystem.theme.components.DialogPreview
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
import io.element.android.libraries.designsystem.theme.components.DialogPreview
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.TextButton
import io.element.android.libraries.ui.strings.CommonStrings

View file

@ -26,8 +26,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.ui.strings.CommonStrings

View file

@ -23,8 +23,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
@Composable

View file

@ -25,7 +25,6 @@ data class AvatarData(
val url: String? = null,
val size: AvatarSize,
) {
val initial by lazy {
(name?.takeIf { it.isNotBlank() } ?: id)
.let { dn ->

View file

@ -29,7 +29,6 @@ import io.element.android.libraries.designsystem.theme.components.TextButton
*/
@Immutable
sealed interface ButtonVisuals {
val action: () -> Unit
/**

View file

@ -29,9 +29,9 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.airbnb.android.showkase.annotation.ShowkaseComposable
import io.element.android.libraries.designsystem.components.list.CheckboxListItem
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.DialogPreview
import io.element.android.libraries.designsystem.theme.components.ListSupportingText
import io.element.android.libraries.designsystem.theme.components.SimpleAlertDialogContent

View file

@ -27,9 +27,9 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.airbnb.android.showkase.annotation.ShowkaseComposable
import io.element.android.libraries.designsystem.components.list.RadioButtonListItem
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.DialogPreview
import io.element.android.libraries.designsystem.theme.components.ListSupportingText
import io.element.android.libraries.designsystem.theme.components.SimpleAlertDialogContent

View file

@ -29,7 +29,8 @@ import androidx.lifecycle.Lifecycle
* Inspired from https://stackoverflow.com/questions/68847559/how-can-i-detect-keyboard-opening-and-closing-in-jetpack-compose
*/
enum class Keyboard {
Opened, Closed
Opened,
Closed
}
// Note: it does not work as expected...

View file

@ -166,7 +166,7 @@ internal fun SingleSelectionListItemCustomFormattertPreview() {
options = listOptionOf("Option 1", "Option 2", "Option 3"),
supportingText = "Supporting text",
onSelectionChanged = {},
resultFormatter = { "Selected index: $it"},
resultFormatter = { "Selected index: $it" },
selected = 1,
displayResultInTrailingContent = true,
)

View file

@ -24,11 +24,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.theme.components.OutlinedTextField
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.compound.theme.ElementTheme
@Composable
fun TextFieldListItem(

View file

@ -23,23 +23,22 @@ import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import kotlinx.collections.immutable.ImmutableList
import kotlin.math.max
fun DrawScope.drawWaveform(
waveformData: ImmutableList<Float>,
canvasSize: DpSize,
canvasSizePx: Size,
brush: Brush,
minimumGraphAmplitude: Float = 2F,
lineWidth: Dp = 2.dp,
linePadding: Dp = 2.dp,
) {
val centerY = canvasSize.height.toPx() / 2
val centerY = canvasSizePx.height / 2
val cornerRadius = lineWidth / 2
waveformData.forEachIndexed { index, amplitude ->
val drawingAmplitude = max(minimumGraphAmplitude, amplitude * (canvasSize.height.toPx() - 2))
val drawingAmplitude = max(minimumGraphAmplitude, amplitude * (canvasSizePx.height - 2))
drawRoundRect(
brush = brush,
topLeft = Offset(

View file

@ -40,12 +40,13 @@ import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.RequestDisallowInterceptTouchEvent
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.compound.theme.ElementTheme
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
@ -58,7 +59,7 @@ private const val DEFAULT_GRAPHICS_LAYER_ALPHA: Float = 0.99F
*
* @param playbackProgress The current playback progress, between 0 and 1.
* @param showCursor Whether to show the cursor or not.
* @param waveform The waveform to display. Use [FakeWaveformFactory] to generate a fake waveform.
* @param waveform The waveform to display. Use [createFakeWaveform] to generate a fake waveform.
* @param onSeek Callback when the user seeks the waveform. Called with a value between 0 and 1.
* @param modifier The modifier to be applied to the view.
* @param seekEnabled Whether the user can seek the waveform or not.
@ -103,6 +104,11 @@ fun WaveformPlaybackView(
}
}
val density = LocalDensity.current
val waveformWidthPx by remember {
derivedStateOf { with(density) { normalizedWaveformData.size * (lineWidth + linePadding).roundToPx().toFloat() } }
}
val requestDisallowInterceptTouchEvent = remember { RequestDisallowInterceptTouchEvent() }
Canvas(
modifier = Modifier
@ -110,19 +116,20 @@ fun WaveformPlaybackView(
.graphicsLayer(alpha = DEFAULT_GRAPHICS_LAYER_ALPHA)
.let {
if (!seekEnabled) return@let it
it.pointerInteropFilter(requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent) { e ->
return@pointerInteropFilter when (e.action) {
MotionEvent.ACTION_DOWN -> {
if (e.x in 0F..canvasSizePx.width) {
if (e.x in 0F..waveformWidthPx) {
requestDisallowInterceptTouchEvent.invoke(true)
seekProgress.value = e.x / canvasSizePx.width
seekProgress.value = e.x / waveformWidthPx
true
} else false
} else {
false
}
}
MotionEvent.ACTION_MOVE -> {
if (e.x in 0F..canvasSizePx.width) {
seekProgress.value = e.x / canvasSizePx.width
if (e.x in 0F..waveformWidthPx) {
seekProgress.value = e.x / waveformWidthPx
}
true
}
@ -140,11 +147,11 @@ fun WaveformPlaybackView(
) {
canvasSize = size.toDpSize()
canvasSizePx = size
val centerY = canvasSize.height.toPx() / 2
val cornerRadius = lineWidth / 2
// Calculate the size of the waveform by summing the width of all the lines and paddings
drawWaveform(
waveformData = normalizedWaveformData,
canvasSize = canvasSize,
canvasSizePx = canvasSizePx,
brush = brush,
lineWidth = lineWidth,
linePadding = linePadding
@ -152,8 +159,8 @@ fun WaveformPlaybackView(
drawRect(
brush = progressBrush,
size = Size(
width = progressAnimated.value * canvasSize.width.toPx(),
height = canvasSize.height.toPx()
width = progressAnimated.value * waveformWidthPx,
height = canvasSizePx.height
),
blendMode = BlendMode.SrcAtop
)
@ -161,12 +168,12 @@ fun WaveformPlaybackView(
drawRoundRect(
brush = cursorBrush,
topLeft = Offset(
x = progressAnimated.value * canvasSize.width.toPx(),
y = centerY - (canvasSize.height.toPx() - 2) / 2
x = progressAnimated.value * waveformWidthPx,
y = 1f
),
size = Size(
width = lineWidth.toPx(),
height = canvasSize.height.toPx() - 2
height = canvasSizePx.height - 2
),
cornerRadius = CornerRadius(cornerRadius.toPx(), cornerRadius.toPx()),
style = Fill

View file

@ -24,11 +24,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.icons.CompoundDrawables
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.icons.CompoundDrawables
@Composable
fun PreferenceCategory(

View file

@ -19,10 +19,10 @@ package io.element.android.libraries.designsystem.components.preferences
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.theme.components.HorizontalDivider
import io.element.android.compound.theme.ElementTheme
@Composable
fun PreferenceDivider(

View file

@ -95,7 +95,6 @@ private fun PreferenceTopAppBar(
overflow = TextOverflow.Ellipsis
)
}
)
}

View file

@ -55,7 +55,7 @@ fun PreferenceTextField(
style: ListItemStyle = ListItemStyle.Default,
) {
var displayTextFieldDialog by rememberSaveable { mutableStateOf(false) }
val valueToDisplay = if (displayValue(value)) { value } else supportingText
val valueToDisplay = if (displayValue(value)) value else supportingText
ListItem(
modifier = modifier,

View file

@ -55,7 +55,7 @@ internal class OtherIconListPreviewProvider : PreviewParameterProvider<IconChunk
get() {
val chunks = iconsOther.chunked(36)
return chunks.mapIndexed { index, chunk ->
IconChunk(index = index+1, total = chunks.size, icons = chunk.toPersistentList())
IconChunk(index = index + 1, total = chunks.size, icons = chunk.toPersistentList())
}
.asSequence()
}
@ -76,7 +76,8 @@ internal fun IconsCompoundPreview(@PreviewParameter(CompoundIconListPreviewProvi
iconNameTransform = { name ->
name.removePrefix("ic_compound_")
.replace("_", " ")
})
}
)
}
@PreviewsDayNight
@ -88,7 +89,8 @@ internal fun IconsOtherPreview(@PreviewParameter(OtherIconListPreviewProvider::c
iconNameTransform = { name ->
name.removePrefix("ic_")
.replace("_", " ")
})
}
)
}
@Composable

View file

@ -78,10 +78,11 @@ fun Modifier.circularReveal(
val path = Path()
val center = revealFrom.mapTo(size)
val radius = calculateRadius(revealFrom, size)
val scrimColor = if (showScrim)
val scrimColor = if (showScrim) {
Color.Gray
else
} else {
Color.Transparent
}
path.addOval(Rect(center, radius * transitionProgress.value))

View file

@ -18,8 +18,8 @@ package io.element.android.libraries.designsystem.preview
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import io.element.android.libraries.designsystem.theme.components.Surface
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.theme.components.Surface
@Composable
@Suppress("ModifierMissing")

View file

@ -16,6 +16,7 @@
package io.element.android.libraries.designsystem.preview
@Suppress("ktlint:standard:property-naming")
object PreviewGroup {
const val AppBars = "App Bars"
const val Avatars = "Avatars"

View file

@ -26,8 +26,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
/**
* Horizontal ruler is a debug composable that displays a horizontal ruler.

View file

@ -26,8 +26,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
/**
* Vertical ruler is a debug composable that displays a vertical ruler.

View file

@ -21,8 +21,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.ButtonSize
import io.element.android.libraries.designsystem.theme.components.OutlinedButton

View file

@ -25,10 +25,10 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
import io.element.android.libraries.designsystem.preview.WithFontScale
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.compound.theme.ElementTheme
/**
* Return the maximum value between the receiver value and the value with fontScale applied.

View file

@ -109,7 +109,7 @@ val SemanticColors.pinDigitBg
}
val SemanticColors.currentUserMentionPillText
get() = if (isLight) {
get() = if (isLight) {
// We want LightDesignTokens.colorGreen1100
Color(0xff005c45)
} else {
@ -118,7 +118,7 @@ val SemanticColors.currentUserMentionPillText
}
val SemanticColors.currentUserMentionPillBackground
get() = if (isLight) {
get() = if (isLight) {
// We want LightDesignTokens.colorGreenAlpha400
Color(0x3b07b661)
} else {
@ -130,7 +130,7 @@ val SemanticColors.mentionPillText
get() = textPrimary
val SemanticColors.mentionPillBackground
get() = if (isLight) {
get() = if (isLight) {
// We want LightDesignTokens.colorGray400
Color(0x1f052e61)
} else {

View file

@ -232,10 +232,11 @@ internal fun AlertDialogContent(
// Align the title to the center when an icon is present.
Modifier
.then(
if (applyPaddingToContents)
if (applyPaddingToContents) {
Modifier
else
} else {
Modifier.padding(DialogContentDefaults.externalHorizontalPadding)
}
)
.padding(DialogContentDefaults.titlePadding)
.align(
@ -364,8 +365,10 @@ private fun AlertDialogFlowRow(
val mainAxisPositions = IntArray(childrenMainAxisSizes.size) { 0 }
with(arrangement) {
arrange(
mainAxisLayoutSize, childrenMainAxisSizes,
layoutDirection, mainAxisPositions
mainAxisLayoutSize,
childrenMainAxisSizes,
layoutDirection,
mainAxisPositions
)
}
placeables.forEachIndexed { j, placeable ->
@ -444,7 +447,8 @@ internal fun DialogWithTitleIconAndOkButtonPreview() {
)
},
title = "Dialog Title",
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
content = "A dialog is a type of modal window that appears in front of app content to provide critical information," +
" or prompt for a decision to be made. Learn more",
submitText = "OK",
onSubmitClicked = {},
)
@ -460,7 +464,8 @@ internal fun DialogWithTitleAndOkButtonPreview() {
DialogPreview {
SimpleAlertDialogContent(
title = "Dialog Title",
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
content = "A dialog is a type of modal window that appears in front of app content to provide critical information," +
" or prompt for a decision to be made. Learn more",
submitText = "OK",
onSubmitClicked = {},
)
@ -475,7 +480,8 @@ internal fun DialogWithOnlyMessageAndOkButtonPreview() {
ElementThemedPreview(showBackground = false) {
DialogPreview {
SimpleAlertDialogContent(
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
content = "A dialog is a type of modal window that appears in front of app content to provide critical information," +
" or prompt for a decision to be made. Learn more",
submitText = "OK",
onSubmitClicked = {},
)

View file

@ -33,9 +33,9 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.compound.theme.ElementTheme
@Composable
fun BottomSheetDragHandle(
@ -68,7 +68,6 @@ fun BottomSheetDragHandle(
}
}
@PreviewsDayNight
@Composable
internal fun BottomSheetDragHandlePreview() = ElementPreview {

View file

@ -147,25 +147,29 @@ private fun ButtonInternal(
val contentPadding = when (size) {
ButtonSize.Medium -> when (style) {
ButtonStyle.Filled,
ButtonStyle.Outlined -> if (hasStartDrawable)
ButtonStyle.Outlined -> if (hasStartDrawable) {
PaddingValues(start = 16.dp, top = 10.dp, end = 24.dp, bottom = 10.dp)
else
} else {
PaddingValues(start = 24.dp, top = 10.dp, end = 24.dp, bottom = 10.dp)
ButtonStyle.Text -> if (hasStartDrawable)
}
ButtonStyle.Text -> if (hasStartDrawable) {
PaddingValues(start = 12.dp, top = 10.dp, end = 16.dp, bottom = 10.dp)
else
} else {
PaddingValues(start = 12.dp, top = 10.dp, end = 12.dp, bottom = 10.dp)
}
}
ButtonSize.Large -> when (style) {
ButtonStyle.Filled,
ButtonStyle.Outlined -> if (hasStartDrawable)
ButtonStyle.Outlined -> if (hasStartDrawable) {
PaddingValues(start = 24.dp, top = 13.dp, end = 32.dp, bottom = 13.dp)
else
} else {
PaddingValues(start = 32.dp, top = 13.dp, end = 32.dp, bottom = 13.dp)
ButtonStyle.Text -> if (hasStartDrawable)
}
ButtonStyle.Text -> if (hasStartDrawable) {
PaddingValues(start = 12.dp, top = 13.dp, end = 16.dp, bottom = 13.dp)
else
} else {
PaddingValues(start = 16.dp, top = 13.dp, end = 16.dp, bottom = 13.dp)
}
}
}
@ -179,12 +183,13 @@ private fun ButtonInternal(
ButtonStyle.Filled -> null
ButtonStyle.Outlined -> BorderStroke(
width = 1.dp,
color = if (destructive)
color = if (destructive) {
ElementTheme.colors.borderCriticalPrimary.copy(
alpha = if (enabled) 1f else 0.5f
)
else
} else {
ElementTheme.colors.borderInteractiveSecondary
}
)
ButtonStyle.Text -> null
}
@ -254,11 +259,14 @@ sealed interface IconSource {
}
enum class ButtonSize {
Medium, Large
Medium,
Large
}
internal enum class ButtonStyle {
Filled, Outlined, Text;
Filled,
Outlined,
Text;
@Composable
fun getColors(destructive: Boolean): ButtonColors = when (this) {

View file

@ -31,9 +31,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.state.ToggleableState
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.compound.theme.ElementTheme
// Designs in https://www.figma.com/file/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?type=design&mode=design&t=qb99xBP5mwwCtGkN-1

View file

@ -72,8 +72,7 @@ fun CircularProgressIndicator(
internal fun CircularProgressIndicatorPreview() = ElementThemedPreview(vertical = false) {
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
// Indeterminate progress
CircularProgressIndicator(
)
CircularProgressIndicator()
// Fixed progress
CircularProgressIndicator(
progress = { 0.90F }

View file

@ -38,7 +38,8 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
fun FloatingActionButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
shape: Shape = CircleShape, // FloatingActionButtonDefaults.shape,
// FloatingActionButtonDefaults.shape
shape: Shape = CircleShape,
containerColor: Color = FloatingActionButtonDefaults.containerColor,
contentColor: Color = contentColorFor(containerColor),
elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(),

View file

@ -77,8 +77,7 @@ fun LinearProgressIndicator(
internal fun LinearProgressIndicatorPreview() = ElementThemedPreview(vertical = false) {
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
// Indeterminate progress
LinearProgressIndicator(
)
LinearProgressIndicator()
// Fixed progress
LinearProgressIndicator(
progress = { 0.90F }

View file

@ -119,9 +119,13 @@ fun ListItem(
androidx.compose.material3.ListItem(
headlineContent = decoratedHeadlineContent,
modifier = if (onClick != null) Modifier
.clickable(enabled = enabled, onClick = onClick)
.then(modifier) else modifier,
modifier = if (onClick != null) {
Modifier
.clickable(enabled = enabled, onClick = onClick)
.then(modifier)
} else {
modifier
},
overlineContent = null,
supportingContent = decoratedSupportingContent,
leadingContent = decoratedLeadingContent,
@ -374,7 +378,6 @@ internal fun ListItemDisabledWithIconPreview() = PreviewItems.OneLineListItemPre
@Suppress("ModifierMissing")
private object PreviewItems {
@Composable
fun ThreeLinesListItemPreview(
modifier: Modifier = Modifier,

View file

@ -27,9 +27,9 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.compound.theme.ElementTheme
// Designs: https://www.figma.com/file/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?type=design&node-id=425%3A24208&mode=design&t=G5hCfkLB6GgXDuWe-1

View file

@ -81,7 +81,6 @@ fun ListSupportingText(
}
object ListSupportingTextDefaults {
/** Specifies the padding to use for the supporting text. */
@Immutable
sealed interface Padding {

View file

@ -34,12 +34,12 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.preview.sheetStateForPreview
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

View file

@ -119,9 +119,12 @@ private fun ContentToPreview() {
displayHandle = true,
sheetState = ModalBottomSheetState(ModalBottomSheetValue.Expanded, density = LocalDensity.current),
sheetContent = {
Text(text = "Sheet Content", modifier = Modifier
.padding(start = 16.dp, end = 16.dp, bottom = 20.dp)
.background(color = Color.Green))
Text(
text = "Sheet Content",
modifier = Modifier
.padding(start = 16.dp, end = 16.dp, bottom = 20.dp)
.background(color = Color.Green)
)
}
) {
Text(text = "Content", modifier = Modifier.background(color = Color.Red))

View file

@ -30,9 +30,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.compound.theme.ElementTheme
// Designs in https://www.figma.com/file/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?type=design&node-id=425%3A24202&mode=design&t=qb99xBP5mwwCtGkN-1

View file

@ -151,7 +151,6 @@ fun <T> SearchBar(
}
object ElementSearchBarDefaults {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun inactiveColors() = SearchBarDefaults.colors(

View file

@ -37,7 +37,7 @@ fun Slider(
modifier: Modifier = Modifier,
enabled: Boolean = true,
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
/*@IntRange(from = 0)*/
// @IntRange(from = 0)
steps: Int = 0,
onValueChangeFinished: (() -> Unit)? = null,
colors: SliderColors = SliderDefaults.colors(),

View file

@ -32,9 +32,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.compound.theme.ElementTheme
import androidx.compose.material3.Switch as Material3Switch
// Designs in https://www.figma.com/file/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?type=design&node-id=425%3A24203&mode=design&t=qb99xBP5mwwCtGkN-1

View file

@ -282,11 +282,13 @@ private fun CustomStandardBottomSheet(
if (anchoredDraggableState.anchors.size > 1 && sheetSwipeEnabled) {
if (currentValue == SheetValue.PartiallyExpanded) {
expand(expandActionLabel) {
scope.launch { expand() }; true
scope.launch { expand() }
true
}
} else {
collapse(partialExpandActionLabel) {
scope.launch { partialExpand() }; true
scope.launch { partialExpand() }
true
}
}
if (!state.skipHiddenState) {
@ -314,7 +316,6 @@ private fun CustomStandardBottomSheet(
*/
@ExperimentalFoundationApi
class DraggableAnchorsConfig<T> {
internal val anchors = mutableMapOf<T, Float>()
/**
@ -344,7 +345,6 @@ internal fun <T : Any> DraggableAnchors(
): DraggableAnchors<T> = MapDraggableAnchors(DraggableAnchorsConfig<T>().apply(builder).anchors)
private class MapDraggableAnchors<T>(private val anchors: Map<T, Float>) : DraggableAnchors<T> {
override fun positionOf(value: T): Float = anchors[value] ?: Float.NaN
override fun hasAnchorFor(value: T) = anchors.containsKey(value)
@ -498,10 +498,10 @@ internal fun rememberSheetState(
initialValue: SheetValue = SheetValue.Hidden,
skipHiddenState: Boolean = false,
): CustomSheetState {
val density = LocalDensity.current
return rememberSaveable(
skipPartiallyExpanded, confirmValueChange,
skipPartiallyExpanded,
confirmValueChange,
saver = CustomSheetState.Saver(
skipPartiallyExpanded = skipPartiallyExpanded,
confirmValueChange = confirmValueChange,

View file

@ -35,21 +35,22 @@ import kotlinx.coroutines.CancellationException
@OptIn(ExperimentalFoundationApi::class)
@Stable
@ExperimentalMaterial3Api
class CustomSheetState @Deprecated(
class CustomSheetState
@Deprecated(
message = "This constructor is deprecated. " +
"Please use the constructor that provides a [Density]",
"Please use the constructor that provides a [Density]",
replaceWith = ReplaceWith(
"SheetState(" +
"skipPartiallyExpanded, LocalDensity.current, initialValue, " +
"confirmValueChange, skipHiddenState)"
"skipPartiallyExpanded, LocalDensity.current, initialValue, " +
"confirmValueChange, skipHiddenState)"
)
) constructor(
)
constructor(
internal val skipPartiallyExpanded: Boolean,
initialValue: SheetValue = Hidden,
confirmValueChange: (SheetValue) -> Boolean = { true },
internal val skipHiddenState: Boolean = false,
) {
/**
* State of a sheet composable, such as [ModalBottomSheet]
*
@ -77,11 +78,12 @@ class CustomSheetState @Deprecated(
) : this(skipPartiallyExpanded, initialValue, confirmValueChange, skipHiddenState) {
this.density = density
}
init {
if (skipPartiallyExpanded) {
require(initialValue != PartiallyExpanded) {
"The initial value must not be set to PartiallyExpanded if skipPartiallyExpanded " +
"is set to true."
"is set to true."
}
}
if (skipHiddenState) {
@ -168,7 +170,7 @@ class CustomSheetState @Deprecated(
suspend fun partialExpand() {
check(!skipPartiallyExpanded) {
"Attempted to animate to partial expanded when skipPartiallyExpanded was enabled. Set" +
" skipPartiallyExpanded to false to use this function."
" skipPartiallyExpanded to false to use this function."
}
animateTo(PartiallyExpanded)
}
@ -194,7 +196,7 @@ class CustomSheetState @Deprecated(
suspend fun hide() {
check(!skipHiddenState) {
"Attempted to animate to hidden when skipHiddenState was enabled. Set skipHiddenState" +
" to false to use this function."
" to false to use this function."
}
animateTo(Hidden)
}
@ -254,7 +256,7 @@ class CustomSheetState @Deprecated(
internal var density: Density? = null
private fun requireDensity() = requireNotNull(density) {
"SheetState did not have a density attached. Are you using SheetState with " +
"BottomSheetScaffold or ModalBottomSheet component?"
"BottomSheetScaffold or ModalBottomSheet component?"
}
companion object {
@ -278,7 +280,7 @@ class CustomSheetState @Deprecated(
*/
@Deprecated(
message = "This function is deprecated. Please use the overload where Density is" +
" provided.",
" provided.",
replaceWith = ReplaceWith(
"Saver(skipPartiallyExpanded, confirmValueChange, LocalDensity.current)"
)
@ -290,7 +292,7 @@ class CustomSheetState @Deprecated(
) = Saver<CustomSheetState, SheetValue>(
save = { it.currentValue },
restore = { savedValue ->
CustomSheetState(skipPartiallyExpanded, savedValue, confirmValueChange)
CustomSheetState(skipPartiallyExpanded, savedValue, confirmValueChange)
}
)
}

View file

@ -24,10 +24,10 @@ import androidx.compose.material3.rememberDatePickerState
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
import io.element.android.libraries.designsystem.theme.components.AlertDialogContent
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.theme.components.AlertDialogContent
@Preview(group = PreviewGroup.DateTimePickers)
@Composable

View file

@ -24,11 +24,11 @@ import androidx.compose.material3.TimePickerLayoutType
import androidx.compose.material3.rememberTimePickerState
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import io.element.android.libraries.designsystem.theme.components.AlertDialogContent
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
import io.element.android.libraries.designsystem.theme.components.AlertDialogContent
@OptIn(ExperimentalMaterial3Api::class)
@Preview(widthDp = 600, group = PreviewGroup.DateTimePickers)

View file

@ -30,7 +30,8 @@ import io.element.android.libraries.designsystem.theme.components.Snackbar
fun SnackbarHost(hostState: SnackbarHostState, modifier: Modifier = Modifier) {
androidx.compose.material3.SnackbarHost(hostState, modifier) { data ->
Snackbar(
modifier = Modifier.padding(12.dp), // Add default padding
// Add default padding
modifier = Modifier.padding(12.dp),
message = data.visuals.message,
action = data.visuals.actionLabel?.let { ButtonVisuals.Text(it, data::performAction) },
dismissAction = if (data.visuals.withDismissAction) {
@ -38,7 +39,9 @@ fun SnackbarHost(hostState: SnackbarHostState, modifier: Modifier = Modifier) {
IconSource.Vector(CompoundIcons.Close),
data::dismiss
)
} else null,
} else {
null
},
)
}
}

Some files were not shown because too many files have changed in this diff Show more