Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal actual fun ModalBottomSheetDialog(
usePlatformDefaultWidth = false,
usePlatformInsets = false,
scrimColor = Color.Transparent,
animateTransition = false,
),
content = content
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal actual fun ModalWideNavigationRailDialog(
usePlatformDefaultWidth = false,
usePlatformInsets = false,
scrimColor = Color.Transparent,
animateTransition = false
),
content = content
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal actual fun BasicEdgeToEdgeDialog(
usePlatformInsets = false,
useSoftwareKeyboardInset = false,
scrimColor = Color.Transparent,
animateTransition = false,
),
) {
val predictiveBackState = rememberPredictiveBackState()
Expand Down
1 change: 1 addition & 0 deletions compose/ui/ui/api/desktop/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -4353,6 +4353,7 @@ public final class androidx/compose/ui/window/DialogProperties {
public synthetic fun <init> (ZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ZZZZZJILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ZZZZZJLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ZZZZZJZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getDismissOnBackPress ()Z
public final fun getDismissOnClickOutside ()Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.ExtendedFloatingActionButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -38,6 +39,7 @@ import androidx.compose.ui.window.Dialog
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.runBlocking
import org.jetbrains.skia.Image
import org.jetbrains.skiko.MainUIDispatcher
import org.junit.Ignore
import org.junit.Rule
Expand Down Expand Up @@ -94,7 +96,7 @@ class ImageComposeSceneTest {

@Test
fun `run dialog in center`() {
val image = renderComposeScene(
val image = renderComposeSceneOnIdle(
width = 80,
height = 40,
) {
Expand Down Expand Up @@ -130,4 +132,20 @@ class ImageComposeSceneTest {
scene.close()
}
}
}

@OptIn(ExperimentalTime::class)
private fun renderComposeSceneOnIdle(
width: Int,
height: Int,
density: Density = Density(1f),
content: @Composable () -> Unit
): Image = ImageComposeScene(
width = width,
height = height,
density = density,
content = content
).use {
val time = it.runUntilIdle()
it.render(time)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import java.awt.image.MultiResolutionImage
import java.text.AttributedString
import javax.swing.Icon
import javax.swing.ImageIcon
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
import org.jetbrains.skiko.MainUIDispatcher
Expand Down Expand Up @@ -272,4 +275,18 @@ internal inline fun <R> ImageComposeScene.useInUiThread(
crossinline block: (ImageComposeScene) -> R
): R = runBlocking(MainUIDispatcher) {
use(block)
}
}

@OptIn(ExperimentalTime::class)
internal fun ImageComposeScene.runUntilIdle(
initialTime: Duration = Duration.ZERO,
frameDuration: Duration = 16.milliseconds
): Duration {
var time = initialTime
render(time)
while (hasInvalidations()) {
time += frameDuration
render(time)
}
return time
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ internal object SkikoComposeUiFlags {
@Suppress("MutableBareField")
@JvmField
var isClearFocusOnMouseDownEnabled: Boolean = true

@Suppress("MutableBareField")
@JvmField
var isDialogAnimationEnabled: Boolean = true
}

/**
Expand All @@ -43,4 +47,12 @@ var ComposeUiFlags.useLegacyRenderNodeLayers by SkikoComposeUiFlags::useLegacyRe
* More granular control is available in the various platform-specific entry points.
*/
@ExperimentalComposeUiApi
var ComposeUiFlags.isClearFocusOnMouseDownEnabled by SkikoComposeUiFlags::isClearFocusOnMouseDownEnabled
var ComposeUiFlags.isClearFocusOnMouseDownEnabled by SkikoComposeUiFlags::isClearFocusOnMouseDownEnabled

/**
* When enabled the [androidx.compose.ui.window.Dialog] appear and disappear with animation.
*
* Note that it's a temporary flag, it will be removed in the future.
*/
@ExperimentalComposeUiApi
var ComposeUiFlags.isDialogAnimationEnabled by SkikoComposeUiFlags::isDialogAnimationEnabled
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ internal fun easeInOutTimingFunction(progress: Float): Float = if (progress < 0.
(-2f * progress * progress) + (4f * progress) - 1f
}

internal fun easeOutTimingFunction(progress: Float): Float {
return -progress * (progress - 2f)
}

internal suspend fun withAnimationProgress(
duration: Duration,
timingFunction: (Float) -> Float = ::easeInOutTimingFunction,
update: (Float) -> Unit
) {
update(0f)

var firstFrameTime = 0L
var firstFrameTime: Long? = null
var progressDuration = Duration.ZERO
while (progressDuration < duration) {
withFrameNanos { frameTime ->
if (firstFrameTime == 0L) {
if (firstFrameTime == null) {
firstFrameTime = frameTime
}
progressDuration = (frameTime - firstFrameTime).nanoseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ internal fun rememberComposeSceneLayer(
layer.density = density
layer.layoutDirection = layoutDirection

DisposableEffect(Unit) {
onDispose {
layer.close()
}
}
return layer
}

Expand Down
Loading
Loading