Kotlin/Wasm and keyboard events

Hi I’ve been trying find any documentation about this but couldn’t find anything, I tried using desktop compose approach, but no luck, I couldn’t move a single square with my keyboard arrows, if anyone out there can give me pointers on how to archive it in kotlin/wasm I appreciate it.

@Composable @Preview fun mainScreen() { var xPosition by remember { mutableStateOf(50f) } Column( modifier = Modifier .fillMaxSize() .background(color = Color.Red) .onPreviewKeyEvent { event: KeyEvent -> if (event.type == KeyEventType.KeyDown) { when (event.key) { Key.DirectionLeft -> { // Left arrow key xPosition -= 10f true } Key.DirectionRight -> { // Right arrow key xPosition += 10f true } else -> false } } else false }, verticalArrangement = Arrangement.Center ) { Box( modifier = Modifier .size(100.dp) ) { Canvas(modifier = Modifier.fillMaxSize()) { drawRect( color = Color.Blue, topLeft = androidx.compose.ui.geometry.Offset(xPosition, 0f), size = androidx.compose.ui.geometry.Size(100f, 100f) ) } } } } 

submitted by /u/olrc
[link] [comments]

Continue ReadingKotlin/Wasm and keyboard events

Building KMP Library with resources for iOS

We have a project, where we use compose multiplatform with the multiplatform resources library. The library will be distributed as both a Cocoapods dependency and Swift Package Manager dependency. This inherently means that the project our shared code will be used in doesn’t reside in the same repo. We’re experiencing differences when building through XCode (from the sample project inside the library repo) and from the command line. For example when running podPublishDebugXCFramework the build/compose/ios/<name>/compose-resources directory is missing. The generated podspec within the build folder has the resources directory specified, but since the dir is missing, this leads to MissingResource crashes

# the directory doesn't exist when running podPublishDebugXCFrameworkspec.resources = ['build/compose/ios/KMPPaymentCards/compose-resources'] 

When building through AS or XC (where the gradle syncFrameworks command is hooked as an XC build phase with some mysterious parameters) we have everything we need and the code runs without crashes, showing the expected images. Is there a way to build the library through the command line?

P.s: I know moko-resources have been used a lot, but the library hasn’t been updated recently, there are a lot of open issues on GitHub so I figured it’s safer to stick with the official lib (if possible).

submitted by /u/dephinera_bck
[link] [comments]

Continue ReadingBuilding KMP Library with resources for iOS

Need Help: Integrating Python with Kotlin Multiplatform

I’m currently working on a Kotlin Multiplatform project and I’m exploring ways to integrate Python code into it. I came across Chaquopy (https://chaquo.com/chaquopy/), which is an SDK that allows Python code to run on Android. However, my project needs support across multiple platforms, not just Android.

does anyone have Any recommendations for tools or libraries that support this?

submitted by /u/Vegetable-Practice85
[link] [comments]

Continue ReadingNeed Help: Integrating Python with Kotlin Multiplatform

Kotlin Coroutines and Loom

Loyal viewer David had a lot of questions in the comments to the last episode (https://youtu.be/ACk2HkvVKnA), where we learned to compose higher order functions to create http4k request handlers. He liked the idea, but was worried about the performance of calling business logic that used Kotlin coroutines from the non-suspend handlers.

This got me wondering whether project Loom and Java virtual threads make this a non-issue. So today I’ll start by looking at why operating system threads limit the throughput of our servers, and how virtual threads solve that problem. Once we have that working, then we can use more virtual threads to invoke suspend functions from plain-old functions like http4k handlers.

With project Loom I think we really can have the best of both worlds, and that I have the benchmarks to prove it.

In this episode

  • 00:00:55 Create an http4k server and make actual HTTP requests to it
  • 00:05:14 Now use an executor to make the requests
  • 00:07:42 Now submit 1000 simultaneousish requests
  • 00:08:25 Measure just the time to process the requests
  • 00:10:42 Shift the checking of the Responses out of the executor code
  • 00:12:43 Separate setup from the measurement
  • 00:15:00 Calling a slower function is much slower because we exhaust the server thread pool
  • 00:16:42 We can use Loom virtual threads to “not have” a thread pool
  • 00:19:30 The results are in
  • 00:20:15 Some connection reset errors?
  • 00:21:25 Rationalised code to record performance and errors
  • 00:23:08 More throughput results
  • 00:23:45 More on those connection resets
  • 00:27:36 Now what about calling suspend funs?
  • 00:32:59 Review

There is a playlist of http4k content https://www.youtube.com/playlist?list=PL1ssMPpyqocg5TKqmiGWlvi3O5L8XPe8Q

If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It’s about far more than just the syntax differences between the languages – it shows how to upgrade your thinking to a more functional style.

submitted by /u/dmcg
[link] [comments]

Continue ReadingKotlin Coroutines and Loom

Free Review Copies of “Kotlin Design Patterns and Best Practices- Third Edition” against your unbiased review.

Hi everyone,
Packt is about to release the third edition of ” Kotlin Design Patterns and Best Practices ” by Alexey Soshin.

As part of our marketing activities, we are offering free digital copies of the book in return for unbiased feedback in the form of a reader review.

Key Features of the book

  • Start from basic Kotlin syntax and go all the way to advanced topics like Coroutines and structural concurrency
  • Learn how to select and implement the right design pattern for your next Kotlin project
  • Get to grips with concurrent and reactive microservices with Ktor and Vert.x

If you feel you might be interested in this opportunity please comment below on or before 15th April.

https://preview.redd.it/2548xow5jntc1.png?width=690&format=png&auto=webp&s=c618c6fdd3363160495d7335ba5aa1db04d0901d

submitted by /u/Round_Boysenberry518
[link] [comments]

Continue ReadingFree Review Copies of “Kotlin Design Patterns and Best Practices- Third Edition” against your unbiased review.

End of content

No more pages to load