From e3608db6347be2950dbd61bd7c300e89bfde44c2 Mon Sep 17 00:00:00 2001 From: macmade Date: Sat, 14 Dec 2024 19:53:53 +0100 Subject: [PATCH] feat(Watch): Info sheet --- SDO-Mobile.xcodeproj/project.pbxproj | 8 +++ SDO-Watch/Views/ContentView.swift | 27 ++++++++-- SDO-Watch/Views/InfoDetailView.swift | 48 ++++++++++++++++++ SDO-Watch/Views/InfoView.swift | 73 ++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 SDO-Watch/Views/InfoDetailView.swift create mode 100644 SDO-Watch/Views/InfoView.swift diff --git a/SDO-Mobile.xcodeproj/project.pbxproj b/SDO-Mobile.xcodeproj/project.pbxproj index 1372fec..4c78320 100644 --- a/SDO-Mobile.xcodeproj/project.pbxproj +++ b/SDO-Mobile.xcodeproj/project.pbxproj @@ -39,6 +39,8 @@ 054DE7C32D0DE37900A52D1A /* SDOApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 054DE7C02D0DE37900A52D1A /* SDOApp.swift */; }; 054DE7C42D0DE41600A52D1A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 054DE6F82D0DD66F00A52D1A /* Preview Assets.xcassets */; }; 054DE7C62D0DE54500A52D1A /* TextButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 054DE71B2D0DD7FE00A52D1A /* TextButtonView.swift */; }; + 054DE7C82D0E08DC00A52D1A /* InfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 054DE7C72D0E08D900A52D1A /* InfoView.swift */; }; + 054DE7CC2D0E0AD800A52D1A /* InfoDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 054DE7CB2D0E0AD200A52D1A /* InfoDetailView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -140,6 +142,8 @@ 054DE7712D0DDBB000A52D1A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = Info.plist; sourceTree = ""; }; 054DE7BF2D0DE37900A52D1A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 054DE7C02D0DE37900A52D1A /* SDOApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDOApp.swift; sourceTree = ""; }; + 054DE7C72D0E08D900A52D1A /* InfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoView.swift; sourceTree = ""; }; + 054DE7CB2D0E0AD200A52D1A /* InfoDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoDetailView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -388,6 +392,8 @@ isa = PBXGroup; children = ( 054DE7BF2D0DE37900A52D1A /* ContentView.swift */, + 054DE7C72D0E08D900A52D1A /* InfoView.swift */, + 054DE7CB2D0E0AD200A52D1A /* InfoDetailView.swift */, 054DE7C02D0DE37900A52D1A /* SDOApp.swift */, ); path = Views; @@ -531,8 +537,10 @@ 054DE7A22D0DDFEB00A52D1A /* ImageInfo.swift in Sources */, 054DE7A32D0DDFEB00A52D1A /* SDO.swift in Sources */, 054DE7A42D0DDFEB00A52D1A /* ImageData.swift in Sources */, + 054DE7CC2D0E0AD800A52D1A /* InfoDetailView.swift in Sources */, 054DE7BC2D0DE27F00A52D1A /* PreviewData.swift in Sources */, 054DE7A52D0DDFEB00A52D1A /* RuntimeError.swift in Sources */, + 054DE7C82D0E08DC00A52D1A /* InfoView.swift in Sources */, 054DE7C62D0DE54500A52D1A /* TextButtonView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/SDO-Watch/Views/ContentView.swift b/SDO-Watch/Views/ContentView.swift index 92d3582..b89b99c 100644 --- a/SDO-Watch/Views/ContentView.swift +++ b/SDO-Watch/Views/ContentView.swift @@ -29,6 +29,7 @@ struct ContentView: View @State private var images: [ ImageData ] = [] @State private var lastRefresh = Date() @State private var isLoading = false + @State private var isShowingInfoSheet = false var body: some View { @@ -67,12 +68,28 @@ struct ContentView: View ForEach( self.images, id: \.uuid ) { - if let image = $0.image + info in if let image = info.image { - Image( uiImage: image ) - .resizable() - .aspectRatio( contentMode: .fill ) - Text( $0.title ) + VStack + { + Button() + { + self.isShowingInfoSheet = true + } + label: + { + Image( uiImage: image ) + .resizable() + .aspectRatio( contentMode: .fill ) + } + .disabled( info.text == nil ) + .sheet( isPresented: $isShowingInfoSheet ) + { + InfoView( image: info ).padding( .horizontal ) + } + } + .buttonStyle( .borderless ) + Text( info.title ) .font( .caption2 ) .bold() .multilineTextAlignment( .center ) diff --git a/SDO-Watch/Views/InfoDetailView.swift b/SDO-Watch/Views/InfoDetailView.swift new file mode 100644 index 0000000..289cd27 --- /dev/null +++ b/SDO-Watch/Views/InfoDetailView.swift @@ -0,0 +1,48 @@ +/******************************************************************************* + * The MIT License (MIT) + * + * Copyright (c) 2023, Jean-David Gadina - www.xs-labs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +import SwiftUI + +struct InfoDetailView: View +{ + @State public var title: String + @State public var text: String + + var body: some View + { + VStack( alignment: .leading ) + { + Text( self.title ) + .font( .caption ) + .foregroundStyle( .secondary ) + Text( self.text ) + .font( .caption ) + } + } +} + +#Preview +{ + InfoDetailView( title: "Lorem ipsum:", text: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit" ).padding() +} diff --git a/SDO-Watch/Views/InfoView.swift b/SDO-Watch/Views/InfoView.swift new file mode 100644 index 0000000..3b8d7b9 --- /dev/null +++ b/SDO-Watch/Views/InfoView.swift @@ -0,0 +1,73 @@ +/******************************************************************************* + * The MIT License (MIT) + * + * Copyright (c) 2023, Jean-David Gadina - www.xs-labs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +import SwiftUI + +struct InfoView: View +{ + @State public var image: ImageData + + var body: some View + { + ScrollView + { + VStack( alignment: .leading, spacing: 10 ) + { + Text( self.image.title ) + .font( .title3 ) + .bold() + + if let text = self.image.text + { + Text( text ) + } + + if let location = self.image.location + { + InfoDetailView( title: "Where:", text: location ) + } + + if let wavelength = self.image.wavelength + { + InfoDetailView( title: "Wavelength:", text: wavelength ) + } + + if let ions = self.image.ions + { + InfoDetailView( title: "Primary Ions Seen:", text: ions ) + } + + if let temperature = self.image.temperature + { + InfoDetailView( title: "Characteristic Temperature:", text: temperature ) + } + } + } + } +} + +#Preview +{ + InfoView( image: PreviewData.images.first! ) +}