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

Adds Paintable class to represent generic image #1868

Merged
merged 1 commit into from
Dec 13, 2023
Merged

Conversation

fstanis
Copy link
Contributor

@fstanis fstanis commented Dec 13, 2023

WHAT

Adds a new Paintable interface that can be used to represent "any kind of image".

WHY

This decouples most parts of the library from coil while making it trivial to still use it (see CoilPaintable) and removes the need to use Any across the codebase.

HOW

By replacing uses of Any with Paintable in the codebase, which itself has only one method, which returns a Painter that can be used inside both Icon and Image elements. This logic previously lived in individual components (see Chip delta) and is now encapsulated in the various implementations of this interface.

Checklist 📋

  • Add explicit visibility modifier and explicit return types for public declarations
  • Run spotless check
  • Run tests
  • Update metalava's signature text files

@fstanis fstanis requested review from yschimke and luizgrp December 13, 2023 12:59
Copy link
Collaborator

@yschimke yschimke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned we are inventing an alternative Slot API....

@@ -87,8 +87,8 @@ public fun ToggleButton(
*/
@Composable
public fun ToggleButton(
checkedIcon: Any,
notCheckedIcon: Any,
checkedIcon: PaintableIcon,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be just Paintable, why this specific PaintableIcon?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be surfacing the lack of implementation in the current code of ToggleButton and Button to also support Image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PaintableIcon is a subtype used just to indicate "this could be used in an Icon instead of an Image". This is to keep compatibility with existing code that in some places uses Icon or Image and in some only Icon (like here).

contentScale = ContentScale.Crop,
alpha = LocalContentAlpha.current,
)
if (it is PaintableIcon) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we avoid repeating this? pull it out somewhere?

Copy link
Member

@luizgrp luizgrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the improvements, even though it might look like it is making the API a bit less convenient.

}

@Stable
public class CoilPaintable(private val model: Any?, private val placeholder: Painter? = null) : Paintable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to have "Coil" in the name, exposing the implementation details? ImageLoadingPaintable would be my suggestion but doesn't read great..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this get extracted to a separate module as previously suggested, then it should be fine to keep the name, and having "-coil" in the name of the lib.
Worth doing that extraction before next release (not necessarily in this PR) to avoid having 2 separated "big" API changes in the same area?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, moving this to a separate -coil library will be a quick follow-up. I only added it here to stay backwards-compatible.

@fstanis fstanis force-pushed the main branch 6 times, most recently from ca8e0db to 6daba44 Compare December 13, 2023 17:57
@fstanis fstanis merged commit 6d2f78f into google:main Dec 13, 2023
4 checks passed
@fstanis fstanis mentioned this pull request Dec 14, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants