Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How ScrollView Layout Direction to right-to-left in SwiftUI?

How can we set right to left layout direction in Horizontal ScrollView in swiftUI?

something like this:

ScrollView(showsHorizontalIndicator: false) {
    HStack {
        VStack {
            Image("1")
            Text("one")
        }
        VStack {
            Image("2")
            Text("two")
        }
        VStack {
            Image("3")
            Text("three")
        }
    }
}

so when simulator run, I want to see Image("1") in right hand side and swipe to right to can access to Image("3")

like image 443
Sajjad Avatar asked Jul 05 '19 19:07

Sajjad


1 Answers

You can make any view you want right-to-left by giving your view below modifiers:

.flipsForRightToLeftLayoutDirection(true)
.environment(\.layoutDirection, .rightToLeft)

In your case, it is going to be like this:

ScrollView(showsHorizontalIndicator: false) {
    HStack {
        VStack {
            Image("1")
            Text("one")
        }
        VStack {
            Image("2")
            Text("two")
        }
        VStack {
            Image("3")
            Text("three")
        }
    }
}
.flipsForRightToLeftLayoutDirection(true)
.environment(\.layoutDirection, .rightToLeft)

GoodLuck dadash ;)

like image 154
FRIDDAY Avatar answered Nov 18 '22 03:11

FRIDDAY