FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(android): honour clipToBounds on layouts · NativeScript/NativeScript@93dd5f6 · GitHub

Commit 93dd5f6

Browse files
committed
fix(android): honour clipToBounds on layouts
`clipToBounds` on a LayoutBase only logged a warning on Android. Map it to the ViewGroup's clipChildren and clipToPadding, which is what a child that draws outside itself (a box-shadow, a translated view) needs from its parent. A layout still clips by default; setting clipToBounds to false on the parent layout is now enough, matching iOS where the same property on the parent view controls the same thing.
1 parent 6dba52f commit 93dd5f6

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

‎packages/core/ui/layouts/layout-base.android.ts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ export class LayoutBase extends LayoutBaseCommon {
1111
return true;
1212
}
1313
[clipToBoundsProperty.setNative](value: boolean) {
14-
// TODO: Use ClipRectangle if API > 16!
15-
16-
// We can't implement this without calling setClipChildren(false) on every ancestor up in the visual tree,
17-
// which will kill performance. It will also lead to unwanted side effects such as other totally unrelated
18-
// views being affected by setting the parents' setClipChildren to false.
19-
// The problem in Android is that a ViewGroup either clips ALL of its children or it does not. Unlike iOS, the clipping
20-
// cannot be controlled on a per view basis. So clipToBounds=false will have to be somehow achieved with stacking different
21-
// views on top of one another in an AbsoluteLayout or GridLayout. There is always a workaround when playing with layouts.
22-
//
23-
// The following article explains this in detail:
24-
// http://stackoverflow.com/questions/25044085/when-drawing-outside-the-view-clip-bounds-with-android-how-do-i-prevent-underli
25-
console.warn(`clipToBounds with value false is not supported on Android. You can use this.android.getParent().setClipChildren(false) as an alternative`);
14+
// Android clips per parent, not per child: a ViewGroup either confines
15+
// every child to its own bounds or none of them. A view that must draw
16+
// outside itself (a box-shadow, a translated child) therefore needs its
17+
// parent layout's clipToBounds set to false, not its own.
18+
const nativeView = this.nativeViewProtected;
19+
nativeView.setClipChildren(value);
20+
nativeView.setClipToPadding(value);
2621
}
2722

2823
[isPassThroughParentEnabledProperty.setNative](value: boolean) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL