-
Notifications
You must be signed in to change notification settings - Fork 23
Add swipe-to-delete for expenses with undo functionality #281
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
Open
Devasy
wants to merge
1
commit into
main
Choose a base branch
from
jules-mobile-swipe-delete-10402885468975125804
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| import React from 'react'; | ||
| import AppNavigator from './navigation/AppNavigator'; | ||
| import { PaperProvider } from 'react-native-paper'; | ||
| import { GestureHandlerRootView } from 'react-native-gesture-handler'; | ||
| import { AuthProvider } from './context/AuthContext'; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <AuthProvider> | ||
| <PaperProvider> | ||
| <AppNavigator /> | ||
| </PaperProvider> | ||
| </AuthProvider> | ||
| <GestureHandlerRootView style={{ flex: 1 }}> | ||
| <AuthProvider> | ||
| <PaperProvider> | ||
| <AppNavigator /> | ||
| </PaperProvider> | ||
| </AuthProvider> | ||
| </GestureHandlerRootView> | ||
| ); | ||
| } |
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 @@ | ||
| module.exports = function(api) { | ||
| api.cache(true); | ||
| return { | ||
| presets: ['babel-preset-expo'], | ||
| plugins: ['react-native-reanimated/plugin'], | ||
| }; | ||
| }; |
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,69 @@ | ||
| import React, { useRef } from 'react'; | ||
| import { StyleSheet, View } from 'react-native'; | ||
| import ReanimatedSwipeable from 'react-native-gesture-handler/ReanimatedSwipeable'; | ||
| import Reanimated, { useAnimatedStyle, interpolate, Extrapolation } from 'react-native-reanimated'; | ||
| import { IconButton } from 'react-native-paper'; | ||
|
|
||
| const SwipeableExpenseRow = ({ children, onSwipeableOpen }) => { | ||
| const swipeableRef = useRef(null); | ||
|
|
||
| const renderRightActions = (progress, drag) => { | ||
| const style = useAnimatedStyle(() => { | ||
| const scale = interpolate( | ||
| drag.value, | ||
| [-80, 0], | ||
| [1, 0], | ||
| Extrapolation.CLAMP | ||
| ); | ||
| return { | ||
| transform: [{ scale }], | ||
| }; | ||
| }); | ||
|
|
||
| return ( | ||
| <View style={styles.rightActionContainer}> | ||
| <Reanimated.View style={[styles.rightAction, style]}> | ||
| <IconButton | ||
| icon="delete" | ||
| iconColor="white" | ||
| size={24} | ||
| onPress={() => { | ||
| swipeableRef.current?.close(); | ||
| onSwipeableOpen(); | ||
| }} | ||
| /> | ||
| </Reanimated.View> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <ReanimatedSwipeable | ||
| ref={swipeableRef} | ||
| renderRightActions={renderRightActions} | ||
| onSwipeableOpen={onSwipeableOpen} | ||
| rightThreshold={40} | ||
| > | ||
| {children} | ||
| </ReanimatedSwipeable> | ||
| ); | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| rightActionContainer: { | ||
| width: 80, | ||
| backgroundColor: '#dd2c00', | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| marginBottom: 16, // Matches the card margin in GroupDetailsScreen | ||
| borderTopRightRadius: 12, // Approximate card radius | ||
| borderBottomRightRadius: 12, | ||
| }, | ||
| rightAction: { | ||
| flex: 1, | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| }, | ||
| }); | ||
|
|
||
| export default SwipeableExpenseRow; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
useAnimatedStylecalled inside a nested function violates the Rules of Hooks.renderRightActionsis a callback, not a React component or custom hook. CallinguseAnimatedStyleinside it can lead to unpredictable behavior. Extract the right action into its own component.Additionally,
onSwipeableOpencan be triggered twice for the same expense: once via theonSwipeableOpenprop onReanimatedSwipeable(Line 44) when the user swipes past the threshold, and again via theonPresshandler (Line 32) if the user taps the delete button. InGroupDetailsScreen, this callshandleDeletetwice for the same item, causing the first pending expense to be immediately committed and a duplicate API call.Proposed fix: extract RightAction into its own component and remove duplicate trigger
Note: Even with the extraction, both the swipe-open and button-press paths call the same
handleDelete, but this eliminates the double-fire scenario where theonSwipeableOpenprop fires on gesture and the buttononPressfires separately. If the library firesonSwipeableOpenwhenclose()is called after a full open, consider adding a guard (e.g., a ref flag) to prevent duplicate calls.🧰 Tools
🪛 Biome (2.3.14)
[error] 11-11: This hook is being called from a nested function, but all hooks must be called unconditionally from the top-level component.
For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level
(lint/correctness/useHookAtTopLevel)
🤖 Prompt for AI Agents