Hi everyone! 😄
I tried creating Neumorphism UI with Jetpack Compose. You can take a look at the lib/code here - https://github.com/CuriousNikhil/neumorphic-compose
I’m learning this and probability of the code being correct/holding best practices may be less. 😅
I’ve a couple of questions.
The idea is simple, I’ve created a custom modifier by extending the
DrawModifier
and I’m drawing the shadows using
contentDrawScope
provided by
DrawModifier
.
1. First of all, Is this a correct to extend the modifiers?
2. To render the shadows(GradientDrawable) smoothly, I’m using RenderScript (I know it’s going to be deprecated in the Android12. I’ll migrate.). I need
context
param to invoke renderscript api. Is it okay to pass
context
param in the Modifier?
💣 4
jetpack compose 6
Nikhil
05/30/2021, 5:56 PM
d
Derek Ellis
05/30/2021, 8:13 PM
For 2, couldn't you use
LocalContext
instead of having to pass it in as a parameter?
☝🏻 2
☝️ 2
☝🏼 1
n
Nikhil
05/31/2021, 4:11 AM
But
LocalContext.current
needs to be called from another
@Composable
function.
This is simple Modifier
d
Derek Ellis
05/31/2021, 4:27 AM
You can mark your modifier function with
@Composable
c
Chachako
05/31/2021, 4:47 AM
No, this is incorrect,
composed
Modifier should be used, this will allow you to call the
LocalContext.current
in the Modifier
n
Nikhil
05/31/2021, 5:26 AM
@Chachako Thanks! I missed this. This is nice! I’ll use this^