Skip to content

Commit

Permalink
Fix FXIOS-9525 - Adjust edit address view when keyboard is shown/hidd…
Browse files Browse the repository at this point in the history
…en (backport #22498) (#22516)

Fix FXIOS-9525 - Adjust edit address view when keyboard is shown/hidden (#22498)

* fix: adjust edit address view when keyboard is shown

* refactor: move keyboard handling inside view instead of extension

* fix: account for button when hidden

* fix: lint

(cherry picked from commit 9b3356e)

Co-authored-by: Issam Mani <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and issammani authored Oct 14, 2024
1 parent 60d6ba6 commit 6e6fbf0
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import UIKit
import WebKit
import SwiftUI
import Common
import Shared
import struct MozillaAppServices.UpdatableAddressFields

class EditAddressViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler, Themeable {
class EditAddressViewController: UIViewController,
WKNavigationDelegate,
WKScriptMessageHandler,
Themeable,
KeyboardHelperDelegate {
private lazy var removeButton: RemoveAddressButton = {
let button = RemoveAddressButton()
button.setTitle(.Addresses.Settings.Edit.RemoveAddressButtonTitle, for: .normal)
Expand Down Expand Up @@ -55,6 +60,7 @@ class EditAddressViewController: UIViewController, WKNavigationDelegate, WKScrip
setupWebView()
setupRemoveButton()
listenForThemeChange(view)
KeyboardHelper.defaultHelper.addDelegate(self)
}

override func viewDidDisappear(_ animated: Bool) {
Expand All @@ -78,6 +84,7 @@ class EditAddressViewController: UIViewController, WKNavigationDelegate, WKScrip
guard let webView else { return }
view.addSubview(stackView)
stackView.addArrangedSubview(webView)
stackView.isLayoutMarginsRelativeArrangement = true
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
Expand Down Expand Up @@ -201,6 +208,18 @@ class EditAddressViewController: UIViewController, WKNavigationDelegate, WKScrip

self.present(alertController, animated: true, completion: nil)
}

// MARK: - KeyboardHelperDelegate
func keyboardHelper(_ keyboardHelper: KeyboardHelper, keyboardWillShowWithState state: KeyboardState) {
let coveredHeight = state.intersectionHeightForView(view)
// Adjust stackView's bottom inset when the keyboard appears
stackView.layoutMargins.bottom = removeButton.isHidden ? 0 : coveredHeight
}

func keyboardHelper(_ keyboardHelper: KeyboardHelper, keyboardWillHideWithState state: KeyboardState) {
// Reset the bottom inset when the keyboard hides
stackView.layoutMargins.bottom = 0
}
}

struct EditAddressViewControllerRepresentable: UIViewControllerRepresentable {
Expand Down

1 comment on commit 6e6fbf0

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error!

InterpreterError at template.tasks[0].extra[0].treeherder[1].symbol: unknown context value cron

Please sign in to comment.