Skip to content

Instantly share code, notes, and snippets.

@novinfard
Created June 29, 2021 00:36
Show Gist options
  • Save novinfard/e54174fe40928a299e70aa6b9b6868ec to your computer and use it in GitHub Desktop.
Save novinfard/e54174fe40928a299e70aa6b9b6868ec to your computer and use it in GitHub Desktop.
[Detect RTL in SwiftUI views]
struct ContentView: View {
let text = "این یک متن تست است. در این متن به بررسی عملکرد زبان های راست به چپ می‌پردازیم."
@Environment(\.layoutDirection) var direction
var body: some View {
VStack(spacing: 16) {
Text(text)
HStack {
Spacer()
.frame(width: 16)
image
Spacer()
}
Spacer()
}
}
@ViewBuilder
var image: some View {
if direction == .rightToLeft {
Image(systemName: "pencil.circle.fill")
.resizable()
.frame(width: 100, height: 100)
.rotationEffect(.degrees(90))
} else {
Image(systemName: "pencil.circle.fill")
.resizable()
.frame(width: 100, height: 100)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment