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 {
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 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()
}
}

4
examples/issues/build.gradle.kts

@ -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"))
}
}

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
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

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
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
)

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
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
)

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.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()
Row(horizontalArrangement = Arrangement.Center) {
CreatedBy(issue)
}
Column(modifier = Modifier.padding(15.dp).fillMaxSize().verticalScroll(state)) {
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 {
Text(
text = body.body,
modifier = Modifier.padding(4.dp),
style = MaterialTheme.typography.body1
)
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

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

@ -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()
}
}

Loading…
Cancel
Save