diff --git a/banner/build.gradle b/banner/build.gradle index 8c0aeb6..31d0354 100644 --- a/banner/build.gradle +++ b/banner/build.gradle @@ -17,7 +17,7 @@ afterEvaluate { // You can then customize attributes of the publication as shown below. groupId = 'com.zj.banner' artifactId = 'banner' - version = '2.6.1' + version = '2.6.2' } // // Creates a Maven publication called “debug”. // debug(MavenPublication) { diff --git a/banner/src/main/java/com/zj/banner/BannerPager.kt b/banner/src/main/java/com/zj/banner/BannerPager.kt index 4abb10c..5845bec 100644 --- a/banner/src/main/java/com/zj/banner/BannerPager.kt +++ b/banner/src/main/java/com/zj/banner/BannerPager.kt @@ -6,7 +6,6 @@ import android.util.Log import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.PagerState @@ -66,7 +65,7 @@ fun BannerPager( } val coroutineScope = rememberCoroutineScope() - Box(modifier = modifier.height(config.bannerHeight)) { + Box(modifier = modifier) { HorizontalPager( modifier = Modifier, state = pagerState, @@ -108,6 +107,7 @@ fun BannerPager( .fillMaxSize() .padding(config.bannerImagePadding), shape = config.shape, + imageRatio = config.imageRatio, contentScale = config.contentScale ) { Log.d(TAG, "item is :${item.javaClass}") @@ -116,7 +116,7 @@ fun BannerPager( } ) - LaunchedEffect(key1 = pagerState){ + LaunchedEffect(key1 = pagerState) { var position: Int = pagerState.currentPage Log.d(TAG, "finish update before, position=$position") if (position == 0) { diff --git a/banner/src/main/java/com/zj/banner/ui/BannerCard.kt b/banner/src/main/java/com/zj/banner/ui/BannerCard.kt index 7cad5e2..e664eb1 100644 --- a/banner/src/main/java/com/zj/banner/ui/BannerCard.kt +++ b/banner/src/main/java/com/zj/banner/ui/BannerCard.kt @@ -1,6 +1,7 @@ package com.zj.banner.ui import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Card import androidx.compose.runtime.Composable @@ -26,6 +27,7 @@ fun BannerCard( modifier: Modifier = Modifier, shape: Shape = RoundedCornerShape(10.dp), contentScale: ContentScale, + imageRatio: Float = 2f, onBannerClick: () -> Unit, ) { if (bean.data == null) { @@ -37,6 +39,6 @@ fun BannerCard( modifier = modifier ) { val imgModifier = Modifier.clickable(onClick = onBannerClick) - ImageLoader(bean.data, imgModifier, contentScale) + ImageLoader(bean.data, imgModifier.aspectRatio(imageRatio), contentScale) } } diff --git a/banner/src/main/java/com/zj/banner/ui/config/BannerConfig.kt b/banner/src/main/java/com/zj/banner/ui/config/BannerConfig.kt index 0dc9193..e78fa6a 100644 --- a/banner/src/main/java/com/zj/banner/ui/config/BannerConfig.kt +++ b/banner/src/main/java/com/zj/banner/ui/config/BannerConfig.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.unit.dp data class BannerConfig( // banner 高度 - var bannerHeight: Dp = 210.dp, + var imageRatio: Float = 2f, // banner 图片距离四周的 padding 值 var bannerImagePadding: Dp = 8.dp, // banner 图片的 shape