Skip to content

Commit

Permalink
chore: wrap TouchableRipple in forwardRef (#4192)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarNestorov authored Nov 23, 2023
1 parent 0699acc commit 5f15f79
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
32 changes: 20 additions & 12 deletions src/components/TouchableRipple/TouchableRipple.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getTouchableRippleColors } from './utils';
import { Settings, SettingsContext } from '../../core/settings';
import { useInternalTheme } from '../../core/theming';
import type { ThemeProp } from '../../types';
import { forwardRef } from '../../utils/forwardRef';
import hasTouchHandler from '../../utils/hasTouchHandler';

const ANDROID_VERSION_LOLLIPOP = 21;
Expand All @@ -37,17 +38,20 @@ export type Props = PressableProps & {
theme?: ThemeProp;
};

const TouchableRipple = ({
style,
background,
borderless = false,
disabled: disabledProp,
rippleColor,
underlayColor,
children,
theme: themeOverrides,
...rest
}: Props) => {
const TouchableRipple = (
{
style,
background,
borderless = false,
disabled: disabledProp,
rippleColor,
underlayColor,
children,
theme: themeOverrides,
...rest
}: Props,
ref: React.ForwardedRef<View>
) => {
const theme = useInternalTheme(themeOverrides);
const { rippleEffectEnabled } = React.useContext<Settings>(SettingsContext);

Expand Down Expand Up @@ -88,6 +92,7 @@ const TouchableRipple = ({
return (
<Pressable
{...rest}
ref={ref}
disabled={disabled}
style={[borderless && styles.overflowHidden, style]}
android_ripple={androidRipple}
Expand All @@ -100,6 +105,7 @@ const TouchableRipple = ({
return (
<Pressable
{...rest}
ref={ref}
disabled={disabled}
style={[borderless && styles.overflowHidden, style]}
>
Expand Down Expand Up @@ -134,4 +140,6 @@ const styles = StyleSheet.create({
},
});

export default TouchableRipple;
const Component = forwardRef(TouchableRipple);

export default Component as typeof Component & { supported: boolean };
32 changes: 20 additions & 12 deletions src/components/TouchableRipple/TouchableRipple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Platform,
StyleProp,
StyleSheet,
View,
ViewStyle,
} from 'react-native';

Expand All @@ -16,6 +17,7 @@ import { getTouchableRippleColors } from './utils';
import { Settings, SettingsContext } from '../../core/settings';
import { useInternalTheme } from '../../core/theming';
import type { ThemeProp } from '../../types';
import { forwardRef } from '../../utils/forwardRef';
import hasTouchHandler from '../../utils/hasTouchHandler';

export type Props = PressableProps & {
Expand Down Expand Up @@ -101,17 +103,20 @@ export type Props = PressableProps & {
*
* @extends Pressable props https://reactnative.dev/docs/Pressable#props
*/
const TouchableRipple = ({
style,
background: _background,
borderless = false,
disabled: disabledProp,
rippleColor,
underlayColor: _underlayColor,
children,
theme: themeOverrides,
...rest
}: Props) => {
const TouchableRipple = (
{
style,
background: _background,
borderless = false,
disabled: disabledProp,
rippleColor,
underlayColor: _underlayColor,
children,
theme: themeOverrides,
...rest
}: Props,
ref: React.ForwardedRef<View>
) => {
const theme = useInternalTheme(themeOverrides);
const { calculatedRippleColor } = getTouchableRippleColors({
theme,
Expand Down Expand Up @@ -267,6 +272,7 @@ const TouchableRipple = ({
return (
<Pressable
{...rest}
ref={ref}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
disabled={disabled}
Expand Down Expand Up @@ -306,4 +312,6 @@ const styles = StyleSheet.create({
},
});

export default TouchableRipple;
const Component = forwardRef(TouchableRipple);

export default Component as typeof Component & { supported: boolean };

0 comments on commit 5f15f79

Please sign in to comment.