react-native icon indicating copy to clipboard operation
react-native copied to clipboard

TouchableNativeFeedback's ripples aren't affected by borderRadius on Android 9

Open jeffchienzabinet opened this issue 10 years ago • 50 comments

This is a bit of a problem when creating buttons with borderRadius and TouchableNativeFeedback, and the ripples extend out. I'm not an expert but I suppose setNativeBackground needs to get the corner radius when making the mask for the RippleDrawable and setBorderRadius may need to remake the background drawable somehow.

jeffchienzabinet avatar Mar 16 '16 04:03 jeffchienzabinet

Attached the following images to represent graphically what is proposed

before after

Images were taken from Michael Evans Blog - Android Ripples With Rounded Corners

jonathanpalma avatar Jun 04 '16 16:06 jonathanpalma

It's supposed to be implemented in https://github.com/facebook/react-native/pull/6515 but I can't make it work :/

antoinerousseau avatar Jul 14 '16 01:07 antoinerousseau

I realize that PR got reverted

antoinerousseau avatar Jul 14 '16 01:07 antoinerousseau

FWIW, as of 0.30, the ripple effect works with respect to the borderRadius of its parent , but it requires its borderless argument to be set to true. Eg:

<View style={{borderRadius: 24, backgroundColor: '#F66', width: 48,height: 48}}> <TouchableNativeFeedback background={TouchableNativeFeedback.Ripple('#AAF', true)}> [snip] </TouchableNativeFeedback> </View> If this is the intented effect, it should probably be made explicit, and added to the documentation. It it's a side effect (no pun intented), #6515 still makes sense.

reyesr avatar Jul 25 '16 05:07 reyesr

@reyesr OMG thank you so much for this! 👍

tituswoo avatar Jul 25 '16 09:07 tituswoo

@reyesr IT WORKS!!! Thank you so much buddy!! :raised_hands:

jonathanpalma avatar Aug 05 '16 02:08 jonathanpalma

Looks like this is resolved. Feel free to open a new issue if you're still having troubles with it

ericvicenti avatar Nov 14 '16 20:11 ericvicenti

Re-opening since this issue has re-surfaced on Android P.

satya164 avatar Aug 20 '18 10:08 satya164

Just to illustrate from Android P:

screenshot_20180820-124834_2

ferrannp avatar Aug 20 '18 10:08 ferrannp

@reyesr thank you..yet it worked for me after I added a View inside TochableNativeFeedback with the same parent style .. like:

        <View style={{ borderRadius: 20, backgroundColor: '#2f2', width: 80, height: 80 }}>
            <TouchableNativeFeedback background={TouchableNativeFeedback.Ripple('#AAF', true)}>
                <View style={{ borderRadius: 20, backgroundColor: '#2f2', width: 80, height: 80 }}>
                    <Text> test button </Text>
                </View>
             </TouchableNativeFeedback> 
         </View>

lalosh avatar Sep 01 '18 12:09 lalosh

0.55 + Android Pie = The ripple is not affected by the borderRadius. Tried all the variations (View from outside, View from inside, both).

yaronlevi avatar Sep 26 '18 14:09 yaronlevi

This issue was never solved, the solution given in a comment above is a hack.

aMarCruz avatar Oct 11 '18 23:10 aMarCruz

Any updates on the issue?

yaronlevi avatar Oct 19 '18 12:10 yaronlevi

<View style={{ borderRadius: 5, overflow: 'hidden' }}>
  <TouchableNativeFeedback onPress={() => {}} background={TouchableNativeFeedback.Ripple('red')}>
    {'CLICK CLICK'}
  </TouchableNativeFeedback>
</View>

You guys should try to wrap your TouchableNativeFeedback in a view with a border-radius and an hidden overflow.

balthazar avatar Nov 14 '18 15:11 balthazar

@balthazar , wrapping the touchable hides the effect of borderless ripple. This is undesired in Floating Action Buttons components.

aMarCruz avatar Nov 14 '18 16:11 aMarCruz

@aMarCruz I'm not talking about borderless ripples here, as my example shows.

balthazar avatar Nov 14 '18 16:11 balthazar

I've been trying the button issue with https://github.com/kmagiera/react-native-gesture-handler. Looks like it works correctly using the buttons from the library on Android P:

ripple-p

ferrannp avatar Dec 19 '18 14:12 ferrannp

For me it works when I set in TouchableRipple.js the useForeground true + borderless false

  disabled={disabled}
          useForeground={true}
          background={
            background != null
              ? background
              : TouchableNativeFeedback.Ripple(calculatedRippleColor, false)
          }

Also on e.g. the FAB its needs an overflow: 'hidden' style. Works for me on both iOS and Android!

  touchable: {
    borderRadius: 28,
    overflow: 'hidden',
  },

I'm running the latest Android (9 Pie)

RichardLindhout avatar Jan 14 '19 22:01 RichardLindhout

Thanks @RichardLindhout

If anyone is still experiencing this on the latest release please submit a new issue

rickhanlonii avatar Mar 19 '19 16:03 rickhanlonii

@rickhanlonii That's a workaround which we can't use if oveflow: hidden is not desirable. The behavior is still different between Android versions and buggy.

satya164 avatar Mar 19 '19 16:03 satya164