Skip to content

Commit

Permalink
不进行固定 Banner 高度,让用户自行定义
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujiang2 committed Jul 21, 2023
1 parent 3a1cb48 commit 6e6b6bb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion banner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions banner/src/main/java/com/zj/banner/BannerPager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,7 +65,7 @@ fun <T : BaseBannerBean> BannerPager(
}
val coroutineScope = rememberCoroutineScope()

Box(modifier = modifier.height(config.bannerHeight)) {
Box(modifier = modifier) {
HorizontalPager(
modifier = Modifier,
state = pagerState,
Expand Down Expand Up @@ -108,6 +107,7 @@ fun <T : BaseBannerBean> BannerPager(
.fillMaxSize()
.padding(config.bannerImagePadding),
shape = config.shape,
imageRatio = config.imageRatio,
contentScale = config.contentScale
) {
Log.d(TAG, "item is :${item.javaClass}")
Expand All @@ -116,7 +116,7 @@ fun <T : BaseBannerBean> BannerPager(
}
)

LaunchedEffect(key1 = pagerState){
LaunchedEffect(key1 = pagerState) {
var position: Int = pagerState.currentPage
Log.d(TAG, "finish update before, position=$position")
if (position == 0) {
Expand Down
4 changes: 3 additions & 1 deletion banner/src/main/java/com/zj/banner/ui/BannerCard.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,6 +27,7 @@ fun <T : BaseBannerBean> BannerCard(
modifier: Modifier = Modifier,
shape: Shape = RoundedCornerShape(10.dp),
contentScale: ContentScale,
imageRatio: Float = 2f,
onBannerClick: () -> Unit,
) {
if (bean.data == null) {
Expand All @@ -37,6 +39,6 @@ fun <T : BaseBannerBean> BannerCard(
modifier = modifier
) {
val imgModifier = Modifier.clickable(onClick = onBannerClick)
ImageLoader(bean.data, imgModifier, contentScale)
ImageLoader(bean.data, imgModifier.aspectRatio(imageRatio), contentScale)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e6b6bb

Please sign in to comment.