Skip to content

Commit

Permalink
refactor: remove haptic
Browse files Browse the repository at this point in the history
  • Loading branch information
howljs committed Jul 13, 2024
1 parent 5aa4cad commit 50d7d18
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 93 deletions.
1 change: 0 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"axios": "^1.6.7",
"expo": "^51.0.2",
"expo-constants": "~16.0.1",
"expo-haptics": "~13.0.1",
"expo-linking": "~6.3.1",
"expo-router": "~3.5.11",
"expo-secure-store": "~13.0.1",
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"expo-haptics": "^12.8.1",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"react": "18.2.0",
"react-native": "0.73.4",
"react-native-builder-bob": "^0.20.0",
"react-native-gesture-handler": "^2.14.0",
"react-native-haptic-feedback": "^2.2.0",
"react-native-reanimated": "^3.6.2",
"release-it": "^15.0.0",
"typescript": "^5.2.2"
Expand Down
10 changes: 5 additions & 5 deletions src/context/CalendarProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import type {
DateType,
GoToDateOptions,
} from '../types';
import Haptic from '../utils/HapticService';
// import Haptic from '../utils/HapticService';
import { parseDateTime, startOfWeek } from '../utils/dateUtils';
import {
calculateSlots,
Expand Down Expand Up @@ -151,7 +151,7 @@ const CalendarProvider: React.ForwardRefRenderFunction<
ref
) => {
// TODO: Implement haptic feedback
const useHaptic = false;
// const useHaptic = false;
// TODO: Implement all day events
const useAllDayEvent = false;
// TODO: Implement RTL
Expand Down Expand Up @@ -489,9 +489,9 @@ const CalendarProvider: React.ForwardRefRenderFunction<
const snapToInterval =
numberOfDays > 1 && scrollByDay ? columnWidth : undefined;

useEffect(() => {
Haptic.setEnabled(useHaptic);
}, [useHaptic]);
// useEffect(() => {
// Haptic.setEnabled(useHaptic);
// }, [useHaptic]);

const context = useMemo<CalendarContextProps>(
() => ({
Expand Down
110 changes: 55 additions & 55 deletions src/utils/HapticService.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import { NativeModules } from 'react-native';

class HapticService {
public isHapticFeedbackEnabled: boolean = false;
public useExpoHaptics: boolean = false;

constructor() {
const expoConstants =
NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
this.useExpoHaptics = !!expoConstants;
}

public setEnabled(isEnabled: boolean) {
this.isHapticFeedbackEnabled = isEnabled;
}

public impact() {
if (!this.isHapticFeedbackEnabled) {
return;
}

if (this.useExpoHaptics) {
const ExpoHaptics = require('expo-haptics');
return ExpoHaptics.impactAsync(ExpoHaptics.ImpactFeedbackStyle.Medium);
}

const ReactNativeHapticFeedback =
require('react-native-haptic-feedback').default;
return ReactNativeHapticFeedback.trigger('impactMedium', {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: true,
});
}

public selection() {
if (!this.isHapticFeedbackEnabled) {
return;
}
if (this.useExpoHaptics) {
const ExpoHaptics = require('expo-haptics');
return ExpoHaptics.selectionAsync();
}

const ReactNativeHapticFeedback =
require('react-native-haptic-feedback').default;
return ReactNativeHapticFeedback.trigger('selection', {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: true,
});
}
}

const Haptic = new HapticService();

export default Haptic;
// import { NativeModules } from 'react-native';

// class HapticService {
// public isHapticFeedbackEnabled: boolean = false;
// public useExpoHaptics: boolean = false;

// constructor() {
// const expoConstants =
// NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
// this.useExpoHaptics = !!expoConstants;
// }

// public setEnabled(isEnabled: boolean) {
// this.isHapticFeedbackEnabled = isEnabled;
// }

// public impact() {
// if (!this.isHapticFeedbackEnabled) {
// return;
// }

// if (this.useExpoHaptics) {
// const ExpoHaptics = require('expo-haptics');
// return ExpoHaptics.impactAsync(ExpoHaptics.ImpactFeedbackStyle.Medium);
// }

// const ReactNativeHapticFeedback =
// require('react-native-haptic-feedback').default;
// return ReactNativeHapticFeedback.trigger('impactMedium', {
// enableVibrateFallback: true,
// ignoreAndroidSystemSettings: true,
// });
// }

// public selection() {
// if (!this.isHapticFeedbackEnabled) {
// return;
// }
// if (this.useExpoHaptics) {
// const ExpoHaptics = require('expo-haptics');
// return ExpoHaptics.selectionAsync();
// }

// const ReactNativeHapticFeedback =
// require('react-native-haptic-feedback').default;
// return ReactNativeHapticFeedback.trigger('selection', {
// enableVibrateFallback: true,
// ignoreAndroidSystemSettings: true,
// });
// }
// }

// const Haptic = new HapticService();

// export default Haptic;
30 changes: 0 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2721,7 +2721,6 @@ __metadata:
eslint: ^8.51.0
eslint-config-prettier: ^9.0.0
eslint-plugin-prettier: ^5.0.1
expo-haptics: ^12.8.1
jest: ^29.7.0
lodash: ^4.17.21
luxon: ^3.4.4
Expand All @@ -2730,7 +2729,6 @@ __metadata:
react-native: 0.73.4
react-native-builder-bob: ^0.20.0
react-native-gesture-handler: ^2.14.0
react-native-haptic-feedback: ^2.2.0
react-native-reanimated: ^3.6.2
release-it: ^15.0.0
rrule: ^2.8.1
Expand Down Expand Up @@ -9224,24 +9222,6 @@ __metadata:
languageName: node
linkType: hard

"expo-haptics@npm:^12.8.1":
version: 12.8.1
resolution: "expo-haptics@npm:12.8.1"
peerDependencies:
expo: "*"
checksum: 5448146ecd392e7a4ffc4ca5f222adcf673ff5f177e0e1dda98032a35d50578e44aa76e51ddebdc43206e588c91cb328d37dce667d636ca8c809f5e2d140fb55
languageName: node
linkType: hard

"expo-haptics@npm:~13.0.1":
version: 13.0.1
resolution: "expo-haptics@npm:13.0.1"
peerDependencies:
expo: "*"
checksum: 5419e6451d3718dde8fb099eb710d7c90448d75d00d44e8b42ec301ec45d52bdb52e6ef2959fd0f207abcbe090b0c851b8bd94aba90343053d5435e4e545a997
languageName: node
linkType: hard

"expo-keep-awake@npm:~13.0.1":
version: 13.0.1
resolution: "expo-keep-awake@npm:13.0.1"
Expand Down Expand Up @@ -15811,7 +15791,6 @@ __metadata:
babel-plugin-module-resolver: ^5.0.0
expo: ^51.0.2
expo-constants: ~16.0.1
expo-haptics: ~13.0.1
expo-linking: ~6.3.1
expo-router: ~3.5.11
expo-secure-store: ~13.0.1
Expand Down Expand Up @@ -15862,15 +15841,6 @@ __metadata:
languageName: node
linkType: hard

"react-native-haptic-feedback@npm:^2.2.0":
version: 2.2.0
resolution: "react-native-haptic-feedback@npm:2.2.0"
peerDependencies:
react-native: ">=0.60.0"
checksum: e7ce6b303a799dc7fd1c5851379b555b65052c3ef7fefe836c7881f125e4057134462554a996762e67ecc7f01e82e45dc3bcad17cc232b53511006160d5f98ed
languageName: node
linkType: hard

"react-native-helmet-async@npm:2.0.4":
version: 2.0.4
resolution: "react-native-helmet-async@npm:2.0.4"
Expand Down

0 comments on commit 50d7d18

Please sign in to comment.