Skip to content
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

View will lost background color when set borderRadius and height is large enough on Android device #15826

Open
peixin opened this issue Sep 6, 2017 · 62 comments
Labels
Bug Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Priority: Low

Comments

@peixin
Copy link

peixin commented Sep 6, 2017

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

No

Environment

@mjmasn's environment:

Environment:
  OS: Linux 4.13
  Node: 8.11.0
  Yarn: 1.7.0
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: N/A
  Android Studio: 3.1 AI-173.4670197

Packages: (wanted => installed)
  react: ^16.4.1 => 16.4.1
  react-native: ^0.55.4 => 0.55.4

@beiming's environment:

Environment:
  OS: macOS
  Node: 7.7.1
  npm: 4.1.2

Packages: (wanted => installed)
  react-native: ^0.47.2 => 0.47.2

Target Platform: 
  Android
  Android version: 4.4.4
  Screen resolution: 720 x 1280

Steps to Reproduce

// index.android.js

import React, {Component} from 'react';
import {AppRegistry, View, Text, ScrollView} from 'react-native';

class App extends Component {
    render() {
        return (
            <ScrollView>
                <View style={{
                    // if `borderRadius` > 0 and `height` is large enough like 3000 (2000 is ok on my android device), `backgroundColor` will disappear.
                    borderRadius: 1,
                    height: 3000,
                    backgroundColor: 'red',
                    alignItems: 'center',
                    justifyContent: 'center'
                }}>
                    <Text>Test</Text>
                </View>
            </ScrollView>

        );
    }
}

AppRegistry.registerComponent('App', () => App);

Run react-native run-android on a device, it does not reproduce on an AVD.

Expected Behavior

It will be show a long view, with red background, and scroll view show Test in center.

Actual Behavior

It will be show a long view, but no background color (white, maybe transparent), and scroll view show Test in center.

@mike-niemand
Copy link

I have the same proble. Any resolution?

@gregblass
Copy link

Also getting this. I'm using simple Material Design card views. 2px border radius and a white background color set to a View element. If the card is long, it drops the background color and the background grey color shows through.

@gregblass
Copy link

Also worth noting that this does not happen using Genymotion - only with an actual device (Motorola Moto G).

@gregblass
Copy link

Tried updating to the latest Android on my device - this is still happening. I guess I'll be forced to remove the border radius on my Android cards until this is addressed.

If anyone knows of a workaround, please let me know!

@tikkichan4
Copy link

I got the same problem.... it is confusing because i have many large height views in my app

@stale
Copy link

stale bot commented Jan 27, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 27, 2018
@stale stale bot closed this as completed Feb 3, 2018
@gregblass
Copy link

Hey now!

I'm not sure if this should be marked stale yet.

@gregblass
Copy link

Really common use case that I ran into is standard material design guidelines for 'Card' components, with dynamic content. If the content got long...the background color magically disappeared!!

Really gives an engineer credibility after they've pitched react native to a client.

So yeah...I'd review this one before closing it!

@JasonWoof
Copy link

I am suffering from this bug too.

I'm going to see if it's possible to simulate a tall box with rounded corners by having a short header view rounded top corners and no bottom border, then a resizing tall middle row with just left/right border, and a short bottom row with rounded bottom corners and no top border.

@JasonWoof
Copy link

That didn't work. It won't render the left/top/right borders when I set borderBottomWidth: 0.

@mjmasn
Copy link
Contributor

mjmasn commented May 14, 2018

This should still be open. Anyone want to write a bot to fight all these overeager fb bots and keep issues open? 😂

@nbaghiro
Copy link

nbaghiro commented May 15, 2018

This issue is still happening. It is happening for ScrollView in my case.

@Guodadada

This comment has been minimized.

@rkbhochalya
Copy link

I'm having this issue as well. I have created an example: https://snack.expo.io/@rkbhochalya/rn-view-background-color-issue. Try changing the numberOfLines. Background color is lost if we set the numberOfLines to 283 or more. However it works well for any number of lines if we remove border radius from the View.

@mjmasn
Copy link
Contributor

mjmasn commented Jun 27, 2018

@hramos could you please reopen this one? Still an issue in 0.55.4

Environment:
  OS: Linux 4.13
  Node: 8.11.0
  Yarn: 1.7.0
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: N/A
  Android Studio: 3.1 AI-173.4670197

Packages: (wanted => installed)
  react: ^16.4.1 => 16.4.1
  react-native: ^0.55.4 => 0.55.4

@hramos hramos reopened this Jun 28, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 28, 2018
@hramos hramos added the Platform: Android Android applications. label Jun 28, 2018
@hramos
Copy link
Contributor

hramos commented Jun 28, 2018

@mjmasn can you confirm this is still an issue in 0.56?

@Twishka
Copy link

Twishka commented Jul 10, 2018

@hramos It most certainly is, although I can only see it appearing on Android emulators and not on iOS emulators.

@rizwanahmed19

This comment has been minimized.

@patrickkempff
Copy link
Contributor

I added borderColor and borderWidth to the following example: https://snack.expo.io/BkIGFyGNX
the borders are rendered, but not how you would expect them to be.
onlayout returns the correct height.

@hushicai
Copy link

hushicai commented Aug 7, 2018

+1

react-native: 0.48.4

I was just using a View, and there are a lot of sub Views, the height of View is very large, then the View's backgroundColor disappear in android device.

@hramos
Copy link
Contributor

hramos commented Aug 8, 2018

Thanks @hushicai, though we're only interested in repros in 0.56 or newer. 0.56 is the current release as of this writing.

@mjmasn
Copy link
Contributor

mjmasn commented Sep 3, 2018

Update: This issue exists in Android 4.2 and below (API level 17 and below).

@hramos another super weird one that seems related - seems on Android 4 devices (4.1.2 tested) the background (edit: and the stroke) vanishes if the view is 32px or more wider than the screen width. Our view needs to be 2 * screen width, with top left/right border radius of screen width. Workaround for now is just to remove the rounded edges on Android 4 but it's not ideal.

const styles = StyleSheet.create({
  thing: {
    position: 'absolute',
    backgroundColor: '#000',
  }
});
render() {
  const {width, height} = Dimensions.get('window');

  // Working
  return (
    <View>
      <View style={[styles.thing, {
        height, 
        width: width + 31, 
        borderTopLeftRadius: 10, 
        borderTopRightRadius: 10,
      }]} /> 
    </View>
  );
}
render() {
  const {width, height} = Dimensions.get('window');

  // Background disappears
  return (
    <View>
      <View style={[styles.thing, {
        height, 
        width: width + 32, 
        borderTopLeftRadius: 10, 
        borderTopRightRadius: 10,
      }]} /> 
    </View>
  );
}

We're on RN 0.56.0 now so I can confirm this is still an issue - will try 0.57.0 once it's officially released.

  React Native Environment Info:
    System:
      OS: Linux 4.15 Ubuntu 16.04.5 LTS (Xenial Xerus)
      CPU: x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
      Memory: 1.00 GB / 15.54 GB
      Shell: 4.3.48 - /bin/bash
    Binaries:
      Node: 8.11.0 - ~/.nvm/versions/node/v8.11.0/bin/node
      Yarn: 1.9.4 - /usr/bin/yarn
      npm: 5.6.0 - ~/.nvm/versions/node/v8.11.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      Android SDK:
        Build Tools: 23.0.1, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.3
        API Levels: 16, 19, 22, 23, 26, 27
    IDEs:
      Android Studio: 3.1 AI-173.4670197
    npmPackages:
      react: ^16.4.2 => 16.4.2 
      react-native: 0.56.0 => 0.56.0 
    npmGlobalPackages:
      create-react-native-app: 1.0.0
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

@davidmarciano
Copy link

davidmarciano commented Sep 15, 2018

Same here when rendered a View with borderRadius inside ScrollView

@pribeh
Copy link

pribeh commented Oct 19, 2018

Assuming you're applying the rounded corners to an entire list, this could be circumvented if the header and footer of a scrollview were positioned above and below the ScrollContentContainerViewClass. Right now applying the style to the contentContainerStyle will often produce the same effect. But if there was a way to render the header and footer outside of the container view and apply separate styling you could make them short enough to apply the rounded corners to them if need be. Either that or add an extra class to the inner list content which does not include the header and footer.

@realchiu

This comment has been minimized.

@CyxouD
Copy link

CyxouD commented Oct 16, 2019

Reproducable on RN 61.1, Pixel 3, API 23 emulator, but as far as remember could reproduce on physical devices with higher Android also
Edit: reproducible on physical devices

@Brainyoo
Copy link

Still a problem in rn 0.61.2 with Samsung Galaxy s7

@cyqui
Copy link

cyqui commented Oct 23, 2019

Same issue: after upgrading to RN 0.61.2, i am losing the background of many elements.
Downgraded to 0.60: It works.

Update: we are using NativeBase "Content", so it's the same as everyone: "Scrollview" containing childs with a background + radius looses the background. Wrapping everything with two views + overflow hidden is not viable in my opinion as there is too many views concerned.

@CyxouD
Copy link

CyxouD commented Nov 14, 2019

Tried to solve this issue generally with my BaseCard component (https://gist.github.com/CyxouD/42723de50446d85c6b4f0122b0c68c15). Idea is the same as @fartymonk suggested, but tries to solve it for different input props. It worked in all cases throughout my app, in cases where it doesn't work && not needed (because bug doesn't happen) you can disable this behaviour with fixAndroidBehaviour prop. Also you can disable shadow with withoutShadow prop

@abedolinger
Copy link

I used @fartymonk's solution as well, making an AndroidFixWrapper component that's styled only if Platform.OS === 'android'. Since View sizes need to be tailored to the component, I used a styling factory that responds to the type prop for sizing, and added in an unnoticeably transparent background to the inner View (rgba(0, 0, 0, 0.001)). I'm on 0.61.1, full info at the bottom.

Component:

import React, { useMemo } from 'react';
import { View, Platform } from 'react-native';
import stylesFactory from './AndroidFixWrapper.styles';

export default ({
	children,
	type,
}: {
	children: React.ReactChild;
	type?: 'bigIcon' | 'button' | // etc;
}) => {
	const styles = useMemo(() => stylesFactory(type), []);
	return (
		<View style={Platform.OS === 'android' && styles.androidContainer1}>
			<View style={Platform.OS === 'android' && styles.androidContainer2}>
				{children}
			</View>
		</View>
	);
};

styles:

import { StyleSheet, ViewStyle } from 'react-native';

interface WrapperStyle {
	width?: string | number;
	height?: string | number;
}

const containers = type => {
	switch (type) {
		case 'bigIcon': return [
			{
				width: '100%',
				height: 120,
			},
			{
				height: 100,
				width: 120,
			},
		];
// etc...
export default type => {
	const [ androidContainer1, androidContainer2 ]: WrapperStyle[] = containers(type);
	const center = {
		justifyContent: 'center' as ViewStyle['justifyContent'],
		alignItems: 'center' as ViewStyle['alignItems'],
	};
	const transparentBackground = { backgroundColor: 'rgba(0, 0, 0, 0.001)' };

	return StyleSheet.create({
		androidContainer1: {
			...androidContainer1,
			...center,
		},
		androidContainer2: {
			...androidContainer2,
			...center,
			...transparentBackground,
		},
	});
};

In use:

<AndroidFixWrapper type="bigIcon">
    <BigIcon
    // etc...
    />
</AndroidFixWrapper>

react-native info:

System:
    OS: macOS 10.15
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
    Memory: 94.53 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.11.0 - ~/.nvm/versions/node/v12.11.0/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v12.11.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5977832
    Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.10.1 => 16.10.1 
    react-native: 0.61.1 => 0.61.1 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Hope this gets figured out soon, but seeing that this thread is two years old and going strong, it's either a really tricky problem or not a priority. Or both.

@marcosalles
Copy link

marcosalles commented Jan 13, 2020

Using an android 8.1.0 emulator and react-native 0.59.8, this issue is still there.
It happens for me using border-radius > 0 and a component with height > ~5940px (5932 is ok, 5960 breaks).

My component also loses its border properties, not only the background color. Since I need the border color and width, @fartymonk's solution is not really applicable. I can think of a few unholy solutions for my case, tho.

@SergiOnGit
Copy link

Same with me!

React Native version: 0.61.5

@ishiharas
Copy link

Using a physical device (Samsung Galaxy S7) with Android 8.0.0 and it happens for me with using border-radius bigger than 0 and a component height bigger than 2000px. Everything below is okay.

Like @marcosalles mentioned it looses the border-radius and backgroundColor properties.
It also looks like commenting the border-radius out leaves the backgroundColor property like it was.
React Native Version: 0.61.5

@ndbeyer
Copy link

ndbeyer commented Apr 1, 2020

I had a similar issue where the background color of components that were wrapped in a ScrollView disappeared (only on android device) when the ScrollView had a minHeight of 100% instead of 100vh.

<View>
  <ScrollView style={{contentContainer: { minHeight: "100%" }}}>
     //...children with disappearing background
  </ScrollView>
</View>
<View>
  <ScrollView style={{contentContainer: { minHeight: "100vh" }}}>
     //...everything fine
  </ScrollView>
</View>

In another case, the same problem appeared (again only android device) when a ScrollView with min-height: 100vh was wrapped in another flex View.

<View style={{flex: 1}}>
  <ScrollView style={{contentContainer: { minHeight: "100vh" }}}>
     //...children with disappearing background
  </ScrollView>
</View>
<View style={{minHeight: "100vh"}}>
  <ScrollView style={{contentContainer: { minHeight: "100vh" }}}>
     //...everything fine
  </ScrollView>
</View>

@everfire130
Copy link
Contributor

Same with me!

React Native version: 0.62.0

@ManalLiaquat
Copy link

I have also had this issue of backgroundColor problem, I fixed it by just passing the background color to scrollView, and it is happening when height of the content increases.

<ScrollView contentContainerStyle={{ backgroundColor: '#fff' }}>
    <View>large vertical content here</View>
</ScrollView>

@miladnikad
Copy link

After 3 years ...

@dagan-arbox
Copy link

image
Same shit different day.

@ghost
Copy link

ghost commented Jul 18, 2020

still an issue

@scrapecoder
Copy link

facing same issue v0.62.2

@SubhashisPK
Copy link

Still an issue in react-native 0.62.2

@dylancoots-mwi
Copy link

Glad to see that after hours of googling, others are having the same issue as well. I set the borderRadius property to 0 and it resolves the issue; however, I wish i could keep my rounded corners >.<

@everfire130
Copy link
Contributor

If you use the react-navigation.
You can

import { enableScreens } from 'react-native-screens';
enableScreens();

It will be fine.
But maybe bring a performance loss

@SyntappZ
Copy link

SyntappZ commented Oct 21, 2020

Same still happening lol using expo version 38.0.8, i got this bug testing my app on lg k8 running android 8.1, but also tested on android emulator running android 8.1 but there was no bug on the emulator, this bug is so random lol.

I have solved the problem now with using 2 views and the inner view having the background color along with overflow hidden and the outer view having the border radius and that seems to work good enough for me.

<View style={styles.androidBugFixWrapper}>
     <View style={{ ...styles.main, backgroundColor: mediumColor }}>
        {docs.map((item) => {
            return (
              <RenderDocs
                docs={item.docs}
                title={item.title}
                key={item.title}
                navigation={navigation}
                lightColor={lightColor}
                mainTextColor={mainTextColor}
             />
           );
        })}
    </View>
</View>

styles

 main: {
    paddingHorizontal: 10,
    paddingTop: 20,
    paddingBottom: 10,
  },
  androidBugFixWrapper: {
    borderTopLeftRadius: 30,
    borderTopRightRadius: 30,
    overflow: 'hidden'
  },

@devmartinez0
Copy link

devmartinez0 commented Oct 28, 2020

Having this issue with react native version 0.63.2, only on android, iOS is working fine, even the error messages and warnings are changing the background color

@fabOnReact
Copy link
Contributor

I tried to reproduce this both in the rn-tester project and in a separate project https://github.com/fabriziobertoglio1987/AwesomeProject/tree/15826

I built the project using the latest react-native master HEAD commit fabOnReact@41b6884

I also checked the node_modules, the commit was there and could not reproduce the issue on API 28. I remain available. Thanks a lot ☮️

CLICK TO OPEN TESTS RESULTS

@vaibhavpadalia
Copy link

It is still an issue on Android where elevation and borderRadius are used on a long list. Not reproduced on all the devices and it's pretty random.
FYI React Native version - 0.67.2

@rameainc
Copy link

React Native 0.69.5 - still an issue

@trinhvanminh
Copy link

react-native: 0.64.3 - still an issue

@amanjareck
Copy link

react native 0.71 - still an issue

@Mosericko
Copy link

6 years later 😅...

@Akifcan
Copy link

Akifcan commented Jul 18, 2023

I had the same issue today and none of the solution below not worked for me.

After I used ImageBackground instead View and use the background color as background image


 box: {
      paddingVertical: 40,
      paddingHorizontal: 20,
      justifyContent: 'center',
      alignItems: 'center',
      gap,
      borderRadius: 30,
      overflow: 'hidden',
    },

 <ImageBackground
     // I created a  large box via figma and use with ImageBackground 
      source={require('../../assets/common/images/box.png')}
      style={styles.box}>
      {children}
    </ImageBackground>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Priority: Low
Projects
None yet
Development

No branches or pull requests