From bb604a0c95fe344a5a5f4392c6bd33bc941b2ce5 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 1 Mar 2022 21:52:16 -0600 Subject: Failed to add horizontal scroll to events table --- iosApp/iosApp.xcodeproj/project.pbxproj | 4 +++ .../xcshareddata/swiftpm/Package.resolved | 6 ++-- .../iosApp/Details/Reports/UnitReportsView.swift | 24 ++++++++----- iosApp/iosApp/Shared/SidewaysScroller.swift | 42 ++++++++++++++++++++++ 4 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 iosApp/iosApp/Shared/SidewaysScroller.swift diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj index 8aefd98..8e5838d 100644 --- a/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 7555FF83242A565900829871 /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* RootView.swift */; }; E312E74F27B366060018C5DE /* DevicesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E312E74E27B366060018C5DE /* DevicesViewModel.swift */; }; E3141B8B27B9E91F00CE777C /* UnitReportsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3141B8A27B9E91F00CE777C /* UnitReportsViewModel.swift */; }; + E31D721527CF159900CDA320 /* SidewaysScroller.swift in Sources */ = {isa = PBXBuildFile; fileRef = E31D721427CF159900CDA320 /* SidewaysScroller.swift */; }; E3385A4F27B0D8A10025311C /* UnitCommandsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3385A4E27B0D8A10025311C /* UnitCommandsViewModel.swift */; }; E33A236027A4FD2C00DD647F /* UnitMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33A235F27A4FD2C00DD647F /* UnitMapView.swift */; }; E33A236527A530F300DD647F /* SmallLabelStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33A236427A530F300DD647F /* SmallLabelStyle.swift */; }; @@ -73,6 +74,7 @@ 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E312E74E27B366060018C5DE /* DevicesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevicesViewModel.swift; sourceTree = ""; }; E3141B8A27B9E91F00CE777C /* UnitReportsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitReportsViewModel.swift; sourceTree = ""; }; + E31D721427CF159900CDA320 /* SidewaysScroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidewaysScroller.swift; sourceTree = ""; }; E3385A4E27B0D8A10025311C /* UnitCommandsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitCommandsViewModel.swift; sourceTree = ""; }; E33A235F27A4FD2C00DD647F /* UnitMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitMapView.swift; sourceTree = ""; }; E33A236427A530F300DD647F /* SmallLabelStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallLabelStyle.swift; sourceTree = ""; }; @@ -268,6 +270,7 @@ E33A236627A64E4500DD647F /* MarkerTransformations.swift */, E33A237227A7581A00DD647F /* Utils.swift */, E34A2F4727A7878200AD8AEB /* HyperlinkText.swift */, + E31D721427CF159900CDA320 /* SidewaysScroller.swift */, ); path = Shared; sourceTree = ""; @@ -410,6 +413,7 @@ E3141B8B27B9E91F00CE777C /* UnitReportsViewModel.swift in Sources */, E38F242027A27B550069FC45 /* LoadingView.swift in Sources */, E38F241E27A270D50069FC45 /* UnitsView.swift in Sources */, + E31D721527CF159900CDA320 /* SidewaysScroller.swift in Sources */, 7555FF83242A565900829871 /* RootView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2b63f64..f925bad 100644 --- a/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -132,8 +132,8 @@ "repositoryURL": "https://github.com/openalloc/SwiftTabler", "state": { "branch": null, - "revision": "3a6c0ba6c1e1e9bcd29c2fb628dc7f1037307ec5", - "version": "0.6.0" + "revision": "03d8c9f20d34142b0bb9a31f15b3e6d8c47b39c7", + "version": "0.6.4" } }, { @@ -141,7 +141,7 @@ "repositoryURL": "https://github.com/ivan-avalos/SwiftUIX", "state": { "branch": "master", - "revision": "9b02351a947aa5ac1d2b3a5d576f9591960a89fc", + "revision": "fa1358cc48610d1de52de29111923a52e92a17d9", "version": null } } diff --git a/iosApp/iosApp/Details/Reports/UnitReportsView.swift b/iosApp/iosApp/Details/Reports/UnitReportsView.swift index 5a34ea5..9973189 100644 --- a/iosApp/iosApp/Details/Reports/UnitReportsView.swift +++ b/iosApp/iosApp/Details/Reports/UnitReportsView.swift @@ -33,15 +33,19 @@ struct UnitReportsView: View { wrappedValue: UnitReportsViewModel(deviceId: unit.device.id)) } + private var eventsConfig: TablerListConfig { + TablerListConfig(gridItems: eventsGridItems) + } + private var eventsGridItems: [GridItem] = [ - GridItem(.flexible(), alignment: .leading), - GridItem(.flexible(), alignment: .leading), - GridItem(.flexible(), alignment: .leading), - GridItem(.flexible(), alignment: .leading), + GridItem(.flexible(minimum: 100), alignment: .leading), + GridItem(.flexible(minimum: 100), alignment: .leading), + GridItem(.flexible(minimum: 100), alignment: .leading), + GridItem(.flexible(minimum: 100), alignment: .leading), ] @ViewBuilder - private func eventsHeader(_ ctx: TablerSortContext) -> some View { + private func eventsHeader(_ ctx: Binding>) -> some View { Text("events-table-datetime") Text("events-table-event") Text("events-table-geofence") @@ -90,10 +94,12 @@ struct UnitReportsView: View { VStack { if unitReportsViewModel.reportType == .events { if let report = unitReportsViewModel.report as? ReportController.ReportEventsReport { - TablerList(TablerListConfig(gridItems: eventsGridItems), - headerContent: eventsHeader, - rowContent: eventsRow, - results: report.events) + SidewaysScroller(minWidth: 400) { + TablerList(eventsConfig, + headerContent: eventsHeader, + rowContent: eventsRow, + results: report.events) + } } else { Spacer() } diff --git a/iosApp/iosApp/Shared/SidewaysScroller.swift b/iosApp/iosApp/Shared/SidewaysScroller.swift new file mode 100644 index 0000000..262b121 --- /dev/null +++ b/iosApp/iosApp/Shared/SidewaysScroller.swift @@ -0,0 +1,42 @@ +// +// SidewaysScroller.swift +// +// Copyright 2022 FlowAllocator LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +import SwiftUI + +/// wrap a view in a horizontal scroll view, for display of large tables on compact display area +public struct SidewaysScroller: View { + var minWidth: CGFloat + @ViewBuilder var content: () -> Content + + public init(minWidth: CGFloat, + @ViewBuilder content: @escaping () -> Content) + { + self.minWidth = minWidth + self.content = content + } + + public var body: some View { + GeometryReader { geo in + ScrollView(.horizontal) { + VStack(alignment: .leading) { + content() + } + .frame(minWidth: max(minWidth, geo.size.width)) + } + } + } +} -- cgit v1.2.3