question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] setClipChildren doesn't seems to resolve overflow

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

OS: macOS High Sierra 10.13.1 Node: 6.10.3 Yarn: 1.2.1 npm: 3.10.10 Watchman: 4.7.0 Xcode: Xcode 9.1 Build version 9B55 Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.50.3 => 0.50.3

Target Platform: Android

Steps to Reproduce

  1. Create a custom native component that overrides setClipChildren on Android, ex: ViewWithoutOverflow
  2. Create a JS component using ViewWithoutOverflow as wrapper and specifying some width/height
  3. Add a View inside with position absolute and greater width

Expected Behavior

Lately, we’re having some troubles with overflow on Android devices (as expected). I was able to fix it adding <item name="android:clipChildren">false</item> on src/main/res/values/styles.xml:

success

That was terrible: my animations started to show a very bad FPS. So, I decided to create a native component that handles this, and use only in some places… but I couldn’t make it work yet.

Can I get the same result presented changing styles.xml with setClipChildren on a custom native component?

Actual Behavior

With the native component(ViewWithoutOverflow) the overflow: hidden still stands.

error

Reproducible Demo

ViewWithoutOverflowPackage.java

public class ViewWithoutOverflowPackage implements ReactPackage {

    // @Override
    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        return Collections.emptyList();
    }

    // @Override
    public List<Class<? extends JavaScriptModule>> createJSModules() {
        return Collections.emptyList();
    }

    // @Override
    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Arrays.<ViewManager>asList(
                new ViewWithoutOverflowManager()
        );
    }
}

ViewWithoutOverflowManager.java

public class ViewWithoutOverflowManager extends ViewGroupManager<ViewWithoutOverflowLayout> {

    @Override
     protected ViewWithoutOverflowLayout createViewInstance(ThemedReactContext reactContext) {
        return new ViewWithoutOverflowLayout(reactContext);
     }

    @Override
    public String getName() {
        return "ViewWithoutOverflow";
    }

}

ViewWithoutOverflowLayout.java

public class ViewWithoutOverflowLayout extends ReactViewGroup {

    public ViewWithoutOverflowLayout(Context context) {
        super(context);

        setClipChildren(false);
        setClipToPadding(false);
    }

}

ViewWithoutOverflow.android.js

import { requireNativeComponent } from 'react-native';

export default requireNativeComponent('ViewWithoutOverflow', null);

DemoScreen.js

import * as React from 'react';
import { View } from 'react-native';

import ViewWithoutOverflow  from './ViewWithoutOverflow';

class DemoScreen extends React.PureComponent {
  render() {
    return (
      <ViewWithoutOverflow style={{
        width: 200,
        height: 200,
        backgroundColor: 'green',
      }}>
        <View style={{
          position: 'absolute',
          left: 0,
          top: 0,
          width: 400,
          height: 100,
          backgroundColor: 'red',
        }} />
      </ViewWithoutOverflow>
    );
  }
}

export default DemoScreen;

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:22
  • Comments:5

github_iconTop GitHub Comments

8reactions
sibeliuscommented, Apr 10, 2018
1reaction
isaachinmancommented, Apr 10, 2018

@felippepuhle Would you be willing to formally release this as a component via npm for those of us less comfortable working with Android codebases?

Read more comments on GitHub >

github_iconTop Results From Across the Web

clipChildren is not working even though set to false?
I know its late, but this is the simplest complete answer: just put on every layout : android:clipChildren="false" android:clipToPadding="false".
Read more >
overflow - SVG: Scalable Vector Graphics - MDN Web Docs
The overflow attribute sets what to do when an element's content is too big to fit in its block formatting context.
Read more >
ConstraintLayout and negative margins [37103660]
Library used (constraint-layout): Version used: 1.0.0-alpha1. The constraint-layout ignores any negative margins and process them as zeroes ...
Read more >
Coordinator layout with viewpager with recyclerview as adapter
createBitmap(Bitmap.java:620) at android.support.design.widget. ... android:clipChildren="false" android:clipToPadding="false" ...
Read more >
LinearLayout | Android Developers
To control how linear layout aligns all the views it contains, set a value ... This view is invisible, and it doesn't take...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found