-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: Apply proper border radius to box shadow and view sublayers #9881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Apply proper border radius to box shadow and view sublayers #9881
Conversation
@NathanWalker Whenever possible, I believe we should revert this one as it's unsafe. |
@CatchABus if of any interest to you I had done this in another cross platform framework Titanium. I can fins the code if you need |
Sure! It could be a good addition! Note: I tend to think that using main layer with masksToBounds and clipsToBounds for shadows will keep causing trouble in the future. Maybe we should also consider the use of a sublayer for shadows as one solution? |
@CatchABus it s all here https://github.com/Akylas/titanium_mobile/blob/master/iphone/Classes/TiUIView.m#L610= . If you have any question ping me on discord. |
I agree - I was working on the initial box-shadow implementation and had tinkered with the idea of using proper sublayers for shadows - allowing stacking multiple shadows etc, however there was a major roadblock (fixable I would imagine, but still was major)... Given an ios view, you can add as many subviews as you want, however you cannot move them behind the parent view, only above it (at least if I remember correctly, been a while...) - which meant we couldn't easily add a shadow layer to existing views and move them behind the view. The approach I was playing around with was adding an extra parent view to hold the original view + the shadow layers, but managing that was kinda tricky as core View handling is set up to handle the root view and not anything above. Wrapping every view in a extra view seemed like a bad solution, as it would double the number of views rendered even if most of them don't render a shadow. Ideally the following structure could work:
|
Perhaps, this issue gets solved using |
I'm not sure - I'm pretty sure I tried every possible combination, and could not move my shadow layer below the actual view - inserting it at various indices or zPositions, was always above the view. But if that works, that'd be perfect 👍 |
@rigor789 I'm not sure if I understood correctly but I have this plugin for neumorphism styling: https://github.com/CatchABus/nativescript-plugins/tree/master/packages/ui-neumorphiclayout |
@CatchABus I just remembered - I never deleted the tests I did here (they are ignored, as we return early): NativeScript/packages/core/utils/native-helper.ios.ts Lines 126 to 203 in eb4c4a3
removing the early return yields the following: With some logging - here are the resulting layers: Haven't had a closer look at your plugin, or what it does differently - but if you want you can try the above:
I guess the difference is that in your plugin you have a |
I see, I get it now! To solve this, we can apply view background color to shadow layer. Seeing where this goes, perhaps we should stop setting background color to native views directly and have a |
PR Checklist
What is the current behavior?
In iOS:
I found those problems while using an iPad. Box-shadow radius was probably miscalculated because of a scale factor that may be higher than 1.


What is the new behavior?
Border radius will be properly calculated for view box-shadow and sublayers. It seems that
toDeviceIndependentPixels
works better and returns the same value as the rest of applied view border-radiuses.This change will also attempt to apply corner radius to all sublayers. Sublayers will usually consist of a gradient layer and a border layer.
There are also cases that border layer has sublayers but there is a need for a whole refactor to make those look good, that is why we apply radius to top-level layers for now.
This is new shadow radius with gradient background:

Fixes/Closes #9869 .