From f780b9260e007af689989d2ddf99aa683e7ee178 Mon Sep 17 00:00:00 2001 From: vixer93 Date: Fri, 19 Jul 2024 01:31:49 +0900 Subject: [PATCH 1/2] Add timetable item card --- app-ios/Package.swift | 7 +- .../Resources/Media.xcassets/Contents.json | 6 ++ .../ic_favorite_fill.imageset/Contents.json | 15 +++ .../ic_favorite_fill.imageset/favorite.svg | 8 ++ .../Contents.json | 15 +++ .../ic_favorite_outline.svg | 8 ++ .../Timetable}/LanguageTag.swift | 6 +- .../Timetable}/RoomTag.swift | 8 +- .../Timetable/TimetableItemView.swift | 96 +++++++++++++++++++ 9 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 app-ios/Sources/CommonComponents/Resources/Media.xcassets/Contents.json create mode 100644 app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/Contents.json create mode 100644 app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/favorite.svg create mode 100644 app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/Contents.json create mode 100644 app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/ic_favorite_outline.svg rename app-ios/Sources/{TimetableDetailFeature/Component => CommonComponents/Timetable}/LanguageTag.swift (82%) rename app-ios/Sources/{TimetableDetailFeature/Component => CommonComponents/Timetable}/RoomTag.swift (91%) create mode 100644 app-ios/Sources/CommonComponents/Timetable/TimetableItemView.swift diff --git a/app-ios/Package.swift b/app-ios/Package.swift index a0286295a..aca912d67 100644 --- a/app-ios/Package.swift +++ b/app-ios/Package.swift @@ -42,6 +42,10 @@ let package = Package( name: "ContributorFeature", targets: ["ContributorFeature"] ), + .library( + name: "CommonComponents", + targets: ["CommonComponents"] + ), ], dependencies: [ .package(url: "https://github.com/pointfreeco/swift-composable-architecture.git", exact: "1.10.2"), @@ -94,6 +98,7 @@ let package = Package( .firebaseAuth, .firebaseRemoteConfig, .tca, + .commonComponents, ] ), .testTarget( @@ -198,7 +203,7 @@ let package = Package( .tca ] ), - .target(name: "CommonComponents", dependencies: [.theme]), + .target(name: "CommonComponents", dependencies: [.theme, .kmpModule]), // Please run ./gradlew app-ios-shared:assembleSharedXCFramework first .binaryTarget(name: "KmpModule", path: "../app-ios-shared/build/XCFrameworks/debug/shared.xcframework"), ] diff --git a/app-ios/Sources/CommonComponents/Resources/Media.xcassets/Contents.json b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/Contents.json b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/Contents.json new file mode 100644 index 000000000..3a36c12e6 --- /dev/null +++ b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "favorite.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "preserves-vector-representation" : true + } +} diff --git a/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/favorite.svg b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/favorite.svg new file mode 100644 index 000000000..e3fbd7e6a --- /dev/null +++ b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_fill.imageset/favorite.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/Contents.json b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/Contents.json new file mode 100644 index 000000000..0a1fa3779 --- /dev/null +++ b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "ic_favorite_outline.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "preserves-vector-representation" : true + } +} diff --git a/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/ic_favorite_outline.svg b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/ic_favorite_outline.svg new file mode 100644 index 000000000..c4eefef24 --- /dev/null +++ b/app-ios/Sources/CommonComponents/Resources/Media.xcassets/ic_favorite_outline.imageset/ic_favorite_outline.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app-ios/Sources/TimetableDetailFeature/Component/LanguageTag.swift b/app-ios/Sources/CommonComponents/Timetable/LanguageTag.swift similarity index 82% rename from app-ios/Sources/TimetableDetailFeature/Component/LanguageTag.swift rename to app-ios/Sources/CommonComponents/Timetable/LanguageTag.swift index bb84d2f3d..1f144f04f 100644 --- a/app-ios/Sources/TimetableDetailFeature/Component/LanguageTag.swift +++ b/app-ios/Sources/CommonComponents/Timetable/LanguageTag.swift @@ -1,14 +1,14 @@ import SwiftUI import Theme -struct LanguageTag: View { +public struct LanguageTag: View { let languageLabel: String - init(_ languageLabel: String) { + public init(_ languageLabel: String) { self.languageLabel = languageLabel } - var body: some View { + public var body: some View { Text(languageLabel) .textStyle(.labelMedium) .foregroundStyle(AssetColors.Surface.onSurfaceVariant.swiftUIColor) diff --git a/app-ios/Sources/TimetableDetailFeature/Component/RoomTag.swift b/app-ios/Sources/CommonComponents/Timetable/RoomTag.swift similarity index 91% rename from app-ios/Sources/TimetableDetailFeature/Component/RoomTag.swift rename to app-ios/Sources/CommonComponents/Timetable/RoomTag.swift index 778ae4863..308891593 100644 --- a/app-ios/Sources/TimetableDetailFeature/Component/RoomTag.swift +++ b/app-ios/Sources/CommonComponents/Timetable/RoomTag.swift @@ -1,8 +1,8 @@ import SwiftUI import Theme -struct RoomTag: View { - enum Room { +public struct RoomTag: View { + public enum Room { case arcticFox case bumblebee case chipmunk @@ -12,11 +12,11 @@ struct RoomTag: View { let room: Room - init(_ room: Room) { + public init(_ room: Room) { self.room = room } - var body: some View { + public var body: some View { HStack(spacing: 5) { Rectangle() .frame(width: 10, height: 10) diff --git a/app-ios/Sources/CommonComponents/Timetable/TimetableItemView.swift b/app-ios/Sources/CommonComponents/Timetable/TimetableItemView.swift new file mode 100644 index 000000000..b3abf7fa5 --- /dev/null +++ b/app-ios/Sources/CommonComponents/Timetable/TimetableItemView.swift @@ -0,0 +1,96 @@ +import SwiftUI +import Theme +import class shared.TimetableItem + +public struct TimetableItemView: View { + let timetableItem: TimetableItem + let isFavorite: Bool + let onTap: (TimetableItem) -> Void + let onTapFavorite: (TimetableItem) -> Void + + public init( + timetableItem: TimetableItem, + isFavorite: Bool, + onTap: @escaping (TimetableItem) -> Void, + onTapFavorite: @escaping (TimetableItem) -> Void + ) { + self.timetableItem = timetableItem + self.isFavorite = isFavorite + self.onTap = onTap + self.onTapFavorite = onTapFavorite + } + + public var body: some View { + Button { + onTap(timetableItem) + } label: { + VStack(alignment: .leading, spacing: 8) { + HStack(spacing: 4) { + RoomTag(.arcticFox) + ForEach(timetableItem.language.labels, id: \.self) { label in + LanguageTag(label) + } + Spacer() + Button { + onTapFavorite(timetableItem) + } label: { + Image(isFavorite ? .icFavoriteFill : .icFavoriteOutline) + .resizable() + .renderingMode(.template) + .foregroundColor( + isFavorite ? + AssetColors.Primary.primaryFixed.swiftUIColor + : + AssetColors.Surface.onSurfaceVariant.swiftUIColor + ) + .frame(width: 24, height: 24) + } + } + + Text(timetableItem.title.currentLangTitle) + .textStyle(.titleMedium) + .foregroundColor(AssetColors.Surface.onSurface.swiftUIColor) + .multilineTextAlignment(.leading) + + ForEach(timetableItem.speakers, id: \.id) { speaker in + HStack(spacing: 8) { + Group { + if let url = URL(string: speaker.iconUrl) { + AsyncImage(url: url) { + $0.image?.resizable() + } + } else { + Circle().stroke(Color.gray) + } + } + .frame(width: 32, height: 32) + .clipShape(Circle()) + + Text(speaker.name) + .textStyle(.titleSmall) + .foregroundStyle(AssetColors.Surface.onSurfaceVariant.swiftUIColor) + .lineLimit(1) + } + } + } + .frame(maxWidth: .infinity) + .padding(12) + .background(AssetColors.Surface.surface.swiftUIColor, in: RoundedRectangle(cornerRadius: 4)) + .overlay(RoundedRectangle(cornerRadius: 4).stroke(AssetColors.Outline.outlineVariant.swiftUIColor, lineWidth: 1)) + } + } +} + +#Preview { + VStack { + TimetableItemView( + timetableItem: TimetableItem.Session.companion.fake(), + isFavorite: true, + onTap: { _ in }, + onTapFavorite: { _ in } + ) + .padding(.horizontal, 16) + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(Color.black) +} From b8474fb15018fb269e29de02493925a9f02f8c71 Mon Sep 17 00:00:00 2001 From: vixer93 Date: Fri, 19 Jul 2024 20:26:29 +0900 Subject: [PATCH 2/2] Fix for comment --- .../{TimetableItemView.swift => TimetableCard.swift} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename app-ios/Sources/CommonComponents/Timetable/{TimetableItemView.swift => TimetableCard.swift} (98%) diff --git a/app-ios/Sources/CommonComponents/Timetable/TimetableItemView.swift b/app-ios/Sources/CommonComponents/Timetable/TimetableCard.swift similarity index 98% rename from app-ios/Sources/CommonComponents/Timetable/TimetableItemView.swift rename to app-ios/Sources/CommonComponents/Timetable/TimetableCard.swift index b3abf7fa5..d9661bbfb 100644 --- a/app-ios/Sources/CommonComponents/Timetable/TimetableItemView.swift +++ b/app-ios/Sources/CommonComponents/Timetable/TimetableCard.swift @@ -2,7 +2,7 @@ import SwiftUI import Theme import class shared.TimetableItem -public struct TimetableItemView: View { +public struct TimetableCard: View { let timetableItem: TimetableItem let isFavorite: Bool let onTap: (TimetableItem) -> Void @@ -83,7 +83,7 @@ public struct TimetableItemView: View { #Preview { VStack { - TimetableItemView( + TimetableCard( timetableItem: TimetableItem.Session.companion.fake(), isFavorite: true, onTap: { _ in },