mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-30 04:01:02 +00:00
Display statuses with appropriate alignment for right-to-left languages (#256)
This commit is contained in:
parent
45ec990384
commit
a37d059026
2 changed files with 12 additions and 3 deletions
|
@ -7,11 +7,13 @@ import SwiftUI
|
|||
public struct EmojiTextApp: View {
|
||||
private let markdown: HTMLString
|
||||
private let emojis: [any CustomEmoji]
|
||||
private let language: String?
|
||||
private let append: (() -> Text)?
|
||||
|
||||
public init(_ markdown: HTMLString, emojis: [Emoji], append: (() -> Text)? = nil) {
|
||||
public init(_ markdown: HTMLString, emojis: [Emoji], language: String? = nil, append: (() -> Text)? = nil) {
|
||||
self.markdown = markdown
|
||||
self.emojis = emojis.map { RemoteEmoji(shortcode: $0.shortcode, url: $0.url) }
|
||||
self.language = language
|
||||
self.append = append
|
||||
}
|
||||
|
||||
|
@ -23,8 +25,15 @@ public struct EmojiTextApp: View {
|
|||
}
|
||||
} else if emojis.isEmpty {
|
||||
Text(markdown.asSafeMarkdownAttributedString)
|
||||
.environment(\.layoutDirection, isRTL() ? .rightToLeft : .leftToRight)
|
||||
} else {
|
||||
EmojiText(markdown: markdown.asMarkdown, emojis: emojis)
|
||||
.environment(\.layoutDirection, isRTL() ? .rightToLeft : .leftToRight)
|
||||
}
|
||||
}
|
||||
|
||||
private func isRTL() -> Bool {
|
||||
// Arabic, Hebrew, Persian, Urdu, Kurdish, Azeri, Dhivehi
|
||||
return ["ar", "he", "fa", "ur", "ku", "az", "dv"].contains(self.language)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ public struct StatusRowView: View {
|
|||
private func makeStatusContentView(status: AnyStatus) -> some View {
|
||||
Group {
|
||||
if !status.spoilerText.asRawText.isEmpty {
|
||||
EmojiTextApp(status.spoilerText, emojis: status.emojis)
|
||||
EmojiTextApp(status.spoilerText, emojis: status.emojis, language: status.language)
|
||||
.font(.scaledBody)
|
||||
Button {
|
||||
withAnimation {
|
||||
|
@ -230,7 +230,7 @@ public struct StatusRowView: View {
|
|||
|
||||
if !viewModel.displaySpoiler {
|
||||
HStack {
|
||||
EmojiTextApp(status.content, emojis: status.emojis)
|
||||
EmojiTextApp(status.content, emojis: status.emojis, language: status.language)
|
||||
.font(.scaledBody)
|
||||
.environment(\.openURL, OpenURLAction { url in
|
||||
routerPath.handleStatus(status: status, url: url)
|
||||
|
|
Loading…
Reference in a new issue