Skip to content

Commit

Permalink
Merge pull request #80 from ltttttttttttt/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ltttttttttttt authored Jan 4, 2024
2 parents 4a51a33 + 6f5b7e4 commit 903110f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ComposeViews/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plugins {
group = "io.github.ltttttttttttt"
//上传到mavenCentral命令: ./gradlew publishAllPublicationsToSonatypeRepository
//mavenCentral后台: https://s01.oss.sonatype.org/#stagingRepositories
version = "$composeVersion.3"
version = "$composeVersion.4"

kotlin {
androidTarget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,12 @@ fun ComposePager(
})
.clipScrollableContainer(orientation)
.onSizeChanged {
//大小变更时,滚动到正确的位置
coroutineScope.launch {
composePagerState.setOffset(0f)
if (composePagerState.size != it) {
composePagerState.size = it
//大小变更时,滚动到正确的位置
coroutineScope.launch {
composePagerState.setOffset(0f)
}
}
}
) { measurableList/* 可测量的(子控件) */, constraints/* 约束条件 */ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
package com.lt.compose_views.compose_pager

import androidx.compose.animation.core.Animatable
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.unit.IntSize
import kotlinx.coroutines.flow.Flow

/**
Expand All @@ -40,6 +48,9 @@ class ComposePagerState {
//记录ComposePager的宽高中的对应方向的值
internal var mainAxisSize by mutableStateOf(0)

//记录当前的size大小,如果大小变更后自动滚动到正确的位置(适配可以改变window大小的场景)
internal var size by mutableStateOf(IntSize.Zero)

/**
* 获取ComposePager当前所在的索引
* Get current index in the [ComposePager]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DateSelectorState(
internal var months by mutableStateOf(ArrayList((1..12).map { it.toString() }))
internal var days by mutableStateOf(ArrayList((1..31).map { it.toString() }))

fun getYear(): String = years[yearState.getSelectIndex()]
fun getMonth(): String = months[monthState.getSelectIndex()]
fun getDay(): String = days[dayState.getSelectIndex()]
fun getYear(): String = years[yearState.getSelectIndex() % years.size]
fun getMonth(): String = months[monthState.getSelectIndex() % months.size]
fun getDay(): String = days[dayState.getSelectIndex() % days.size]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ version
```kotlin
dependencies {
...
implementation("io.github.ltttttttttttt:ComposeViews:$version")//this, such as 1.5.10.1
implementation("io.github.ltttttttttttt:ComposeViews:$version")//this, such as 1.5.10.4
}
```

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ version
```kotlin
dependencies {
...
implementation("io.github.ltttttttttttt:ComposeViews:$version")//this,比如1.5.10.1
implementation("io.github.ltttttttttttt:ComposeViews:$version")//this,比如1.5.10.4
}
```

Expand Down

0 comments on commit 903110f

Please sign in to comment.