Created
June 29, 2021 00:36
-
-
Save novinfard/e54174fe40928a299e70aa6b9b6868ec to your computer and use it in GitHub Desktop.
[Detect RTL in SwiftUI views]
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
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