react-native-dialogs icon indicating copy to clipboard operation
react-native-dialogs copied to clipboard

Move to promises and not use dismissListener as it causes aborts

Open varungupta85 opened this issue 7 years ago • 13 comments

Just wanted to share the code to move to promises instead of callbacks as discussed in #92

It contains some other changes also that are specific to my use case such as removing the dismissListener as it has been causing aborts in my app. I don't expect for the PR to merged. Just wanted to share the code for moving to promises. Please feel free to close the PR.

varungupta85 avatar Aug 05 '18 13:08 varungupta85

Hey @varungupta85 thanks for being so persistant here. I haven't got a chance yet to dive into this. Are you sure getting rid of dismissListener is the way to go? How can we detect dismiss now?

Noitidart avatar Aug 09 '18 14:08 Noitidart

Personally I don't think that removing dismissListener is the way to go.

vonovak avatar Aug 09 '18 15:08 vonovak

I also think removing dismissListener isn't right approach. It seems like a simple race condition we can fix. I don't even think we have to move to promise based. Just a correct small edit is needed I think.

Noitidart avatar Aug 10 '18 06:08 Noitidart

One other way of fixing the problem could be to pass the onDismiss handler separately to the java code such that even if both the action handler and the onDismiss handlers are called, they are separate callbacks and hence won't run into the multiple callback invocation problem.

varungupta85 avatar Aug 15 '18 05:08 varungupta85

@varungupta85 I like that idea. I'll do some testing.

Noitidart avatar Aug 15 '18 15:08 Noitidart

I can modify the PR as per above idea to pass two callbacks instead of one if you guys are okay with it.

varungupta85 avatar Aug 18 '18 12:08 varungupta85

@varungupta85 yes please do that.

In the mean time though how did testing out the branch here go, it should fix the crash when pressing on buttons for 99% certain - https://github.com/aakashns/react-native-dialogs/issues/92#issuecomment-412324888

Noitidart avatar Aug 18 '18 12:08 Noitidart

@Noitidart I will update the PR as soon as I get time to work on it.

I was not able to test the branch you mentioned since it still contains the mCallbackConsumed flag which masks the problem. I couldn't reproduce the abort on my setup/phones even earlier.

varungupta85 avatar Aug 20 '18 10:08 varungupta85

Thanks @varungupta85 for your effort here! I'm real busy so i appreicate your help! I will be out all day today but will follow up to see your work.

Noitidart avatar Feb 18 '19 16:02 Noitidart

@Noitidart As I mentioned in the PR, I only submitted the PR to share what would be involved in using Promises in the native side also as that is a cleaner API. This PR contains changes that were specific to my requirements. So, I don't expect the PR to be merged but it can start off with someone interested in using Promises on the native side also.

varungupta85 avatar Feb 19 '19 05:02 varungupta85

I really appreciate that @varungupta85 - I would love to move to a promise based API on the native side. I actually am learning the native development by working on this.

Noitidart avatar Feb 19 '19 11:02 Noitidart

Thanks Varun for being so consistent with this. I haven't merged yet because I don't totally understand the code, to see if it has any reprecussions. I'll have to sit down with the code soon. Or if anyone else is more familiar, would be awesome to get an analysis.

Noitidart avatar May 31 '19 13:05 Noitidart

Does anyone understand the implications of this and can review this PR?

Noitidart avatar Oct 06 '19 18:10 Noitidart