This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1876594 - Refactor
ThumbnailStorage
to be an implicit dependenc…
…y within a factory helper
- Loading branch information
1 parent
ab7cc95
commit f0429a5
Showing
15 changed files
with
114 additions
and
152 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
fenix/app/src/main/java/org/mozilla/fenix/compose/ComposableFactory.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,75 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.compose | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import mozilla.components.concept.base.images.ImageLoadRequest | ||
import org.mozilla.fenix.components.components | ||
import org.mozilla.fenix.theme.FirefoxTheme | ||
import org.mozilla.fenix.compose.ThumbnailImage as ThumbnailImageContent | ||
|
||
/** | ||
* Factory object used to instantiate Composables with preview-breaking dependencies, such as | ||
* [components]. | ||
*/ | ||
object ComposableFactory { | ||
|
||
/** | ||
* Loads a thumbnail belonging to a [ImageLoadRequest], fetching asynchronously the bitmap from storage. | ||
* If this is in a preview, an empty box will be rendered instead. | ||
* | ||
* @param request [ImageLoadRequest] used to fetch the thumbnail bitmap. | ||
* @param contentScale [ContentScale] used to draw image content. | ||
* @param alignment [Alignment] used to draw the image content. | ||
* @param modifier [Modifier] used to draw the image content. | ||
* @param fallbackContent The content to display with a thumbnail is unable to be loaded. | ||
*/ | ||
@Composable | ||
fun ThumbnailImage( | ||
request: ImageLoadRequest, | ||
contentScale: ContentScale, | ||
alignment: Alignment, | ||
modifier: Modifier = Modifier, | ||
fallbackContent: @Composable () -> Unit, | ||
) { | ||
if (inComposePreview) { | ||
Box(modifier = modifier.background(color = FirefoxTheme.colors.layer3)) | ||
} else { | ||
ThumbnailImageContent( | ||
request = request, | ||
contentScale = contentScale, | ||
alignment = alignment, | ||
modifier = modifier, | ||
fallbackContent = fallbackContent, | ||
) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* This preview does not demo anything. This is to ensure that [ComposableFactory.ThumbnailImage] | ||
* does not break other previews. | ||
*/ | ||
@Preview | ||
@Composable | ||
private fun ThumbnailImagePreview() { | ||
FirefoxTheme { | ||
ComposableFactory.ThumbnailImage( | ||
request = ImageLoadRequest("1", 1, false), | ||
modifier = Modifier.size(50.dp), | ||
contentScale = ContentScale.Crop, | ||
alignment = Alignment.Center, | ||
fallbackContent = {}, | ||
) | ||
} | ||
} |
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
Oops, something went wrong.