Skip to content

Instantly share code, notes, and snippets.

@metin-atalay
Created August 10, 2022 14:14
Show Gist options
  • Save metin-atalay/bdf28a604fe9678403730d14f02946ca to your computer and use it in GitHub Desktop.
Save metin-atalay/bdf28a604fe9678403730d14f02946ca to your computer and use it in GitHub Desktop.
SwiftUI RTL ScrollView
import SwiftUI
struct ScrollViewRTL<Content: View>: View {
@ViewBuilder var content: Content
@Environment(\.layoutDirection) private var layoutDirection
var type: RowType
init(type: RowType, @ViewBuilder content: () -> Content) {
self.type = type
self.content = content()
}
@ViewBuilder var body: some View {
ScrollView(type.scrollAxis, showsIndicators: false) {
content
.rotation3DEffect(Angle(degrees: layoutDirection == .rightToLeft ? -180 : 0), axis: (
x: CGFloat(0),
y: CGFloat(layoutDirection == .rightToLeft ? -10 : 0),
z: CGFloat(0)))
}
.rotation3DEffect(Angle(degrees: layoutDirection == .rightToLeft ? 180 : 0), axis: (
x: CGFloat(0),
y: CGFloat(layoutDirection == .rightToLeft ? 10 : 0),
z: CGFloat(0)))
}
}
public enum RowType {
case hList
case vList
var scrollAxis: Axis.Set {
switch self {
case .hList:
return .horizontal
case .vList:
return .vertical
}
}
}
@mouness2020
Copy link

@metin-atalay
Copy link
Author

hi @mouness2020, what is your RTL problem? We use it and working well. Can you give me more detail please let's fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment