Closed luiguild closed 4 years ago
@luiguild use Direction.CW
for now it will work. Will have to find why it does not work without
Thanks for your support @farfromrefug. I will test this in Monday and then I coming back to report to you.
Hello @farfromrefug
(I'm helping @luiguild with this implementation on iOS.)
This is what we have so far:
With this code:
const backgroundPaint = new Paint()
backgroundPaint.setAntiAlias(true)
backgroundPaint.setColor(new Color(this.backgroundColor))
backgroundPaint.setStyle(Style.FILL)
canvas.drawPaint(backgroundPaint)
canvas.save()
We get a dark overlay:
However, when trying to add the clipPath
we couldn't get the desired output: an dark overlay with circle (see @luiguild's print screen).
const clipPath = new Path()
clipPath.addCircle(this.clipX, this.clipY, this.clipRadius, Direction.CW)
canvas.clipPath(clipPath, Op.DIFFERENCE)
const backgroundPaint = new Paint()
backgroundPaint.setAntiAlias(true)
backgroundPaint.setColor(new Color(this.backgroundColor))
backgroundPaint.setStyle(Style.FILL)
canvas.drawPaint(backgroundPaint)
canvas.save()
Either the hole overlay is suppressed, when using CCW
.
or - when using CW
- we get the opposite of what we want
I tried also a combination of all Op
found here, but none of then work
export enum Op {
DIFFERENCE,
INTERSECT,
REPLACE,
REVERSE_DIFFERENCE,
UNION,
XOR,
}
Any idea of what we are missing?
One thing that I would like to add, but I'm not sure if it is related, is that while running the project on iOS, I noticed this conflict warning below and later I found that it is used here https://github.com/nativescript-community/ui-canvas/blob/242bc26f36153d28e6ca8394c9192b297b0d170f/plugin/platforms/ios/src/BezierUtils.m#L695
~/.../Build/Intermediates.noindex/ArchiveIntermediates/appnativescriptvue/IntermediateBuildFilesPath/.../Objects-normal/arm64/UIBezierPath+Elements.o conflicts with same method from another category
@farfromrefug @luiguild please share a repro example of what you want (android) and what s not working (ios). No be careful Op are not working on iOS for clipPath and i am not sure i can make it work. clipPath are a bit tricky and should be used only if necessary. About the warning i dont se the relation with the linked source.
Hi @farfromrefug the example working on Android https://github.com/luiguild/nativescript-ui-canvas-test
this is the output running the demo project on both platforms:
iOS Emulator (same on device) | Android - Galaxy Tab 6S
@ronalson @luiguild basic support implemented in 4.0.33
@farfromrefug just confirming that it's now working properly on iOS.
thanks very much for the super-fast response.
Can we close this ?
Sure! Thanks!
@farfromrefug how to do the same thing but now using addRoundRect
?
we are trying this:
const clipPath = new Path()
clipPath.addRoundRect(new RectF(200, 400, 200, 400), 10, 10, Direction.CW)
canvas.clipPath(clipPath, Op.DIFFERENCE)
but nothing happen even in iOS or Android, any idea?
solved using this:
const clipPath = new Path()
const rect = createRectF(
200,
400,
200,
400
)
clipPath.addRoundRect(
rect,
10,
10,
Direction.CW
)
canvas.clipPath(clipPath, Op.DIFFERENCE)
thanks again!
@luiguild wait you mean the rectf constructor did not work ?
@farfromrefug yep, you are right, using the constructor I was unable to do the same thing that when I used the creactRectF
method
@luiguild thanks I ll.fix it
@farfromrefug just to track another thing that is not related, but I figure out right now. I get an error when I try use this:
canvas.save()
const rect = createRectF(
100,
100,
100,
100
)
canvas.drawRoundRect(
rect,
10,
10,
fillPaint
)
canvas.restore()
Sometimes I get this
Error: java.lang.Exception: Failed resolving method drawRoundRect on class android.graphics.Canvas
and sometimes this
Error: java.lang.Exception: Failed resolving method drawRoundRect on class android.view.RecordingCanvas
@luiguild ok so first new RectF works. But you did not understand the arguments. You dont pass the width!
This is the difference with createRectF
Now about your error i cant really help without more info. That error means you passed arguments to drawRoundRect
which are not good and it cant find the method with the arguments you passed. I need to know what you pass in that moment
const clipPath = new Path() clipPath.addRoundRect(new RectF(200, 400, 200, 400), 10, 10, Direction.CW) canvas.clipPath(clipPath, Op.DIFFERENCE)
@farfromrefug no sir, I pass 4 parameters, x: 200
, y: 400
, width: 200
and height: 400
, like in the docs say, 4 parameters: left
, top
, right
and bottom
... Look that's the same values pass to the createRectF
method. Obviously that's values are symbolic, and I obviously use some variables to fill this values in my app, but the method's contract it's correct...
It's 'the same' case in my second thing about drawRoundRect
, the contract it's correct too. 4 parameters, RectF, rx, ry and Paint.
If it's not, help me to figure out whats the discrepancy with my code and the official documentation please. Thank you again.
@farfromrefug forget it about drawRoundRect
, I found the error in my code, It's not in there, I could make it's works! Thanks!
Make sure to check the demo app(s) for sample usage
done
Make sure to check the existing issues in this repository
done
Which platform(s) does your issue occur on?
Please, provide the following version numbers that your issue occurs with:
"@nativescript/core": "~7.0.0"
"@nativescript/android": "7.0.1", "@nativescript/ios": "7.0.4"
Plugin(s):
Please, tell us how to recreate the issue in as much detail as possible.
1 - create a CanvasView and invoke @draw event
Is there any code involved?
This code result in different renderings in iOS and Android. In Android works perfectly (like always) but in iOS don't (like always)... the entire canvas content disappear, like have's nothing to draw, all others methods are ignored on
drawEvent
without any errors, he just ignore and block all other (canvas) things to draw on screenis not necessary put the iOS screenshot because it's just a red screen, without the
clipPath
and the black background (sorry for the biggest image, I don't know how to reduce the preview)(every day I ask to myself why in 2020 we still trying making apps for iOS, holy God)