firescript / nativescript-contacts

A nativescript module that gives access to the native contact directory.
MIT License
28 stars 32 forks source link

ViewHierarchy error on iOS #75

Closed Bidou44 closed 3 years ago

Bidou44 commented 5 years ago

When selecting a contact, I would like to open a custom view if there are multiple addresses registered for that contact.

So the code looks like this

getContact().then((result: GetContactResult) => {
      if (result.response === 'selected') {
          if (result.data.postalAddresses != null && result.data.postalAddresses.length > 1) {
             openMultipleAddressPopup(result.data);
          } else {
            ...
      }

On iOS, this always throws an exception, because the contact frame is not completely closed when showing my custom view. A dirty workaround is to put a timeout() to ensure that the contact frame is correctly closed, but this is really not a good solution. Putting a value of 1 sec for the timeout seems to make the whole thing work 90% of the time, which is clearly insufficient.

So it would be good to be notified when the contact window closed. If I'm not wrong, this is a native functionality of iOS (when you open the contact window, you can pass a callback that will be called when the frame is completely closed).

This Stackoverflow thread explains this problem quite well: https://stackoverflow.com/questions/55769425/nativescript-javascript-modal-dialog-fails-with-viewhierarchy-error-on-ios

dlcole commented 5 years ago

I'm the author of the referenced SO thread and would love to see a fix to this issue. The bypass I'm using is not always dependable.

dlcole commented 4 years ago

@aranmohyeddin you can try adding a timeout as listed above. Yes, it's bogus, but it can get you working again. I've had to up my timeout to 750ms over the various {N} updates to dependably bypass this error.

Bidou44 commented 4 years ago

@dlcole Well, as written it's not a good solution, we have put more than 1 second for the timeout and checking the logs shows that the problem still happens for some user... could someone fix this properly? Unfortunately, I'm not a iOS developer....

dlcole commented 4 years ago

I hit this problem again today, trying to display a confirmation prompt after selecting a contact :-(. So, I debugged it further and developed a fix, replacing some deprecated iOS APIs with newer ones. I'll post a pull request in the near future.

Bidou44 commented 4 years ago

Sounds good, not sure though that the owner is still active, so it may never be merged :(

Bidou44 commented 3 years ago

Hi @firescript, could you create a new npm release with that fix?

firescript commented 3 years ago

Hi @Bidou44 - I just bumped the npm release version.

Bidou44 commented 3 years ago

@firescript @dlcole Thank you so much for your help guys. It's working like a charm! I think that this PR is also fixing other reported issues