Created
April 28, 2020 15:50
-
-
Save mattyoung/554794ff2d4d8d0871455f9ea6b9bf6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import SwiftUI | |
| struct UndoRightToLeftMirroring: ViewModifier { | |
| // @Environment(\.layoutDirection) var layoutDirection | |
| // @ViewBuilder | |
| func body(content: Content) -> some View { | |
| content // !!! Just do this undo the mirroring | |
| // VStack { | |
| // if layoutDirection == .leftToRight { | |
| // content | |
| // } else { | |
| // content | |
| //// .rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0)) // no effect here | |
| // } | |
| // | |
| // Text("\(self.layoutDirection == .leftToRight ? ".leftToRight" : ".rightToLeft")") | |
| // } | |
| } | |
| } | |
| struct RIghtToLeftLayoutOddnessWidget: View { | |
| @Environment(\.layoutDirection) var layoutDirection | |
| var isHorizontal: Bool | |
| func horizontal() -> some View { | |
| HStack { | |
| ForEach(9...11, id: \.self) { index in | |
| VStack { | |
| Text("\(index)") | |
| // .rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0)) // work here | |
| .modifier(UndoRightToLeftMirroring()) // but not inside modifier | |
| Color.green | |
| } | |
| } | |
| } | |
| } | |
| func vertical() -> some View { | |
| VStack { | |
| Color.blue | |
| Color.red | |
| } | |
| } | |
| @ViewBuilder | |
| var body: some View { | |
| VStack { | |
| if isHorizontal { | |
| horizontal() | |
| } else { | |
| vertical() | |
| } | |
| Text("\(self.layoutDirection == .leftToRight ? ".leftToRight" : ".rightToLeft")") | |
| } | |
| } | |
| } | |
| struct RIghtToLeftLayoutOddness: View { | |
| var body: some View { | |
| VStack { | |
| RIghtToLeftLayoutOddnessWidget(isHorizontal: true) | |
| RIghtToLeftLayoutOddnessWidget(isHorizontal: true) | |
| .environment(\.layoutDirection, .rightToLeft) | |
| } | |
| } | |
| } | |
| struct RIghtToLeftLayoutOddness_Previews: PreviewProvider { | |
| static var previews: some View { | |
| RIghtToLeftLayoutOddness() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment