-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Component: SwipeButton #2263
Merged
Merged
Component: SwipeButton #2263
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
187c9f7
Component: SwipeButton
shubhamkmr04 1ac83d6
Add Swipe button to PaymentRequest view
shubhamkmr04 aa40a82
Ensure swipe button stays within container bounds + Use slider for in…
shubhamkmr04 8a31fcf
Add animated text opacity based on swipe button position
shubhamkmr04 88d346b
Add fontfamily to the button text
shubhamkmr04 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 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,139 @@ | ||
import React, { useRef } from 'react'; | ||
import { | ||
View, | ||
Text, | ||
StyleSheet, | ||
Animated, | ||
PanResponder, | ||
PanResponderGestureState, | ||
GestureResponderEvent, | ||
Dimensions | ||
} from 'react-native'; | ||
|
||
import CaretRight from '../assets/images/SVG/Caret Right.svg'; | ||
import { themeColor } from '../utils/ThemeUtils'; | ||
|
||
interface SwipeButtonProps { | ||
onSwipeSuccess: () => void; | ||
swipeButtonStyle?: object; | ||
instructionText?: string; | ||
instructionsStyle?: object; | ||
containerStyle?: object; | ||
} | ||
|
||
const SwipeButton: React.FC<SwipeButtonProps> = ({ | ||
onSwipeSuccess, | ||
swipeButtonStyle, | ||
instructionText = '', | ||
instructionsStyle, | ||
containerStyle | ||
}) => { | ||
const pan = useRef(new Animated.Value(0)).current; | ||
const screenWidth = Dimensions.get('window').width; | ||
|
||
const containerWidth = screenWidth - 40; | ||
const swipeButtonWidth = 50; | ||
const maxTranslation = containerWidth - swipeButtonWidth; | ||
|
||
const textOpacity = pan.interpolate({ | ||
inputRange: [0, maxTranslation / 2, maxTranslation], | ||
outputRange: [1, 0, 0], | ||
extrapolate: 'clamp' | ||
}); | ||
|
||
const panResponder = useRef( | ||
PanResponder.create({ | ||
onStartShouldSetPanResponder: () => true, | ||
onPanResponderGrant: () => { | ||
pan.setOffset(pan._value); | ||
pan.setValue(0); | ||
}, | ||
onPanResponderMove: (e, gesture) => { | ||
const newValue = gesture.dx; | ||
if (newValue >= 0 && newValue <= maxTranslation) { | ||
pan.setValue(newValue); | ||
} | ||
}, | ||
onPanResponderRelease: ( | ||
e: GestureResponderEvent, | ||
gesture: PanResponderGestureState | ||
) => { | ||
if (gesture.dx > maxTranslation * 0.6) { | ||
onSwipeSuccess(); | ||
Animated.spring(pan, { | ||
toValue: maxTranslation, | ||
useNativeDriver: false | ||
}).start(); | ||
} else { | ||
Animated.spring(pan, { | ||
toValue: 0, | ||
useNativeDriver: false | ||
}).start(); | ||
} | ||
} | ||
}) | ||
).current; | ||
|
||
return ( | ||
<View style={[styles.container, containerStyle]}> | ||
<Animated.View | ||
style={[ | ||
styles.instructionsContainer, | ||
instructionsStyle, | ||
{ opacity: textOpacity } | ||
]} | ||
> | ||
<Text style={[styles.instructions]}>{instructionText}</Text> | ||
</Animated.View> | ||
<Animated.View | ||
style={[ | ||
styles.swipeButton, | ||
swipeButtonStyle, | ||
{ transform: [{ translateX: pan }] } | ||
]} | ||
{...panResponder.panHandlers} | ||
> | ||
<CaretRight | ||
fill={themeColor('background')} | ||
width={24} | ||
height={24} | ||
/> | ||
</Animated.View> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
height: 50, | ||
backgroundColor: '#ccc', | ||
borderRadius: 5, | ||
marginHorizontal: 20, | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}, | ||
instructionsContainer: { | ||
alignItems: 'center' | ||
}, | ||
instructions: { | ||
fontSize: 16, | ||
fontFamily: 'PPNeueMontreal-Book', | ||
color: 'black' | ||
}, | ||
swipeButton: { | ||
position: 'absolute', | ||
left: 0, | ||
width: 50, | ||
height: 50, | ||
color: 'black', | ||
backgroundColor: 'white', | ||
borderRadius: 5, | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}, | ||
textStyle: { | ||
fontSize: 18 | ||
} | ||
}); | ||
|
||
export default SwipeButton; |
This file contains 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 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.
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.
I believe we need to define our font here
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.
yup, did it