-
Notifications
You must be signed in to change notification settings - Fork 3k
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
refactor add payment dynamic #7847
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React from 'react'; | ||
import {View, TouchableOpacity} from 'react-native'; | ||
import {View, TouchableOpacity, Dimensions} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import PaymentMethodList from '../PaymentMethodList'; | ||
import ROUTES from '../../../../ROUTES'; | ||
|
@@ -42,6 +42,7 @@ class BasePaymentsPage extends React.Component { | |
formattedSelectedPaymentMethod: {}, | ||
anchorPositionTop: 0, | ||
anchorPositionLeft: 0, | ||
addPaymentMethodButton: null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing in this file. This isn't needed, and can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've explained the reason for the comment below, it is the same. |
||
}; | ||
|
||
this.paymentMethodPressed = this.paymentMethodPressed.bind(this); | ||
|
@@ -52,10 +53,29 @@ class BasePaymentsPage extends React.Component { | |
this.deletePaymentMethod = this.deletePaymentMethod.bind(this); | ||
this.hidePasswordPrompt = this.hidePasswordPrompt.bind(this); | ||
this.navigateToTransferBalancePage = this.navigateToTransferBalancePage.bind(this); | ||
this.setMenuPosition = this.setMenuPosition.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
PaymentMethods.getPaymentMethods(); | ||
if (this.props.shouldListenForResize) { | ||
this.dimensionsSubscription = Dimensions.addEventListener('change', this.setMenuPosition); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
if (!this.props.shouldListenForResize || !this.dimensionsSubscription) { | ||
return; | ||
} | ||
this.dimensionsSubscription.remove(); | ||
} | ||
|
||
setMenuPosition() { | ||
if (!this.state.addPaymentMethodButton) { | ||
return; | ||
} | ||
const buttonPosition = getClickedElementLocation(this.state.addPaymentMethodButton); | ||
this.setPositionAddPaymentMenu(buttonPosition); | ||
} | ||
|
||
getSelectedPaymentMethodID() { | ||
|
@@ -92,13 +112,10 @@ class BasePaymentsPage extends React.Component { | |
* @param {String} account | ||
*/ | ||
paymentMethodPressed(nativeEvent, accountType, account) { | ||
let position = getClickedElementLocation(nativeEvent); | ||
if (this.props.shouldListenForResize) { | ||
window.addEventListener('resize', () => { | ||
position = getClickedElementLocation(nativeEvent); | ||
this.setPositionAddPaymentMenu(position); | ||
}); | ||
} | ||
const position = getClickedElementLocation(nativeEvent); | ||
this.setState({ | ||
addPaymentMethodButton: nativeEvent, | ||
}); | ||
if (accountType) { | ||
let formattedSelectedPaymentMethod; | ||
if (accountType === CONST.PAYMENT_METHODS.PAYPAL) { | ||
|
@@ -168,19 +185,13 @@ class BasePaymentsPage extends React.Component { | |
* Hide the add payment modal | ||
*/ | ||
hideAddPaymentMenu() { | ||
if (this.props.shouldListenForResize) { | ||
window.removeEventListener('resize', null); | ||
} | ||
this.setState({shouldShowAddPaymentMenu: false}); | ||
} | ||
|
||
/** | ||
* Hide the default / delete modal | ||
*/ | ||
hideDefaultDeleteMenu() { | ||
if (this.props.shouldListenForResize) { | ||
window.removeEventListener('resize', null); | ||
} | ||
this.setState({shouldShowDefaultDeleteMenu: false}); | ||
} | ||
|
||
|
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.
Are you sure we need to put this in state? wouldn't a class variable suffice?
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.
@rushatgabhane The position of the menu belongs to position of the button that user clicking on. Thus, when use listener we need to re-assign this button when any click event happens, the possible way to re-assign any variables to the listener in this case needs to use state.
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 know this is old, but I don't understand this explanation and it seems wrong. @rushatgabhane please try to address all comments before approving 🙇♂️
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.
@marcaaron im sorry about it (and i don't understand it either)
yess!