Skip to content

Commit

Permalink
Merge pull request #95 from Tlaster/compose-1.5.0-beta02
Browse files Browse the repository at this point in the history
update dependencies
  • Loading branch information
Tlaster authored Aug 14, 2023
2 parents 5c877cd + 734087a commit 197ea49
Show file tree
Hide file tree
Showing 44 changed files with 170 additions and 153 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ extra.apply {
set("jvmTarget", "17")

// Android configurations
set("android-compile", 33)
set("android-compile", 34)
set("android-build-tools", "34.0.0")
set("androidMinSdk", 21)
set("androidTargetSdk", 33)
set("androidTargetSdk", 34)

// Js & Node
set("webpackCliVersion", "5.1.4")
set("nodeVersion", "16.13.0")

set("ktlintVersion", "0.42.1")
set("ktlintVersion", "0.50.0")
}
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ kotlin.code.style=official
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx4g
# TODO: https://github.com/JetBrains/compose-jb/issues/2046
kotlin.native.cacheKind=none
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions] # also check project root build.gradle.kts for versions
androidx-animation = "1.5.0-beta03"
androidx-foundation = "1.5.0-beta03"
androidx-animation = "1.5.0"
androidx-foundation = "1.5.0"
androidx-appcompat = "1.6.1"
androidx-coreKtx = "1.10.1"
androidxActivityVer = "1.7.2"
Expand All @@ -11,11 +11,11 @@ junitJupiterApi = "5.10.0"
kotlin = "1.9.0"
kotlinxCoroutinesCore = "1.7.3"
lifecycleRuntimeKtx = "2.6.1"
material = "1.5.0-beta03"
material = "1.5.0"
moleculeRuntime = "1.2.0"
savedstateKtx = "1.2.1"
spotless = "6.20.0"
jetbrainsComposePlugin = "1.5.0-beta01"
jetbrainsComposePlugin = "1.5.0-beta02"
skiko = "0.7.76"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fun <T> producePresenter(
fun <T, E> rememberPresenter(
keys: List<Any?> = emptyList(),
useImmediateClock: Boolean = false,
body: @Composable (flow: Flow<E>) -> T
body: @Composable (flow: Flow<E>) -> T,
): Pair<T, Channel<E>> {
val (channel, action) = rememberAction<E>(keys = keys)
val presenter = rememberPresenterState(keys = keys, useImmediateClock = useImmediateClock) { body(action) }
Expand Down Expand Up @@ -147,7 +147,7 @@ fun <T, E> rememberPresenter(
*/
@Composable
fun <T, E> rememberNestedPresenter(
body: @Composable (flow: Flow<E>) -> T
body: @Composable (flow: Flow<E>) -> T,
): Pair<T, Channel<E>> {
val channel = remember { Channel<E>(Channel.UNLIMITED) }
val flow = remember { channel.consumeAsFlow() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ val ViewModel.viewModelScope: CoroutineScope
}
return setTagIfAbsent(
JOB_KEY,
CloseableCoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
CloseableCoroutineScope(SupervisorJob() + Dispatchers.Main.immediate),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ fun <T : ViewModel> viewModel(
"Require LocalSavedStateHolder not null"
}
return remember(
modelClass, keys, creator, stateHolder, savedStateHolder
modelClass,
keys,
creator,
stateHolder,
savedStateHolder,
) {
stateHolder.getViewModel(keys, modelClass = modelClass) {
creator(savedStateHolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,32 @@ open class PreComposeActivity : FragmentActivity() {

fun PreComposeActivity.setContent(
parent: CompositionContext? = null,
content: @Composable () -> Unit
content: @Composable () -> Unit,
) {
val existingComposeView = window.decorView
.findViewById<ViewGroup>(android.R.id.content)
.getChildAt(0) as? ComposeView

if (existingComposeView != null) with(existingComposeView) {
setParentCompositionContext(parent)
setContent {
ContentInternal(content)
if (existingComposeView != null) {
with(existingComposeView) {
setParentCompositionContext(parent)
setContent {
ContentInternal(content)
}
}
} else ComposeView(this).apply {
// Set content and parent **before** setContentView
// to have ComposeView create the composition on attach
setParentCompositionContext(parent)
setContent {
ContentInternal(content)
} else {
ComposeView(this).apply {
// Set content and parent **before** setContentView
// to have ComposeView create the composition on attach
setParentCompositionContext(parent)
setContent {
ContentInternal(content)
}
// Set the view tree owners before setting the content view so that the inflation process
// and attach listeners will see them already present
setOwners()
setContentView(this, DefaultActivityContentLayoutParams)
}
// Set the view tree owners before setting the content view so that the inflation process
// and attach listeners will see them already present
setOwners()
setContentView(this, DefaultActivityContentLayoutParams)
}
}

Expand Down Expand Up @@ -106,7 +110,7 @@ private fun PreComposeActivity.ProvideAndroidCompositionLocals(
val savedStateHolder = remember(saveableStateRegistry) {
SavedStateHolder(
"root",
saveableStateRegistry
saveableStateRegistry,
)
}

Expand All @@ -125,5 +129,5 @@ private fun PreComposeActivity.ProvideAndroidCompositionLocals(

private val DefaultActivityContentLayoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.WRAP_CONTENT,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlin.coroutines.EmptyCoroutineContext

@Composable
fun <T : R, R> StateFlow<T>.collectAsStateWithLifecycle(
context: CoroutineContext = EmptyCoroutineContext
context: CoroutineContext = EmptyCoroutineContext,
): State<R> {
return collectAsStateWithLifecycle(initial = this.value, context = context)
}
Expand All @@ -33,13 +33,13 @@ fun <T : R, R> StateFlow<T>.collectAsStateWithLifecycle(
@Composable
fun <T : R, R> Flow<T>.collectAsStateWithLifecycle(
initial: R,
context: CoroutineContext = EmptyCoroutineContext
context: CoroutineContext = EmptyCoroutineContext,
): State<R> {
val lifecycleOwner = checkNotNull(LocalLifecycleOwner.current)
return collectAsStateWithLifecycle(
initial = initial,
lifecycle = lifecycleOwner.lifecycle,
context = context
context = context,
)
}

Expand All @@ -52,14 +52,16 @@ fun <T : R, R> Flow<T>.collectAsStateWithLifecycle(
fun <T : R, R> Flow<T>.collectAsStateWithLifecycle(
initial: R,
lifecycle: Lifecycle,
context: CoroutineContext = EmptyCoroutineContext
context: CoroutineContext = EmptyCoroutineContext,
): State<R> {
return produceState(initial, this, lifecycle, context) {
lifecycle.repeatOnLifecycle {
if (context == EmptyCoroutineContext) {
this@collectAsStateWithLifecycle.collect { this@produceState.value = it }
} else withContext(context) {
this@collectAsStateWithLifecycle.collect { this@produceState.value = it }
} else {
withContext(context) {
this@collectAsStateWithLifecycle.collect { this@produceState.value = it }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import kotlin.coroutines.resume
* again.
*/
suspend fun Lifecycle.repeatOnLifecycle(
block: suspend CoroutineScope.() -> Unit
block: suspend CoroutineScope.() -> Unit,
) {
if (currentState === Lifecycle.State.Destroyed) {
return
Expand Down Expand Up @@ -138,5 +138,5 @@ suspend fun Lifecycle.repeatOnLifecycle(
* @see Lifecycle.repeatOnLifecycle
*/
suspend fun LifecycleOwner.repeatOnLifecycle(
block: suspend CoroutineScope.() -> Unit
block: suspend CoroutineScope.() -> Unit,
): Unit = lifecycle.repeatOnLifecycle(block)
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal class BackStackManager : LifecycleObserver {
parentSavedStateHolder = _savedStateHolder,
requestNavigationLock = {
canNavigate = !it
}
},
)
}

Expand All @@ -139,12 +139,14 @@ internal class BackStackManager : LifecycleObserver {
PopUpTo.Prev -> backStack.lastIndex - 1
is PopUpTo.Route -> if (popUpTo.route.isNotEmpty()) {
backStack.indexOfLast { it.hasRoute(popUpTo.route, path, options.includePath) }
} else 0
} else {
0
}
}
if (index != -1) {
val stacksToDrop = backStack.subList(
if (popUpTo.inclusive) index else index + 1,
backStack.size
backStack.size,
)
backStacks.value -= stacksToDrop
stacksToDrop.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ fun NavHost(
NavHostContent(composeStateHolder, entry)
}
} else {

var prevWasSwiped by remember {
mutableStateOf(false)
}
Expand Down Expand Up @@ -196,8 +195,8 @@ fun NavHost(
0f
} else {
1f
}
)
},
),
) {
SwipeItem(
dismissState = dismissState,
Expand Down Expand Up @@ -244,16 +243,16 @@ private fun SwipeItem(
?.graphicsLayer {
translationX =
swipeProperties.slideInHorizontally(size.width.toInt())
.toFloat() -
.toFloat() -
swipeProperties.slideInHorizontally(
dismissState.offset.value.absoluteValue.toInt()
dismissState.offset.value.absoluteValue.toInt(),
)
}?.drawWithContent {
drawContent()
drawRect(
swipeProperties.shadowColor,
alpha = (1f - dismissState.progress.fraction) *
swipeProperties.shadowColor.alpha
swipeProperties.shadowColor.alpha,
)
}?.pointerInput(0) {
// prev entry should not be interactive until fully appeared
Expand Down Expand Up @@ -282,7 +281,7 @@ private fun NavHostContent(
LocalLifecycleOwner provides entry,
content = {
entry.ComposeContent()
}
},
)
}
}
Expand Down Expand Up @@ -312,15 +311,14 @@ private fun CustomSwipeToDismiss(
spaceToSwipe: Dp = 10.dp,
modifier: Modifier = Modifier,
dismissThreshold: ThresholdConfig,
dismissContent: @Composable () -> Unit
dismissContent: @Composable () -> Unit,
) = BoxWithConstraints(modifier) {

val width = constraints.maxWidth.toFloat()
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl

val anchors = mutableMapOf(
0f to DismissValue.Default,
width to DismissValue.DismissedToEnd
width to DismissValue.DismissedToEnd,
)

val shift = with(LocalDensity.current) {
Expand All @@ -341,11 +339,11 @@ private fun CustomSwipeToDismiss(
resistance = ResistanceConfig(
basis = width,
factorAtMin = SwipeableDefaults.StiffResistanceFactor,
factorAtMax = SwipeableDefaults.StandardResistanceFactor
)
factorAtMax = SwipeableDefaults.StandardResistanceFactor,
),
)
.offset { IntOffset(x = -shift, 0) }
.graphicsLayer { translationX = state.offset.value }
.graphicsLayer { translationX = state.offset.value },

) {
dismissContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Navigator {
stateHolder = stateHolder,
savedStateHolder = savedStateHolder,
lifecycleOwner = lifecycleOwner,
persistNavState = persistNavState
persistNavState = persistNavState,
)
_pendingNavigation?.let {
stackManager.push(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RouteBuilder(
deepLinks = deepLinks,
swipeProperties = swipeProperties,
content = content,
)
),
)
}

Expand All @@ -55,7 +55,7 @@ class RouteBuilder(
GroupRoute(
route = route,
initialRoute = actualInitialRoute,
)
),
)
}

Expand All @@ -70,7 +70,7 @@ class RouteBuilder(
) {
floating(
route,
content
content,
)
}

Expand All @@ -87,7 +87,7 @@ class RouteBuilder(
FloatingRoute(
route = route,
content = content,
)
),
)
}

Expand Down
Loading

0 comments on commit 197ea49

Please sign in to comment.