Skip to content

Commit

Permalink
chore: wrap TouchableRipple in forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarNestorov committed Nov 20, 2023
1 parent e7df069 commit b2874d4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 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 };
33 changes: 20 additions & 13 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 All @@ -287,7 +293,6 @@ const TouchableRipple = ({
</Pressable>
);
};

/**
* Whether ripple effect is supported.
*/
Expand All @@ -306,4 +311,6 @@ const styles = StyleSheet.create({
},
});

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

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

0 comments on commit b2874d4

Please sign in to comment.