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

[FR]: Feature Request: Add Extensions for Icon Handling with ImageVector and DrawableRes #120

Closed
2 tasks done
zeoowl-dev opened this issue Oct 3, 2023 · 1 comment · Fixed by #129
Closed
2 tasks done
Assignees
Labels
@feature New feature or request @priority-medium
Milestone

Comments

@zeoowl-dev
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

Currently, dealing with icons in Jetpack Compose can involve handling both ImageVector and DrawableRes icons separately. It would be convenient to have some extensions or utility functions that simplify working with icons, allowing users to seamlessly switch between ImageVector and DrawableRes icons without the need for explicit conversions.

Describe the solution

Add extensions or utility functions to the Icon class in the dev.teogor.ceres.ui.foundation.graphics package to provide easy access to icons using both ImageVector and DrawableRes.

Example Usage:

// Create an Icon using ImageVector
val imageVectorIcon = Icons.Filled.Wallpaper.asImageVectorIcon()

// Create an Icon using DrawableRes
val drawableResIcon = R.drawable.ic_wallpaper.asDrawableResourceIcon()

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@teogor teogor self-assigned this Oct 3, 2023
@teogor teogor added @priority-medium @feature New feature or request labels Oct 3, 2023
@teogor teogor added this to the 1.0.0-alpha03 milestone Oct 3, 2023
@teogor
Copy link
Owner

teogor commented Oct 3, 2023

That seems like a more efficient approach for generating the Icon type class. We are planning to implement this enhancement in our next release.

// IconExtensions.kt

package dev.teogor.ceres.ui.foundation.graphics

import androidx.annotation.DrawableRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Wallpaper
import androidx.compose.ui.graphics.vector.ImageVector

/**
 * Extension function to create an Icon using ImageVector.
 * @receiver The ImageVector you want to use as an Icon.
 * @return An ImageVectorIcon.
 */
fun ImageVector.asImageVectorIcon(): Icon.ImageVectorIcon {
    return Icon.ImageVectorIcon(this)
}

/**
 * Extension function to create an Icon using a DrawableRes.
 * @receiver The DrawableRes identifier you want to use as an Icon.
 * @return A DrawableResourceIcon.
 */
fun Int.asDrawableResourceIcon(): Icon.DrawableResourceIcon {
    return Icon.DrawableResourceIcon(this)
}

// Example usage:
// val imageVectorIcon = Icons.Filled.Wallpaper.asImageVectorIcon()
// val drawableResIcon = R.drawable.ic_wallpaper.asDrawableResourceIcon()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@feature New feature or request @priority-medium
Projects
Development

Successfully merging a pull request may close this issue.

2 participants