Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions platform/jewel/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_signature_body_expression_wrapping = multiline
ktlint_ignore_back_ticked_identifier = true
ktlint_standard_annotation = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_chain-method-continuation = disabled
ktlint_standard_class-signature = disabled
ktlint_standard_condition-wrapping = disabled
Expand All @@ -38,6 +39,7 @@ ktlint_standard_function-literal = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_import-ordering = disabled
ktlint_standard_indent = disabled
ktlint_standard_max-line-length = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_string-template-indent = disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.ZeroCornerSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocal
import androidx.compose.runtime.CompositionLocalContext
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -31,10 +30,10 @@ import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
import androidx.compose.ui.layout.boundsInRoot
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.semantics.popup
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntRect
import androidx.compose.ui.unit.IntSize
Expand Down Expand Up @@ -166,7 +165,6 @@ private fun JPopupImpl(
blendingEnabled: Boolean,
content: @Composable () -> Unit,
) {
val popupDensity = LocalDensity.current
val component = LocalComponent.current

val currentContent by rememberUpdatedState(content)
Expand Down Expand Up @@ -232,8 +230,8 @@ private fun JPopupImpl(

Layout(
content = {
CompositionLocalProvider(LocalComponent provides this@apply) {
ProvideValuesFromOtherContext(compositionLocalContext) { currentContent() }
CompositionLocalProvider(compositionLocalContext) {
CompositionLocalProvider(LocalComponent provides this@apply) { currentContent() }
}
},
modifier = Modifier.semantics { popup() },
Expand All @@ -252,7 +250,7 @@ private fun JPopupImpl(
JBR.getRoundedCornersManager()
.setRoundedCorners(
dialog,
cornerSize.toPx(size.toSize(), popupDensity) / dialog.density(),
cornerSize.toPx(size.toSize(), Density(dialog.density())) / dialog.density(),
)
}
}
Expand All @@ -270,7 +268,7 @@ private fun JPopupImpl(

val rectValue = popupRectangle
LaunchedEffect(rectValue) {
val rectangle = rectValue?.withDensity(popupDensity.density) ?: return@LaunchedEffect
val rectangle = rectValue?.withDensity(dialog.density()) ?: return@LaunchedEffect
dialog.size = rectangle.size
dialog.location = rectangle.location.fromCurrentScreenToGlobal(window)
}
Expand Down Expand Up @@ -412,16 +410,6 @@ private fun Rectangle.withDensity(density: Float): Rectangle =
floor(height / density).toInt(),
)

/**
* When inheriting from another context, we need to ensure that values already provided in the current context are not
* overridden.
*/
@Composable
private fun ProvideValuesFromOtherContext(context: CompositionLocalContext, content: @Composable () -> Unit) {
val existingContext = currentCompositionLocalContext
CompositionLocalProvider(context) { CompositionLocalProvider(existingContext, content) }
}
Comment on lines -420 to -423
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was a bit redundant. The context parameter had its value assigned by val compositionLocalContext by rememberUpdatedState(currentCompositionLocalContext)

Then existingContext also fetched the information from currentCompositionLocalContext.

At the end of the day they were both providing the same values 😵‍💫


/** Returns the screen density of the component's current monitor. */
private fun Component.density(): Float =
graphicsConfiguration.device.defaultConfiguration.defaultTransform.scaleX.toFloat()
Expand Down
Loading