Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Compose (1.2.0) and Kotlin (1.7.0). #1293

Merged
merged 21 commits into from
Jul 22, 2022
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
4 changes: 1 addition & 3 deletions buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ private inline fun <reified T : BaseExtension> Project.setupBaseModule(
"-Xno-call-assertions",
"-Xno-param-assertions",
"-Xno-receiver-assertions",
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-requires-opt-in/#requiresoptin
"-Xopt-in=kotlin.RequiresOptIn"
)
if (project.name != "coil-test") {
arguments += "-Xopt-in=coil.annotation.ExperimentalCoilApi"
arguments += "-opt-in=coil.annotation.ExperimentalCoilApi"
}
// https://youtrack.jetbrains.com/issue/KT-41985
freeCompilerArgs += arguments
Expand Down
8 changes: 8 additions & 0 deletions coil-base/api/coil-base.api
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ public final class coil/memory/MemoryCache$Key : android/os/Parcelable {
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class coil/memory/MemoryCache$Key$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcoil/memory/MemoryCache$Key;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcoil/memory/MemoryCache$Key;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class coil/memory/MemoryCache$Value {
public fun <init> (Landroid/graphics/Bitmap;Ljava/util/Map;)V
public synthetic fun <init> (Landroid/graphics/Bitmap;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down
2 changes: 1 addition & 1 deletion coil-compose-base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setupLibraryModule(publish = true) {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.get()
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
}

Expand Down
2 changes: 1 addition & 1 deletion coil-compose-singleton/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setupLibraryModule(publish = true) {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.get()
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
}

Expand Down
3 changes: 1 addition & 2 deletions coil-sample-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ setupAppModule {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.get()
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
}

Expand All @@ -34,6 +34,5 @@ dependencies {

implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.accompanist.insets)
implementation(libs.compose.material)
}
52 changes: 16 additions & 36 deletions coil-sample-compose/src/main/java/coil/sample/LazyStaggeredGrid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@
*/
package coil.sample

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.LocalOverScrollConfiguration
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.rememberScrollableState
import androidx.compose.foundation.gestures.scrollBy
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -47,38 +43,22 @@ fun LazyStaggeredGrid(
}

val scope = rememberCoroutineScope { Dispatchers.Main.immediate }
val scrollConnections = List(columnCount) { index ->
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
val delta = available.y
scope.launch {
states.forEachIndexed { stateIndex, state ->
if (stateIndex != index) {
state.scrollBy(-delta)
}
}
}
return Offset.Zero
}
}
val scrollableState = rememberScrollableState { delta ->
scope.launch { states.forEach { it.scrollBy(-delta) } }
delta
}
val gridScope = RealLazyStaggeredGridScope(columnCount).apply(content)

// Disable overscroll otherwise it'll only overscroll one column.
@OptIn(ExperimentalFoundationApi::class)
CompositionLocalProvider(LocalOverScrollConfiguration provides null) {
Row {
for (index in 0 until columnCount) {
LazyColumn(
contentPadding = contentPadding,
state = states[index],
modifier = Modifier
.nestedScroll(scrollConnections[index])
.weight(1f)
) {
for ((key, itemContent) in gridScope.items(index)) {
item(key) { itemContent() }
}
Row(Modifier.scrollable(scrollableState, Orientation.Vertical)) {
for (index in 0 until columnCount) {
LazyColumn(
contentPadding = contentPadding,
state = states[index],
userScrollEnabled = false,
modifier = Modifier.weight(1f)
) {
for ((key, itemContent) in gridScope.items(index)) {
item(key) { itemContent() }
}
}
}
Expand Down
42 changes: 18 additions & 24 deletions coil-sample-compose/src/main/java/coil/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
Expand All @@ -33,8 +34,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import coil.memory.MemoryCache
import coil.request.ImageRequest
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.ProvideWindowInsets

class MainActivity : ComponentActivity() {

Expand All @@ -53,26 +52,24 @@ private fun Content(viewModel: MainViewModel = viewModel()) {
onPrimary = Color.Black
)
) {
ProvideWindowInsets {
Scaffold(
topBar = {
Toolbar(
assetType = viewModel.assetType.collectAsState().value,
onAssetTypeChange = { viewModel.assetType.value = it }
Scaffold(
topBar = {
Toolbar(
assetType = viewModel.assetType.collectAsState().value,
onAssetTypeChange = { viewModel.assetType.value = it }
)
},
content = { padding ->
Box(Modifier.padding(padding)) {
ScaffoldContent(
screen = viewModel.screen.collectAsState().value,
onScreenChange = { viewModel.screen.value = it },
images = viewModel.images.collectAsState().value
)
},
content = { padding ->
Box(Modifier.padding(padding)) {
ScaffoldContent(
screen = viewModel.screen.collectAsState().value,
onScreenChange = { viewModel.screen.value = it },
images = viewModel.images.collectAsState().value
)
}
}
)
BackHandler { viewModel.onBackPressed() }
}
}
)
BackHandler { viewModel.onBackPressed() }
}
}

Expand All @@ -81,13 +78,10 @@ private fun Toolbar(
assetType: AssetType,
onAssetTypeChange: (AssetType) -> Unit,
) {
val topPadding = with(LocalDensity.current) {
LocalWindowInsets.current.systemBars.top.toDp()
}
TopAppBar(
title = { Text(stringResource(R.string.app_name)) },
actions = { AssetTypeButton(assetType, onAssetTypeChange) },
modifier = Modifier.padding(top = topPadding)
modifier = Modifier.statusBarsPadding()
)
}

Expand Down
9 changes: 4 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
accompanist = "0.23.1"
androidx-activity = "1.4.0"
androidx-lifecycle = "2.4.1"
androidx-test = "1.4.0"
compose = "1.1.1"
compose = "1.2.0-rc03"
composeCompiler = "1.2.0"
coroutines = "1.6.4"
ktlint = "0.44.0"
okhttp = "4.10.0"
Expand All @@ -16,11 +16,10 @@ ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "10.3.0" }

[libraries]
gradlePlugin-android = "com.android.tools.build:gradle:7.2.1"
gradlePlugin-kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
gradlePlugin-kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
gradlePlugin-mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.21.0"

accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" }
accompanist-insets = { module = "com.google.accompanist:accompanist-insets", version.ref = "accompanist" }
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version = "0.24.13-rc" }

androidx-activity = { module = "androidx.activity:activity-ktx", version.ref = "androidx-activity" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
Expand Down