PhoneNumberKit icon indicating copy to clipboard operation
PhoneNumberKit copied to clipboard

Unable to dismiss country picker when presented modally.

Open DhavalBhimani opened this issue 4 years ago • 8 comments

When i use below line to present modally. it do not dismiss when clicked on the country cell in CountryCodePickerViewController.

PhoneNumberKit.CountryCodePicker.forceModalPresentation = true

DhavalBhimani avatar Jan 25 '20 09:01 DhavalBhimani

@DhavalBhimani can you provide more information, such as what version of iOS, Xcode, version number for PhoneNumberKit, etc. ?

It can be difficult to help out if we can’t reproduce the issue first.

isupremedyou avatar Jan 25 '20 13:01 isupremedyou

I also have this issue. iOS version 13.1.3, PhoneNumberKit version 3.2.0. When the user selects country code, it doesn't close CountryCodePickerViewController, but behind him, it goes to the previous view controller in the NavigationController stack. I fixed this by changing string 459 in the TextField.swift from

if let nav = containingViewController?.navigationController {

to

let nav = containingViewController?.navigationController if nav != nil && PhoneNumberKit.CountryCodePicker.forceModalPresentation == false {

But probably I set forceModalPresentation in the wrong way initially? I added to viewDidLoad() of my view controller these strings:

PhoneNumberKit.CountryCodePicker.commonCountryCodes = ["it", "ru", "ua", "us"] PhoneNumberKit.CountryCodePicker.forceModalPresentation = true

Alc77 avatar Jan 30 '20 16:01 Alc77

Hi I have also faced with this issue. Can you also make navigation controller public property, there is any possibility to customise it, just UINavigationController in following code:

@objc func didPressFlagButton() { guard withDefaultPickerUI else { return } let vc = CountryCodePickerViewController(phoneNumberKit: phoneNumberKit) vc.delegate = self if let nav = containingViewController?.navigationController, !PhoneNumberKit.CountryCodePicker.forceModalPresentation { nav.pushViewController(vc, animated: true) } else { let nav = UINavigationController(rootViewController: vc) containingViewController?.present(nav, animated: true) } }

salminalex avatar Feb 04 '20 21:02 salminalex

If the containingViewController has a navigation controller and countryCodePicker is forced presented modally, the view is not dismissed. Needs fixing!!!

nikeshakya avatar Feb 19 '20 10:02 nikeshakya

Anyone have a clue on how to present this in SwiftUI?

mroushdy avatar Apr 20 '20 00:04 mroushdy

This statement in countryCodePickerViewControllerDidPickCountry(_:) of CountryCodePickerDelegate seem out of place.

      if let nav = containingViewController?.navigationController {
          nav.popViewController(animated: true)
      } else {
          containingViewController?.dismiss(animated: true)
      }

It should call for dismissal at tableView(_:, didSelectRowAt:) of CountryCodePickerViewController instead. Current code dismisses presenting vc, not modally presented one.

illabo avatar May 26 '20 07:05 illabo

+1, I have same issue

Eke avatar May 16 '22 04:05 Eke

Does anyone want to open a PR fixing it?

bguidolim avatar May 16 '22 14:05 bguidolim

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 22 '22 04:08 github-actions[bot]