-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add tooltip to KeyValueGridView #1399
Draft
marianaSchibsted
wants to merge
19
commits into
master
Choose a base branch
from
addTooltipToKeyValueGridView
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
890eb8c
Add new property infoTooltip to KeyValuePair
marianaSchibsted a73d79b
Handle icon and tooltip in KeyValueGridView
marianaSchibsted 8637f0a
Add new Key value pair to the demo view
marianaSchibsted a7de64c
Modify info button
marianaSchibsted 26b6e42
Add a new UIAplication extension
marianaSchibsted e307b87
Extension
marianaSchibsted 07008be
Fix issue with dismissing the tooltip
marianaSchibsted fe11889
Add more to demo
marianaSchibsted fc9ca40
Change a property name
marianaSchibsted 29dde26
Fix snapshot tests
marianaSchibsted 280c2cf
Merge branch 'master' into addTooltipToKeyValueGridView
marianaSchibsted bcbfa7c
Use initialiser for UIStackView
marianaSchibsted 85ca822
Refactor infoButton
marianaSchibsted fa52aac
Fix UIApplication
marianaSchibsted 0d10afb
Add accessibilityLabel to infoButton
marianaSchibsted d1a0434
Dismiss the tooltip on scroll
marianaSchibsted 14c3657
Dismiss tooltip on scroll
marianaSchibsted 2fc01c5
Revert changes
marianaSchibsted 4d96211
Remove overlay, dismiss the tooltip by click on icon or it self
marianaSchibsted 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
Binary file modified
BIN
+24.8 KB
(110%)
...sts/__Snapshots__/ComponentViewTests/KeyValueGridDemoView.dark_iPad_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.84 KB
(100%)
...s/__Snapshots__/ComponentViewTests/KeyValueGridDemoView.dark_iPhone_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+27.2 KB
(110%)
...ts/__Snapshots__/ComponentViewTests/KeyValueGridDemoView.light_iPad_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.87 KB
(100%)
.../__Snapshots__/ComponentViewTests/KeyValueGridDemoView.light_iPhone_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -17,6 +17,8 @@ public class KeyValueGridView: UIView { | |
private var titleStyle: Warp.Typography = .body | ||
private var valueStyle: Warp.Typography = .bodyStrong | ||
private lazy var verticalStackView = UIStackView(axis: .vertical, spacing: Warp.Spacing.spacing200, alignment: .leading, distribution: .equalSpacing, withAutoLayout: true) | ||
private weak var activeTooltipView: UIView? | ||
private weak var activeInfoButton: UIView? | ||
|
||
// MARK: - Initializers | ||
|
||
|
@@ -80,11 +82,45 @@ public class KeyValueGridView: UIView { | |
} | ||
|
||
private func createCellView(for pair: KeyValuePair) -> UIView { | ||
let stackView = UIStackView(axis: .vertical, spacing: Warp.Spacing.spacing25, alignment: .leading, distribution: .equalSpacing, withAutoLayout: true) | ||
let stackView = UIStackView( | ||
axis: .vertical, | ||
spacing: Warp.Spacing.spacing25, | ||
alignment: .leading, | ||
distribution: .equalSpacing, | ||
withAutoLayout: true | ||
) | ||
|
||
let titleLabel = Label(style: titleStyle, numberOfLines: 2, withAutoLayout: true) | ||
titleLabel.lineBreakMode = .byWordWrapping | ||
|
||
let titleContainer = UIStackView( | ||
axis: .horizontal, | ||
spacing: Warp.Spacing.spacing100, | ||
alignment: .center, | ||
distribution: .fill, | ||
withAutoLayout: true | ||
) | ||
|
||
titleLabel.text = pair.title | ||
titleContainer.addArrangedSubview(titleLabel) | ||
|
||
if let infoText = pair.infoTooltip, !infoText.isEmpty { | ||
let infoButton = UIButton(type: .custom) | ||
infoButton.setImage(Warp.Icon.info.uiImage, for: .normal) | ||
infoButton.translatesAutoresizingMaskIntoConstraints = false | ||
infoButton.accessibilityLabel = pair.infoTooltipAccessibilityLabel | ||
NSLayoutConstraint.activate([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bstien Like this? |
||
infoButton.widthAnchor.constraint(equalToConstant: Warp.Spacing.spacing200), | ||
infoButton.heightAnchor.constraint(equalToConstant: Warp.Spacing.spacing200) | ||
]) | ||
infoButton.addAction(UIAction(handler: { [weak self] action in | ||
guard let view = action.sender as? UIView else { return } | ||
self?.toggleTooltip(infoText, from: infoButton) | ||
}), for: .touchUpInside) | ||
|
||
titleContainer.addArrangedSubview(infoButton) | ||
} | ||
|
||
let valueLabel = PaddableLabel(style: valueStyle, numberOfLines: 2, withAutoLayout: true) | ||
valueLabel.lineBreakMode = .byWordWrapping | ||
valueLabel.setTextCopyable(true) | ||
|
@@ -95,11 +131,12 @@ public class KeyValueGridView: UIView { | |
valueLabel.textPadding = .init(vertical: 0, horizontal: valueStyle.horizontalPadding) | ||
} | ||
|
||
titleLabel.text = pair.title | ||
valueLabel.text = pair.value | ||
|
||
stackView.addArrangedSubviews([titleLabel, valueLabel]) | ||
stackView.arrangedSubviews.forEach { $0.setContentCompressionResistancePriority(.required, for: .vertical) } | ||
stackView.addArrangedSubviews([titleContainer, valueLabel]) | ||
stackView.arrangedSubviews.forEach { | ||
$0.setContentCompressionResistancePriority(.required, for: .vertical) | ||
} | ||
|
||
stackView.isAccessibilityElement = true | ||
if let accessibilityLabel = pair.accessibilityLabel { | ||
|
@@ -119,6 +156,49 @@ public class KeyValueGridView: UIView { | |
stackView.spacing = Warp.Spacing.spacing200 | ||
return stackView | ||
} | ||
|
||
private func toggleTooltip(_ text: String, from infoButton: UIView) { | ||
if let activeTooltip = activeTooltipView, activeInfoButton === infoButton { | ||
dismissTooltip() | ||
} else { | ||
dismissTooltip() | ||
showTooltip(text, from: infoButton) | ||
} | ||
} | ||
|
||
private func showTooltip(_ text: String, from sourceView: UIView) { | ||
let tooltipView = Warp.Tooltip(title: text, arrowEdge: .bottom).uiView | ||
tooltipView.translatesAutoresizingMaskIntoConstraints = false | ||
tooltipView.isUserInteractionEnabled = true | ||
|
||
addSubview(tooltipView) | ||
|
||
// Convert the button’s frame to the KeyValueGridView’s coordinate system | ||
let buttonFrameInSelf = sourceView.convert(sourceView.bounds, to: self) | ||
|
||
NSLayoutConstraint.activate([ | ||
tooltipView.topAnchor.constraint(equalTo: self.topAnchor, constant: buttonFrameInSelf.maxY - Warp.Spacing.spacing50), | ||
tooltipView.centerXAnchor.constraint(equalTo: self.leftAnchor, constant: buttonFrameInSelf.midX), | ||
tooltipView.leadingAnchor.constraint(greaterThanOrEqualTo: self.leadingAnchor, constant: Warp.Spacing.spacing100), | ||
tooltipView.trailingAnchor.constraint(lessThanOrEqualTo: self.trailingAnchor, constant: -Warp.Spacing.spacing100) | ||
]) | ||
|
||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTooltipTap(_:))) | ||
tooltipView.addGestureRecognizer(tapGesture) | ||
|
||
activeTooltipView = tooltipView | ||
activeInfoButton = sourceView | ||
} | ||
|
||
@objc private func handleTooltipTap(_ gesture: UITapGestureRecognizer) { | ||
dismissTooltip() | ||
} | ||
|
||
private func dismissTooltip() { | ||
activeTooltipView?.removeFromSuperview() | ||
activeTooltipView = nil | ||
activeInfoButton = nil | ||
} | ||
} | ||
|
||
// MARK: - Private types | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no label for VoiceOver users for this button. How should the button and the presentation work for them?