-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fixes the multiline text heights #1427
Changes from all commits
7a14c10
92ae90d
88f8b35
63bb1f1
01d8bc3
062b23b
f9d4d0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,14 +67,11 @@ public final class NetworkProtectionPopover: NSPopover { | |
statusReporter: statusReporter, | ||
menuItems: menuItems) | ||
|
||
let controller: NSViewController | ||
|
||
let view = NetworkProtectionStatusView(model: model).environment(\.dismiss, { [weak self] in | ||
self?.close() | ||
}).fixedSize() | ||
.padding(.vertical, 10) | ||
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. This was removed thanks to the multiline-text height fixes, which were causing the popover height to be off. |
||
controller = NSHostingController(rootView: view) | ||
|
||
let controller = NSHostingController(rootView: view) | ||
contentViewController = controller | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,6 +193,7 @@ public struct NetworkProtectionStatusView: View { | |
HStack(spacing: 0) { | ||
Text(message) | ||
.makeSelectable() | ||
.multilineText() | ||
.foregroundColor(defaultTextColor) | ||
|
||
Spacer() | ||
|
@@ -219,8 +220,9 @@ public struct NetworkProtectionStatusView: View { | |
.padding([.top], 8) | ||
|
||
Text(UserText.networkProtectionStatusViewFeatureDesc) | ||
.applyDescriptionAttributes(colorScheme: colorScheme) | ||
.multilineText() | ||
.multilineTextAlignment(.center) | ||
.applyDescriptionAttributes(colorScheme: colorScheme) | ||
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. Not sure it was necessary to move this below, but I wanted the first thing to happen to be the fixing of the height. |
||
.fixedSize(horizontal: false, vertical: true) | ||
.padding(EdgeInsets(top: 8, leading: 16, bottom: 16, trailing: 16)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// MultilineTextHeightFixer.swift | ||
// | ||
// Copyright © 2023 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
import SwiftUI | ||
|
||
/// Fixes the height for multiline text fields, which seem to suffer from a layout issue where | ||
/// their height isn't properly honored. | ||
/// | ||
private struct MultilineTextHeightFixer: ViewModifier { | ||
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. We implemented this with @brindy 's help. We discussed it's probably reusable but that it may be best to leave it here for now. |
||
@State var textHeight: CGFloat? | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.background( | ||
GeometryReader { geometry in | ||
Color.clear // This is just to have something to attach .onReceive to. | ||
.onReceive(Just(geometry.size)) { _ in | ||
textHeight = geometry.size.height | ||
} | ||
}) | ||
.frame(height: textHeight) | ||
} | ||
} | ||
|
||
extension View { | ||
|
||
/// Meant to be used for multiline-text. This is currently only applying a modifier | ||
/// | ||
@ViewBuilder | ||
func multilineText() -> some View { | ||
self.fixedSize(horizontal: false, vertical: true) | ||
.modifier(MultilineTextHeightFixer()) | ||
} | ||
} |
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 was no need to separate the declaration of
controller
in this line and then assign it in line 76, so I unified both.