Closed cryptrr closed 1 year ago
This error happens during compile time hence the compose compiler must be checking for every usage of rememberPagerState(). So I guess the compose compiler should also be downgraded to prevent this error.
How did you get 1.5.0-beta
for foundation in androidMain
?
I added this snipped to inside the Column
in App.kt
(in commonMain
) and it works perfectly for me:
val pagerState = rememberPagerState()
HorizontalPager(
pageCount = 10,
modifier = Modifier.fillMaxWidth().padding(top = 32.dp),
state = pagerState
){
Text(
text = "Page $it",
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth().background(Color.LightGray).padding(40.dp)
)
}
I have no idea :/ This is my androidMain dependencies list
val androidMain by getting {
dependencies {
api("androidx.activity:activity-compose:1.7.2")
implementation("androidx.media3:media3-exoplayer:1.0.2")
implementation("androidx.media3:media3-ui:1.0.2")
implementation("androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha10")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.10.1")
implementation ("com.github.skydoves:cloudy:0.1.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("com.google.accompanist:accompanist-systemuicontroller:0.31.3-beta")
}
}
and I'm using the default imports for commonMain
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.material)
implementation(compose.materialIconsExtended)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
....
}
Still I have foundation 1.5.0-beta in androidMain and 1.4.0 in commonMain
All of these dependencies are somehow using 1.5.0-beta in androidMain
It's got to do with some third party libraries bumping it up.
You can run the gradle dependencies
task from inside androidApp
to see the tree of dependencies.
In your case, compose 1.5.0-beta01 is pulled in by
Thanks. Is downgrading these dependencies the only way to fix this problem?
I checked the dependency tree. Weirdly it says even material3:1.0.1 is depending upon foundation 1.5.0-beta1
Removing accompanist and constraintlayout removed foundation 1.5.0 . Thanks.
Downgrading accompanist to v0.30.1 uses compose 1.4.0 and fixes this.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Describe the bug
Using 'rememberPagerState(Int = ..., Float = ...): PagerState' is an error. Please use the overload where you can provide a source of truth for the pageCount.
I'm using the official compose multiplatform template. From here
androidMain is using foundation 1.5.0-beta01 while commonMain is using 1.4.0
old overloads of rememberPagerState has been force disabled in Foundation 1.5.0-beta with the above error.
So it is impossible to use Pagers in commonMain code because the latest version of foundation available for multiplatform is 1.4.0 and does not have the overloads necessary to compile.
So how to downgrade
foundation
in androidMain since i'm not seeing this gradle dependency in theval androidMain by getting {}
block.Or do I need to copy all the code from foundation 1.5.0-beta?
Affected platforms Select one of the platforms below:
Versions
To Reproduce Steps and/or the code snippet to reproduce the behavior:
Using 'rememberPagerState(Int = ..., Float = ...): PagerState' is an error. Please use the overload where you can provide a source of truth for the pageCount.
Expected behavior The foundation versions should be same or there should be a better way to downgrade