https://kotlinlang.org logo
r

rsktash

03/02/2021, 4:44 PM
[SOLVED]: There is bug with
Path.op
methods (
androidx.compose.ui.graphics.Path
). The method is ignoring last param options. All of them
difference
,
intersect
reverseDifference
doing
union
path
@jim
This android view snippet
This is compose view snippet
r

romainguy

03/02/2021, 5:09 PM
@Nader Jawad
r

rsktash

03/02/2021, 5:09 PM
I think the issue is originating from skija lib
n

Nader Jawad

03/02/2021, 5:10 PM
Looks like you're doing the path op but drawing a different path parameter
r

rsktash

03/02/2021, 5:11 PM
Yes I tried with all options but it is drawing with union operation
r

romainguy

03/02/2021, 5:14 PM
Do you have the issue with Compose Desktop or on Android?
If Compose Desktop it might be an issue in skija/skiko
r

rsktash

03/02/2021, 5:17 PM
First i tested with AS preview. Now I’m testing with android device
The same with android device
Maybe there is issue with binding?
d

dector

03/02/2021, 5:28 PM
I think you need to use
addRect()
instead of
drawRect()
🙂
👍 1
n

Nader Jawad

03/02/2021, 5:29 PM
Oh that's a good point, the calls in the apply method for the path should be path operations not drawing calls as part of the drawScope receiver scope
r

romainguy

03/02/2021, 5:30 PM
Good catch :)
r

rsktash

03/02/2021, 5:32 PM
@dector 🙈 Thank you
n

Nader Jawad

03/02/2021, 5:35 PM
One thing to note is that this is a good opportunity to leverage
Modifier.drawWithCache
as it breaks up the drawing operation into 2 steps that can be used to conditionally allocate and cache paths instead of allocating them on each draw call. Because the initial scope of drawWithCache isn't a DrawScope it makes it more difficult to call into drawing APIs instead of path operations
r

rsktash

03/02/2021, 5:36 PM
Thank you @Nader Jawad too. I’ll try it
@Daniel
👍 1
@Nader Jawad Is there a sample or doc for
Modifier.drawWithCache
d

Daniel

03/02/2021, 5:45 PM
@Nader Jawad @jvmusin. I've found drawWithCache super confusing
I initially thought it was broken, then happened to hear in a stream (by Leland Richardson) that it only cached calls in the initial draw with cache scope, not in the drawBehind/drawWithContent calls. The documentation is not at all clear about that
I also have an issue where it isn't invalidating if a state read in the cache scope is read. I'm not sure if that's intended behavior or not
n

Nader Jawad

03/02/2021, 5:47 PM
drawWithCache does invalidate the cache on state reads as well
d

Daniel

03/02/2021, 5:48 PM
let me try and repro and file a bug then
We have a few samples of the usage here. It is used a lot in the implementation of compose and simplifies a lot of remember/boilerplate code as well. The cached parameters will be reused unless either the size changed or a state parameter that is read has changed
🙏 1
d

Daniel

03/02/2021, 5:58 PM
It was my mistake. I had a call to graphicsLayer higher up in the modifier chain, and I didn't realize that would interfere. Reading the docs a second time though its clear that's expected behavior
n

Nader Jawad

03/02/2021, 5:59 PM
This should also be supported in graphicsLayer usages as well
d

Daniel

03/02/2021, 6:04 PM
Thanks for letting me know @Nader Jawad. I filed a bug with a repro project. https://issuetracker.google.com/issues/181589173
👀 1
n

Nader Jawad

03/02/2021, 6:10 PM
Thanks! Will take a look
👍 2
20 Views