### ImageViewer Setup Source: https://github.com/skydoves/landscapist/blob/main/README.md Configures a full-screen image viewer with paging, zoom, and swipe-to-dismiss. Use `rememberImageViewerState` to manage the viewer's state. ```kotlin import com.skydoves.landscapist.gallery.ImageViewer import com.skydoves.landscapist.gallery.rememberImageViewerState val viewerState = rememberImageViewerState( initialPage = startIndex, pageCount = { imageUrls.size }, ) ImageViewer( images = imageUrls, state = viewerState, zoomableConfig = ZoomableConfig( minZoom = 1f, maxZoom = 5f, doubleTapZoom = 2f, ), onDismiss = { navController.popBackStack() }, topBar = { current, total -> TopAppBar( backgroundColor = Color.Black.copy(alpha = 0.5f), title = { Text("${current + 1} / $total", color = Color.White) }, ) }, ) ``` -------------------------------- ### Basic ImageGallery Setup Source: https://github.com/skydoves/landscapist/blob/main/README.md Renders a grid of images using `LazyVerticalGrid`. Supports various image sources and plugins like Shimmer. Customize tiles using the `content` lambda. ```kotlin import com.skydoves.landscapist.gallery.ImageGallery ImageGallery( images = imageUrls, columns = GridCells.Fixed(3), imageOptions = ImageOptions(contentScale = ContentScale.Crop), component = rememberImageComponent { +ShimmerPlugin( shimmer = Shimmer.Resonate( baseColor = Color.DarkGray, highlightColor = Color.LightGray, ), ) }, onImageClick = { index, imageModel -> // open ImageViewer at `index` }, ) ``` -------------------------------- ### ImageGallery with Plugins and ImageOptions Source: https://github.com/skydoves/landscapist/blob/main/docs/gallery.md Integrate Landscapist plugins and customize image rendering options like content scale. Requires 'rememberImageComponent' for plugin setup. ```kotlin ImageGallery( images = imageUrls, imageOptions = ImageOptions(contentScale = ContentScale.Crop), component = rememberImageComponent { +ShimmerPlugin( shimmer = Shimmer.Resonate( baseColor = Color.DarkGray, highlightColor = Color.LightGray, ), ) }, ) ``` -------------------------------- ### Create Landscapist Instance (Other Platforms) Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-core.md Obtain the singleton Landscapist instance for non-Android platforms (iOS, Desktop, Web). Custom configurations can be applied, but disk caching requires manual setup. ```kotlin import com.skydoves.landscapist.core.Landscapist // Get the singleton instance with default configuration val landscapist = Landscapist.getInstance() // Or create a custom instance val landscapist = Landscapist.builder() .config( LandscapistConfig( memoryCacheSize = 64 * 1024 * 1024L, // Note: Disk cache requires platform-specific setup ) ) .build() ``` -------------------------------- ### Handling Loading States in LandscapistImage Source: https://github.com/skydoves/landscapist/blob/main/README.md Example of how to define custom composables for loading, success, and failure states when using LandscapistImage. ```kotlin LandscapistImage( imageModel = { imageUrl }, loading = { Box(modifier = Modifier.fillMaxSize()) { CircularProgressIndicator(modifier = Modifier.align(Alignment.Center)) } }, success = { state, painter -> Image( painter = painter, contentDescription = "Loaded image" ) }, failure = { Text("Failed to load image") } ) ``` -------------------------------- ### Fresco Initialization Source: https://github.com/skydoves/landscapist/blob/main/fresco/src/main/generated/baselineProfiles/baseline-prof.txt Methods for initializing the Fresco library with different configurations. ```APIDOC ## Fresco Initialization ### Description Provides methods to initialize the Fresco image pipeline with various configuration options. ### Methods - `initialize(Context context, ImagePipelineConfig imagePipelineConfig)` - `initialize(Context context, ImagePipelineConfig imagePipelineConfig, DraweeConfig draweeConfig)` - `initialize(Context context, ImagePipelineConfig imagePipelineConfig, DraweeConfig draweeConfig, boolean enableBitmapPool)` - `initializeDrawee(Context context, DraweeConfig draweeConfig)` ### Parameters - **context** (Context) - Required - The Android application context. - **imagePipelineConfig** (ImagePipelineConfig) - Required - Configuration for the image pipeline. - **draweeConfig** (DraweeConfig) - Optional - Configuration for Drawee components. - **enableBitmapPool** (boolean) - Optional - Flag to enable the bitmap pool. ``` -------------------------------- ### Manage Memory Cache Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-core.md Access, clear, trim, and get stats for the memory cache. The memory cache uses an LRU eviction policy. ```kotlin val memoryCache = landscapist.config.memoryCache memoryCache?.clear() memoryCache?.trimToSize(32 * 1024 * 1024L) // 32MB val size = memoryCache?.size val maxSize = memoryCache?.maxSize ``` -------------------------------- ### Basic Image Options with Fresco Source: https://github.com/skydoves/landscapist/blob/main/docs/image-options.md Pass an ImageOptions instance to configure content scale, alignment, description, color filter, alpha, and tag for FrescoImage. ```kotlin FrescoImage( imageOptions = ImageOptions( contentScale = ContentScale.Crop, alignment = Alignment.Center, contentDescription = "profile image", colorFilter = null, alpha = 1f, tag = "user profile image" ), ..) ) ``` -------------------------------- ### Take Snapshot Images with Paparazzi Source: https://github.com/skydoves/landscapist/blob/main/README.md Use Paparazzi to take snapshot images of your Jetpack Compose UI. This example demonstrates capturing a GlideImage with a preview placeholder. ```kotlin paparazzi.snapshot { CompositionLocalProvider(LocalInspectionMode provides true) { GlideImage( modifier = Modifier.fillMaxSize(), imageModel = { ".." }, previewPlaceholder = painterResource(R.drawable.placeholder) ) } } ``` -------------------------------- ### Initialize Fresco with ImagePipelineConfig Source: https://github.com/skydoves/landscapist/blob/main/docs/fresco/overview.md Set up Fresco with ImagePipelineConfig in your Application class. It's recommended to use OkHttpImagePipelineConfigFactory for network configurations and caching. ```kotlin class App : Application() { override fun onCreate() { super.onCreate() val pipelineConfig = OkHttpImagePipelineConfigFactory .newBuilder(this, OkHttpClient.Builder().build()) .setDiskCacheEnabled(true) .setDownsampleEnabled(true) .setResizeAndRotateEnabledForNetwork(true) .build() Fresco.initialize(this, pipelineConfig) } } ``` -------------------------------- ### Configure Cache Policies Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-core.md Control caching behavior per request using predefined policies like ENABLED, READ_ONLY, WRITE_ONLY, or DISABLED. Example shows reading from cache and writing only. ```kotlin CachePolicy.ENABLED CachePolicy.READ_ONLY CachePolicy.WRITE_ONLY CachePolicy.DISABLED val request = ImageRequest.builder() .model(url) .memoryCachePolicy(CachePolicy.ENABLED) .diskCachePolicy(CachePolicy.READ_ONLY) .build() ``` -------------------------------- ### Import Landscapist BOM and Libraries (Groovy) Source: https://github.com/skydoves/landscapist/blob/main/docs/bom.md Import the Landscapist BOM to manage versions of all Landscapist libraries. Then, import individual Landscapist libraries as needed. ```Groovy dependencies { // Import the landscapist BOM implementation "com.github.skydoves:landscapist-bom:$version" // Import landscapist libraries implementation "com.github.skydoves:landscapist-glide" implementation "com.github.skydoves:landscapist-coil" implementation "com.github.skydoves:landscapist-fresco" implementation "com.github.skydoves:landscapist-animation" implementation "com.github.skydoves:landscapist-placeholder" implementation "com.github.skydoves:landscapist-palette" implementation "com.github.skydoves:landscapist-transformation" implementation "com.github.skydoves:landscapist-zoomable" } ``` -------------------------------- ### Add Custom Plugin using + operator Source: https://github.com/skydoves/landscapist/blob/main/docs/image-component-and-plugin.md Add custom plugins like CircularRevealPlugin and LoadingPlugin to the ImageComponent using the '+' operator. This example shows integration with Glide, Coil, and Fresco. ```kotlin GlideImage( component = rememberImageComponent { +CircularRevealPlugin() +LoadingPlugin(source) }, .. ) ``` ```kotlin CoilImage( component = rememberImageComponent { +CircularRevealPlugin() +LoadingPlugin(source) }, .. ) ``` ```kotlin FrescoImage( component = rememberImageComponent { +CircularRevealPlugin() +LoadingPlugin(source) }, .. ) ``` -------------------------------- ### Custom Landscapist Instance Configuration Source: https://github.com/skydoves/landscapist/blob/main/README.md Shows how to create and provide a custom Landscapist instance with specific configurations, like memory cache size, to the composition tree. ```kotlin import com.skydoves.landscapist.core.Landscapist import com.skydoves.landscapist.image.LocalLandscapist import androidx.compose.runtime.CompositionLocalProvider // Create custom instance val customLandscapist = Landscapist.builder(context) .config( LandscapistConfig( memoryCacheSize = 128 * 1024 * 1024L // 128MB ) ) .build() // Provide to composition CompositionLocalProvider(LocalLandscapist provides customLandscapist) { LandscapistImage( imageModel = { imageUrl }, // Will use the custom instance ) } ``` -------------------------------- ### Add Custom Plugin using add() Source: https://github.com/skydoves/landscapist/blob/main/docs/image-component-and-plugin.md Add custom plugins like CircularRevealPlugin and LoadingPlugin to the ImageComponent using the add() method. This example shows integration with Glide, Coil, and Fresco. ```kotlin GlideImage( component = rememberImageComponent { add(CircularRevealPlugin()) add(LoadingPlugin(source)) }, .. ) ``` ```kotlin CoilImage( component = rememberImageComponent { add(CircularRevealPlugin()) add(LoadingPlugin(source)) }, .. ) ``` ```kotlin FrescoImage( component = rememberImageComponent { add(CircularRevealPlugin()) add(LoadingPlugin(source)) }, .. ) ``` -------------------------------- ### Combine Multiple Landscapist Plugins Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Demonstrates how to combine multiple plugins sequentially to achieve complex image loading effects. Plugins are applied in the order they are added. ```kotlin LandscapistImage( imageModel = { imageUrl }, component = rememberImageComponent { // Plugins are applied in order +ShimmerPlugin() +CrossfadePlugin(duration = 550) +PalettePlugin { palette -> /* ... */ } +CircularRevealPlugin() } ) ``` -------------------------------- ### Extract Primary Colors with PalettePlugin Source: https://github.com/skydoves/landscapist/blob/main/README.md Utilize `PalettePlugin` to extract primary color sets from an image. The extracted palette can be used to dynamically style UI elements. This example demonstrates updating a state variable with the loaded palette. ```kotlin var palette by rememberPaletteState(null) GlideImage( // CoilImage, FrescoImage also can be used. imageModel = { poster.image }, component = rememberImageComponent { +PalettePlugin { palette = it } } ) Crossfade( targetState = palette, modifier = Modifier .padding(horizontal = 8.dp) .size(45.dp) ) { Box( modifier = Modifier .background(color = Color(it?.lightVibrantSwatch?.rgb ?: 0)) .fillMaxSize() ) } ``` -------------------------------- ### Add Landscapist BOM and Libraries Source: https://github.com/skydoves/landscapist/blob/main/README.md Import the Landscapist Bill of Materials (BOM) to manage library versions. Then, include the desired Landscapist libraries for image loading, placeholders, palettes, transformations, and zoomable functionality. ```kotlin dependencies { // Import the landscapist BOM implementation("com.github.skydoves:landscapist-bom:$version") // Import landscapist libraries implementation("com.github.skydoves:landscapist-glide") // fresco or coil implementation("com.github.skydoves:landscapist-placeholder") implementation("com.github.skydoves:landscapist-palette") implementation("com.github.skydoves:landscapist-transformation") implementation("com.github.skydoves:landscapist-zoomable") } ``` -------------------------------- ### Import Landscapist BOM and Libraries (KTS) Source: https://github.com/skydoves/landscapist/blob/main/docs/bom.md Import the Landscapist BOM to manage versions of all Landscapist libraries. Then, import individual Landscapist libraries as needed using Kotlin DSL. ```Kotlin dependencies { // Import the landscapist BOM implementation("com.github.skydoves:landscapist-bom:$version") // Import landscapist libraries implementation("com.github.skydoves:landscapist-glide") implementation("com.github.skydoves:landscapist-coil") implementation("com.github.skydoves:landscapist-fresco") implementation("com.github.skydoves:landscapist-animation") implementation("com.github.skydoves:landscapist-placeholder") implementation("com.github.skydoves:landscapist-palette") implementation("com.github.skydoves:landscapist-transformation") implementation("com.github.skydoves:landscapist-zoomable") } ``` -------------------------------- ### LandscapistImage with Plugins Source: https://github.com/skydoves/landscapist/blob/main/README.md Demonstrates using LandscapistImage with multiple plugins for shimmer effect, crossfade animation, and blur transformation. ```kotlin import com.skydoves.landscapist.components.rememberImageComponent import com.skydoves.landscapist.placeholder.shimmer.ShimmerPlugin import com.skydoves.landscapist.animation.crossfade.CrossfadePlugin import com.skydoves.landscapist.transformation.blur.BlurTransformationPlugin LandscapistImage( imageModel = { imageUrl }, modifier = Modifier.fillMaxWidth(), component = rememberImageComponent { +ShimmerPlugin( baseColor = Color.Gray, highlightColor = Color.LightGray ) +CrossfadePlugin(duration = 550) +BlurTransformationPlugin(radius = 10) } ) ``` -------------------------------- ### Configure LandscapistConfig Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-core.md Set up memory and disk cache sizes, network timeouts, user agent, default headers, and image decoding options. Customize event listeners and interceptors for advanced control. ```kotlin val config = LandscapistConfig( // Memory cache configuration memoryCacheSize = 64 * 1024 * 1024L, // 64MB (default) memoryCache = null, // Use custom memory cache implementation // Disk cache configuration diskCacheSize = 100 * 1024 * 1024L, // 100MB (default) diskCache = null, // Use custom disk cache implementation // Network configuration networkConfig = NetworkConfig( connectTimeout = 10.seconds, readTimeout = 30.seconds, userAgent = "MyApp/1.0", defaultHeaders = mapOf("Accept" to "image/*"), followRedirects = true, maxRedirects = 5 ), // Image decoding configuration maxBitmapSize = 4096, // Maximum bitmap dimension allowRgb565 = true, // Use RGB_565 for images without alpha (saves memory) // Performance options weakReferencesEnabled = true, // Keep weak references to evicted cache entries // Event listener for monitoring eventListenerFactory = EventListener.Factory { request -> object : EventListener { override fun onStart(request: ImageRequest) { println("Started: ${request.model}") } override fun onSuccess(request: ImageRequest, result: ImageResult.Success) { println("Success: ${result.dataSource}") } override fun onFailure(request: ImageRequest, reason: Throwable) { println("Failed: ${reason.message}") } } }, // Request/response interceptors interceptors = listOf( // Custom interceptor for modifying requests/responses ) ) ``` -------------------------------- ### Provide a Custom Landscapist Instance Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Configure a global Landscapist instance with custom cache sizes and network settings using `Landscapist.builder`. Provide this custom instance to the composition tree using `CompositionLocalProvider` to affect all `LandscapistImage` composables within that tree. ```kotlin import com.skydoves.landscapist.core.Landscapist import com.skydoves.landscapist.core.LandscapistConfig import com.skydoves.landscapist.image.LocalLandscapist import androidx.compose.runtime.CompositionLocalProvider // Create custom Landscapist instance val customLandscapist = Landscapist.builder(context) .config( LandscapistConfig( memoryCacheSize = 128 * 1024 * 1024L, // 128MB diskCacheSize = 200 * 1024 * 1024L, // 200MB networkConfig = NetworkConfig( connectTimeout = 15.seconds, userAgent = "MyApp/1.0" ) ) ) .build() // Provide to composition tree CompositionLocalProvider(LocalLandscapist provides customLandscapist) { // All LandscapistImage composables in this tree will use customLandscapist LandscapistImage( imageModel = { imageUrl } ) } ``` -------------------------------- ### Create Landscapist Instance (Android) Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-core.md Create a Landscapist instance on Android using a Context for automatic disk cache configuration. Default settings can be used, or custom cache sizes can be specified. ```kotlin import com.skydoves.landscapist.core.Landscapist import com.skydoves.landscapist.core.LandscapistConfig // Create with default configuration val landscapist = Landscapist.builder(context).build() // Or with custom configuration val landscapist = Landscapist.builder(context) .config( LandscapistConfig( memoryCacheSize = 64 * 1024 * 1024L, // 64MB diskCacheSize = 100 * 1024 * 1024L, // 100MB ) ) .build() ``` -------------------------------- ### Basic Image Loading with LandscapistImage Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Load an image from a URL and display it with a specified size. Landscapist handles fetching, caching, decoding, and rendering. ```kotlin import com.skydoves.landscapist.image.LandscapistImage LandscapistImage( imageModel = { "https://example.com/image.jpg" }, modifier = Modifier.size(200.dp) ) ``` -------------------------------- ### Image Loading with ImageOptions for Customization Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Configure image display options like content scale, alignment, color filter, and alpha. This snippet demonstrates advanced customization for visual presentation. ```kotlin import com.skydoves.landscapist.ImageOptions import androidx.compose.ui.layout.ContentScale LandscapistImage( imageModel = { imageUrl }, modifier = Modifier .fillMaxWidth() .height(250.dp), imageOptions = ImageOptions( contentScale = ContentScale.Crop, alignment = Alignment.Center, contentDescription = "Profile picture", colorFilter = ColorFilter.tint(Color.Red), alpha = 0.8f ) ) ``` -------------------------------- ### Custom RequestOptions and TransitionOptions Source: https://github.com/skydoves/landscapist/blob/main/docs/glide/options.md Apply custom caching strategies and loading transformations using RequestOptions and DiskCacheStrategy. ```kotlin GlideImage( imageModel = { imageUrl }, requestOptions = { RequestOptions() .override(256, 256) .diskCacheStrategy(DiskCacheStrategy.ALL) .centerCrop() } ) ``` -------------------------------- ### Load Network Image with Custom Cache Sizes (Android) Source: https://github.com/skydoves/landscapist/blob/main/README.md Demonstrates creating a Landscapist instance with custom memory and disk cache sizes for Android. The image loading result is delivered as a Flow. ```kotlin import com.skydoves.landscapist.core.Landscapist import com.skydoves.landscapist.core.LandscapistConfig import com.skydoves.landscapist.core.ImageRequest import kotlinx.coroutines.flow.collect // Create a Landscapist instance (typically once in your app) val landscapist = Landscapist.builder(context) .config( LandscapistConfig( memoryCacheSize = 64 * 1024 * 1024L, // 64MB diskCacheSize = 100 * 1024 * 1024L, // 100MB ) ) .build() // Load an image lifecycleScope.launch { val request = ImageRequest.builder() .model("https://example.com/image.jpg") .size(width = 800, height = 600) .build() landscapist.load(request).collect { when (it) { is ImageResult.Loading -> { // Show loading state } is ImageResult.Success -> { val imageBitmap = it.data // Use the loaded ImageBitmap } is ImageResult.Failure -> { // Handle error } } } } ``` -------------------------------- ### Basic ImageGallery Usage Source: https://github.com/skydoves/landscapist/blob/main/docs/gallery.md Displays a list of images using the ImageGallery component. Ensure 'imageUrls' is a stable list of image models. ```kotlin import com.skydoves.landscapist.gallery.ImageGallery ImageGallery( images = imageUrls, onImageClick = { index, imageModel -> navController.navigate("viewer/$index") }, ) ``` -------------------------------- ### Basic ImageViewer Initialization Source: https://github.com/skydoves/landscapist/blob/main/docs/gallery.md Initialize ImageViewer with a list of image URLs and a state object. The state manages the current page and total page count. Use this for standard image viewing. ```kotlin import com.skydoves.landscapist.gallery.ImageViewer import com.skydoves.landscapist.gallery.rememberImageViewerState val viewerState = rememberImageViewerState( initialPage = startIndex, pageCount = { imageUrls.size }, ) ImageViewer( images = imageUrls, state = viewerState, onDismiss = { navController.popBackStack() }, onPageChanged = { page -> currentPage = page }, ) ``` -------------------------------- ### Load Network Image with Default Instance (KMP) Source: https://github.com/skydoves/landscapist/blob/main/README.md Shows how to load an image using the default Landscapist singleton instance in Kotlin Multiplatform. This function returns the ImageBitmap or null. ```kotlin import com.skydoves.landscapist.core.Landscapist import com.skydoves.landscapist.core.ImageRequest // Get the default instance (works on all platforms) val landscapist = Landscapist.getInstance() suspend fun loadImage(url: String): ImageBitmap? { val request = ImageRequest.builder() .model(url) .build() var bitmap: ImageBitmap? = null landscapist.load(request).collect { if (it is ImageResult.Success) { bitmap = it.data } } return bitmap } ``` -------------------------------- ### Basic Image Options with Coil Source: https://github.com/skydoves/landscapist/blob/main/docs/image-options.md Pass an ImageOptions instance to configure content scale, alignment, description, color filter, alpha, and tag for CoilImage. ```kotlin CoilImage( imageOptions = ImageOptions( contentScale = ContentScale.Crop, alignment = Alignment.Center, contentDescription = "profile image", colorFilter = null, alpha = 1f, tag = "user profile image" ), ..) ) ``` -------------------------------- ### Fresco Initialization and Accessors Source: https://github.com/skydoves/landscapist/blob/main/benchmark-landscapist-app/src/release/generated/baselineProfiles/baseline-prof.txt Methods for initializing Fresco and accessing its core components. ```APIDOC ## Fresco ### Description Entry point for Fresco image pipeline initialization and access. ### Methods - `getImagePipeline()`: Returns the ImagePipeline instance. - `getImagePipelineFactory()`: Returns the ImagePipelineFactory instance. - `initialize(Context, ImagePipelineConfig)`: Initializes Fresco with a context and configuration. - `initialize(Context, ImagePipelineConfig, DraweeConfig)`: Initializes Fresco with context, image pipeline config, and Drawee config. - `initialize(Context, ImagePipelineConfig, DraweeConfig, boolean)`: Initializes Fresco with extended configuration options. - `initializeDrawee(Context, DraweeConfig)`: Initializes the Drawee components of Fresco. - `newDraweeControllerBuilder()`: Creates a new builder for Drawee controllers. ``` -------------------------------- ### Format Code with Spotless Source: https://github.com/skydoves/landscapist/blob/main/CONTRIBUTING.md Run this command to ensure your code changes adhere to the project's formatting standards before submitting a pull request. ```gradle ./gradlew spotlessApply ``` -------------------------------- ### Run Instrumented Load-Time Benchmark Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/performance-comparison.md Execute the instrumented load-time benchmark for all four wrappers. This command runs the benchmark on connected Android devices. ```bash ./gradlew :app:connectedDebugAndroidTest \ -Pandroid.testInstrumentationRunnerArguments.class=com.github.skydoves.landscapistdemo.ImageLibraryBenchmark ``` -------------------------------- ### Load Animated GIF or WebP Image Source: https://github.com/skydoves/landscapist/blob/main/docs/fresco/animated-image.md Use the FrescoWebImage composable to load animated GIFs and WebP images. Pass an AbstractDraweeController with the image URI and set autoPlayAnimations to true. ```kotlin FrescoWebImage( controllerBuilder = { Fresco.newDraweeControllerBuilder() .setUri(poster.gif) // GIF or Webp image url. .setAutoPlayAnimations(true) }, modifier = Modifier .fillMaxWidth() .height(300.dp) ) ``` -------------------------------- ### Dump Public API Source: https://github.com/skydoves/landscapist/blob/main/CONTRIBUTING.md Execute this command to generate a dump of the library's public binary API. This is crucial for ensuring that changes do not introduce binary incompatibilities. ```gradle ./gradlew apiDump ``` -------------------------------- ### Basic Image Options with Glide Source: https://github.com/skydoves/landscapist/blob/main/docs/image-options.md Pass an ImageOptions instance to configure content scale, alignment, description, color filter, alpha, and tag for GlideImage. ```kotlin GlideImage( imageOptions = ImageOptions( contentScale = ContentScale.Crop, alignment = Alignment.Center, contentDescription = "profile image", colorFilter = null, alpha = 1f, tag = "user profile image" ), ..) ) ``` -------------------------------- ### NativeCodeSetup Source: https://github.com/skydoves/landscapist/blob/main/app/src/main/baseline-prof.txt Configuration for native code usage in the image pipeline. ```APIDOC ## NativeCodeSetup ### Description Manages the usage of native code within the image pipeline. ### Methods - **getUseNativeCode()**: Returns a boolean indicating whether native code is currently enabled. - **setUseNativeCode(boolean useNativeCode)**: Enables or disables the use of native code. ``` -------------------------------- ### Full-Screen Image Viewer with Pinch-to-Zoom Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Implement a full-screen image viewer with pinch-to-zoom and pan capabilities. Requires `ZoomablePlugin` and `rememberZoomableState`. Enable `enableSubSampling` for very large images. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Close import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp import com.skydoves.landscapist.ImageOptions import com.skydoves.landscapist.LandscapistImage import com.skydoves.landscapist.components.rememberImageComponent import com.skydoves.landscapist.plugins.ZoomablePlugin import com.skydoves.landscapist.plugins.rememberZoomableState @Composable fun FullScreenImageViewer( imageUrl: String, onDismiss: () -> Unit ) { val zoomableState = rememberZoomableState( minScale = 1f, maxScale = 5f ) Box( modifier = Modifier .fillMaxSize() .background(Color.Black) .clickable { onDismiss() } ) { LandscapistImage( imageModel = { imageUrl }, modifier = Modifier.fillMaxSize(), imageOptions = ImageOptions( contentScale = ContentScale.Fit, alignment = Alignment.Center ), component = rememberImageComponent { +ZoomablePlugin( state = zoomableState, enableSubSampling = true // For very large images ) }, loading = { Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { Column(horizontalAlignment = Alignment.CenterHorizontally) { CircularProgressIndicator(color = Color.White) Spacer(Modifier.height(16.dp)) Text("Loading high resolution image...", color = Color.White) } } } ) // Close button IconButton( onClick = onDismiss, modifier = Modifier .align(Alignment.TopEnd) .padding(16.dp) ) { Icon( imageVector = Icons.Default.Close, contentDescription = "Close", tint = Color.White ) } // Zoom indicator Text( text = "Zoom: ${(zoomableState.scale * 100).toInt()}%", color = Color.White, modifier = Modifier .align(Alignment.BottomCenter) .padding(16.dp) .background(Color.Black.copy(alpha = 0.5f), RoundedCornerShape(8.dp)) .padding(horizontal = 16.dp, vertical = 8.dp) ) } } ``` -------------------------------- ### Configure NetworkConfig Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-core.md Adjust HTTP client connection and read timeouts, specify the User-Agent, and define default headers for all requests. Control redirect behavior. ```kotlin val networkConfig = NetworkConfig( connectTimeout = 15.seconds, // Connection timeout readTimeout = 60.seconds, // Read timeout userAgent = "MyApp/2.0", // User-Agent header defaultHeaders = mapOf( // Default headers for all requests "Accept" to "image/*", "Accept-Encoding" to "gzip" ), followRedirects = true, // Follow HTTP redirects maxRedirects = 5 // Maximum redirect hops ) ``` -------------------------------- ### Use Thumbnail URLs Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Provide a fallback to thumbnailUrl when available to optimize loading of images in lists. ```kotlin imageModel = { item.thumbnailUrl ?: item.fullUrl } ``` -------------------------------- ### Implement Custom Placeholders with PlaceholderPlugin Source: https://github.com/skydoves/landscapist/blob/main/README.md Use PlaceholderPlugin.Loading and PlaceholderPlugin.Failure to display custom painters while an image is loading or fails to load. The source should be an ImageBitmap, ImageVector, or Painter. ```kotlin GlideImage( .. component = rememberImageComponent { +PlaceholderPlugin.Loading(painterResource(id = R.drawable.placeholder_loading)) +PlaceholderPlugin.Failure(painterResource(id = R.drawable.placeholder_failure)) }, ) ``` -------------------------------- ### Implement Loading and Failure Placeholders Source: https://github.com/skydoves/landscapist/blob/main/docs/placeholder.md Use PlaceholderPlugin.Loading and PlaceholderPlugin.Failure to display custom images during image loading or upon failure. The source for the painter should be ImageBitmap, ImageVector, or Painter. ```kotlin GlideImage( component = rememberImageComponent { +PlaceholderPlugin.Loading(painterResource(id = R.drawable.placeholder_loading)) +PlaceholderPlugin.Failure(painterResource(id = R.drawable.placeholder_failure)) }, .. ) ``` ```kotlin CoilImage( component = rememberImageComponent { +PlaceholderPlugin.Loading(painterResource(id = R.drawable.placeholder_loading)) +PlaceholderPlugin.Failure(painterResource(id = R.drawable.placeholder_failure)) }, .. ) ``` ```kotlin FrescoImage( component = rememberImageComponent { +PlaceholderPlugin.Loading(painterResource(id = R.drawable.placeholder_loading)) +PlaceholderPlugin.Failure(painterResource(id = R.drawable.placeholder_failure)) }, .. ) ``` -------------------------------- ### FrescoImage with matchParentSize Source: https://github.com/skydoves/landscapist/blob/main/docs/custom-composable.md Shows how to implement `Modifier.matchParentSize()` within the loading, success, and failure slots of a FrescoImage composable. This ensures that the content in these slots adopts the size of the parent composable. ```kotlin FrescoImage( imageUrl = url, modifier = Modifier.size(200.dp), imageOptions = ImageOptions(contentScale = ContentScale.Fit), loading = { Box(modifier = Modifier.matchParentSize()) { CircularProgressIndicator(modifier = Modifier.align(Alignment.Center)) } }, success = { state, painter -> Image( painter = painter, contentDescription = null, modifier = Modifier.matchParentSize(), contentScale = ContentScale.Fit, ) }, failure = { Image( painter = painterResource(R.drawable.ic_error), contentDescription = null, modifier = Modifier.matchParentSize(), contentScale = ContentScale.Fit, ) }, ) ``` -------------------------------- ### Combined Custom States for Image Loading Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Demonstrates how to combine custom loading, success, and failure composables within a single LandscapistImage instance for comprehensive state management. ```kotlin LandscapistImage( imageModel = { imageUrl }, modifier = Modifier .fillMaxWidth() .height(200.dp), loading = { Box(Modifier.fillMaxSize()) { CircularProgressIndicator(Modifier.align(Alignment.Center)) } }, success = { _, painter -> Image( painter = painter, contentDescription = null, contentScale = ContentScale.Crop ) }, failure = { Box( Modifier .fillMaxSize() .background(Color.LightGray) ) { Text( text = "Error", modifier = Modifier.align(Alignment.Center) ) } } ) ``` -------------------------------- ### ImageGallery with Grid Layout Customization Source: https://github.com/skydoves/landscapist/blob/main/docs/gallery.md Customize the grid layout of ImageGallery using parameters like 'columns', 'contentPadding', and 'aspectRatio'. ```kotlin ImageGallery( images = imageUrls, columns = GridCells.Adaptive(minSize = 120.dp), contentPadding = PaddingValues(4.dp), horizontalArrangement = Arrangement.spacedBy(4.dp), verticalArrangement = Arrangement.spacedBy(4.dp), aspectRatio = 1f, ) ``` -------------------------------- ### Run Macrobenchmark for Frame Timing Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/performance-comparison.md Execute the Macrobenchmark for Landscapist on a specific device or connected device. This benchmark measures frame timing and jank during scrolling. ```bash ./gradlew :benchmark-landscapist:pixel6api31BenchmarkAndroidTest ``` ```bash ./gradlew :benchmark-landscapist:connectedBenchmarkAndroidTest ``` -------------------------------- ### Image Grid with Different Sizes using LandscapistImage Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Efficiently loads images in a grid where items have different dimensions. Includes ShimmerPlugin and CrossfadePlugin for enhanced user experience. ```kotlin LazyVerticalGrid( columns = GridCells.Fixed(2), contentPadding = PaddingValues(8.dp) ) { items(imageList) { LandscapistImage( imageModel = { item.url }, modifier = Modifier .fillMaxWidth() .aspectRatio(item.aspectRatio) .padding(4.dp) .clip(RoundedCornerShape(8.dp)), imageOptions = ImageOptions( contentScale = ContentScale.Crop ), component = rememberImageComponent { +ShimmerPlugin() +CrossfadePlugin() } ) } } ``` -------------------------------- ### Image Gallery and Viewer with Shared Transitions Source: https://github.com/skydoves/landscapist/blob/main/docs/gallery.md This snippet demonstrates how to set up shared element transitions between an ImageGallery and an ImageViewer using ImageSharedTransitionConfig. Ensure the same config is passed to both components for seamless animation. ```kotlin SharedTransitionLayout { AnimatedContent( targetState = showViewer, transitionSpec = { fadeIn() togetherWith fadeOut() }, label = "gallery-viewer", ) { viewerVisible -> val animatedContentScope = this if (!viewerVisible) { ImageGallery( images = imageUrls, onImageClick = { index, _ -> selectedPage = index showViewer = true }, sharedTransition = ImageSharedTransitionConfig( sharedTransitionScope = this@SharedTransitionLayout, animatedContentScope = animatedContentScope, ), ) } else { ImageViewer( images = imageUrls, state = rememberImageViewerState( initialPage = selectedPage, pageCount = { imageUrls.size }, ), onDismiss = { showViewer = false }, sharedTransition = ImageSharedTransitionConfig( sharedTransitionScope = this@SharedTransitionLayout, animatedContentScope = animatedContentScope, ), ) } } } ``` -------------------------------- ### Enable RGB_565 for Memory Optimization Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Set allowRgb565 to true in LandscapistConfig for images without transparency to reduce memory usage. ```kotlin LandscapistConfig(allowRgb565 = true) ``` -------------------------------- ### Assemble Release AAR and Check Size Source: https://github.com/skydoves/landscapist/blob/main/performance/README.md This command builds the release AAR for the landscapist-core module and then lists its file size. It's used to verify the binary size of the library. ```bash ./gradlew :landscapist-core:assembleRelease ls -l landscapist-core/build/outputs/aar/landscapist-core-release.aar ``` -------------------------------- ### ImageGallery with Selection Mode Source: https://github.com/skydoves/landscapist/blob/main/docs/gallery.md Enable multi-selection in ImageGallery by setting 'selectable' to true and managing 'selectedIndices' and 'onSelectionChanged'. A custom 'selectionOverlay' can be provided. ```kotlin var selectedIndices by remember { mutableStateOf(emptySet()) } ImageGallery( images = imageUrls, selectable = true, selectedIndices = selectedIndices, onSelectionChanged = { selectedIndices = it }, selectionOverlay = { _, selected -> if (selected) { Box( modifier = Modifier .fillMaxSize() .background(Color.Black.copy(alpha = 0.3f)), contentAlignment = Alignment.TopEnd, ) { Icon( imageVector = Icons.Default.CheckCircle, contentDescription = null, tint = MaterialTheme.colors.primary, modifier = Modifier.padding(6.dp).size(24.dp).clip(CircleShape), ) } } }, ) ``` -------------------------------- ### PipelineDraweeControllerBuilder Source: https://github.com/skydoves/landscapist/blob/main/fresco/src/main/generated/baselineProfiles/baseline-prof.txt Methods for building and configuring PipelineDraweeController instances. ```APIDOC ## PipelineDraweeControllerBuilder ### Description Builder class for creating and configuring `PipelineDraweeController` instances, which manage image loading and display. ### Methods - `newDraweeControllerBuilder() -> PipelineDraweeControllerBuilder` - `PipelineDraweeControllerBuilder(Context context, PipelineDraweeControllerFactory pipelineDraweeControllerFactory, ImagePipeline imagePipeline, Set requestListeners, Set requestListenerTags)` - `getCacheKey() -> CacheKey` - `convertCacheLevelToRequestLevel(AbstractDraweeControllerBuilder.CacheLevel cacheLevel) -> ImageRequest.RequestLevel` ### Parameters - **context** (Context) - Required - The Android application context. - **pipelineDraweeControllerFactory** (PipelineDraweeControllerFactory) - Required - Factory for creating Drawee controllers. - **imagePipeline** (ImagePipeline) - Required - The Fresco image pipeline instance. - **requestListeners** (Set) - Optional - Set of request listener identifiers. - **requestListenerTags** (Set) - Optional - Set of request listener tags. - **cacheLevel** (AbstractDraweeControllerBuilder.CacheLevel) - Required - The cache level to convert. ``` -------------------------------- ### Load Network Image with FrescoImage Source: https://github.com/skydoves/landscapist/blob/main/docs/fresco/overview.md Use the FrescoImage composable function to load network images. Customize image loading behavior with ImageOptions like contentScale and alignment. ```kotlin FrescoImage( imageUrl = stringImageUrl, // loading a network image using an URL. imageOptions = ImageOptions( contentScale = ContentScale.Crop, alignment = Alignment.Center ) ) ``` -------------------------------- ### AccessibilityNodeInfoCompat Methods Source: https://github.com/skydoves/landscapist/blob/main/benchmark-landscapist-app/src/release/generated/baselineProfiles/baseline-prof.txt This section details various methods available on the AccessibilityNodeInfoCompat class for managing accessibility information. ```APIDOC ## AccessibilityNodeInfoCompat Methods ### Description Provides methods to interact with and modify accessibility node information. ### Methods - `isFocusable()Z`: Checks if the node is focusable. - `isFocused()Z`: Checks if the node is currently focused. - `obtain()Landroidx/core/view/accessibility/AccessibilityNodeInfoCompat;`: Creates a new AccessibilityNodeInfoCompat. - `setAccessibilityDataSensitive(Z)V`: Sets whether the accessibility data is sensitive. - `setAccessibilityFocused(Z)V`: Sets the accessibility focus state. - `setAvailableExtraData(Ljava/util/List;)V`: Sets a list of available extra data. - `setBooleanProperty(IZ)V`: Sets a boolean property for the node. - `setBoundsInScreen(Landroid/graphics/Rect;)V`: Sets the bounds of the node in the screen. - `setCheckable(Z)V`: Sets whether the node is checkable. - `setClassName(Ljava/lang/CharSequence;)V`: Sets the class name of the node. - `setClickable(Z)V`: Sets whether the node is clickable. - `setCollectionInfo(Ljava/lang/Object;)V`: Sets collection information for the node. - `setContentDescription(Ljava/lang/CharSequence;)V`: Sets the content description for the node. - `setDrawingOrder(I)V`: Sets the drawing order for the node. - `setEditable(Z)V`: Sets whether the node is editable. - `setEnabled(Z)V`: Sets whether the node is enabled. - `setFocusable(Z)V`: Sets whether the node is focusable. - `setFocused(Z)V`: Sets the focus state of the node. - `setImportantForAccessibility(Z)V`: Sets whether the node is important for accessibility. - `setLongClickable(Z)V`: Sets whether the node is long clickable. - `setMaxTextLength(I)V`: Sets the maximum text length for the node. - `setPackageName(Ljava/lang/CharSequence;)V`: Sets the package name for the node. - `setPaneTitle(Ljava/lang/CharSequence;)V`: Sets the pane title for the node. - `setParent(Landroid/view/View;)V`: Sets the parent view of the node. - `setParent(Landroid/view/View;I)V`: Sets the parent view and its position. - `setPassword(Z)V`: Sets whether the node represents a password. - `setScreenReaderFocusable(Z)V`: Sets whether the node is focusable for screen readers. - `setScrollable(Z)V`: Sets whether the node is scrollable. - `setSource(Landroid/view/View;I)V`: Sets the source view and its position. - `setStateDescription(Ljava/lang/CharSequence;)V`: Sets the state description for the node. - `setText(Ljava/lang/CharSequence;)V`: Sets the text for the node. - `setViewIdResourceName(Ljava/lang/String;)V`: Sets the view ID resource name. - `setVisibleToUser(Z)V`: Sets whether the node is visible to the user. - `unwrap()Landroid/view/accessibility/AccessibilityNodeInfo;`: Unwraps the AccessibilityNodeInfoCompat to an AccessibilityNodeInfo. - `wrap(Landroid/view/accessibility/AccessibilityNodeInfo;)Landroidx/core/view/accessibility/AccessibilityNodeInfoCompat;`: Wraps an AccessibilityNodeInfo into an AccessibilityNodeInfoCompat. ``` -------------------------------- ### Custom Ktor Network Configuration Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Optimize network loading by configuring custom Ktor settings such as timeouts, redirects, and default headers for image requests. ```kotlin val landscapist = Landscapist.builder(context) .config( LandscapistConfig( networkConfig = NetworkConfig( connectTimeout = 5.seconds, // Fast fail for poor connections readTimeout = 30.seconds, // Reasonable timeout for large images followRedirects = true, maxRedirects = 3, // Prevent redirect loops defaultHeaders = mapOf( "Accept" to "image/webp,image/jpeg,image/png,image/*", "Accept-Encoding" to "gzip, deflate" ) ) ) ) .build() ``` -------------------------------- ### Custom Loading and Failure Composable with Fresco Source: https://github.com/skydoves/landscapist/blob/main/docs/custom-composable.md Implement custom loading indicators and failure fallbacks for FrescoImage. This requires imports for Box, CircularProgressIndicator, Alignment, and Text. ```kotlin FrescoImage( // displays an indicator while loading an image. loading = { Box(modifier = Modifier.matchParentSize()) { CircularProgressIndicator( modifier = Modifier.align(Alignment.Center) ) } }, // displays an error fallback if fails to load an image. failure = { Text(text = "image request failed.") }, .. ) ``` -------------------------------- ### Migrate Plugins from GlideImage to LandscapistImage Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Demonstrates that plugins like ShimmerPlugin and CrossfadePlugin work identically when migrating from GlideImage to LandscapistImage. ```kotlin GlideImage( imageModel = { imageUrl }, component = rememberImageComponent { +ShimmerPlugin() +CrossfadePlugin() } ) LandscapistImage( imageModel = { imageUrl }, component = rememberImageComponent { +ShimmerPlugin() +CrossfadePlugin() } ) ``` -------------------------------- ### Reproduce Landscapist-Core AAR Size Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/performance-comparison.md Use this Gradle command to build the release AAR for the landscapist-core module. Then, check the file size to verify the artifact size. ```bash ./gradlew :landscapist-core:assembleRelease ls -l landscapist-core/build/outputs/aar/landscapist-core-release.aar # 320,771 bytes = 313 KiB ``` -------------------------------- ### Add Image Gallery Dependency Source: https://github.com/skydoves/landscapist/blob/main/docs/gallery.md Include this dependency in your `build.gradle` file to use the image gallery components. ```kotlin dependencies { implementation("com.github.skydoves:landscapist-image-gallery:$version") } ``` -------------------------------- ### Cross-Platform Image Sources for LandscapistImage Source: https://github.com/skydoves/landscapist/blob/main/docs/landscapist/landscapist-image.md Shows image sources supported across multiple platforms including network URLs for all, and file paths for Desktop and iOS. Platform-specific models require checking core documentation. ```kotlin LandscapistImage(imageModel = { "https://example.com/image.jpg" }) ``` ```kotlin LandscapistImage(imageModel = { "/path/to/image.jpg" }) ```