Skip to content

Commit

Permalink
Updated twitter compose detekt to 0.0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
LachlanMcKee committed Dec 6, 2022
1 parent 41a611e commit dcfa373
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Pending changes

- [#287](https://github.com/bumble-tech/appyx/pull/287)**Added**: Introduced a new `rememberCombinedHandler` implementation that takes an immutable list to avoid non-skippable compositions. The previous implementation is now deprecated.
- [#287](https://github.com/bumble-tech/appyx/pull/287)**Added**: `ImmutableList` has been added to avoid non-skippable compositions.
- [#289](https://github.com/bumble-tech/appyx/issues/289)**Added**: Introduced `interop-rx3` for RxJava 3 support. This has identical functionality to `interop-rx2`.

---
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.
plugin-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
plugin-android = "com.android.tools.build:gradle:7.3.1"

detekt-compose = "com.twitter.compose.rules:detekt:0.0.18"
detekt-compose = "com.twitter.compose.rules:detekt:0.0.26"

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.bumble.appyx.core.collections

import androidx.compose.runtime.Immutable

@Immutable
data class ImmutableList<out E>(private val list: List<E>) : List<E> by list

fun <E> immutableListOf(vararg items: E): ImmutableList<E> =
ImmutableList(listOf(*items))

fun <E> List<E>.toImmutableList(): ImmutableList<E> =
ImmutableList(ArrayList(this)) // make a copy as list might be also mutable
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.animation.core.Transition
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.bumble.appyx.core.collections.ImmutableList

class CombinedHandler<T, S>(
private val handlers: List<ModifierTransitionHandler<T, S>>
Expand All @@ -23,6 +24,20 @@ class CombinedHandler<T, S>(
}
}

@Suppress("UnstableCollections")
@Deprecated(
message = "Use rememberCombinedHandler with immutable handlers instead. This function will be removed in 1.1",
replaceWith = ReplaceWith(
"rememberCombinedHandler<T, S>(handlers.toImmutableList<T, S>())",
"com.bumble.appyx.core.collections.toImmutableList",
)
)
@Composable
fun <T, S> rememberCombinedHandler(handlers: List<ModifierTransitionHandler<T, S>>): ModifierTransitionHandler<T, S> =
remember { CombinedHandler(handlers = handlers) }

@Composable
fun <T, S> rememberCombinedHandler(
handlers: ImmutableList<ModifierTransitionHandler<T, S>>
): ModifierTransitionHandler<T, S> =
remember(handlers) { CombinedHandler(handlers = handlers) }
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class StatefulNode2(
val shape = RoundedCornerShape(16.dp)

Column(
modifier = modifier
modifier = Modifier
.size(200.dp)
.align(Alignment.Center)
.background(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.bumble.appyx.core.collections.immutableListOf
import com.bumble.appyx.core.composable.Children
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.navigation.transition.rememberCombinedHandler
Expand Down Expand Up @@ -99,7 +100,7 @@ class ContainerNode internal constructor(
.background(MaterialTheme.colors.background),
navModel = backStack,
transitionHandler = rememberCombinedHandler(
handlers = listOf(rememberBackstackSlider(), rememberBackstackFader())
handlers = immutableListOf(rememberBackstackSlider(), rememberBackstackFader())
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.bumble.appyx.core.collections.ImmutableList
import com.bumble.appyx.core.collections.toImmutableList
import com.bumble.appyx.core.composable.Child
import com.bumble.appyx.core.composable.visibleChildrenAsState
import com.bumble.appyx.core.modality.BuildContext
Expand Down Expand Up @@ -73,7 +75,7 @@ class LazyListContainerNode constructor(
}
}

val children by navModel.visibleChildrenAsState()
val children = navModel.visibleChildrenAsState().value.toImmutableList()
when (selectedMode) {
Column -> ColumnExample(children)
Row -> RowExample(children)
Expand All @@ -83,7 +85,7 @@ class LazyListContainerNode constructor(
}

@Composable
private fun ColumnExample(elements: List<NavElement<NavTarget, out Any?>>) {
private fun ColumnExample(elements: ImmutableList<NavElement<NavTarget, out Any?>>) {
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(horizontal = 16.dp),
Expand All @@ -97,7 +99,7 @@ class LazyListContainerNode constructor(
}

@Composable
private fun RowExample(elements: List<NavElement<NavTarget, out Any?>>) {
private fun RowExample(elements: ImmutableList<NavElement<NavTarget, out Any?>>) {
LazyRow(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(vertical = 16.dp),
Expand All @@ -110,7 +112,7 @@ class LazyListContainerNode constructor(
}

@Composable
private fun GridExample(elements: List<NavElement<NavTarget, out Any?>>) {
private fun GridExample(elements: ImmutableList<NavElement<NavTarget, out Any?>>) {
LazyVerticalGrid(
columns = Fixed(2),
modifier = Modifier.fillMaxSize(),
Expand Down

0 comments on commit dcfa373

Please sign in to comment.