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

kotlin to 1.9.22 & compose-multiplatform to 1.6.0-rc01 #432

Merged
merged 13 commits into from
Feb 14, 2024
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

5 changes: 5 additions & 0 deletions app/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ plugins {

kotlin {
sourceSets {
all {
languageSettings {
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}
commonMain {
dependencies {
api(compose.runtime)
Expand Down
2 changes: 2 additions & 0 deletions app/common/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://github.com/JetBrains/compose-multiplatform/pull/3961
compose.resources.always.generate.accessors=true
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.seiko.imageloader.demo

import io.github.qdsfdhvh.generated.resources.Res
import io.github.qdsfdhvh.common.generated.resources.Res

internal object MR {
val images get() = Res.images
val images get() = Res.drawable

val colors get() = Res.drawable
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
Expand All @@ -38,7 +38,7 @@ import kotlinx.coroutines.withContext
@Composable
fun BackButton(onBack: () -> Unit) {
IconButton(onBack) {
Icon(Icons.Default.ArrowBack, "back")
Icon(Icons.AutoMirrored.Filled.ArrowBack, "back")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import co.touchlab.kermit.Logger
import com.seiko.imageloader.demo.data.imageJsonData
import com.seiko.imageloader.rememberImagePainter
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.InternalResourceApi
import org.jetbrains.compose.resources.readResourceBytes

@OptIn(ExperimentalResourceApi::class)
@OptIn(ExperimentalResourceApi::class, InternalResourceApi::class)
@Composable
fun OtherImagesScene(
onBack: () -> Unit,
Expand Down Expand Up @@ -107,7 +108,7 @@ fun OtherImagesScene(
}
item {
val imageBytes by produceState<ByteArray?>(null) {
value = readResourceBytes("composeRes/images/cat.jpg")
value = readResourceBytes("drawable/cat.jpg")
}
imageBytes?.let {
ImageItem(it)
Expand Down
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ allprojects {
}
}
}

// fix order of android release lint tasks
listOf(
"generateReleaseLintVitalModel",
"lintVitalAnalyzeRelease",
).forEach { name ->
tasks.matching { it.name == name }.configureEach {
dependsOn(tasks.matching { it.name == "copyFontsToAndroidAssets" })
}
}
}

tasks.dokkaHtmlMultiModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ package com.seiko.imageloader.component.fetcher

import com.seiko.imageloader.option.Options
import okio.Buffer
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.ImageResource
import org.jetbrains.compose.resources.InternalResourceApi
import org.jetbrains.compose.resources.getPathByEnvironment
import org.jetbrains.compose.resources.getSystemEnvironment
import org.jetbrains.compose.resources.readResourceBytes

@OptIn(ExperimentalResourceApi::class)
class ComposeResourceFetcher {
class Factory : Fetcher.Factory {
override fun create(data: Any, options: Options): Fetcher? {
if (data is ImageResource) {
return ImageResourceFetcher(data)
if (data is DrawableResource) {
return DrawableResourceFetcher(data)
}
return null
}
}

private class ImageResourceFetcher(
private val resource: ImageResource,
private class DrawableResourceFetcher(
private val resource: DrawableResource,
) : Fetcher {
@OptIn(ExperimentalResourceApi::class)
@OptIn(InternalResourceApi::class)
override suspend fun fetch(): FetchResult {
val path = resource.getPathByEnvironment()
val path = resource.getPathByEnvironment(getSystemEnvironment())
return FetchResult.OfSource(
source = Buffer().apply {
write(readResourceBytes(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ internal actual suspend fun FileResource.toFetchResult(options: Options): FetchR
}

@OptIn(ExperimentalForeignApi::class)
@Suppress("INVISIBLE_MEMBER")
internal actual suspend fun ImageResource.toFetchResult(options: Options): FetchResult? {
val uiImage: UIImage = this.toUIImage()
?: throw IllegalArgumentException("can't read UIImage of $this")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal actual suspend fun FileResource.toFetchResult(options: Options): FetchR
}

@OptIn(ExperimentalForeignApi::class)
@Suppress("INVISIBLE_MEMBER")
internal actual suspend fun ImageResource.toFetchResult(options: Options): FetchResult? {
val nsImage: NSImage = this.toNSImage()
?: throw IllegalArgumentException("can't read NSImage of $this")
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ kotlin.mpp.androidSourceSetLayoutVersion=2
org.jetbrains.compose.experimental.uikit.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
# https://github.com/JetBrains/compose-multiplatform/pull/3961
compose.resources.always.generate.accessors=true
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.2.1"
compose-multiplatform = "1.6.0-dev1334"
kotlin = "1.9.21"
agp = "8.2.2"
compose-multiplatform = "1.6.0-rc01"
kotlin = "1.9.22"
kotlinx-coroutines = "1.8.0-RC2"
kotlinx-serialization = "1.6.2"
androidx-core-ktx = "1.12.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Looper
import android.view.View
import androidx.compose.runtime.RememberObserver
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.geometry.Size
Expand Down Expand Up @@ -41,7 +42,7 @@ actual fun Image.toPainter(): Painter {
private class DrawablePainter(
val drawable: Drawable,
) : Painter(), RememberObserver {
private var drawInvalidateTick by mutableStateOf(0)
private var drawInvalidateTick by mutableIntStateOf(0)
private var drawableIntrinsicSize by mutableStateOf(drawable.intrinsicSize)

private val callback: Drawable.Callback by lazy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.seiko.imageloader.component.mapper

import android.annotation.SuppressLint
import android.content.ContentResolver.SCHEME_ANDROID_RESOURCE
import android.content.Context
import com.eygraber.uri.Uri
Expand All @@ -15,6 +16,7 @@ class ResourceUriMapper(
private val context: Context? = null,
) : Mapper<Uri> {

@SuppressLint("DiscouragedApi")
override fun map(data: Any, options: Options): Uri? {
if (data !is Uri) return null
if (!isApplicable(data)) return null
Expand Down
25 changes: 25 additions & 0 deletions lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2021 Google LLC
~
~ 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.
-->

<lint>
<!-- https://issuetracker.google.com/issues/181142248 -->
<issue id="UnsafeExperimentalUsageWarning" severity="ignore" />
<issue id="UnsafeExperimentalUsageError" severity="ignore" />

<!-- https://issuetracker.google.com/issues/182388985 -->
<issue id="InvalidFragmentVersionForActivityResult" severity="ignore" />
</lint>
Loading