SwiftEntryKit icon indicating copy to clipboard operation
SwiftEntryKit copied to clipboard

Entry ignores keyboard binding if TextField becomes firstResponder before display

Open SDPrio opened this issue 5 years ago • 4 comments

Describe the bug If a UITextField is/becomes the first responder before the entry is displayed, the keyboard will correctly appear when the entry is show. However in this case the .keyboardRelation binding does not work.

To Reproduce Create a simple ViewController with a UITextField which becomes the first responder before the entry is shown:

    let viewController = SomeViewController()
    
    var attributes = EKAttributes()
    attributes = .float
    attributes.windowLevel = .normal
    attributes.position = .center
    attributes.displayDuration = .infinity
    
    attributes.entranceAnimation = .init(translate: .init(duration: 0.65, anchorPosition: .bottom,  spring: .init(damping: 1, initialVelocity: 0)))
    attributes.exitAnimation = .init(translate: .init(duration: 0.65, anchorPosition: .top, spring: .init(damping: 1, initialVelocity: 0)))
    attributes.popBehavior = .animated(animation: .init(translate: .init(duration: 0.65, spring: .init(damping: 1, initialVelocity: 0))))
    
    attributes.entryInteraction = .absorbTouches
    attributes.screenInteraction = .dismiss
    
    attributes.entryBackground = .color(color: .white)
    attributes.screenBackground = .color(color: UIColor(white: 50.0/255.0, alpha: 0.3))
    
    attributes.roundCorners = .all(radius: 20)
    attributes.border = .value(color: UIColor(white: 0.6, alpha: 1), width: 1)
    attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 3))
    attributes.scroll = .enabled(swipeable: false, pullbackAnimation: .jolt)
    attributes.statusBar = .light
    
    // Define the keyboard binding
    attributes.positionConstraints.keyboardRelation = .bind(offset: .init(bottom: 15, screenEdgeResistance: 0))
    attributes.positionConstraints.maxSize = .init(width: .constant(value: min(UIScreen.main.bounds.width, UIScreen.main.bounds.height)), height: .intrinsic)
    
    // Problem does NOT show if didAppear is used instead
    attributes.lifecycleEvents.willAppear = {
        viewController.someTextField.becomeFirstResponder()
    }
    SwiftEntryKit.display(entry: viewController, using: attributes, presentInsideKeyWindow: true)

Expected behavior Keyboard and EntryView should appear at the same time while the entry is correctly positioned relative to the keyboard.

Result Instead the entry appears in the center position defined by the attributes and completely ignores the keyboard.

iPhone (please complete the following information):

  • Device: iOS all
  • iOS Version: iOS9+
  • Xcode Version 10
  • SwiftEntryKit Release #1.0.1

SDPrio avatar Jul 11 '19 08:07 SDPrio

Same behaviour here. Are there any updates on this?

mixable avatar Jan 15 '20 08:01 mixable

Same behaviour on my end.

andrewpluu avatar May 08 '20 22:05 andrewpluu

Same behaviour here. Are there any updates on this?

LuckyRoc avatar Jul 12 '21 06:07 LuckyRoc

SwiftEntryKit.display(entry: self, using: alertAttributes,presentInsideKeyWindow: true) will work

LuckyRoc avatar Jul 12 '21 06:07 LuckyRoc