Skip to content

Commit

Permalink
feat: add pressColor and pressOpacity props to drawerItem (#8834)
Browse files Browse the repository at this point in the history
Co-authored-by: Petra Daneva <p.daneva@dineout.bg>
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
  • Loading branch information
3 people committed Jan 29, 2021
1 parent 3367ddf commit 52dbe4b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
21 changes: 19 additions & 2 deletions packages/drawer/src/views/DrawerItem.tsx
Expand Up @@ -7,7 +7,6 @@ import {
ViewStyle,
TextStyle,
Platform,
TouchableWithoutFeedbackProps,
} from 'react-native';
import { Link, useTheme } from '@react-navigation/native';
import Color from 'color';
Expand Down Expand Up @@ -56,6 +55,20 @@ type Props = {
* Background color for item when its inactive.
*/
inactiveBackgroundColor?: string;
/**
* Color of the touchable effect on press.
* Only supported on Android.
*
* @platform android
*/
pressColor?: string;
/**
* Opacity of the touchable effect on press.
* Only supported on iOS.
*
* @platform ios
*/
pressOpacity?: string;
/**
* Style object for the label element.
*/
Expand All @@ -74,7 +87,7 @@ const Touchable = ({
accessibilityRole,
delayPressIn,
...rest
}: TouchableWithoutFeedbackProps & {
}: React.ComponentProps<typeof TouchableItem> & {
to?: string;
children: React.ReactNode;
onPress?: () => void;
Expand Down Expand Up @@ -132,6 +145,8 @@ export default function DrawerItem(props: Props) {
inactiveBackgroundColor = 'transparent',
style,
onPress,
pressColor,
pressOpacity,
...rest
} = props;

Expand All @@ -155,6 +170,8 @@ export default function DrawerItem(props: Props) {
style={[styles.wrapper, { borderRadius }]}
accessibilityRole="button"
accessibilityState={{ selected: focused }}
pressColor={pressColor}
pressOpacity={pressOpacity}
to={to}
>
<React.Fragment>
Expand Down
6 changes: 3 additions & 3 deletions packages/drawer/src/views/TouchableItem.ios.tsx
Expand Up @@ -5,14 +5,14 @@ import { BaseButton, BaseButtonProperties } from 'react-native-gesture-handler';
const AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);

type Props = BaseButtonProperties & {
activeOpacity: number;
pressOpacity: number;
};

const useNativeDriver = Platform.OS !== 'web';

export default class TouchableItem extends React.Component<Props> {
static defaultProps = {
activeOpacity: 0.3,
pressOpacity: 0.3,
borderless: true,
enabled: true,
};
Expand All @@ -27,7 +27,7 @@ export default class TouchableItem extends React.Component<Props> {
overshootClamping: true,
restDisplacementThreshold: 0.01,
restSpeedThreshold: 0.01,
toValue: active ? this.props.activeOpacity : 1,
toValue: active ? this.props.pressOpacity : 1,
useNativeDriver,
}).start();

Expand Down
7 changes: 3 additions & 4 deletions packages/drawer/src/views/TouchableItem.tsx
Expand Up @@ -11,15 +11,14 @@ import {
TouchableNativeFeedback,
TouchableOpacity,
View,
ViewProps,
TouchableWithoutFeedbackProps,
} from 'react-native';

export type Props = ViewProps & {
export type Props = TouchableWithoutFeedbackProps & {
pressColor?: string;
pressOpacity?: string;
disabled?: boolean | null;
borderless?: boolean;
delayPressIn?: number;
onPress?: () => void;
children: React.ReactNode;
};

Expand Down
25 changes: 0 additions & 25 deletions packages/routers/src/__tests__/StackRouter.test.tsx
Expand Up @@ -1119,31 +1119,6 @@ it("doesn't push nonexistent screen", () => {
options
)
).toBe(null);

expect(
router.getStateForAction(
{
stale: false,
type: 'stack',
key: 'root',
index: 1,
routeNames: ['baz', 'bar', 'qux'],
routes: [
{ key: 'baz', name: 'baz' },
{ key: 'bar', name: 'bar' },
],
},
{
type: 'PUSH',
payload: {
name: 'far',
key: 'test',
params: { answer: 42 },
},
},
options
)
).toBe(null);
});

it('ensures unique ID for push', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/stack/src/views/BorderlessButton.tsx
Expand Up @@ -5,7 +5,7 @@ import { BaseButton, BaseButtonProperties } from 'react-native-gesture-handler';
const AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);

type Props = BaseButtonProperties & {
activeOpacity: number;
pressOpacity: number;
};

const useNativeDriver = Platform.OS !== 'web';
Expand All @@ -27,7 +27,7 @@ export default class BorderlessButton extends React.Component<Props> {
overshootClamping: true,
restDisplacementThreshold: 0.01,
restSpeedThreshold: 0.01,
toValue: active ? this.props.activeOpacity : 1,
toValue: active ? this.props.pressOpacity : 1,
useNativeDriver,
}).start();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/stack/src/views/TouchableItem.ios.tsx
Expand Up @@ -5,7 +5,7 @@ import { BaseButton, BaseButtonProperties } from 'react-native-gesture-handler';
const AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);

type Props = BaseButtonProperties & {
activeOpacity: number;
pressOpacity: number;
};

const useNativeDriver = Platform.OS !== 'web';
Expand All @@ -27,7 +27,7 @@ export default class TouchableItem extends React.Component<Props> {
overshootClamping: true,
restDisplacementThreshold: 0.01,
restSpeedThreshold: 0.01,
toValue: active ? this.props.activeOpacity : 1,
toValue: active ? this.props.pressOpacity : 1,
useNativeDriver,
}).start();

Expand Down

0 comments on commit 52dbe4b

Please sign in to comment.