Skip to content

DialogDismissibleView - refactor to function #1170

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 7 commits into from
Feb 28, 2021

Conversation

M-i-k-e-l
Copy link
Collaborator

Description

DialogDismissibleView - refactor to function

Changelog

DialogDismissibleView - refactor to function

Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

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

@M-i-k-e-l
I think there's is a misusage of the useCallback hook.
I wrote a few comments, but overall I think it most cases you don't to use useCallback

The main purpose for using it for a function is when you want to pass a callback as a prop for another component.
And since here it's not the case, most function can just be a regular functions.

const prevSwipeDirections = useRef<PanDirectionsProps>();
const visible = useRef<boolean>(Boolean(propsVisible));

const getHiddenLocation = useCallback((left: number, top: number): LocationProps => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you using useCallback here? You're not passing it as a prop

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But it's being used in onLayout which is passed as a prop.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then I think it's enough that only onLayout will be wrapped with useCallback, no?
getHiddenLocation can be a pure function that has no dependencies

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are we leaving this as is (following our meeting today)?

private thresholdX = 0;
private thresholdY = 0;
private ref = React.createRef<any>();
const animateTo = useCallback((toValue: number, animationEndCallback?: Animated.EndCallback) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for useCallback

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Used in onLayout as well.


constructor(props: Props) {
super(props);
const isSwiping = useCallback((): boolean => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also here.. useCallback seem redundant.
Even the function content only use reference values

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, verify you really need to declare a return type.
Typescript usually handles it automaticaly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

isSwiping is used in onDrag which is used in useEffect.
Removed a couple of return values.

@M-i-k-e-l M-i-k-e-l requested a review from ethanshar February 15, 2021 19:46
Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

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

Approved.
There's is a conflict needed to resolve

@M-i-k-e-l M-i-k-e-l merged commit 8e22e11 into master Feb 28, 2021
@M-i-k-e-l M-i-k-e-l deleted the Infra/reanimated-2-part-1-refactor-dialog branch October 4, 2021 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants