iosswiftuiright-to-leftswiftui-listswiftui-searchable

RTL language issue in SwiftUI


I have issue in SwiftUI with Right to Left Languages (Arabic)

The navigation bar is correct, but check the list row and text editor, its flipped to the left edge, which it must be in the right edge in Arabic, the default language in project file, is Arabic, also the built in options menu for the search bar is flipped

struct ContentView: View {
    
    @State private var searchText: String = ""
    @State private var text: String = "تجريبي"
    
    var body: some View {
        
        NavigationStack {
                
            
            List {
                Section {
                    Text("مرحبا")
                    
                    TextEditor(text: self.$text)
                }
            }
            .navigationTitle("جديد")
        }
        .searchable(text: self.$searchText, placement: .navigationBarDrawer(displayMode: .always))
    }
}

Screen1 Screen2

sample project

The list content should start appearing from right edge, also the search bar options menu should be flipped


Solution

  • I solved the problem in List by adding this code:

    @Environment(\.layoutDirection) private var layoutDirection
    
    List {
        // text views …  
    }
    .scaleEffect(x: self.layoutDirection == .rightToLeft ? -1 : 1)
    

    But the issue on the search bar menu options remains unsolved.