Fix: while running in the simulator. Dapp browser's URL bar can only become first responder once

pull/1254/head
Hwee-Boon Yar 5 years ago
parent 59cd53f08a
commit 767c1d7590
  1. 14
      AlphaWallet/Browser/ViewControllers/BrowserViewController.swift
  2. 11
      AlphaWallet/Browser/Views/DappBrowserNavigationBar.swift
  3. 11
      AlphaWallet/Core/Collection+UIView.swift

@ -113,7 +113,19 @@ final class BrowserViewController: UIViewController {
}
@objc private func keyboardWillHide(notification: NSNotification) {
if let _ = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue, let _ = notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue {
//If there's a external keyboard (or on simulator with software keyboard disabled):
// When text input starts. beginRect: size.height=0 endRect: size.height ~54. origin.y remains at ~812 (out of the screen)
// When text input ends. beginRect: size.height ~54 endRect: size.height = 0. origin.y remains at 812 (out of the screen)
//Note the above. keyboardWillHide() is called for both when input starts and ends for external keyboard. Probably because the keyboard is hidden in both cases
guard let beginRect = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue, let endRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return }
let isExternalKeyboard = beginRect.origin == endRect.origin && (beginRect.size.height == 0 || endRect.size.height == 0)
let isEnteringEditModeWithExternalKeyboard: Bool
if isExternalKeyboard {
isEnteringEditModeWithExternalKeyboard = beginRect.size.height == 0 && endRect.size.height > 0
} else {
isEnteringEditModeWithExternalKeyboard = false
}
if !isExternalKeyboard || !isEnteringEditModeWithExternalKeyboard {
webView.scrollView.contentInset.bottom = 0
//Must exit editing more explicitly (and update the nav bar buttons) because tapping on the web view can hide keyboard
delegate?.dismissKeyboard(inBrowserViewController: self)

@ -24,6 +24,7 @@ private struct Layout {
}
final class DappBrowserNavigationBar: UINavigationBar {
private let stackView = UIStackView()
private let moreButton = UIButton()
private let changeServerButton = UIButton()
private let cancelEditingButton = UIButton()
@ -53,6 +54,9 @@ final class DappBrowserNavigationBar: UINavigationBar {
}
hide.hideAll()
show.showAll()
UIView.animate(withDuration: 0.3) {
self.stackView.layoutIfNeeded()
}
}
}
var isBrowserOnly: Bool {
@ -119,7 +123,7 @@ final class DappBrowserNavigationBar: UINavigationBar {
changeServerButton.setContentCompressionResistancePriority(.required, for: .horizontal)
changeServerButton.setContentHuggingPriority(.required, for: .horizontal)
let stackView = UIStackView(arrangedSubviews: [
stackView.addArrangedSubviews([
spacer0,
backButton,
forwardButton,
@ -136,7 +140,6 @@ final class DappBrowserNavigationBar: UINavigationBar {
stackView.axis = .horizontal
stackView.distribution = .fill
stackView.spacing = 4
addSubview(stackView)
NSLayoutConstraint.activate([
@ -200,9 +203,7 @@ final class DappBrowserNavigationBar: UINavigationBar {
dismissKeyboard()
switch state {
case .editingURLTextField:
UIView.animate(withDuration: 0.3) {
self.state = .notEditingURLTextField
}
case .notEditingURLTextField, .browserOnly:
//We especially don't want to switch (and animate) to .notEditingURLTextField when we are closing .browserOnly mode
break
@ -280,9 +281,7 @@ extension DappBrowserNavigationBar: UITextFieldDelegate {
}
public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
UIView.animate(withDuration: 0.3) {
self.state = .editingURLTextField
}
return true
}
}

@ -3,6 +3,17 @@
import UIKit
extension Collection where Element == UIView {
var alpha: CGFloat {
set {
for each in self {
each.alpha = alpha
}
}
get {
return 1
}
}
func hideAll() {
for each in self {
each.isHidden = true

Loading…
Cancel
Save