Skip to content

Commit

Permalink
haptics on tab presses
Browse files Browse the repository at this point in the history
  • Loading branch information
gkasdorf committed Oct 20, 2023
1 parent 1245c43 commit 1182b88
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/components/Navigation/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,32 @@ import {
} from '@src/state';
import { Image } from 'expo-image';
import { StyleSheet } from 'react-native';
import { playHaptic } from '@helpers/haptics';

const Tab = createBottomTabNavigator();

let lastPress = 0;

const onTabPress = (): void => {
const onHomeTabPress = (): void => {
const now = Date.now();

if (now < lastPress + 200) {
setHomePress();
}

lastPress = now;

void playHaptic();
};

const onTabLongPress = (): void => {
const onHomeTabLongPress = (): void => {
setDrawerOpen(true);
};

const onTabPress = (): void => {
void playHaptic();
};

interface ProfileTabIconProps {
color: string;
}
Expand All @@ -61,6 +68,9 @@ export default function Tabs(): React.JSX.Element {
screenOptions={{
headerShown: false,
}}
screenListeners={{
tabPress: onTabPress,
}}
>
<Tab.Screen
name="Home"
Expand All @@ -69,8 +79,8 @@ export default function Tabs(): React.JSX.Element {
tabBarIcon: ({ color }) => <Home color={color} size={24} />,
}}
listeners={{
tabPress: onTabPress,
tabLongPress: onTabLongPress,
tabPress: onHomeTabPress,
tabLongPress: onHomeTabLongPress,
}}
/>
<Tab.Screen
Expand Down

0 comments on commit 1182b88

Please sign in to comment.