Skip to content

Conversation

@freeboub
Copy link

Description

Fix rippleColor declaration on pressable
fix: #3246
I think colorValue can be used without processColor but here an Int32 is needed

Test plan

I tested with the sample included in the package.
I didn't retest with old architecture but no impact expected, And I already tested it sucessfully

Copy link
Member

@latekvo latekvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, the overall premise of this PR is great, it removes the necessity to use processColor on paper when using hexadecimal colors.
Unfortunately these changes cause a crash when you try setting ripple_color by the color's name (red). I'm currently looking into why fabric works, while paper doesn't, and if the two architectures simply have varying workflows, or some other issues.

mViewManager.setEnabled(view, value == null ? true : (boolean) value);
break;
case "rippleColor":
mViewManager.setRippleColor(view, ColorPropConverter.getColor(value, view.getContext()));
Copy link
Member

@latekvo latekvo Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing ColorPropConverter.getColor(value, view.getContext() breaks paper builds when trying to set the color by it's name (green or red).
This issue only affects paper.

foreground?: boolean;
borderless?: boolean;
enabled?: WithDefault<boolean, true>;
rippleColor?: ColorValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to avoid overwriting this type?
Color may also be described as a string (red or green), replacing this type with Int32 removes that possibility.

@freeboub
Copy link
Author

freeboub commented Dec 8, 2024

@latekvo Sorry for the delayed answer, but I am a bit lost to find the best fix...
I agree keeping ColorValue in the spec file would be better

  • If I just remove processColor from the JS, It works as is with new arch (Then can keep the ColorValue)
  • but it fails with paper in ColorPropConverter.getColor because the input is a string, not an integer...

Do you think it is a good idea to remove the processColor in JS ? if yes, do you know which call should be done on paper version to transform the string color to integer color on native side ?

Notice that processColor return a ProcessedColorValue, not a ColorValue, I also tried to replace the type to ProcessedColorValue, not better with fabric ...

@freeboub freeboub marked this pull request as draft December 20, 2024 22:41
latekvo added a commit that referenced this pull request Feb 3, 2025
## Description

Android ripple currently does not work on `Fabric`, as all values passed
to `RawButton` and it's inheritors are passed through `processColor`,
which is crucial on `Paper`, and broken on `Fabric`.

This PR disables usage of `processColor`, when running on `Fabric`.

Note: `isFabric` cannot be moved out of the body of the `Pressable`, as
it likely won't be initialised before the `Pressable` starts being
rendered. More details
[here](https://github.com/software-mansion/react-native-gesture-handler/blob/b3d8fd91dca195267bdc33aa20fd6f5cd37d7fe2/src/utils.ts#L47).

Fixes #3246
Fixes #3312
Supersedes #3250
Likely could add a workaround for
software-mansion/react-native-reanimated#6935

## Test plan

<details>
<summary>
Collapsed test code
</summary>

```tsx
import React from 'react';
import { Pressable as RNPressable, StyleSheet, Text } from 'react-native';
import {
  BaseButton,
  GestureHandlerRootView,
  RectButton,
  Pressable,
} from 'react-native-gesture-handler';

const App = () => {
  return (
    <GestureHandlerRootView>
      <RectButton style={styles.wrapperCustom} rippleColor={'blue'}>
        <Text style={styles.text}>RectButton</Text>
      </RectButton>
      <BaseButton style={styles.wrapperCustom} rippleColor={'blue'}>
        <Text style={styles.text}>BaseButton</Text>
      </BaseButton>
      <Pressable
        style={styles.wrapperCustom}
        android_ripple={{ color: 'blue' }}>
        {({ pressed }) => (
          <Text style={styles.text}>
            {pressed ? 'Pressed!' : 'Pressable from react-native'}
          </Text>
        )}
      </Pressable>
      <RNPressable
        style={styles.wrapperCustom}
        android_ripple={{ color: 'blue' }}>
        {({ pressed }) => (
          <Text style={styles.text}>
            {pressed ? 'Pressed!' : 'Pressable from react-native'}
          </Text>
        )}
      </RNPressable>
      <Pressable
        style={styles.wrapperCustom}
        android_ripple={{ color: '#00f' }}>
        {({ pressed }) => (
          <Text style={styles.text}>
            {pressed ? 'Pressed!' : 'Pressable from react-native'}
          </Text>
        )}
      </Pressable>
      <RNPressable
        style={styles.wrapperCustom}
        android_ripple={{ color: '#00f' }}>
        {({ pressed }) => (
          <Text style={styles.text}>
            {pressed ? 'Pressed!' : 'Pressable from react-native'}
          </Text>
        )}
      </RNPressable>
    </GestureHandlerRootView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    gap: 16,
    padding: 16,
  },
  text: {
    fontSize: 32,
  },
  wrapperCustom: {
    borderRadius: 8,
    padding: 6,
    flex: 1,
    backgroundColor: 'papayawhip',
    borderColor: 'red',
    borderWidth: 2,
  },
  logBox: {
    flex: 1,
    padding: 20,
    margin: 10,
    borderWidth: StyleSheet.hairlineWidth,
    borderColor: '#f0f0f0',
    backgroundColor: '#f9f9f9',
  },
});

export default App;

```

</details>
@freeboub
Copy link
Author

replaced by: #3369 let's close this PR

@freeboub freeboub closed this Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Pressable] android_ripple / color doesn't work correctly

2 participants