Skip to content

Buttons(iOS | Android): BorderRadius issue with styled components #2594

Closed
@hirbod

Description

@hirbod

Description

We're attempting to port all instances of Pressable from react-native to RNGH Buttons (e.g., RectButton). We utilize NativeWind (akin to Tailwind) and convert them into styled components as follows:

import { RectButton } from "react-native-gesture-handler";
const StyledRectButton = styled(RectButton);

Setting a borderRadius is straightforward:

<StyledRectButton tw="rounded-full" />

This approach works seamlessly for every component. However, it encounters issues with the Buttons exported by RNGH. I've identified the root of the problem: the Buttons incorporate an Animated.View as a child within the Button and derive the borderRadius from the flattened Stylesheet.

While passing borderRadius via the style prop to the StyledComponent does work, it complicates the process. You can see the relevant code here:

const resolvedStyle = StyleSheet.flatten(style ?? {});
return (
<BaseButton
{...rest}
style={resolvedStyle}
onActiveStateChange={this.onActiveStateChange}>
<Animated.View
style={[
btnStyles.underlay,
{
opacity: this.opacity,
backgroundColor: this.props.underlayColor,
borderRadius: resolvedStyle.borderRadius,
borderTopLeftRadius: resolvedStyle.borderTopLeftRadius,
borderTopRightRadius: resolvedStyle.borderTopRightRadius,
borderBottomLeftRadius: resolvedStyle.borderBottomLeftRadius,
borderBottomRightRadius: resolvedStyle.borderBottomRightRadius,
},
]}
/>
{children}
</BaseButton>
);
}
}

Ideally, we'd like to pass the child component (turning it into an AnimatedStyledView) and be able to add tw/className props to it, without the need to wrap it in an outer view. At present, migration is unfeasible for us because wrapping the RNGH Button with a view disrupts a significant amount of our styling.

If I recall correctly, we could modify the children's styles in the past. However, this wouldn't be particularly helpful now, as we need the ability to pass our styled props from Tailwind.

Steps to reproduce

See the Snack
https://snack.expo.dev/@hirbod/rngh-button-nativewind?platform=ios

Works fine on web, but does not work on iOS. On iOS, it does apply the borderRadius correctly for the view with the underlayColor (see the red color) but it fails for the main view.

On Android, it fails completely and doesn't even add a color or anything at all.

Snack or a link to a repository

https://snack.expo.dev/@hirbod/rngh-button-nativewind?&platform=ios

Gesture Handler version

2.9.0

React Native version

0.72.3

Platforms

Android, iOS

JavaScript runtime

None

Workflow

Expo bare workflow

Architecture

Paper (Old Architecture)

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Platform: AndroidThis issue is specific to AndroidPlatform: iOSThis issue is specific to iOSRepro providedA reproduction with a snack or repo is provided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions