tkach / PinCodeTextField

MIT License
260 stars 100 forks source link

Issues with keyplane, leaks, and snapshotting #45

Open agirault opened 5 years ago

agirault commented 5 years ago

Using Swift 4.2, iOS 12.0:

Sample code:

In the UIViewController holding the PinCodeTextField:

viewDidLoad() {
  super.viewDidLoad()
  pinCodeTextField.allowedCharacterSet = CharacterSet.decimalDigits
  pinCodeTextField.keyboardType = UIKeyboardType.numberPad
  pinCodeTextField.font = UIFont(name: "CustomFont", size: 20.0) ?? UIFont.systemFont(ofSize: 20)
  pinCodeTextField.underlineColor = UIColor.customColor
  pinCodeTextField.updatedUnderlineColor = UIColor.customColor
}

override func viewDidAppear(_ animated: Bool) {
  super.viewDidAppear(animated)
  pinCodeTextField.text = ""
  pinCodeTextField.becomeFirstResponder()
}

override func viewWillDisappear(_ animated: Bool) {
  super.viewWillDisappear(animated)
  pinCodeTextField.resignFirstResponder()
}

In AppDelegate:

    func applicationWillResignActive(_ application: UIApplication) {
        // Hide keyboard in background
        window?.endEditing(true)
    }

Errors are:

  1. When calling pinCodeField.becomeFirstResponder():

    Can't find keyplane that supports type 4 for keyboard iPhone-PortraitTruffle-NumberPad; using 20615_PortraitTruffle_iPhone-Simple-Pad_Default

    Seems to be due to using UIKeyboardType.numberPad, but I do need the number pad, and the funny thing is that the app does show the number pad properly and not the default pad:

  2. Also when calling pinCodeField.becomeFirstResponder(), I get 6 leaks:

    Malloc  32 Bytes    QuartzCore  CA::AttrList::set(unsigned int, _CAValueType, void const*)
    UIKeyboardPredictionView    688 Bytes   UIKitCore   +[UIKeyboardPredictionView sharedInstance]
    Malloc  16 Bytes    QuartzCore  CA::Layer::setter(unsigned int, _CAValueType, void const*)
    CALayer 32 Bytes    QuartzCore  +[CALayer allocWithZone:]
    Malloc  288 Bytes   QuartzCore  -[CALayer init]
    Malloc  16 Bytes    QuartzCore  CA::AttrList::Node::alloc_memory(_CAValueType)
    screen shot 2018-11-27 at 12 13 53 pm
  3. When going in the background:

[Snapshotting] Snapshotting a view (0x150810200, UIKeyboardImpl) that is not in a visible window requires afterScreenUpdates:YES.

It seems that calling endEditing or resignFirstResponder while the app goes in the background causes this issue.