From 4878fbad464b8e45a6419c4fe97e3ed091a740f8 Mon Sep 17 00:00:00 2001 From: Kilian Koeltzsch Date: Sun, 14 Feb 2021 13:33:21 +0100 Subject: [PATCH 1/2] Introduce FlipGroup w/ BorderlessMessageView --- Nio.xcodeproj/project.pbxproj | 4 ++ .../MessageView/BorderlessMessageView.swift | 12 +----- Nio/Shared Views/FlipGroup.swift | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 Nio/Shared Views/FlipGroup.swift diff --git a/Nio.xcodeproj/project.pbxproj b/Nio.xcodeproj/project.pbxproj index b79b4595..99e49715 100644 --- a/Nio.xcodeproj/project.pbxproj +++ b/Nio.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ 392389CC238EBB1500B2E1DF /* ReverseList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392389CB238EBB1400B2E1DF /* ReverseList.swift */; }; 393411D1239087D2003B49B8 /* EventCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 393411D0239087D2003B49B8 /* EventCollectionTests.swift */; }; 3964D5D625C4BB8600617C35 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3964D5CC25C4BB0200617C35 /* Configuration.swift */; }; + 396F072F25D94BEC00C9907A /* FlipGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396F072E25D94BEC00C9907A /* FlipGroup.swift */; }; 3984654523B7ECBA006C173B /* MXURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3984654423B7ECBA006C173B /* MXURL.swift */; }; 3984654823B8D809006C173B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 3984654723B8D809006C173B /* SDWebImageSwiftUI */; }; 39B834C0243FC42000AE1EA0 /* TypingIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B834BF243FC42000AE1EA0 /* TypingIndicatorView.swift */; }; @@ -234,6 +235,7 @@ 3955DD36245C371C00827F07 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 395DDC1825C0C2D6002FC413 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/Localizable.strings; sourceTree = ""; }; 3964D5CC25C4BB0200617C35 /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; + 396F072E25D94BEC00C9907A /* FlipGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlipGroup.swift; sourceTree = ""; }; 3984654423B7ECBA006C173B /* MXURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXURL.swift; sourceTree = ""; }; 3997DCCF245732F000763C07 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = ""; }; 39B834BF243FC42000AE1EA0 /* TypingIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypingIndicatorView.swift; sourceTree = ""; }; @@ -474,6 +476,7 @@ A51F762B25D6E9950061B4A4 /* MessageTextViewWrapper.swift */, CAAF5BF72478696F006FDC33 /* UITextViewWrapper.swift */, 4B29F5B42466EC240084043B /* ImagePicker.swift */, + 396F072E25D94BEC00C9907A /* FlipGroup.swift */, ); path = "Shared Views"; sourceTree = ""; @@ -1094,6 +1097,7 @@ CAFCB323245F6E6700869320 /* NSAttributedString+Extensions.swift in Sources */, CAF2AE892458EEBC00D84133 /* AttributedText.swift in Sources */, CAC46D5B23A2734C0079C24F /* EnvironmentValues.swift in Sources */, + 396F072F25D94BEC00C9907A /* FlipGroup.swift in Sources */, 39C932072384BB13004449E1 /* RecentRoomsView.swift in Sources */, CAC46D6F23A56BBE0079C24F /* GroupingIterator.swift in Sources */, 392221B2243D0CCC004D8794 /* RoomTopicEventView.swift in Sources */, diff --git a/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift b/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift index 7650c515..cb1ca3b3 100644 --- a/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift +++ b/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift @@ -87,22 +87,14 @@ struct BorderlessMessageView: View where Model: MessageViewModelProtocol var bodyView: some View { VStack(alignment: isMe ? .trailing : .leading, spacing: 0) { - if isMe { - HStack { - if !self.connectedEdges.contains(.bottomEdge) { - self.timestampView - } - self.conditionalBadgedContentView - } - } else { - HStack { + HStack { + FlipGroup(flippedIf: isMe) { self.conditionalBadgedContentView if !self.connectedEdges.contains(.bottomEdge) { self.timestampView } } } - GroupedReactionsView(reactions: model.reactions) } } diff --git a/Nio/Shared Views/FlipGroup.swift b/Nio/Shared Views/FlipGroup.swift new file mode 100644 index 00000000..b328c1f4 --- /dev/null +++ b/Nio/Shared Views/FlipGroup.swift @@ -0,0 +1,37 @@ +import SwiftUI + +// Credit goes to https://stackoverflow.com/a/62652866/1843020 + +// swiftlint:disable:next identifier_name +@ViewBuilder func FlipGroup( + flippedIf condition: Bool, + @ViewBuilder _ content: @escaping () -> TupleView<(V1, V2)> +) -> some View { + let pair = content() + if condition { + TupleView((pair.value.1, pair.value.0)) + } else { + TupleView((pair.value.0, pair.value.1)) + } +} + +struct FlipGroup_Previews: PreviewProvider { + static var previews: some View { + Group { + HStack { + FlipGroup(flippedIf: false) { + Text("A") + Text("B") + } + } + + HStack { + FlipGroup(flippedIf: true) { + Text("A") + Text("B") + } + } + } + .previewLayout(.sizeThatFits) + } +} From 94854c2b6f59201677e8fb7acf304cc176afc7af Mon Sep 17 00:00:00 2001 From: Kilian Koeltzsch Date: Tue, 16 Feb 2021 22:11:36 +0100 Subject: [PATCH 2/2] Rename FlipGroup to Flipped --- Nio.xcodeproj/project.pbxproj | 8 ++++---- .../Event Views/MessageView/BorderlessMessageView.swift | 2 +- Nio/Shared Views/{FlipGroup.swift => Flipped.swift} | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) rename Nio/Shared Views/{FlipGroup.swift => Flipped.swift} (81%) diff --git a/Nio.xcodeproj/project.pbxproj b/Nio.xcodeproj/project.pbxproj index 99e49715..e5ecb77f 100644 --- a/Nio.xcodeproj/project.pbxproj +++ b/Nio.xcodeproj/project.pbxproj @@ -35,7 +35,7 @@ 392389CC238EBB1500B2E1DF /* ReverseList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392389CB238EBB1400B2E1DF /* ReverseList.swift */; }; 393411D1239087D2003B49B8 /* EventCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 393411D0239087D2003B49B8 /* EventCollectionTests.swift */; }; 3964D5D625C4BB8600617C35 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3964D5CC25C4BB0200617C35 /* Configuration.swift */; }; - 396F072F25D94BEC00C9907A /* FlipGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396F072E25D94BEC00C9907A /* FlipGroup.swift */; }; + 396F072F25D94BEC00C9907A /* Flipped.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396F072E25D94BEC00C9907A /* Flipped.swift */; }; 3984654523B7ECBA006C173B /* MXURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3984654423B7ECBA006C173B /* MXURL.swift */; }; 3984654823B8D809006C173B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 3984654723B8D809006C173B /* SDWebImageSwiftUI */; }; 39B834C0243FC42000AE1EA0 /* TypingIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B834BF243FC42000AE1EA0 /* TypingIndicatorView.swift */; }; @@ -235,7 +235,7 @@ 3955DD36245C371C00827F07 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 395DDC1825C0C2D6002FC413 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/Localizable.strings; sourceTree = ""; }; 3964D5CC25C4BB0200617C35 /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; - 396F072E25D94BEC00C9907A /* FlipGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlipGroup.swift; sourceTree = ""; }; + 396F072E25D94BEC00C9907A /* Flipped.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Flipped.swift; sourceTree = ""; }; 3984654423B7ECBA006C173B /* MXURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXURL.swift; sourceTree = ""; }; 3997DCCF245732F000763C07 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = ""; }; 39B834BF243FC42000AE1EA0 /* TypingIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypingIndicatorView.swift; sourceTree = ""; }; @@ -476,7 +476,7 @@ A51F762B25D6E9950061B4A4 /* MessageTextViewWrapper.swift */, CAAF5BF72478696F006FDC33 /* UITextViewWrapper.swift */, 4B29F5B42466EC240084043B /* ImagePicker.swift */, - 396F072E25D94BEC00C9907A /* FlipGroup.swift */, + 396F072E25D94BEC00C9907A /* Flipped.swift */, ); path = "Shared Views"; sourceTree = ""; @@ -1097,7 +1097,7 @@ CAFCB323245F6E6700869320 /* NSAttributedString+Extensions.swift in Sources */, CAF2AE892458EEBC00D84133 /* AttributedText.swift in Sources */, CAC46D5B23A2734C0079C24F /* EnvironmentValues.swift in Sources */, - 396F072F25D94BEC00C9907A /* FlipGroup.swift in Sources */, + 396F072F25D94BEC00C9907A /* Flipped.swift in Sources */, 39C932072384BB13004449E1 /* RecentRoomsView.swift in Sources */, CAC46D6F23A56BBE0079C24F /* GroupingIterator.swift in Sources */, 392221B2243D0CCC004D8794 /* RoomTopicEventView.swift in Sources */, diff --git a/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift b/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift index cb1ca3b3..3a20557d 100644 --- a/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift +++ b/Nio/Conversations/Event Views/MessageView/BorderlessMessageView.swift @@ -88,7 +88,7 @@ struct BorderlessMessageView: View where Model: MessageViewModelProtocol var bodyView: some View { VStack(alignment: isMe ? .trailing : .leading, spacing: 0) { HStack { - FlipGroup(flippedIf: isMe) { + Flipped(if: isMe) { self.conditionalBadgedContentView if !self.connectedEdges.contains(.bottomEdge) { self.timestampView diff --git a/Nio/Shared Views/FlipGroup.swift b/Nio/Shared Views/Flipped.swift similarity index 81% rename from Nio/Shared Views/FlipGroup.swift rename to Nio/Shared Views/Flipped.swift index b328c1f4..c0e94183 100644 --- a/Nio/Shared Views/FlipGroup.swift +++ b/Nio/Shared Views/Flipped.swift @@ -3,8 +3,8 @@ import SwiftUI // Credit goes to https://stackoverflow.com/a/62652866/1843020 // swiftlint:disable:next identifier_name -@ViewBuilder func FlipGroup( - flippedIf condition: Bool, +@ViewBuilder func Flipped( + if condition: Bool, @ViewBuilder _ content: @escaping () -> TupleView<(V1, V2)> ) -> some View { let pair = content() @@ -19,14 +19,14 @@ struct FlipGroup_Previews: PreviewProvider { static var previews: some View { Group { HStack { - FlipGroup(flippedIf: false) { + Flipped(if: false) { Text("A") Text("B") } } HStack { - FlipGroup(flippedIf: true) { + Flipped(if: true) { Text("A") Text("B") }