diff --git a/ios/RocketChat Watch App/Views/ChatScrollView.swift b/ios/RocketChat Watch App/Views/ChatScrollView.swift new file mode 100644 index 000000000..d500af706 --- /dev/null +++ b/ios/RocketChat Watch App/Views/ChatScrollView.swift @@ -0,0 +1,28 @@ +import SwiftUI + +/// We need to reverse the scroll view to make it look like a Chat list. +/// Since we want to support older WatchOS versions, we made this wrapper to rotate the scroll view, when we can't use defaultScrollAnchor modifier. +/// It should do the trick for older WatchOS versions and have the native implementation for newer ones. +/// We hide the indicators for the flipped scroll view, since they appear reversed. +struct ChatScrollView: View { + private let content: () -> Content + + init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } + + var body: some View { + if #available(watchOS 10.0, *) { + ScrollView { + content() + } + .defaultScrollAnchor(.bottom) + } else { + ScrollView(showsIndicators: false) { + content() + .rotationEffect(.degrees(180)) + } + .rotationEffect(.degrees(180)) + } + } +} diff --git a/ios/RocketChat Watch App/Views/MessageListView.swift b/ios/RocketChat Watch App/Views/MessageListView.swift index e0b747c13..a2a88bf70 100644 --- a/ios/RocketChat Watch App/Views/MessageListView.swift +++ b/ios/RocketChat Watch App/Views/MessageListView.swift @@ -11,7 +11,6 @@ struct MessageListView: View { private let server: Server private let room: Room - @State private var lastMessageID: String? @State private var lastOpen: Date? @FetchRequest private var messages: FetchedResults @@ -37,7 +36,7 @@ struct MessageListView: View { var body: some View { ScrollViewReader { reader in - ScrollView { + ChatScrollView { LazyVStack(alignment: .leading, spacing: 8) { if room.hasMoreMessages { Button("Load More...") { @@ -77,12 +76,6 @@ struct MessageListView: View { .onDisappear { messagesLoader.stop() } - .onReceive(messages.publisher) { _ in - if lastMessageID != messages.last?.id { - reader.scrollTo(messageComposer, anchor: .bottom) - lastMessageID = messages.last?.id - } - } } } } diff --git a/ios/RocketChatRN.xcodeproj/project.pbxproj b/ios/RocketChatRN.xcodeproj/project.pbxproj index f24f0ec76..ace1ac7a3 100644 --- a/ios/RocketChatRN.xcodeproj/project.pbxproj +++ b/ios/RocketChatRN.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 1E598AE42515057D002BDFBD /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E598AE32515057D002BDFBD /* Date+Extensions.swift */; }; 1E598AE725150660002BDFBD /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E598AE625150660002BDFBD /* Data+Extensions.swift */; }; 1E598AE925151A63002BDFBD /* SendMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E598AE825151A63002BDFBD /* SendMessage.swift */; }; + 1E638E992B5F0A2900E645E4 /* ChatScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E638E982B5F0A2900E645E4 /* ChatScrollView.swift */; }; 1E67380424DC529B0009E081 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E67380324DC529B0009E081 /* String+Extensions.swift */; }; 1E680ED92512990700C9257A /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E680ED82512990700C9257A /* Request.swift */; }; 1E6CC61F2513DBF400965591 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7A006F13229C83B600803143 /* GoogleService-Info.plist */; }; @@ -399,6 +400,7 @@ 1E598AE32515057D002BDFBD /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = ""; }; 1E598AE625150660002BDFBD /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = ""; }; 1E598AE825151A63002BDFBD /* SendMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendMessage.swift; sourceTree = ""; }; + 1E638E982B5F0A2900E645E4 /* ChatScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatScrollView.swift; sourceTree = ""; }; 1E6737FF24DC52660009E081 /* NotificationService-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NotificationService-Bridging-Header.h"; sourceTree = ""; }; 1E67380324DC529B0009E081 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; 1E680ED82512990700C9257A /* Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = ""; }; @@ -792,6 +794,7 @@ 1E9A716E2B59CBCA00477BA2 /* AttachmentView.swift */, 1E4AFC262B5B23C600E2AA7D /* RetryView.swift */, 1EDB30F12B5B453A00532C7E /* LoggedInView.swift */, + 1E638E982B5F0A2900E645E4 /* ChatScrollView.swift */, ); path = Views; sourceTree = ""; @@ -1904,6 +1907,7 @@ 1ED038912B507B4C00C007D4 /* RocketChatApp.swift in Sources */, 1E29A2CC2B5857F50093C03C /* RoomListView.swift in Sources */, 1E29A31A2B5868EE0093C03C /* MessageViewModel.swift in Sources */, + 1E638E992B5F0A2900E645E4 /* ChatScrollView.swift in Sources */, 1ED033C42B55C65C004F4930 /* AppRouter.swift in Sources */, 1ED033B02B55B25A004F4930 /* Database.swift in Sources */, 1E9A71712B59CC1300477BA2 /* Attachment.swift in Sources */,