mirror of
https://github.com/jlengrand/compose-multiplatform.git
synced 2026-03-10 15:48:51 +00:00
example/issues: bump compose version to 0.3.0-build154 & fix incompatibilities (#398)
This commit is contained in:
@@ -22,4 +22,11 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":common"))
|
||||
implementation("androidx.activity:activity-compose:1.3.0-alpha02") {
|
||||
exclude(group = "androidx.compose.animation")
|
||||
exclude(group = "androidx.compose.foundation")
|
||||
exclude(group = "androidx.compose.material")
|
||||
exclude(group = "androidx.compose.runtime")
|
||||
exclude(group = "androidx.compose.ui")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package androidx.ui.examples.jetissues
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.runtime.Providers
|
||||
import androidx.compose.ui.platform.setContent
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.ui.examples.jetissues.view.JetIssuesView
|
||||
import androidx.ui.examples.jetissues.view.Repository
|
||||
import androidx.ui.examples.jetissues.data.IssuesRepositoryImpl
|
||||
@@ -15,7 +15,7 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
Providers(Repository provides repo) {
|
||||
CompositionLocalProvider(Repository provides repo) {
|
||||
JetIssuesView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ buildscript {
|
||||
|
||||
dependencies {
|
||||
// __LATEST_COMPOSE_RELEASE_VERSION__
|
||||
classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build146")
|
||||
classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build154")
|
||||
classpath("com.android.tools.build:gradle:4.0.1")
|
||||
// __KOTLIN_COMPOSE_VERSION__
|
||||
classpath(kotlin("gradle-plugin", version = "1.4.21-2"))
|
||||
classpath(kotlin("gradle-plugin", version = "1.4.30"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
package androidx.ui.examples.jetissues.view.common
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.selection.Selection
|
||||
import androidx.compose.ui.text.InternalTextApi
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@OptIn(InternalTextApi::class)
|
||||
@Composable
|
||||
actual fun SelectionContainer(children: @Composable () -> Unit) {
|
||||
val selection = remember { mutableStateOf<Selection?>(null) }
|
||||
androidx.compose.ui.selection.SelectionContainer(
|
||||
selection = selection.value,
|
||||
onSelectionChange = { selection.value = it },
|
||||
children = children
|
||||
)
|
||||
}
|
||||
actual fun VerticalScrollbar(
|
||||
modifier: Modifier,
|
||||
scrollState: ScrollState
|
||||
) = Unit
|
||||
@@ -1,6 +1,11 @@
|
||||
package androidx.ui.examples.jetissues.view.common
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
expect fun SelectionContainer(children: @Composable () -> Unit)
|
||||
expect fun VerticalScrollbar(
|
||||
modifier: Modifier,
|
||||
scrollState: ScrollState
|
||||
)
|
||||
@@ -1,17 +1,15 @@
|
||||
package androidx.ui.examples.jetissues.view.common
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.rememberScrollbarAdapter
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.DesktopSelectionContainer
|
||||
import androidx.compose.ui.selection.Selection
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
actual fun SelectionContainer(children: @Composable () -> Unit) {
|
||||
val selection = remember { mutableStateOf<Selection?>(null) }
|
||||
DesktopSelectionContainer(
|
||||
selection = selection.value,
|
||||
onSelectionChange = { selection.value = it },
|
||||
content = children
|
||||
)
|
||||
}
|
||||
actual fun VerticalScrollbar(
|
||||
modifier: Modifier,
|
||||
scrollState: ScrollState
|
||||
) = androidx.compose.foundation.VerticalScrollbar(
|
||||
rememberScrollbarAdapter(scrollState),
|
||||
modifier
|
||||
)
|
||||
@@ -17,6 +17,7 @@ package androidx.ui.examples.jetissues.view
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -24,7 +25,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import androidx.compose.ui.selection.DisableSelection
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
@@ -35,22 +35,20 @@ import androidx.ui.examples.jetissues.data.*
|
||||
import androidx.ui.examples.jetissues.query.IssueQuery
|
||||
import androidx.ui.examples.jetissues.query.IssuesQuery
|
||||
import androidx.ui.examples.jetissues.query.type.OrderDirection
|
||||
import androidx.ui.examples.jetissues.view.common.SelectionContainer
|
||||
import androidx.ui.examples.jetissues.view.common.VerticalScrollbar
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.ocpsoft.prettytime.PrettyTime
|
||||
import java.lang.Integer.parseInt
|
||||
import java.util.*
|
||||
|
||||
val Repository = ambientOf<IssuesRepository>()
|
||||
val Repository = compositionLocalOf<IssuesRepository> { error("Undefined repository") }
|
||||
|
||||
@Composable
|
||||
fun JetIssuesView() {
|
||||
MaterialTheme(
|
||||
colors = lightThemeColors
|
||||
) {
|
||||
DisableSelection {
|
||||
Main()
|
||||
}
|
||||
Main()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,7 +91,7 @@ fun SingleColumnLayout(currentIssue: MutableState<IssuesQuery.Node?>) {
|
||||
}
|
||||
)
|
||||
},
|
||||
bodyContent = {
|
||||
content = {
|
||||
CurrentIssue(currentIssue.value)
|
||||
}
|
||||
)
|
||||
@@ -140,35 +138,44 @@ fun CurrentIssueStatus(content: @Composable () -> Unit) {
|
||||
|
||||
@Composable
|
||||
fun CurrentIssueActive(issue: IssuesQuery.Node, body: IssueQuery.Issue) {
|
||||
ScrollableColumn(modifier = Modifier.padding(15.dp).fillMaxSize()) {
|
||||
SelectionContainer {
|
||||
Text(
|
||||
text = issue.title,
|
||||
style = MaterialTheme.typography.h5
|
||||
)
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
val state = rememberScrollState()
|
||||
|
||||
Column(modifier = Modifier.padding(15.dp).fillMaxSize().verticalScroll(state)) {
|
||||
SelectionContainer {
|
||||
Text(
|
||||
text = issue.title,
|
||||
style = MaterialTheme.typography.h5
|
||||
)
|
||||
}
|
||||
|
||||
Row(horizontalArrangement = Arrangement.Center) {
|
||||
CreatedBy(issue)
|
||||
}
|
||||
|
||||
Labels(issue.labels)
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
SelectionContainer {
|
||||
Text(
|
||||
text = body.body,
|
||||
modifier = Modifier.padding(4.dp),
|
||||
style = MaterialTheme.typography.body1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Row(horizontalArrangement = Arrangement.Center) {
|
||||
CreatedBy(issue)
|
||||
}
|
||||
|
||||
Labels(issue.labels)
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
SelectionContainer {
|
||||
Text(
|
||||
text = body.body,
|
||||
modifier = Modifier.padding(4.dp),
|
||||
style = MaterialTheme.typography.body1
|
||||
)
|
||||
}
|
||||
VerticalScrollbar(
|
||||
Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
|
||||
state
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun IssuesList(currentIssue: MutableState<IssuesQuery.Node?>) {
|
||||
val scroll = rememberScrollState(0f)
|
||||
val scroll = rememberScrollState()
|
||||
val issuesState = remember { mutableStateOf(IssuesState.OPEN) }
|
||||
val issuesOrder = remember { mutableStateOf(OrderDirection.DESC) }
|
||||
Column {
|
||||
@@ -181,7 +188,7 @@ fun IssuesList(currentIssue: MutableState<IssuesQuery.Node?>) {
|
||||
}
|
||||
)
|
||||
},
|
||||
bodyContent = {
|
||||
content = {
|
||||
Column {
|
||||
FilterTabs(issuesState, scroll)
|
||||
ListBody(
|
||||
@@ -203,7 +210,7 @@ fun OrderButton(order: MutableState<OrderDirection>, scroll: ScrollState) {
|
||||
Button(onClick = {
|
||||
order.value = OrderDirection.ASC
|
||||
runBlocking {
|
||||
scroll.scrollTo(0F)
|
||||
scroll.scrollTo(0)
|
||||
}
|
||||
}) {
|
||||
Text("ASC")
|
||||
@@ -212,7 +219,7 @@ fun OrderButton(order: MutableState<OrderDirection>, scroll: ScrollState) {
|
||||
Button(onClick = {
|
||||
order.value = OrderDirection.DESC
|
||||
runBlocking {
|
||||
scroll.scrollTo(0F)
|
||||
scroll.scrollTo(0)
|
||||
}
|
||||
}) {
|
||||
Text("DESC")
|
||||
@@ -232,7 +239,7 @@ fun FilterTabs(issuesState: MutableState<IssuesState>, scroll: ScrollState) {
|
||||
onClick = {
|
||||
issuesState.value = it
|
||||
runBlocking {
|
||||
scroll.scrollTo(0F)
|
||||
scroll.scrollTo(0)
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -252,25 +259,32 @@ fun ListBody(
|
||||
repo.getIssues(issuesState, issuesOrder, callback = clb)
|
||||
}
|
||||
|
||||
ScrollableColumn(scrollState = scroll) {
|
||||
issues.value.let {
|
||||
when (it) {
|
||||
is UiState.Success -> {
|
||||
for (iss in it.data.nodes) {
|
||||
Box(modifier = Modifier.clickable {
|
||||
currentIssue.value = iss
|
||||
}, contentAlignment = Alignment.CenterStart) {
|
||||
ListItem(iss)
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Column(Modifier.verticalScroll(scroll)) {
|
||||
issues.value.let {
|
||||
when (it) {
|
||||
is UiState.Success -> {
|
||||
for (iss in it.data.nodes) {
|
||||
Box(modifier = Modifier.clickable {
|
||||
currentIssue.value = iss
|
||||
}, contentAlignment = Alignment.CenterStart) {
|
||||
ListItem(iss)
|
||||
}
|
||||
}
|
||||
MoreButton(issues)
|
||||
}
|
||||
MoreButton(issues)
|
||||
}
|
||||
|
||||
is UiState.Loading -> Loader()
|
||||
is UiState.Error -> Error("Issues loading error")
|
||||
is UiState.Loading -> Loader()
|
||||
is UiState.Error -> Error("Issues loading error")
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalScrollbar(
|
||||
Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
|
||||
scroll
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package androidx.ui.examples.jetissues
|
||||
|
||||
import androidx.compose.desktop.Window
|
||||
import androidx.compose.runtime.Providers
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.ui.examples.jetissues.view.JetIssuesView
|
||||
import androidx.ui.examples.jetissues.view.Repository
|
||||
@@ -13,7 +13,7 @@ fun main() = Window(
|
||||
title = "JetIssues",
|
||||
size = IntSize(1440, 768)
|
||||
) {
|
||||
Providers(Repository provides repo) {
|
||||
CompositionLocalProvider(Repository provides repo) {
|
||||
JetIssuesView()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user