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

Component: SwipeButton #2263

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions components/SwipeButton.tsx
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: {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, did it

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;
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@
"views.PaymentRequest.isPmtHashSigValid": "Payment hash signature",
"views.PaymentRequest.isRelaysSigValid": "Relays signature",
"views.PaymentRequest.notAllowedToSend": "This wallet is not allowed to send funds!",
"views.PaymentRequest.slideToPay": "Slide to Pay",
"views.Receive.title": "Receive",
"views.Receive.successCreate": "Successfully created invoice",
"views.Receive.warningLndHub": "Please note that LNDHub has a fixed on-chain address",
Expand Down
78 changes: 61 additions & 17 deletions views/PaymentRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { StackNavigationProp } from '@react-navigation/stack';
import Amount from '../components/Amount';
import AmountInput from '../components/AmountInput';
import Button from '../components/Button';
import SwipeButton from '../components/SwipeButton';
import Conversion from '../components/Conversion';
import FeeLimit from '../components/FeeLimit';
import Header from '../components/Header';
Expand Down Expand Up @@ -1043,21 +1044,9 @@ export default class PaymentRequest extends React.Component<
<LoadingIndicator size={30} />
</>
)}

<View style={styles.button}>
<Button
title={localeString(
'views.PaymentRequest.payInvoice'
)}
icon={
lightningReadyToSend
? {
name: 'send',
size: 25
}
: undefined
}
onPress={() => {
{requestAmount >= 10000 ? (
<SwipeButton
onSwipeSuccess={() => {
if (isZaplocker)
LnurlPayStore.broadcastAttestation();
this.sendPayment({
Expand All @@ -1084,9 +1073,64 @@ export default class PaymentRequest extends React.Component<
timeout_seconds: timeoutSeconds
});
}}
disabled={!lightningReadyToSend}
instructionText={localeString(
'views.PaymentRequest.slideToPay'
)}
containerStyle={{
backgroundColor:
themeColor('secondaryText')
}}
swipeButtonStyle={{
backgroundColor: themeColor('text')
}}
/>
</View>
) : (
<View style={styles.button}>
<Button
title={localeString(
'views.PaymentRequest.payInvoice'
)}
icon={
lightningReadyToSend
? {
name: 'send',
size: 25
}
: undefined
}
onPress={() => {
if (isZaplocker)
LnurlPayStore.broadcastAttestation();
this.sendPayment({
payment_request: paymentRequest,
amount: satAmount
? satAmount.toString()
: undefined,
max_parts:
enableMultiPathPayment
? maxParts
: null,
max_shard_amt:
enableMultiPathPayment
? maxShardAmt
: null,
fee_limit_sat: isLnd
? feeLimitSat
: null,
max_fee_percent: isCLightning
? maxFeePercentFormatted
: null,
outgoing_chan_id:
outgoingChanId,
last_hop_pubkey: lastHopPubkey,
amp: enableAmp,
timeout_seconds: timeoutSeconds
});
}}
disabled={!lightningReadyToSend}
/>
</View>
)}
</View>
)}
</Screen>
Expand Down
Loading