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

Specific border radius corner causes visual bug on other corners #22511

Closed
3 tasks done
atkinchris opened this issue Dec 4, 2018 · 9 comments
Closed
3 tasks done

Specific border radius corner causes visual bug on other corners #22511

atkinchris opened this issue Dec 4, 2018 · 9 comments
Labels
Bug Component: View Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Platform: Android Android applications. Priority: Mid Resolution: Locked This issue was locked by the bot.

Comments

@atkinchris
Copy link

atkinchris commented Dec 4, 2018

Environment

React Native Environment Info:
  System:
    OS: macOS High Sierra 10.13.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 2.98 GB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 8.14.0 - ~/.nvm/versions/node/v8.14.0/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  SDKs:
    Android SDK:
      API Levels: 23, 27
      Build Tools: 27.0.3
  IDEs:
    Xcode: /undefined - /usr/bin/xcodebuild
  npmPackages:
    react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
    react-native: 0.57.4 => 0.57.4
  npmGlobalPackages:
    react-native-cli: 2.0.1

Description

Applying a non-zero border radius value to a specific corner when all other corners are zero, causes the other corners to become slightly curved on Android.

screenshot_20181204-162242

Reproducible Demo

Code Snippet:

<View style={{
  backgroundColor: 'red',
  width: 100,
  height: 100,
  borderWidth: 5,
  borderBottomLeftRadius: 15,
}} />
<View style={{
  backgroundColor: 'green',
  borderWidth: 5,
  width: 100,
  height: 100,
}} />

Expo Snack:

https://snack.expo.io/@atkinchris/border-radius-bug

@wazzupex
Copy link

wazzupex commented Dec 4, 2018

Hi, although it's was not supposed to happen, have you tried to set the other corners radius to 0 ?

@atkinchris
Copy link
Author

@wazzupex - yep! With the below, it does not change. Setting borderRadius: 0 also does not correct it.

backgroundColor: 'red',
width: 100,
height: 100,
borderWidth: 5,
borderBottomLeftRadius: 15,
borderBottomRightRadius: 0,
borderTopLeftRadius: 0,
borderTopRightRadius: 0,

Interestingly, this does not present in Snack's iOS preview - only on Android and real devices.

@hramos hramos added Platform: Android Android applications. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. labels Dec 5, 2018
@bozhouyongqi
Copy link

I faced with this problems too,when I set the borderBottomLeftRadius attribute only,it does affect other corners slightly curved.When I set the borderWidth to 1,it display ok.

@simform-solutions
Copy link

simform-solutions commented Dec 19, 2018

        borderBottomWidth: 5,
        borderTopWidth: 5,
        borderLeftWidth: 5,
        borderRightWidth: 5,

use this

@jigz
Copy link

jigz commented Jan 22, 2019

is this somehow connected to my bug?
img_0092

@kelset
Copy link
Contributor

kelset commented Mar 19, 2019

👋 everyone.

I can confirm that this bug is still present on RN 0.59 - but I investigated a bit further and I noticed that it seems to be related not strictly to the borderRadius but to the borderWidth: when it's set to 0, the bug doesn't show:

Screenshot 2019-03-19 at 16 27 17

This said, we'll look more into this issue in the next few months (hopefully) - if you have more time to dedicate to it it would surely help!

(ps: @JigzPalillo it's hard to tell - probably not)

@Nizarius
Copy link
Contributor

Nizarius commented Apr 10, 2019

@kelset this bug is really annoying in my project. Let's not wait a few months:) I made PR for fixing it.

@atkinchris
Copy link
Author

Succinct PR @Nizarius! I think this needs unit tests to prevent regressions.

dsyang pushed a commit to dsyang/react-native that referenced this issue Apr 12, 2019
…facebook#24390)

Summary:
Fixes facebook#22511

I understand the motivation of adding extraRadiusForOutline to corner radius: without it there can be an empty space between border and view's background color.

So I add simple check: if corner radius is more than zero we still add extraRadiusForOutline. And if not, we don't add it to prevent all the corners to become slightly curved.

[GENERAL] [Fixed] -  fix of Android's bug that causes all the corners to become slightly curved if only specific corners' radius should be more than zero.
Pull Request resolved: facebook#24390

Differential Revision: D14870476

Pulled By: cpojer

fbshipit-source-id: df40fc584a2f8badc499413cb3c4e4d96b9e18cf
@ThakurKarthik
Copy link

is this somehow connected to my bug?
img_0092

Is this fixed?In my case i can see background color of outer view inside a view with border radius in fractional number.

facebook-github-bot pushed a commit that referenced this issue Jul 17, 2019
Summary:
In order to properly set the view's borderRadius the inner*RadiusX/inner*RadiusY should not
be used, since their values are obtained via the following formula:

int innerTopLeftRadiusX = Math.max(topLeftRadius - borderWidth.left, 0);

If topLeftRadius and borderWidth.left have the same value innerTopLeftRadiusX will
be zero and it will cause the top left radius to never be set since
"(innerTopLeftRadiusX > 0 ? extraRadiusForOutline : 0)" will evaluate to zero.
In order to prevent this issue the condition will only consider topLeftRadius, topRightRadius, and etc.

I took a closer look to see if this fix does not causes a regression in #22511

## Changelog

[Android] [FIX] - Correctly set the border radius on android
Pull Request resolved: #25626

Test Plan:
Using the following code and Android certify that the border radius is correctly applied.
```javascript
import React from "react";
import { ScrollView, StyleSheet, Text, View } from "react-native";

export default class App extends React.Component<Props> {
  render() {
    return (
      <ScrollView style={styles.container}>
        <View style={styles.box1}>
          <Text>borderWidth: 2</Text>
          <Text>borderRadius: 2</Text>
        </View>
        <View style={styles.box2}>
          <Text>borderWidth: 2</Text>
          <Text>borderRadius: 2.000001</Text>
        </View>
        <View style={styles.box3}>
          <Text>borderWidth: 5</Text>
          <Text>borderRadius: 5</Text>
        </View>
        <View style={styles.box4}>
          <Text>borderWidth: 5</Text>
          <Text>borderRadius: 5.000001</Text>
        </View>
        <View style={styles.box5}>
          <Text>borderWidth: 10</Text>
          <Text>borderRadius: 10</Text>
        </View>
        <View style={styles.box6}>
          <Text>borderWidth: 10</Text>
          <Text>borderRadius: 11</Text>
        </View>
        <View style={styles.box7}>
          <Text>borderWidth: 10</Text>
          <Text>borderRadius: 5</Text>
        </View>
        <Text>Testing if this does not cause a regression in https://github.com/facebook/react-native/issues/22511</Text>
        <View style={{
          margin: 10,
          backgroundColor: 'red',
          width: 100,
          height: 100,
          borderWidth: 5,
          borderBottomLeftRadius: 15,
        }} />
        <View style={{
          margin: 10,
          backgroundColor: 'green',
          borderWidth: 5,
          width: 100,
          height: 100,
        }} />
      </ScrollView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  box1: {
    margin: 10,
    height: 100,
    borderRadius: 2,
    borderWidth: 2,
    borderColor: "#000000"
  },
  box2: {
    margin: 10,
    height: 100,
    borderRadius: 2.000001,
    borderWidth: 2,
    borderColor: "#000000"
  },
  box3: {
    margin: 10,
    height: 100,
    borderRadius: 5,
    borderWidth: 5,
    borderColor: "#000000"
  },
  box4: {
    margin: 10,
    height: 100,
    borderRadius: 5.000001,
    borderWidth: 5,
    borderColor: "#000000"
  },
  box5: {
    margin: 10,
    height: 100,
    borderRadius: 10,
    borderWidth: 10,
    borderColor: "#000000"
  },
  box6: {
    margin: 10,
    height: 100,
    borderRadius: 11,
    borderWidth: 10,
    borderColor: "#000000"
  },
  box7: {
    margin: 10,
    height: 100,
    borderRadius: 5,
    borderWidth: 10,
    borderColor: "#000000"
  }
});

```

### Without the fix

![not-working](https://user-images.githubusercontent.com/984610/61164801-e1dc6580-a4ee-11e9-91f3-6ca2fab7c461.gif)

### With the fix

![fixed](https://user-images.githubusercontent.com/984610/61164794-db4dee00-a4ee-11e9-88d7-367c29c785ec.gif)

Closes #25591

Reviewed By: osdnk

Differential Revision: D16243602

Pulled By: mdvacca

fbshipit-source-id: 1e16572fdf6936aa19c3d4c01ff6434028652942
grabbou pushed a commit that referenced this issue Aug 7, 2019
Summary:
In order to properly set the view's borderRadius the inner*RadiusX/inner*RadiusY should not
be used, since their values are obtained via the following formula:

int innerTopLeftRadiusX = Math.max(topLeftRadius - borderWidth.left, 0);

If topLeftRadius and borderWidth.left have the same value innerTopLeftRadiusX will
be zero and it will cause the top left radius to never be set since
"(innerTopLeftRadiusX > 0 ? extraRadiusForOutline : 0)" will evaluate to zero.
In order to prevent this issue the condition will only consider topLeftRadius, topRightRadius, and etc.

I took a closer look to see if this fix does not causes a regression in #22511

[Android] [FIX] - Correctly set the border radius on android
Pull Request resolved: #25626

Test Plan:
Using the following code and Android certify that the border radius is correctly applied.
```javascript
import React from "react";
import { ScrollView, StyleSheet, Text, View } from "react-native";

export default class App extends React.Component<Props> {
  render() {
    return (
      <ScrollView style={styles.container}>
        <View style={styles.box1}>
          <Text>borderWidth: 2</Text>
          <Text>borderRadius: 2</Text>
        </View>
        <View style={styles.box2}>
          <Text>borderWidth: 2</Text>
          <Text>borderRadius: 2.000001</Text>
        </View>
        <View style={styles.box3}>
          <Text>borderWidth: 5</Text>
          <Text>borderRadius: 5</Text>
        </View>
        <View style={styles.box4}>
          <Text>borderWidth: 5</Text>
          <Text>borderRadius: 5.000001</Text>
        </View>
        <View style={styles.box5}>
          <Text>borderWidth: 10</Text>
          <Text>borderRadius: 10</Text>
        </View>
        <View style={styles.box6}>
          <Text>borderWidth: 10</Text>
          <Text>borderRadius: 11</Text>
        </View>
        <View style={styles.box7}>
          <Text>borderWidth: 10</Text>
          <Text>borderRadius: 5</Text>
        </View>
        <Text>Testing if this does not cause a regression in https://github.com/facebook/react-native/issues/22511</Text>
        <View style={{
          margin: 10,
          backgroundColor: 'red',
          width: 100,
          height: 100,
          borderWidth: 5,
          borderBottomLeftRadius: 15,
        }} />
        <View style={{
          margin: 10,
          backgroundColor: 'green',
          borderWidth: 5,
          width: 100,
          height: 100,
        }} />
      </ScrollView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  box1: {
    margin: 10,
    height: 100,
    borderRadius: 2,
    borderWidth: 2,
    borderColor: "#000000"
  },
  box2: {
    margin: 10,
    height: 100,
    borderRadius: 2.000001,
    borderWidth: 2,
    borderColor: "#000000"
  },
  box3: {
    margin: 10,
    height: 100,
    borderRadius: 5,
    borderWidth: 5,
    borderColor: "#000000"
  },
  box4: {
    margin: 10,
    height: 100,
    borderRadius: 5.000001,
    borderWidth: 5,
    borderColor: "#000000"
  },
  box5: {
    margin: 10,
    height: 100,
    borderRadius: 10,
    borderWidth: 10,
    borderColor: "#000000"
  },
  box6: {
    margin: 10,
    height: 100,
    borderRadius: 11,
    borderWidth: 10,
    borderColor: "#000000"
  },
  box7: {
    margin: 10,
    height: 100,
    borderRadius: 5,
    borderWidth: 10,
    borderColor: "#000000"
  }
});

```

![not-working](https://user-images.githubusercontent.com/984610/61164801-e1dc6580-a4ee-11e9-91f3-6ca2fab7c461.gif)

![fixed](https://user-images.githubusercontent.com/984610/61164794-db4dee00-a4ee-11e9-88d7-367c29c785ec.gif)

Closes #25591

Reviewed By: osdnk

Differential Revision: D16243602

Pulled By: mdvacca

fbshipit-source-id: 1e16572fdf6936aa19c3d4c01ff6434028652942
@facebook facebook locked as resolved and limited conversation to collaborators Apr 10, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: View Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Platform: Android Android applications. Priority: Mid Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants