Browse Source

example/issues: bump compose version to 0.3.0-build154 & fix incompatibilities (#398)

pull/402/head
Andrew Rudenko 4 years ago committed by GitHub
parent
commit
81bfef76d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      examples/issues/android/build.gradle.kts
  2. 6
      examples/issues/android/src/main/java/androidx/ui/examples/jetissues/MainActivity.kt
  3. 4
      examples/issues/build.gradle.kts
  4. 19
      examples/issues/common/src/androidMain/kotlin/androidx/ui/examples/jetissues/view/common/Platform.kt
  5. 7
      examples/issues/common/src/commonMain/kotlin/androidx/ui/examples/jetissues/view/common/Platform.kt
  6. 22
      examples/issues/common/src/desktopMain/kotlin/androidx/ui/examples/jetissues/common/Platform.kt
  7. 100
      examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt
  8. 4
      examples/issues/desktop/src/jvmMain/kotlin/androidx/ui/examples/jetissues/Main.kt

7
examples/issues/android/build.gradle.kts

@ -22,4 +22,11 @@ android {
dependencies { dependencies {
implementation(project(":common")) 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")
}
} }

6
examples/issues/android/src/main/java/androidx/ui/examples/jetissues/MainActivity.kt

@ -2,8 +2,8 @@ package androidx.ui.examples.jetissues
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Providers import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.setContent import androidx.activity.compose.setContent
import androidx.ui.examples.jetissues.view.JetIssuesView import androidx.ui.examples.jetissues.view.JetIssuesView
import androidx.ui.examples.jetissues.view.Repository import androidx.ui.examples.jetissues.view.Repository
import androidx.ui.examples.jetissues.data.IssuesRepositoryImpl import androidx.ui.examples.jetissues.data.IssuesRepositoryImpl
@ -15,7 +15,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
Providers(Repository provides repo) { CompositionLocalProvider(Repository provides repo) {
JetIssuesView() JetIssuesView()
} }
} }

4
examples/issues/build.gradle.kts

@ -9,10 +9,10 @@ buildscript {
dependencies { dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__ // __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") classpath("com.android.tools.build:gradle:4.0.1")
// __KOTLIN_COMPOSE_VERSION__ // __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.4.21-2")) classpath(kotlin("gradle-plugin", version = "1.4.30"))
} }
} }

19
examples/issues/common/src/androidMain/kotlin/androidx/ui/examples/jetissues/view/common/Platform.kt

@ -1,18 +1,11 @@
package androidx.ui.examples.jetissues.view.common package androidx.ui.examples.jetissues.view.common
import androidx.compose.foundation.ScrollState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier
import androidx.compose.runtime.remember
import androidx.compose.ui.selection.Selection
import androidx.compose.ui.text.InternalTextApi
@OptIn(InternalTextApi::class)
@Composable @Composable
actual fun SelectionContainer(children: @Composable () -> Unit) { actual fun VerticalScrollbar(
val selection = remember { mutableStateOf<Selection?>(null) } modifier: Modifier,
androidx.compose.ui.selection.SelectionContainer( scrollState: ScrollState
selection = selection.value, ) = Unit
onSelectionChange = { selection.value = it },
children = children
)
}

7
examples/issues/common/src/commonMain/kotlin/androidx/ui/examples/jetissues/view/common/Platform.kt

@ -1,6 +1,11 @@
package androidx.ui.examples.jetissues.view.common package androidx.ui.examples.jetissues.view.common
import androidx.compose.foundation.ScrollState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@Composable @Composable
expect fun SelectionContainer(children: @Composable () -> Unit) expect fun VerticalScrollbar(
modifier: Modifier,
scrollState: ScrollState
)

22
examples/issues/common/src/desktopMain/kotlin/androidx/ui/examples/jetissues/common/Platform.kt

@ -1,17 +1,15 @@
package androidx.ui.examples.jetissues.view.common 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.Composable
import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.DesktopSelectionContainer
import androidx.compose.ui.selection.Selection
@Composable @Composable
actual fun SelectionContainer(children: @Composable () -> Unit) { actual fun VerticalScrollbar(
val selection = remember { mutableStateOf<Selection?>(null) } modifier: Modifier,
DesktopSelectionContainer( scrollState: ScrollState
selection = selection.value, ) = androidx.compose.foundation.VerticalScrollbar(
onSelectionChange = { selection.value = it }, rememberScrollbarAdapter(scrollState),
content = children modifier
) )
}

100
examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt

@ -17,6 +17,7 @@ package androidx.ui.examples.jetissues.view
import androidx.compose.foundation.* import androidx.compose.foundation.*
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -24,7 +25,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.selection.DisableSelection
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle 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.IssueQuery
import androidx.ui.examples.jetissues.query.IssuesQuery import androidx.ui.examples.jetissues.query.IssuesQuery
import androidx.ui.examples.jetissues.query.type.OrderDirection 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 kotlinx.coroutines.runBlocking
import org.ocpsoft.prettytime.PrettyTime import org.ocpsoft.prettytime.PrettyTime
import java.lang.Integer.parseInt import java.lang.Integer.parseInt
import java.util.* import java.util.*
val Repository = ambientOf<IssuesRepository>() val Repository = compositionLocalOf<IssuesRepository> { error("Undefined repository") }
@Composable @Composable
fun JetIssuesView() { fun JetIssuesView() {
MaterialTheme( MaterialTheme(
colors = lightThemeColors colors = lightThemeColors
) { ) {
DisableSelection { Main()
Main()
}
} }
} }
@ -93,7 +91,7 @@ fun SingleColumnLayout(currentIssue: MutableState<IssuesQuery.Node?>) {
} }
) )
}, },
bodyContent = { content = {
CurrentIssue(currentIssue.value) CurrentIssue(currentIssue.value)
} }
) )
@ -140,35 +138,44 @@ fun CurrentIssueStatus(content: @Composable () -> Unit) {
@Composable @Composable
fun CurrentIssueActive(issue: IssuesQuery.Node, body: IssueQuery.Issue) { fun CurrentIssueActive(issue: IssuesQuery.Node, body: IssueQuery.Issue) {
ScrollableColumn(modifier = Modifier.padding(15.dp).fillMaxSize()) { Box(Modifier.fillMaxSize()) {
SelectionContainer { val state = rememberScrollState()
Text(
text = issue.title,
style = MaterialTheme.typography.h5
)
}
Row(horizontalArrangement = Arrangement.Center) { Column(modifier = Modifier.padding(15.dp).fillMaxSize().verticalScroll(state)) {
CreatedBy(issue) SelectionContainer {
} Text(
text = issue.title,
style = MaterialTheme.typography.h5
)
}
Labels(issue.labels) Row(horizontalArrangement = Arrangement.Center) {
CreatedBy(issue)
}
Spacer(Modifier.height(8.dp)) Labels(issue.labels)
SelectionContainer { Spacer(Modifier.height(8.dp))
Text(
text = body.body, SelectionContainer {
modifier = Modifier.padding(4.dp), Text(
style = MaterialTheme.typography.body1 text = body.body,
) modifier = Modifier.padding(4.dp),
style = MaterialTheme.typography.body1
)
}
} }
VerticalScrollbar(
Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
state
)
} }
} }
@Composable @Composable
fun IssuesList(currentIssue: MutableState<IssuesQuery.Node?>) { fun IssuesList(currentIssue: MutableState<IssuesQuery.Node?>) {
val scroll = rememberScrollState(0f) val scroll = rememberScrollState()
val issuesState = remember { mutableStateOf(IssuesState.OPEN) } val issuesState = remember { mutableStateOf(IssuesState.OPEN) }
val issuesOrder = remember { mutableStateOf(OrderDirection.DESC) } val issuesOrder = remember { mutableStateOf(OrderDirection.DESC) }
Column { Column {
@ -181,7 +188,7 @@ fun IssuesList(currentIssue: MutableState<IssuesQuery.Node?>) {
} }
) )
}, },
bodyContent = { content = {
Column { Column {
FilterTabs(issuesState, scroll) FilterTabs(issuesState, scroll)
ListBody( ListBody(
@ -203,7 +210,7 @@ fun OrderButton(order: MutableState<OrderDirection>, scroll: ScrollState) {
Button(onClick = { Button(onClick = {
order.value = OrderDirection.ASC order.value = OrderDirection.ASC
runBlocking { runBlocking {
scroll.scrollTo(0F) scroll.scrollTo(0)
} }
}) { }) {
Text("ASC") Text("ASC")
@ -212,7 +219,7 @@ fun OrderButton(order: MutableState<OrderDirection>, scroll: ScrollState) {
Button(onClick = { Button(onClick = {
order.value = OrderDirection.DESC order.value = OrderDirection.DESC
runBlocking { runBlocking {
scroll.scrollTo(0F) scroll.scrollTo(0)
} }
}) { }) {
Text("DESC") Text("DESC")
@ -232,7 +239,7 @@ fun FilterTabs(issuesState: MutableState<IssuesState>, scroll: ScrollState) {
onClick = { onClick = {
issuesState.value = it issuesState.value = it
runBlocking { runBlocking {
scroll.scrollTo(0F) scroll.scrollTo(0)
} }
} }
) )
@ -252,25 +259,32 @@ fun ListBody(
repo.getIssues(issuesState, issuesOrder, callback = clb) repo.getIssues(issuesState, issuesOrder, callback = clb)
} }
ScrollableColumn(scrollState = scroll) { Box(Modifier.fillMaxSize()) {
issues.value.let { Column(Modifier.verticalScroll(scroll)) {
when (it) { issues.value.let {
is UiState.Success -> { when (it) {
for (iss in it.data.nodes) { is UiState.Success -> {
Box(modifier = Modifier.clickable { for (iss in it.data.nodes) {
currentIssue.value = iss Box(modifier = Modifier.clickable {
}, contentAlignment = Alignment.CenterStart) { currentIssue.value = iss
ListItem(iss) }, contentAlignment = Alignment.CenterStart) {
ListItem(iss)
}
} }
MoreButton(issues)
} }
MoreButton(issues)
}
is UiState.Loading -> Loader() is UiState.Loading -> Loader()
is UiState.Error -> Error("Issues loading error") is UiState.Error -> Error("Issues loading error")
}
} }
} }
VerticalScrollbar(
Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
scroll
)
} }
} }
@Composable @Composable

4
examples/issues/desktop/src/jvmMain/kotlin/androidx/ui/examples/jetissues/Main.kt

@ -1,7 +1,7 @@
package androidx.ui.examples.jetissues package androidx.ui.examples.jetissues
import androidx.compose.desktop.Window import androidx.compose.desktop.Window
import androidx.compose.runtime.Providers import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.ui.examples.jetissues.view.JetIssuesView import androidx.ui.examples.jetissues.view.JetIssuesView
import androidx.ui.examples.jetissues.view.Repository import androidx.ui.examples.jetissues.view.Repository
@ -13,7 +13,7 @@ fun main() = Window(
title = "JetIssues", title = "JetIssues",
size = IntSize(1440, 768) size = IntSize(1440, 768)
) { ) {
Providers(Repository provides repo) { CompositionLocalProvider(Repository provides repo) {
JetIssuesView() JetIssuesView()
} }
} }

Loading…
Cancel
Save