generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 53
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
39d3fbe
PM-9501 - fix keyboard issues with hiding the cursor when creating ne…
phil-livefront a73c3eb
Merge branch 'main' into phil/PM-9501-notes-section-keyboard-issues
phil-livefront 484a733
updating to use a UITextView to handle cursor/keyboard issues. Some …
phil-livefront 6785742
Merge branch 'main' into phil/PM-9501-notes-section-keyboard-issues
phil-livefront 91e8bc6
minor updates
phil-livefront 37ecfa8
Merge branch 'main' into phil/PM-9501-notes-section-keyboard-issues
phil-livefront f701d17
getting up to date with `main`
phil-livefront 39774bb
fix tests
phil-livefront 2098f0a
PM-13032 - enable partial selection on Notes
phil-livefront aedafdc
fix content offset within text field
phil-livefront 0a50878
fix offset
phil-livefront 9d06bc7
fix docs
phil-livefront d4e840b
Merge branch 'main' into phil/PM-9501-notes-section-keyboard-issues
phil-livefront 8cfacf4
update snapshots
phil-livefront ced7a31
Revert "update snapshots"
phil-livefront cb072c3
revert last commit and fix snapshots
phil-livefront 09141a4
PR comments
phil-livefront 545352e
Merge branch 'main' into phil/PM-9501-notes-section-keyboard-issues
phil-livefront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
BitwardenShared/UI/Platform/Application/Views/BitwardenMultilineTextField.swift
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
BitwardenShared/UI/Platform/Application/Views/BitwardenUITextView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import SwiftUI | ||
import UIKit | ||
|
||
// MARK: - BitwardenUITextView | ||
|
||
/// A custom `UITextView` wrapped in a `UIViewRepresentable` for use in SwiftUI. | ||
/// | ||
struct BitwardenUITextView: UIViewRepresentable { | ||
// MARK: - Coordinator | ||
|
||
/// A coordinator to act as the delegate for `UITextView`, handling text changes and other events. | ||
/// | ||
class Coordinator: NSObject, UITextViewDelegate { | ||
/// The parent view. | ||
var parent: BitwardenUITextView | ||
|
||
/// The calculated height of the text view. | ||
var calculatedHeight: Binding<CGFloat> | ||
|
||
/// Initializes a new `Coordinator` for the `BitwardenUITextView`. | ||
/// | ||
/// - Parameters: | ||
/// - parent: The parent view that owns this coordinator. | ||
/// - calculatedHeight: The height of the text view. | ||
/// | ||
init( | ||
_ parent: BitwardenUITextView, | ||
calculatedHeight: Binding<CGFloat> | ||
) { | ||
self.parent = parent | ||
self.calculatedHeight = calculatedHeight | ||
} | ||
|
||
func textViewDidChange(_ uiView: UITextView) { | ||
parent.text = uiView.text | ||
parent.recalculateHeight( | ||
view: uiView, | ||
result: calculatedHeight | ||
) | ||
} | ||
} | ||
|
||
// MARK: Properties | ||
|
||
/// The text entered into the text field. | ||
@Binding var text: String | ||
|
||
/// The calculated height of the `UITextView`. This value is dynamically updated based on the | ||
/// content size, and it helps to adjust the height of the view in SwiftUI. | ||
@Binding var calculatedHeight: CGFloat | ||
|
||
/// Indicates whether the `UITextView` is editable. When set to `true`, the user can edit the | ||
/// text. If `false`, the text view is read-only. | ||
var isEditable: Bool = true | ||
|
||
/// Creates and returns the coordinator for the `UITextView`. | ||
/// | ||
/// - Returns: A `Coordinator` instance to manage the `UITextView`'s events. | ||
/// | ||
func makeCoordinator() -> Coordinator { | ||
Coordinator(self, calculatedHeight: $calculatedHeight) | ||
} | ||
|
||
// MARK: - UIViewRepresentable Methods | ||
|
||
/// Creates and configures the `UITextView` for this view. | ||
/// | ||
/// - Parameter context: The context containing the coordinator for this view. | ||
/// - Returns: A configured `UITextView` instance. | ||
/// | ||
func makeUIView(context: Context) -> UITextView { | ||
let textView = UITextView() | ||
textView.adjustsFontForContentSizeCategory = true | ||
textView.autocapitalizationType = .sentences | ||
textView.delegate = context.coordinator | ||
textView.textColor = Asset.Colors.textPrimary.color | ||
textView.isScrollEnabled = false | ||
textView.isEditable = isEditable | ||
textView.isUserInteractionEnabled = true | ||
textView.isSelectable = true | ||
textView.backgroundColor = .clear | ||
textView.tintColor = Asset.Colors.tintPrimary.color | ||
textView.textContainerInset = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0) | ||
textView.textContainer.lineFragmentPadding = 0 | ||
textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) | ||
let customFont = FontFamily.DMSans.regular.font(size: 15) | ||
textView.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: customFont) | ||
return textView | ||
} | ||
|
||
/// Updates the `UITextView` with the latest text when the SwiftUI state changes. | ||
/// | ||
/// - Parameters: | ||
/// - uiView: The `UITextView` instance being updated. | ||
/// - context: The context containing the coordinator for this view. | ||
/// | ||
func updateUIView( | ||
_ uiView: UITextView, | ||
context: Context | ||
) { | ||
if uiView.text != text { | ||
uiView.text = text | ||
} | ||
|
||
recalculateHeight( | ||
8A8F | view: uiView, | |
result: $calculatedHeight | ||
) | ||
} | ||
|
||
/// Recalculates the height of the UIView based on its content size and updates the binding if the height changes. | ||
/// | ||
/// - Parameters: | ||
/// - view: The UIView whose height is to be recalculated. | ||
/// - result: A binding to a CGFloat that stores the height value. | ||
/// | ||
private func recalculateHeight( | ||
view: UIView, | ||
result: Binding<CGFloat> | ||
) { | ||
let newSize = view.sizeThatFits( | ||
CGSize( | ||
width: view.frame.size.width, | ||
height: CGFloat.greatestFiniteMagnitude | ||
) | ||
) | ||
|
||
if result.wrappedValue != newSize.height { | ||
DispatchQueue.main.async { | ||
result.wrappedValue = newSize.height | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[PM-9501][PM-13032] Update keyboard behavior for Notes field #798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account