taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

View+flippedDirection.swift (1561B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 
     10 struct FlippedDirection: ViewModifier {
     11     @Environment(\.layoutDirection) var layoutDirection
     12 
     13     func body(content: Content) -> some View {
     14         let isLeft = layoutDirection == .leftToRight
     15         content
     16             .environment(\.layoutDirection, isLeft ? .rightToLeft : .leftToRight)
     17     }
     18 }
     19 
     20 extension View {
     21     func flippedDirection() -> some View {
     22         self.modifier(FlippedDirection())
     23     }
     24 }
     25 // MARK: -
     26 struct FlippedLeftRight: ViewModifier {
     27     func body(content: Content) -> some View {
     28         content
     29             .rotationEffect(.radians(Double.pi))
     30             .scaleEffect(x: 1, y: -1, anchor: .center)
     31     }
     32 }
     33 
     34 extension View {
     35     func flippedLeftRight() -> some View {
     36         modifier(FlippedLeftRight())
     37     }
     38 }
     39 // MARK: -
     40 struct FlippedUpsideDown: ViewModifier {
     41     func body(content: Content) -> some View {
     42         content
     43             .rotationEffect(.radians(Double.pi))
     44             .scaleEffect(x: -1, y: 1, anchor: .center)
     45     }
     46 }
     47 
     48 extension View {
     49     func flippedUpsideDown() -> some View {
     50         modifier(FlippedUpsideDown())
     51     }
     52 }
     53 
     54 
     55 // Used to reverse the direction of a ScrollView
     56 // need to flip both the ScrollView and each list item
     57 // inspired by https://stackoverflow.com/questions/61520970/swiftui-reverse-scrollview-from-bottom-to-top
     58 //
     59 //Apple has an API when using iOS 17+
     60 //    ScrollView() {
     61 //        // content
     62 //    }
     63 //        .defaultScrollAnchor(.bottom)