Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Android haptic, offer toggle for haptics in the app #3482

Merged
merged 7 commits into from
Apr 11, 2024

Conversation

haileyok
Copy link
Contributor

@haileyok haileyok commented Apr 11, 2024

Fixes #3484

Why

Android Patch

We recently migrated to expo-haptics, mostly in preparation for using Fabric. There's a difference however in how the two libraries run an iOS "light" haptic config on Android.

The previous library used the Vibration API solely, which does not
have any configuration for intensity of vibration. The Vibration API has also been deprecated since SDK 26. See:
https://github.com/mkuczera/react-native-haptic-feedback/blob/master/android/src/main/java/com/mkuczera/vibrateFactory/VibrateWithDuration.java

Expo Haptics is using VibrationManager API on SDK >= 31. See: https://github.com/expo/expo/blob/main/packages/expo-haptics/android/src/main/java/expo/modules/haptics/HapticsModule.kt#L44
The timing and intensity of their haptic configurations though differs greatly from the original implementation. This
patch uses the new VibrationManager API to create the same vibration that would have been seen in the deprecated
Vibration API.

We could just revert this change if we'd rather not use this patch. However, given the deprecated API and the preference I have in using Expo-supported modules as we move into the Fabric migration, I would suggest this change. Given that the haptics were actually not even present at all on Android (many people say that the haptics are actually NEW, not just changed), that feels like more reason to move away from the deprecated API.

Toggle

This issue has actually re-raised a lot of people's complaints about haptics in general. Even some iOS users would rather be able to toggle these off. It also isn't as common a behavior on Android, so some users there want to turn them off anyway. To that end, I've added a haptic toggle preference. The default is still to use haptics, but the user can disable them in the settings screen.

Test Plan

To be honest, I can not tell much of a difference between the two haptics on Android. This is probably because of varying haptic generators in different devices. Regardless, this change is relatively straight forward so I am not worried about that.

Also I have tested the various places that we have haptics in the app, and verified that the toggle does indeed disable haptics when turned on.

Copy link

github-actions bot commented Apr 11, 2024

The Pull Request introduced fingerprint changes against the base commit: 9007810

Fingerprint diff
[{"type":"dir","filePath":"node_modules/expo-haptics/android","reasons":["expoAutolinkingAndroid"],"hash":"61e8ca125d3dce6a811261f44acf7f1833dbbb3b"},{"type":"dir","filePath":"patches","reasons":["patchPackage"],"hash":"9d940021d8864bd3ca6f3afb366f26b2d07e25bc"}]

Generated by PR labeler 🤖

Copy link

github-actions bot commented Apr 11, 2024

Old size New size Diff
6.36 MB 6.36 MB -202 B (-0.00%)

@haileyok haileyok force-pushed the hailey/haptics-config branch from ee3f809 to 7b413d0 Compare April 11, 2024 18:37
@haileyok haileyok marked this pull request as ready for review April 11, 2024 18:43
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readthrough looks good. small nits and suggestions. have not tried on device.

impactAsync(hapticImpact)
}
static impact(type: ImpactFeedbackStyle = hapticImpact) {
if (isWeb) {
static impact(type: ImpactFeedbackStyle = hapticImpact, disabled: boolean) {
Copy link
Collaborator

@gaearon gaearon Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these being used? I can't find callsites. Are these here just in case to match the Expo API? (Asking these about all methods other than default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume just to match, yea. That's how it was set up prior so I maintained the API but I'm fine with removing these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified this down to just playHaptic(disabled: boolean). I don't think we have any intentions of using these other options, those originated from a while back and it does not look like they were ever used from what I can tell.

if (isWeb) {
static notification = (
type: 'success' | 'warning' | 'error',
enabled: boolean,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have enabled here but disabled for others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to invert this one, but removed anyway since we don't use it.

src/lib/haptics.ts Show resolved Hide resolved
removeFeed,
resetSaveFeed,
feedInfo.uri,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintended change? I suppose it doesn't matter but I'm not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter probably picked them up when I added to the deps. Is probably fine, I'm fine with reverting the lint changes though if we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same to the others below.

isHapticsDisabled,
isPinned,
unpinFeed,
feedInfo.uri,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same: unintended or intentional

unlikeFeed,
track,
likeFeed,
feedInfo.uri,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same q

@haileyok haileyok merged commit 740cd02 into main Apr 11, 2024
6 checks passed
@haileyok haileyok deleted the hailey/haptics-config branch April 11, 2024 22:20
estrattonbailey added a commit that referenced this pull request Apr 12, 2024
* origin/main: (455 commits)
  Use getSuggestions endpoint behind the gate (#3499)
  Added `new_profile_scroll_component` to `Gate` type (#3487)
  Fix useGate lint rule (#3486)
  Make bio area scrollable on iOS (#2931)
  Improve Android haptic, offer toggle for haptics in the app (#3482)
  Search - only enable queries once tab is active (#3471)
  [Statsig] Mark Testflight as staging tier (#3470)
  [Statsig] Typecheck gates (#3467)
  Bump to 1.77 (#3468)
  Search - extra tabs (#3408)
  notify slack on production builds (#3461)
  notify slack on production builds (#3460)
  1.76 release preparations (#3459)
  Update zh-CN translation (#3433)
  Italian Localization (#3388)
  [Statsig] Send prev route name (#3456)
  [Statsig] Instrument feed display (#3455)
  Small logic cleanups (#3449)
  Use ALF for the embed consent modal (#3336)
  Onboarding tweaks (#3447)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to turn off tactile responses in the app.
2 participants