Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't depend on kotlinx-coroutines-swing #212

Merged
merged 1 commit into from Mar 10, 2022

Conversation

igordmn
Copy link
Collaborator

@igordmn igordmn commented Mar 10, 2022

Because it overrides Dispatchers.Main

Fixes JetBrains/compose-multiplatform#1943

RelNote:
Compose don't depend on kotlinx-coroutines-swing now. If you use Dispatchers.Swing or Dispatchers.Main in your code, add this dependency into build.gradle.kts:

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutinesVersion")
}

Also, usage of Dispatchers.Swing or Dispatchers.Main inside internals of Compose is implementation details, and can be changed in the future. If you need to avoid race conditions with Compose UI, you can obtain appropriate coroutine scope via rememberCoroutineScope:

import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.application

@OptIn(ExperimentalComposeUiApi::class, androidx.compose.foundation.ExperimentalFoundationApi::class)
fun main() = application {
    val scope = rememberCoroutineScope()
    val someApplicationObject = remember(scope) { SomeApplicationObject(scope) }
    
    DisposableEffect(Unit) {
        SomeGlobalObject.init(scope)
        onDispose {  }
    }
}

Because it overrides Dispatchers.Main

Fixes JetBrains/compose-multiplatform#1943

RelNote:
Compose don't depend on `kotlinx-coroutines-swing` now. So if you use `Dispatchers.Swing` or `Dispatchers.Main` in your code, add this dependency into `build.gradle.kts`:
```
dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutinesVersion")
}
```
@igordmn igordmn requested a review from olonho March 10, 2022 10:36
@igordmn igordmn merged commit 45afb05 into release/1.1.1 Mar 10, 2022
@igordmn igordmn deleted the feature/removeSwingDispatcher branch March 10, 2022 11:40
eymar pushed a commit that referenced this pull request Apr 18, 2022
## Proposed Changes

Use best-matched font rather than "hardcoded"

The original part

```
final FontStyle defaultStyle = new FontStyle(
        (style & Typeface.BOLD) != 0 ? FontStyle.FONT_WEIGHT_BOLD
                : FontStyle.FONT_WEIGHT_NORMAL,
        (style & Typeface.ITALIC) != 0 ? FontStyle.FONT_SLANT_ITALIC
                : FontStyle.FONT_SLANT_UPRIGHT
);
return new Typeface.CustomFallbackBuilder(familyBuilder.build())
       .setStyle(defaultStyle)
       .build();
```

This will make the final `Typeface` ALWAYS have either 400 (FONT_WEIGHT_NORMAL) or 700 (FONT_WEIGHT_BOLD) weight. It is incorrect since fonts passed to these methods could have other font-weight. For example, pass only one font with 500 weight, the final `Typeface` will have 400 weight, making the fallback font displayed as 400 weight rather than 500.

This pull request copies the platform's algorithm to find the best-match font from the font family.

## Testing

Test: Observed that the font weight is correct

## Issues Fixed

Fixes: Fix https://issuetracker.google.com/issues/194553426

This is an imported pull request from androidx#212.

Resolves #212
Github-Pr-Head-Sha: 6d53f95
GitOrigin-RevId: f7c3c64
Change-Id: Ife725d32e207b713811d6be3a728874ad6f2df76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants