https://kotlinlang.org logo
Title
m

Mitchell Syer

08/14/2021, 9:59 PM
Hi, I need some advice on how to migrate some code made with the 0.4.x and below Window API to the new API. I have a custom clickable modifier that takes a click event, gets the x and the y of the click event inside the window, and compares it to the LocalAppWindow.current width and height so that it gives me a % value of where it was clicked. I cant find a good way to do this in the new Window Api, as LocalAppWindow was deprecated.
1
i

Igor Demin

08/14/2021, 10:11 PM
Replacement of
LocalAppWindow.current
is
window
which you can access inside
Window
function or inside any other function if you pass WindowScope there:
Window {
   Box(...clickable { window.width }
   foo()
}

@Composable
fun WindowScope.foo() {
   Box(...clickable { window.width }
}
m

Mitchell Syer

08/15/2021, 3:47 PM
Is there some kind of way I can get that when I am deep in a function tree? Or should I make a CompositonLocal of it myself
i

Igor Demin

08/15/2021, 7:28 PM
Yes, you can make your own composition local, there is no built-in one in the new API
👍 1