generated from JetBrains/compose-multiplatform-template
-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Replace custom image loader with image loader dependency (#99)"
This reverts commit d3e2ccb. While image-loader library is great, it was causing OOM when doing dynamic theming. For some reason I also noticed lot of "blinks" when switching from one image to another in featured image section. So, reverting back to my custom image loader
- Loading branch information
1 parent
a5dad6f
commit 2502fc9
Showing
13 changed files
with
381 additions
and
105 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
shared/src/androidMain/kotlin/dev/sasikanth/rss/reader/components/AsyncImage.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,38 @@ | ||
/* | ||
* Copyright 2023 Sasikanth Miriyampalli | ||
* | ||
* 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 dev.sasikanth.rss.reader.components | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
|
||
@Composable | ||
actual fun AsyncImage( | ||
url: String, | ||
contentDescription: String?, | ||
contentScale: ContentScale, | ||
modifier: Modifier, | ||
) { | ||
Box(modifier) { | ||
coil.compose.AsyncImage( | ||
modifier = Modifier.matchParentSize(), | ||
model = url, | ||
contentDescription = contentDescription, | ||
contentScale = ContentScale.Crop | ||
) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
shared/src/androidMain/kotlin/dev/sasikanth/rss/reader/components/ImageLoader.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,50 @@ | ||
/* | ||
* Copyright 2023 Sasikanth Miriyampalli | ||
* | ||
* 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 dev.sasikanth.rss.reader.components | ||
|
||
import android.content.Context | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import androidx.core.graphics.drawable.toBitmap | ||
import coil.imageLoader | ||
import coil.request.ImageRequest | ||
import coil.request.SuccessResult | ||
import coil.size.Scale | ||
import dev.sasikanth.rss.reader.di.scopes.AppScope | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
@AppScope | ||
class AndroidImageLoader(private val context: Context) : ImageLoader { | ||
|
||
override suspend fun getImage(url: String, size: Int?): ImageBitmap? { | ||
val requestBuilder = | ||
ImageRequest.Builder(context) | ||
.data(url) | ||
.scale(Scale.FILL) | ||
.allowHardware(false) | ||
.memoryCacheKey("$url.dynamic_colors") | ||
|
||
if (size != null) { | ||
requestBuilder.size(size) | ||
} | ||
|
||
return when (val result = context.imageLoader.execute(requestBuilder.build())) { | ||
is SuccessResult -> result.drawable.toBitmap().asImageBitmap() | ||
else -> null | ||
} | ||
} | ||
} |
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
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
25 changes: 25 additions & 0 deletions
25
shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/components/ImageLoader.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,25 @@ | ||
/* | ||
* Copyright 2023 Sasikanth Miriyampalli | ||
* | ||
* 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 dev.sasikanth.rss.reader.components | ||
|
||
import androidx.compose.runtime.staticCompositionLocalOf | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
|
||
interface ImageLoader { | ||
suspend fun getImage(url: String, size: Int?): ImageBitmap? | ||
} | ||
|
||
val LocalImageLoader = staticCompositionLocalOf<ImageLoader?> { null } |
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
51 changes: 51 additions & 0 deletions
51
shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/components/AsyncImage.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,51 @@ | ||
/* | ||
* Copyright 2023 Sasikanth Miriyampalli | ||
* | ||
* 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 dev.sasikanth.rss.reader.components | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import io.ktor.client.request.get | ||
import org.jetbrains.skia.Image | ||
|
||
@Composable | ||
actual fun AsyncImage( | ||
url: String, | ||
contentDescription: String?, | ||
contentScale: ContentScale, | ||
modifier: Modifier, | ||
) { | ||
Box(modifier) { | ||
val imageState by rememberImageLoaderState(url) | ||
|
||
when (imageState) { | ||
is ImageLoaderState.Loaded -> { | ||
Image( | ||
modifier = Modifier.matchParentSize(), | ||
bitmap = (imageState as ImageLoaderState.Loaded).image, | ||
contentDescription = contentDescription, | ||
contentScale = contentScale | ||
) | ||
} | ||
else -> { | ||
// TODO: Handle other cases instead of just showing blank space? | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.