Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tasks.register<Delete>("clean").configure {
delete(rootProject.layout.buildDirectory)
}

private val ktLintVersion = the<LibrariesForLibs>().versions.ktlint.get()
private val catalog = the<LibrariesForLibs>()

allprojects {
// Detekt
Expand All @@ -46,7 +46,7 @@ allprojects {
config.from(files("$rootDir/tools/detekt/detekt.yml"))
}
dependencies {
detektPlugins("io.nlopez.compose.rules:detekt:0.5.8")
detektPlugins(catalog.detekt.compose.rules)
detektPlugins(project(":tests:detekt-rules"))
}

Expand All @@ -64,7 +64,7 @@ allprojects {

// See https://github.com/JLLeitschuh/ktlint-gradle#configuration
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version = ktLintVersion
version = catalog.versions.ktlint.get()
android = true
ignoreFailures = false
enableExperimentalRules = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package io.element.android.features.home.impl.components

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -160,7 +161,7 @@ fun HomeTopBar(
}

@Composable
private fun RoomListMenuItems(
private fun RowScope.RoomListMenuItems(
onToggleSearch: () -> Unit,
onMenuActionClick: (RoomListMenuAction) -> Unit,
canReportBug: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.matrix.api.spaces.SpaceServiceFilter
import io.element.android.libraries.matrix.ui.model.getAvatarData
import io.element.android.libraries.ui.strings.CommonStrings
import kotlinx.collections.immutable.ImmutableList

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -93,7 +94,7 @@ fun SpaceFiltersView(
SpaceFiltersBottomSheetContent(
filters = state.visibleFilters,
searchQuery = state.searchQuery,
onFilterSelected = { filter ->
onSelectFilter = { filter ->
state.eventSink(SpaceFiltersEvent.Selecting.SelectFilter(filter))
}
)
Expand All @@ -105,9 +106,9 @@ fun SpaceFiltersView(

@Composable
private fun SpaceFiltersBottomSheetContent(
filters: List<SpaceServiceFilter>,
filters: ImmutableList<SpaceServiceFilter>,
searchQuery: TextFieldState,
onFilterSelected: (SpaceServiceFilter) -> Unit,
onSelectFilter: (SpaceServiceFilter) -> Unit,
modifier: Modifier = Modifier
) {
Column(
Expand All @@ -133,7 +134,7 @@ private fun SpaceFiltersBottomSheetContent(
items(filters) { filter ->
SpaceFilterItem(
filter = filter,
onClick = { onFilterSelected(filter) }
onClick = { onSelectFilter(filter) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private fun DoneButton(
}

@Composable
private fun Buttons(
private fun ColumnScope.Buttons(
onRetry: () -> Unit,
onCancel: () -> Unit,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.element.android.compound.theme.ElementTheme
import io.element.android.features.location.api.Location
import io.element.android.libraries.designsystem.components.PinVariant
import io.element.android.libraries.designsystem.components.rememberLocationPinBitmap
import kotlinx.collections.immutable.ImmutableList
import kotlinx.serialization.json.JsonPrimitive
import org.maplibre.compose.expressions.dsl.and
import org.maplibre.compose.expressions.dsl.asString
Expand Down Expand Up @@ -66,7 +67,7 @@ data class LocationMarkerData(
*/
@Composable
fun LocationPinMarkers(
markers: List<LocationMarkerData>,
markers: ImmutableList<LocationMarkerData>,
onMarkerClick: ((LocationMarkerData) -> Unit)? = null,
onClusterClick: ((Position) -> Unit)? = null,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -180,6 +181,7 @@ private fun StartLiveLocationActionView(
onActionSuccess: () -> Unit,
modifier: Modifier = Modifier,
) {
val updatedOnActionSuccess by rememberUpdatedState(onActionSuccess)
Box(modifier = modifier) {
val asyncIndicatorState = rememberAsyncIndicatorState()
AsyncIndicatorHost(state = asyncIndicatorState)
Expand All @@ -202,7 +204,7 @@ private fun StartLiveLocationActionView(
}
}
is AsyncAction.Success -> {
LaunchedEffect(action) { onActionSuccess() }
LaunchedEffect(action) { updatedOnActionSuccess() }
}
else -> Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ 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.TopAppBar
import io.element.android.libraries.ui.strings.CommonStrings
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch
import org.maplibre.compose.camera.CameraMoveReason
import org.maplibre.compose.camera.CameraPosition
Expand Down Expand Up @@ -172,7 +173,7 @@ fun ShowLocationView(
trackUserLocation = state.isTrackMyLocation
)
val markers = remember(state.locationShares) {
state.locationShares.map { it.toMarkerData() }
state.locationShares.map { it.toMarkerData() }.toImmutableList()
}
LocationPinMarkers(markers)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private fun Content(errorScreenType: QrCodeErrorScreenType) {
}

@Composable
private fun Buttons(
private fun ColumnScope.Buttons(
onRetry: () -> Unit,
onCancel: () -> Unit,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.consumeWindowInsets
Expand Down Expand Up @@ -412,7 +413,7 @@ fun MessagesView(
}

@Composable
internal fun MessagesMenuActions(
internal fun RowScope.MessagesMenuActions(
displayThreads: Boolean,
roomCallState: RoomCallState,
onJoinCallClick: (isAudioCall: Boolean) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -157,6 +158,7 @@ private fun ScrollHelper(
listState: LazyListState,
onPaginate: () -> Unit,
) {
val updatedOnPaginate by rememberUpdatedState(onPaginate)
val lastVisibleItemIndex by remember {
derivedStateOf { listState.firstVisibleItemIndex + listState.layoutInfo.visibleItemsInfo.size - 1 }
}
Expand All @@ -168,7 +170,7 @@ private fun ScrollHelper(
}
LaunchedEffect(needsPagination, lastVisibleItemIndex) {
if (needsPagination) {
onPaginate()
updatedOnPaginate()
delay(400L)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
package io.element.android.features.messages.impl.timeline.model.event

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.produceState
import androidx.compose.runtime.rememberUpdatedState
import io.element.android.features.location.api.Location
import io.element.android.libraries.designsystem.components.PinVariant
import io.element.android.libraries.designsystem.components.avatar.AvatarData
Expand Down Expand Up @@ -103,16 +105,17 @@ private fun rememberIsLiveLocationActive(
mode: TimelineItemLocationContent.Mode.Live,
currentTimeMillis: () -> Long,
): Boolean {
val updatedCurrentTimeMillis by rememberUpdatedState(currentTimeMillis)
fun TimelineItemLocationContent.Mode.Live.isActive(): Boolean {
return isActive && endTimestamp > currentTimeMillis()
return isActive && endTimestamp > updatedCurrentTimeMillis()
}
return produceState(
initialValue = mode.isActive(),
key1 = mode.endTimestamp,
key2 = mode.isActive,
) {
if (mode.isActive) {
val remainingMillis = mode.endTimestamp - currentTimeMillis()
val remainingMillis = mode.endTimestamp - updatedCurrentTimeMillis()
delay(remainingMillis)
}
value = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fun AdvancedSettingsView(
if (state.liveLocationMinimumDistanceUpdate != null) {
LiveLocationUpdatesSection(
value = state.liveLocationMinimumDistanceUpdate,
onValueSaved = { value ->
onSaveValue = { value ->
state.eventSink(AdvancedSettingsEvents.SetLiveLocationMinimumDistanceUpdate(value))
},
onOpenAppPermissionsClick = onOpenAppSettingsClick,
Expand Down Expand Up @@ -339,7 +339,7 @@ private fun ModerationAndSafety(
@Composable
private fun LiveLocationUpdatesSection(
value: Int,
onValueSaved: (Int) -> Unit,
onSaveValue: (Int) -> Unit,
onOpenAppPermissionsClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Expand Down Expand Up @@ -382,7 +382,7 @@ private fun LiveLocationUpdatesSection(
value = sliderValue.toFloat(),
onValueChange = { sliderValue = it.roundToInt() },
onValueChangeFinish = {
onValueSaved(sliderValue)
onSaveValue(sliderValue)
},
valueRange = valueRange,
colors = SliderDefaults.colors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fun RoomDetailsView(
),
trailingContent = ListItemContent.Custom {
Box(
modifier = modifier
modifier = Modifier
.size(8.dp)
.clip(CircleShape)
.background(ElementTheme.colors.iconAccentPrimary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AddRoomToSpaceNode(
AddRoomToSpaceView(
state = state,
onBackClick = callback::onFinish,
onRoomsAdded = callback::onFinish,
onAddRoom = callback::onFinish,
modifier = modifier
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewParameter
Expand Down Expand Up @@ -57,9 +59,10 @@ import kotlinx.collections.immutable.toImmutableList
fun AddRoomToSpaceView(
state: AddRoomToSpaceState,
onBackClick: () -> Unit,
onRoomsAdded: () -> Unit,
onAddRoom: () -> Unit,
modifier: Modifier = Modifier,
) {
val updatedOnAddRoom by rememberUpdatedState(onAddRoom)
fun onRoomToggled(room: SelectRoomInfo) {
state.eventSink(AddRoomToSpaceEvent.ToggleRoom(room))
}
Expand All @@ -78,7 +81,7 @@ fun AddRoomToSpaceView(
// Navigate back on success
LaunchedEffect(state.saveAction) {
if (state.saveAction is AsyncAction.Success) {
onRoomsAdded()
updatedOnAddRoom()
}
}

Expand Down Expand Up @@ -247,6 +250,6 @@ internal fun AddRoomToSpaceViewPreview(
AddRoomToSpaceView(
state = state,
onBackClick = {},
onRoomsAdded = {},
onAddRoom = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private fun AndroidComposeUiTest<ComponentActivity>.setAddRoomToSpaceView(
AddRoomToSpaceView(
state = state,
onBackClick = onBackClick,
onRoomsAdded = onRoomsAdded,
onAddRoom = onRoomsAdded,
)
}
}
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ autoservice = "1.1.1"

# quality
detekt = "1.23.8"
# Stick to version < 0.5 since error detection is broken. See https://mrmans0n.github.io/compose-rules/detekt/#supported-versions-matrix
detekt_compose_rules = "0.4.28"
# See https://github.com/pinterest/ktlint/releases/
ktlint = "1.8.0"
androidx-test-ext-junit = "1.3.0"
Expand All @@ -72,6 +74,8 @@ android_gradle_plugin = { module = "com.android.tools.build:gradle", version.ref
compose_compiler_plugin = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" }
# https://developer.android.com/studio/write/java8-support#library-desugaring-versions
android_desugar = "com.android.tools:desugar_jdk_libs:2.1.5"
# Used in build.gradle.kts
detekt_compose_rules = { module = "io.nlopez.compose.rules:detekt", version.ref = "detekt_compose_rules" }
kotlin_gradle_plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
metro_gradle_plugin = { module = "dev.zacsweers.metro:gradle-plugin", version.ref = "metro" }
kotlin_compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class SafeChildrenTransitionScope<T : Any, S>(
}

@OptIn(ExperimentalSharedTransitionApi::class)
@Suppress("ContentSlotReused")
@Composable
inline fun <reified NavTarget : Any, State> ParentNode<NavTarget>.SafeChildren(
navModel: NavModel<NavTarget, State>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import androidx.compose.material3.SheetState
import androidx.compose.material3.contentColorFor
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.movableContentOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
Expand Down Expand Up @@ -88,14 +90,15 @@ fun ModalBottomSheet(
dragHandle = dragHandle,
contentWindowInsets = contentWindowInsets,
) {
val movableContent = remember { movableContentOf { content() } }
if (scrollable) {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
) {
content()
movableContent()
}
} else {
content()
movableContent()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private fun PickButton(
}
}

@Suppress("ModifierClickableOrder")
@Composable
private fun BoxScope.OverlayEditButton(
onClick: () -> Unit,
Expand Down
Loading
Loading