-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix History and Bookmarks and ShieldsPanel and 3-Dot menu URL-Eliding…
- Loading branch information
1 parent
ae69ebb
commit 8eeb271
Showing
5 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -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]) | ||
) | ||
) | ||
} | ||
} |