Skip to content

Commit

Permalink
Fix History and Bookmarks and ShieldsPanel and 3-Dot menu URL-Eliding…
Browse files Browse the repository at this point in the history
… (uplift to 1.72.x) (#26248)

Uplift of #26226 (squashed) to beta
  • Loading branch information
brave-builds authored Oct 29, 2024
1 parent ae69ebb commit 8eeb271
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import BraveCore
import BraveShared
import BraveUI
import BraveVPN
import BraveWallet
Expand Down Expand Up @@ -410,8 +411,9 @@ extension BrowserViewController {
.lineLimit(1)
.foregroundColor(Color(.braveLabel))
}
Text(
verbatim: URLFormatter.formatURLOrigin(

URLElidedText(
text: URLFormatter.formatURLOrigin(
forDisplayOmitSchemePathAndTrivialSubdomains: url.absoluteString
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private class URLTextField: UITextField {
defaultTextAttributes[.paragraphStyle, default: NSParagraphStyle()] as! NSParagraphStyle
let style = oldStyle.mutableCopy() as! NSMutableParagraphStyle
style.lineBreakMode = .byTruncatingHead
style.baseWritingDirection = .leftToRight
defaultTextAttributes[.paragraphStyle] = style

self.addTarget(self, action: #selector(didBeginEditing), for: .editingDidBegin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import BraveCore
import BraveShared
import BraveStrings
import DesignSystem
import Favicon
import Preferences
import Shared
import SwiftUI

struct HistoryItemView: View {
Expand Down Expand Up @@ -37,15 +39,18 @@ struct HistoryItemView: View {
.foregroundStyle(Color(braveSystemName: .textPrimary))
}

Text(
URLFormatter.formatURLOrigin(
URLElidedText(
text: URLFormatter.formatURLOrigin(
forDisplayOmitSchemePathAndTrivialSubdomains: url.absoluteString
)
)
.truncationMode(.tail)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
.foregroundStyle(Color(braveSystemName: .textSecondary))
.environment(\.layoutDirection, .leftToRight)
.flipsForRightToLeftLayoutDirection(false)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import BraveCore
import BraveShared
import BraveShields
import BraveUI
import Data
Expand Down Expand Up @@ -35,9 +36,8 @@ struct ShieldsPanelView: View {
self.url = url
self.viewModel = ShieldsSettingsViewModel(tab: tab, domain: domain)
self.actionCallback = callback
self.displayHost = URLFormatter.formatURLOrigin(
forDisplayOmitSchemePathAndTrivialSubdomains: url.absoluteString
)
self.displayHost =
"\u{200E}\(URLFormatter.formatURLOrigin(forDisplayOmitSchemePathAndTrivialSubdomains: url.absoluteString))"
}

private var shieldsEnabledAccessibiltyLabel: String {
Expand Down Expand Up @@ -82,7 +82,7 @@ struct ShieldsPanelView: View {
url: url.absoluteString,
isPrivateBrowsing: viewModel.isPrivateBrowsing
)
Text(displayHost)
URLElidedText(text: displayHost)
.font(.title2)
.foregroundStyle(Color(.bravePrimary))
}
Expand Down Expand Up @@ -187,7 +187,9 @@ struct ShieldsPanelView: View {
}

@ViewBuilder private var shieldSettingsSectionView: some View {
ShieldSettingSectionHeader(title: displayHost)
ShieldSettingSectionHeader(
title: displayHost
)
ShieldSettingRow {
HStack {
Text(Strings.Shields.trackersAndAdsBlocking)
Expand Down Expand Up @@ -309,7 +311,7 @@ private struct ShieldSettingSectionHeader: View {

var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text(title)
URLElidedText(text: title)
.font(.footnote)
.foregroundStyle(Color(.secondaryBraveLabel))
.textCase(.uppercase)
Expand Down
41 changes: 41 additions & 0 deletions ios/brave-ios/Sources/BraveShared/URLElidedTextView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import BraveCore
import SwiftUI
import UIKit

public struct URLElidedText: View {
public var text: String

@Environment(\.font)
private var font: Font?

@Environment(\.truncationMode)
private var truncationMode: Text.TruncationMode

private var paragraphStyle: NSParagraphStyle {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode =
truncationMode == .head
? .byTruncatingHead : truncationMode == .middle ? .byTruncatingMiddle : .byTruncatingTail
paragraphStyle.baseWritingDirection = .leftToRight
return paragraphStyle
}

public init(text: String) {
self.text = text
}

public var body: some View {
// LRM character prevents Text elements from rendering RTL special characters
Text(
AttributedString(
"\u{200E}\(text)",
attributes: .init([.font: font ?? .body, .paragraphStyle: paragraphStyle])
)
)
}
}

0 comments on commit 8eeb271

Please sign in to comment.