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

is onPress memoized? #102

Closed
ansh opened this issue Nov 2, 2022 · 17 comments
Closed

is onPress memoized? #102

ansh opened this issue Nov 2, 2022 · 17 comments

Comments

@ansh
Copy link

ansh commented Nov 2, 2022

Is the onPress prop memoized? Because if it is, there is an issue since I am using state in onPress and it using the wrong state.

Using Expo SDK 46

It seems like onPressIn works because it is directly being passed into the component, but ideally I would like to use onPress as it is significantly better UX.

Here is a reproducible demo: https://snack.expo.dev/@anshnanda/awesomebutton-not-working

@MonchiLin
Copy link

Same issue.

@ansh
Copy link
Author

ansh commented Nov 9, 2022

I have reached a solution via the help of StackOverflow: https://stackoverflow.com/questions/74297972/react-native-really-awesome-button-onpress-does-not-update-function-when-state-c

However, it is clear that this bug needs to be addressed in the repository.

@rcaferati

@eeshankeni
Copy link

Can confirm this bug exists and needs to be fixed. It seems to not be present in the release version

@ansh
Copy link
Author

ansh commented Nov 10, 2022

@eeshankeni It is present in the release version. Check out my demo: https://snack.expo.dev/@anshnanda/awesomebutton-not-working

@eeshankeni
Copy link

Weird, I tried to toggle the button's colour between two options using a state. It worked fine in the release but not in the latest version.

@ansh
Copy link
Author

ansh commented Nov 11, 2022

Can you provide a demo on Snack or a repo/gist? @eeshankeni

@septpointdeux
Copy link

septpointdeux commented Nov 20, 2022

I confirm that the bug is present and it is quite embarassing since we can not use the base functionnality of a button ... "OnPress" playing with some states, which is quite a "basic" for a button

I have fixed using :

image

@awreese
Copy link

awreese commented Nov 21, 2022

@septpointdeux This is effectively the solution I hinted at in my SO answer. Did you apply the fix in a local clone of the repo or are you planning to issue a pull request with the fix applied?

@septpointdeux
Copy link

septpointdeux commented Nov 21, 2022

@awreese Thx i effectively followed your advises on SO 👍. The PR is done.

septpointdeux added a commit to septpointdeux/react-native-really-awesome-button that referenced this issue Nov 21, 2022
@ansh
Copy link
Author

ansh commented Nov 28, 2022

It has been almost a month, with a perfectly good PR created, and the maintainer of this package has not even responded. I have emailed him and he has seen the email many times and yet is probably too busy to maintain this.

So, I have forked the package, cleaned up the code, updated the dependencies, and published it under react-native-raised-button on NPM.

Please find it here https://www.npmjs.com/package/react-native-raised-button?activeTab=readme
and here https://github.com/ansh/react-native-raised-button

Looking forward to your contributions @septpointdeux and @awreese

@eeshankeni
Copy link

eeshankeni commented Dec 4, 2022

Hey @ansh
Thanks for your fork, I've noticed that it too has a the same onPress bug as before and the color of the button does not change with every onPress. Would have made an issue on your repo directly but there seems to be no option.

Do check out my expo snack https://snack.expo.dev/@esean_keni/8465d3
Notice how the button changes colour only after multiple attempts. When it should instead be changing with every press.
Thank you!

@ansh
Copy link
Author

ansh commented Dec 4, 2022

@eeshankeni The example snack I initially gave that did not work with this package works now: https://snack.expo.dev/@anshnanda/awesomebutton-not-working so my fork solved my issue.

Not sure why your example doesn't work. Let me take a look.

@ansh
Copy link
Author

ansh commented Dec 4, 2022

@eeshankeni I have debugged your Snack and it seems like there is another bug in the original react-native-really-awesome-button package! This is actually absurd. I regret using this package now.

But in any case, the simplest fix is not pressing the button back-to-back. If you wait 1-2 seconds between pressing the button, the color changes every time. However, if you press the button in rapid succession, the color doesn't change and it doesn't register the new state. Not sure why this happening (maybe @awreese and @septpointdeux can take another look).

@eeshankeni
Copy link

@ansh damn this package seems more trouble than its worth. Which is unfortunate cause its really rather good

@Darren120
Copy link

is the dev dead?

@ansh
Copy link
Author

ansh commented May 23, 2023

This has been fixed in #108

@ansh ansh closed this as completed May 23, 2023
@ansh
Copy link
Author

ansh commented May 23, 2023

However, since the original dev is not active, I made a fork that works better and will be maintained:
https://github.com/ansh/react-native-raised-button

All done in accordance with the MIT license

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

No branches or pull requests

6 participants