diff --git a/README.md b/README.md index 1c22272..d26de74 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,6 @@ Multiplatform: │ ├── images │ │ ├── vector_image.svg │ │ └── raster_image.png -│ ├── images-night -│ │ ├── vector_image.svg -│ │ └── raster_image.png │ └── strings │ ├── strings_en.xml │ └── strings_ru.xml @@ -77,9 +74,6 @@ Android or JVM: │ ├── images │ │ ├── vector_image.svg │ │ └── raster_image.png -│ ├── images-night -│ │ ├── vector_image.svg -│ │ └── raster_image.png │ └── strings │ ├── strings_en.xml │ └── strings_ru.xml @@ -147,17 +141,27 @@ Recommended for multicolor images. > - For iOS images are generated from 1x to 3x (where 1x is 1:1 in pixels to the specified size) > - For JVM and JS a single image of the specified size is generated. +> **night** +> +> Night/Dark Mode images are supported for Android and iOS by adding the `(night)` modifier. The filename and type of +> the image must match the corresponding day/light version without the `(night)` modifier. +> +> - For Android this creates night images in `drawable-night-nodpi`. +> - For iOS this creates a `"appearances" : [ { "appearance" : "luminosity", "value" : "dark" } ]` entry in the `imageset`. + Filename examples: ``` some_hd_image_(100).jpg app_logo_(orig).svg my_colorful_bitmap_(orig)_(150).png +image_with_night_support_(night).png ``` Kotlin: ```kotlin MainRes.image.some_hd_image MainRes.image.app_logo MainRes.image.my_colorful_bitmap +MainRes.image.image_with_night_support ``` Swift: ```swift @@ -177,15 +181,6 @@ Sample: Image size in Figma is **240x89**. Final image name is **pic_(orig)_(240).png** -#### Night/Dark Mode Images -Night/Dark Mode images are supported for Android and iOS by placing a night version of the image into the -`libres/images-night/` folder. - -The filename and type of the image must match the corresponding day/light version in `libres/images/`. - -- For Android this creates night images in `drawable-night-nodpi`. -- For iOS this creates a `"appearances" : [ { "appearance" : "luminosity", "value" : "dark" } ]` entry in the `imageset`. - ## Jetpack Compose ```kotlin diff --git a/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/LibresImagesGenerationTask.kt b/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/LibresImagesGenerationTask.kt index 9d5ce63..51e6530 100644 --- a/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/LibresImagesGenerationTask.kt +++ b/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/LibresImagesGenerationTask.kt @@ -8,8 +8,8 @@ import io.github.skeptick.libres.plugin.images.declarations.ImagesObjectFile import io.github.skeptick.libres.plugin.images.models.ImageProps import io.github.skeptick.libres.plugin.images.models.ImageSet import io.github.skeptick.libres.plugin.images.processing.removeImage -import io.github.skeptick.libres.plugin.images.processing.saveImageSet import io.github.skeptick.libres.plugin.images.processing.saveImage +import io.github.skeptick.libres.plugin.images.processing.saveImageSet import org.gradle.api.DefaultTask import org.gradle.api.file.FileCollection import org.gradle.api.tasks.* @@ -29,11 +29,6 @@ abstract class LibresImagesGenerationTask : DefaultTask() { @get:PathSensitive(PathSensitivity.RELATIVE) internal abstract var inputDirectory: FileCollection - @get:Incremental - @get:InputFiles - @get:PathSensitive(PathSensitivity.RELATIVE) - internal abstract var nightInputDirectory: FileCollection - @get:OutputDirectories internal abstract var outputSourcesDirectories: Map @@ -43,10 +38,7 @@ abstract class LibresImagesGenerationTask : DefaultTask() { @TaskAction fun apply(inputChanges: InputChanges) { // Update images for changed files - sequenceOf( - inputChanges.getFileChanges(inputDirectory), - inputChanges.getFileChanges(nightInputDirectory), - ).flatten() + inputChanges.getFileChanges(inputDirectory) .forEach { change -> val image = ImageProps(change.file) @@ -57,11 +49,8 @@ abstract class LibresImagesGenerationTask : DefaultTask() { } } - // Generate image catalog - sequenceOf( - inputDirectory.files, - nightInputDirectory.files, - ).flatten() + // Generate image sets + inputDirectory.files .map(::ImageProps) .groupBy(ImageProps::name) .map { (name, files) -> ImageSet(name, files) } @@ -70,13 +59,10 @@ abstract class LibresImagesGenerationTask : DefaultTask() { } // Generate code - sequenceOf( - inputDirectory.files, - nightInputDirectory.files, - ).flatten().toSet() + inputDirectory.files .takeIf { files -> files.isNotEmpty() } - ?.distinctBy(File::nameWithoutExtension) ?.map(::ImageProps) + ?.distinctBy(ImageProps::name) ?.let(::buildImages) ?: buildEmptyImages() } diff --git a/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/ResourcesPlugin.kt b/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/ResourcesPlugin.kt index 4d067fb..26c40b2 100644 --- a/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/ResourcesPlugin.kt +++ b/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/ResourcesPlugin.kt @@ -118,7 +118,6 @@ class ResourcesPlugin : Plugin { private fun Project.registerGeneratorsTasks() { val stringsInputDirectory = File(inputDirectory, "strings") val imagesInputDirectory = File(inputDirectory, "images") - val nightImagesInputDirectory = File(inputDirectory, "images-night") val stringsOutputPackageName = listOfNotNull(outputPackageName, "strings").joinToString(".") val imagesOutputPackageName = listOfNotNull(outputPackageName, "images").joinToString(".") @@ -152,11 +151,6 @@ class ResourcesPlugin : Plugin { !element.isDirectory && element.file.extension.lowercase() in IMAGES_EXTENSIONS } } - task.nightInputDirectory = fileTree(nightImagesInputDirectory) { config -> - config.include { element -> - !element.isDirectory && element.file.extension.lowercase() in IMAGES_EXTENSIONS - } - } task.outputSourcesDirectories = allSourceSets.associateBy(PluginSourceSet::platform) { it.sourcesDir.toOutputDirectory(imagesOutputPackageName) } @@ -254,4 +248,4 @@ class ResourcesPlugin : Plugin { File(absolutePath, packageName.replace('.', File.separatorChar)) } -} +} \ No newline at end of file diff --git a/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/images/models/ImageProps.kt b/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/images/models/ImageProps.kt index 5166d07..3b9e686 100644 --- a/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/images/models/ImageProps.kt +++ b/gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/images/models/ImageProps.kt @@ -11,7 +11,6 @@ internal class ImageProps(val file: File) { val isNightMode: Boolean init { - val directoryName = file.parentFile.name val nameWithoutExtension = file.nameWithoutExtension val parameters = ParametersRegex.findAll(nameWithoutExtension).toList() @@ -19,7 +18,7 @@ internal class ImageProps(val file: File) { this.extension = file.extension.lowercase() this.targetSize = if (!isVector) parameters.firstNotNullOfOrNull { it.groupValues[1].toIntOrNull() } else null this.isTintable = parameters.none { it.groupValues[1].startsWith("orig") } - this.isNightMode = directoryName.endsWith("-night") + this.isNightMode = parameters.any { it.groupValues[1] == "night" } } companion object {