Revery: Opacity doesn't work on images

Created on 26 Mar 2020  路  5Comments  路  Source: revery-ui/revery

Hello ! I cloned the last version of the revery-quickstart and the opacity on images seems broken. All of this codes doesn't work:

<Image ... opacity=0.1 />

```reason


```reason
<Opacity opacity=0.1>
    <View>
        <Image ... opacity=0.1 />
    <View>
</Opacity>
A-primitives bug

Most helpful comment

I achieved to make a setAlpha for reason-skia 馃槃 (see the PR above)
So I'm waiting for validations, and if it's merged I can work on a PR to fix this on Revery

Cool, thank you @JulesGuesnon!

EDIT: You can always point Revery to use your PR of reason-skia. I imagine that whether or not there'll be some comments of the PR, the API will be the same. So that might be an idea while you wait. 馃檪

All 5 comments

As you mentioned in Discord:

I checked github and Image is made with the ppx nativeComponent and under the hood it's an ImageNode object which use Revery_Draw.CanvasContext so I guess it's backed by Skia
But it seems like the opacity is never passed to the context, probably explain why it doesn't work

Here's a basic skia-example with alpha: https://fiddle.skia.org/c/fb3358907fe866eff8f89e0ea13fb056

It seems as our drawImage-method does not take paint as an argument:

https://github.com/revery-ui/revery/blob/395ed2ed531ddc9c8632cb299067e6ce8b87cf43/src/UI/ImageNode.re#L31-L37

My guess would be that we'd have to extend that to perhaps take an option(Paint.t), similar to drawPath:
https://github.com/revery-ui/revery/blob/ced2dde461c316178d4ce320b862a1c9d46a96a6/src/Draw/CanvasContext.re#L141-L143

https://github.com/revery-ui/revery/blob/ced2dde461c316178d4ce320b862a1c9d46a96a6/src/Draw/CanvasContext.re#L165-L178

It also seems as the reason-skia doesn't have bindings for setAlpha/setAlphaf yet.

https://github.com/revery-ui/reason-skia/blob/master/src/Skia.rei#L101-L122

I was looking on how to make a binding on reason-skia to setAlpha/setAlphaf and then make a PR, but the fact is that this 2 functions aren't is the Skia c api. Sadly no sk_paint_set_alpha/sk_paint_set_alphaf here.
So I'm exploring how to do it with the color instead

I achieved to make a setAlpha for reason-skia 馃槃 (see the PR above)
So I'm waiting for validations, and if it's merged I can work on a PR to fix this on Revery

I achieved to make a setAlpha for reason-skia 馃槃 (see the PR above)
So I'm waiting for validations, and if it's merged I can work on a PR to fix this on Revery

Cool, thank you @JulesGuesnon!

EDIT: You can always point Revery to use your PR of reason-skia. I imagine that whether or not there'll be some comments of the PR, the API will be the same. So that might be an idea while you wait. 馃檪

Wow, thanks for diving in and fixing this @JulesGuesnon - just saw your PR 馃憤 And nice catch on the bug.

You can always point Revery to use your PR of reason-skia.

Definitely! You should be able to add a resolution in the package.json like: "reason-skia": "link:../reason-skia", which will pick up your local version. Good way to test the new API on images.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

albertorestifo picture albertorestifo  路  3Comments

bryphe picture bryphe  路  6Comments

bryphe picture bryphe  路  4Comments

bryphe picture bryphe  路  5Comments

jericdeleon picture jericdeleon  路  3Comments