-
Notifications
You must be signed in to change notification settings - Fork 23
[jules] style: Add haptic feedback to all mobile buttons #276
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b460bed
[jules] style: Add haptic feedback to all mobile buttons
google-labs-jules[bot] fb40f64
[jules] fix: Fix closing tag syntax error in FriendsScreen.js
google-labs-jules[bot] bb920c5
[jules] refactor: Use shared withHapticFeedback HOC
google-labs-jules[bot] 0c117e1
Update mobile/components/ui/HapticMenu.js
Devasy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { Appbar } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticAppbarAction = withHapticFeedback(Appbar.Action); | ||
| const HapticAppbarBackAction = withHapticFeedback(Appbar.BackAction); | ||
|
|
||
| export { HapticAppbarAction, HapticAppbarBackAction }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { Button } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticButton = withHapticFeedback(Button); | ||
|
|
||
| export default HapticButton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Card } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticCard = withHapticFeedback(Card, { onlyWhenHandler: true }); | ||
|
|
||
| // Attach subcomponents | ||
| HapticCard.Content = Card.Content; | ||
| HapticCard.Actions = Card.Actions; | ||
| HapticCard.Cover = Card.Cover; | ||
| HapticCard.Title = Card.Title; | ||
|
|
||
| export default HapticCard; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { Checkbox } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticCheckboxItem = withHapticFeedback(Checkbox.Item); | ||
|
|
||
| export default HapticCheckboxItem; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { FAB } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticFAB = withHapticFeedback(FAB); | ||
|
|
||
| export default HapticFAB; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { IconButton } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticIconButton = withHapticFeedback(IconButton); | ||
|
|
||
| export default HapticIconButton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { List } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticListItem = withHapticFeedback(List.Item, { onlyWhenHandler: true }); | ||
| const HapticListAccordion = withHapticFeedback(List.Accordion, { onlyWhenHandler: true }); | ||
|
|
||
| export { HapticListItem, HapticListAccordion }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import React from 'react'; | ||
| import { Menu } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticMenuItem = withHapticFeedback(Menu.Item); | ||
|
|
||
| const HapticMenu = React.forwardRef(({ children, ...props }, ref) => { | ||
| return <Menu ref={ref} {...props}>{children}</Menu>; | ||
| }); | ||
| HapticMenu.displayName = 'HapticMenu'; | ||
|
|
||
| HapticMenu.Item = HapticMenuItem; | ||
|
|
||
| export default HapticMenu; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { SegmentedButtons } from 'react-native-paper'; | ||
| import { withHapticFeedback } from './hapticUtils'; | ||
|
|
||
| const HapticSegmentedButtons = withHapticFeedback(SegmentedButtons, { | ||
| pressProp: 'onValueChange', | ||
| }); | ||
|
|
||
| export default HapticSegmentedButtons; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import React, { forwardRef, useCallback } from 'react'; | ||
| import * as Haptics from 'expo-haptics'; | ||
|
|
||
| /** | ||
| * Higher-Order Component to add haptic feedback to pressable components. | ||
| * | ||
| * @param {React.Component} WrappedComponent - The component to wrap. | ||
| * @param {Object} options - Configuration options. | ||
| * @param {string} options.pressProp - The name of the prop that handles the press event (default: 'onPress'). | ||
| * @param {boolean} options.onlyWhenHandler - If true, haptics only trigger if the handler prop is provided. | ||
| * @returns {React.Component} - The wrapped component with haptic feedback. | ||
| */ | ||
| export const withHapticFeedback = (WrappedComponent, options = {}) => { | ||
| const { pressProp = 'onPress', onlyWhenHandler = false } = options; | ||
|
|
||
| const WithHaptic = forwardRef((props, ref) => { | ||
| const originalHandler = props[pressProp]; | ||
|
|
||
| const handlePress = useCallback( | ||
| (...args) => { | ||
| if (!onlyWhenHandler || originalHandler) { | ||
| Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); | ||
| } | ||
| if (originalHandler) { | ||
| originalHandler(...args); | ||
| } | ||
| }, | ||
| [originalHandler] | ||
| ); | ||
|
|
||
| // Only pass the intercepted handler if we're not in "onlyWhenHandler" mode OR if the handler exists. | ||
| // However, some components might expect the handler prop to always be present or undefined. | ||
| // If onlyWhenHandler is true and originalHandler is missing, we pass undefined to avoid attaching a no-op handler that might make the component look interactive. | ||
| const handlerProps = {}; | ||
| if (onlyWhenHandler && !originalHandler) { | ||
| // Do not attach our handler | ||
| handlerProps[pressProp] = undefined; | ||
| } else { | ||
| handlerProps[pressProp] = handlePress; | ||
| } | ||
|
|
||
| return <WrappedComponent ref={ref} {...props} {...handlerProps} />; | ||
| }); | ||
|
|
||
| const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
| WithHaptic.displayName = `WithHaptic(${displayName})`; | ||
|
|
||
| return WithHaptic; | ||
| }; | ||
|
|
||
| /** | ||
| * Triggers a light haptic feedback for pull-to-refresh actions. | ||
| */ | ||
| export const triggerPullRefreshHaptic = async () => { | ||
| await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Minor inconsistency:
triggerPullRefreshHapticawaits the haptic call whilehandlePressdoes not.In
handlePress(Line 22),Haptics.impactAsyncis fire-and-forget, which is fine for UI responsiveness. Here the call is awaited, meaning the caller'sawait triggerPullRefreshHaptic()will block on the haptic completing. This is unlikely to cause a real problem but is worth noting for consistency — if a caller doesn'tawaitit, theasynckeyword is just unnecessary overhead.🤖 Prompt for AI Agents