From 99c035146cfdd3833fee735c01517ea66ce561f0 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Thu, 21 Mar 2024 17:45:51 -0300 Subject: [PATCH] New toolbar for WatchOS 10 --- ios/RocketChat Watch App/AppView.swift | 2 +- .../ToolbarItemPlacement+Extensions.swift | 11 +++++ .../Views/MessageView.swift | 4 +- .../Views/NavigationCompatibleView.swift | 21 ++++++++++ .../Views/ServerListView.swift | 40 ++++++++++++------- ios/RocketChatRN.xcodeproj/project.pbxproj | 12 ++++++ 6 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 ios/RocketChat Watch App/Extensions/ToolbarItemPlacement+Extensions.swift create mode 100644 ios/RocketChat Watch App/Views/NavigationCompatibleView.swift diff --git a/ios/RocketChat Watch App/AppView.swift b/ios/RocketChat Watch App/AppView.swift index 4aff4df63..ea5200411 100644 --- a/ios/RocketChat Watch App/AppView.swift +++ b/ios/RocketChat Watch App/AppView.swift @@ -12,7 +12,7 @@ struct AppView: View { } var body: some View { - NavigationView { + NavigationCompatibleView { switch router.route { case .loading: ProgressView() diff --git a/ios/RocketChat Watch App/Extensions/ToolbarItemPlacement+Extensions.swift b/ios/RocketChat Watch App/Extensions/ToolbarItemPlacement+Extensions.swift new file mode 100644 index 000000000..359bea7d6 --- /dev/null +++ b/ios/RocketChat Watch App/Extensions/ToolbarItemPlacement+Extensions.swift @@ -0,0 +1,11 @@ +import SwiftUI + +extension ToolbarItemPlacement { + static var `default`: Self { + if #available(watchOS 10.0, *) { + return .topBarLeading + } else { + return .automatic + } + } +} diff --git a/ios/RocketChat Watch App/Views/MessageView.swift b/ios/RocketChat Watch App/Views/MessageView.swift index 07a8be6b9..547f4fda9 100644 --- a/ios/RocketChat Watch App/Views/MessageView.swift +++ b/ios/RocketChat Watch App/Views/MessageView.swift @@ -76,7 +76,7 @@ struct MessageView: View { .foregroundStyle(.secondary) } } - .padding(.bottom, 4) + .padding(.bottom, 2) } if let text = viewModel.info { (Text("\(viewModel.sender ?? "") ").font(.caption.bold().italic()) + Text(text).font(.caption.italic())) @@ -114,7 +114,7 @@ struct MessageView: View { } } } - .padding(.top, 8) + .padding(.top, 4) .sheet(item: $message) { message in MessageActionView( message: message, diff --git a/ios/RocketChat Watch App/Views/NavigationCompatibleView.swift b/ios/RocketChat Watch App/Views/NavigationCompatibleView.swift new file mode 100644 index 000000000..7fe57ddeb --- /dev/null +++ b/ios/RocketChat Watch App/Views/NavigationCompatibleView.swift @@ -0,0 +1,21 @@ +import SwiftUI + +struct NavigationCompatibleView: View { + private let content: () -> Content + + init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } + + var body: some View { + if #available(watchOS 10.0, *) { + NavigationStack { + content() + } + } else { + NavigationView { + content() + } + } + } +} diff --git a/ios/RocketChat Watch App/Views/ServerListView.swift b/ios/RocketChat Watch App/Views/ServerListView.swift index af1621c9b..23e6fc9ab 100644 --- a/ios/RocketChat Watch App/Views/ServerListView.swift +++ b/ios/RocketChat Watch App/Views/ServerListView.swift @@ -21,20 +21,20 @@ struct ServerListView: View { @ViewBuilder private var serverList: some View { - List { - ForEach(servers.sort()) { server in - ServerView(server: server) - .onTapGesture { - router.route(to: .roomList(server)) - } - } - } - .toolbar { - ToolbarItem(placement: .automatic) { - Button("Refresh") { - loadServers() + List(servers.sort()) { server in + ServerView(server: server) + .onTapGesture { + router.route(to: .roomList(server)) } - } + } + } + + @ViewBuilder + private var refreshLabel: some View { + if #available(watchOS 10.0, *) { + Image(systemName: "gobackward") + } else { + Text("Refresh") } } @@ -59,7 +59,19 @@ struct ServerListView: View { RetryView("Unexpected error.", action: loadServers) } } - .navigationTitle("Servers") + .navigationTitle { + Text("Servers").foregroundColor(.red) + } + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .default) { + Button { + loadServers() + } label: { + refreshLabel + } + } + } .onAppear { loadServers() } diff --git a/ios/RocketChatRN.xcodeproj/project.pbxproj b/ios/RocketChatRN.xcodeproj/project.pbxproj index 6b349ef7e..b00e5417f 100644 --- a/ios/RocketChatRN.xcodeproj/project.pbxproj +++ b/ios/RocketChatRN.xcodeproj/project.pbxproj @@ -257,6 +257,10 @@ 1EDFD0FA2B589B8F002FEE5F /* MessagesLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EDFD0F92B589B8F002FEE5F /* MessagesLoader.swift */; }; 1EDFD1062B58A66E002FEE5F /* CancelBag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EDFD1052B58A66E002FEE5F /* CancelBag.swift */; }; 1EDFD1082B58AA77002FEE5F /* RoomsLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EDFD1072B58AA77002FEE5F /* RoomsLoader.swift */; }; + 1EE096F72BACD1E400780078 /* NavigationCompatibleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EE096F62BACD1E400780078 /* NavigationCompatibleView.swift */; }; + 1EE096F82BACD1E400780078 /* NavigationCompatibleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EE096F62BACD1E400780078 /* NavigationCompatibleView.swift */; }; + 1EE096FA2BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EE096F92BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift */; }; + 1EE096FB2BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EE096F92BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift */; }; 1EF5FBD1250C109E00614FEA /* Encryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EF5FBD0250C109E00614FEA /* Encryption.swift */; }; 1EFEB5982493B6640072EDC0 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EFEB5972493B6640072EDC0 /* NotificationService.swift */; }; 1EFEB59C2493B6640072EDC0 /* NotificationService.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 1EFEB5952493B6640072EDC0 /* NotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -566,6 +570,8 @@ 1EDFD0F92B589B8F002FEE5F /* MessagesLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesLoader.swift; sourceTree = ""; }; 1EDFD1052B58A66E002FEE5F /* CancelBag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBag.swift; sourceTree = ""; }; 1EDFD1072B58AA77002FEE5F /* RoomsLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomsLoader.swift; sourceTree = ""; }; + 1EE096F62BACD1E400780078 /* NavigationCompatibleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationCompatibleView.swift; sourceTree = ""; }; + 1EE096F92BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ToolbarItemPlacement+Extensions.swift"; sourceTree = ""; }; 1EF5FBD0250C109E00614FEA /* Encryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encryption.swift; sourceTree = ""; }; 1EFEB5952493B6640072EDC0 /* NotificationService.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationService.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 1EFEB5972493B6640072EDC0 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; @@ -808,6 +814,7 @@ children = ( 1E29A31C2B5871B60093C03C /* Date+Extensions.swift */, 1E675B712BAC49B000438590 /* Color+Extensions.swift */, + 1EE096F92BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift */, ); path = Extensions; sourceTree = ""; @@ -953,6 +960,7 @@ 1E638E982B5F0A2900E645E4 /* ChatScrollView.swift */, 1E06561C2B7E9C1C0081B01F /* MessageActionView.swift */, 1E388AC02B934CD4006FBDB0 /* RemoteImage.swift */, + 1EE096F62BACD1E400780078 /* NavigationCompatibleView.swift */, ); path = Views; sourceTree = ""; @@ -2060,7 +2068,9 @@ 1E29A3242B5874FF0093C03C /* MessageComposerView.swift in Sources */, 1EB375892B55DBFB00AEC3D7 /* Server.swift in Sources */, 1E06561D2B7E9C1C0081B01F /* MessageActionView.swift in Sources */, + 1EE096FA2BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift in Sources */, 1E29A3162B5868DF0093C03C /* MessageListView.swift in Sources */, + 1EE096F72BACD1E400780078 /* NavigationCompatibleView.swift in Sources */, 1E4AFC172B5AF09C00E2AA7D /* Store.swift in Sources */, 1ED1EC8B2B86817100F6620C /* Deeplink.swift in Sources */, 1E29A2F42B585B070093C03C /* SubscriptionsResponse.swift in Sources */, @@ -2140,7 +2150,9 @@ 1ED1EC902B86997F00F6620C /* MessageComposerView.swift in Sources */, 1ED1EC912B86997F00F6620C /* Server.swift in Sources */, 1ED1EC922B86997F00F6620C /* MessageActionView.swift in Sources */, + 1EE096FB2BACD1F200780078 /* ToolbarItemPlacement+Extensions.swift in Sources */, 1ED1EC932B86997F00F6620C /* MessageListView.swift in Sources */, + 1EE096F82BACD1E400780078 /* NavigationCompatibleView.swift in Sources */, 1ED1EC942B86997F00F6620C /* Store.swift in Sources */, 1ED1EC952B86997F00F6620C /* Deeplink.swift in Sources */, 1ED1EC962B86997F00F6620C /* SubscriptionsResponse.swift in Sources */,