-
Notifications
You must be signed in to change notification settings - Fork 0
Book Rate feature support #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
baekteun
wants to merge
1
commit into
feature/quote-add
Choose a base branch
from
feature/book-rate
base: feature/quote-add
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
ONMIR/Feature/BookDetail/BookRatingViewController.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import SwiftUI | ||
| import UIKit | ||
|
|
||
| struct BookRatingView: View { | ||
| let title: String | ||
| let initialRating: Double | ||
| let onRatingChanged: (Double) -> Void | ||
|
|
||
| @Environment(\.dismiss) var dismiss | ||
| @State private var currentRating: Double | ||
|
|
||
| init( | ||
| title: String, | ||
| initialRating: Double, | ||
| onRatingChanged: @escaping (Double) -> Void, | ||
| ) { | ||
| self.title = title | ||
| self.initialRating = initialRating | ||
| self.onRatingChanged = onRatingChanged | ||
| self._currentRating = State(initialValue: initialRating) | ||
| } | ||
|
|
||
| var body: some View { | ||
| VStack(spacing: 24) { | ||
| VStack(spacing: 8) { | ||
| Text("Rate this book") | ||
| .font(.title2) | ||
| .fontWeight(.semibold) | ||
|
|
||
| Text(title) | ||
| .font(.subheadline) | ||
| .foregroundStyle(.secondary) | ||
| .multilineTextAlignment(.center) | ||
| .lineLimit(2) | ||
| } | ||
|
|
||
| VStack(spacing: 16) { | ||
| StarRatingSlider( | ||
| rating: $currentRating, | ||
| minimum: 0.5, | ||
| maximum: 5.0, | ||
| spacing: 12, | ||
| starSize: 40, | ||
| allowHalfStars: true | ||
| ) | ||
|
|
||
| Text(ratingText) | ||
| .font(.headline) | ||
| .foregroundStyle(.orange) | ||
| .contentTransition(.numericText()) | ||
| } | ||
|
|
||
| Button("Rate Book") { | ||
| onRatingChanged(currentRating) | ||
| dismiss() | ||
| } | ||
| .foregroundStyle(Color.buttonText) | ||
| .frame(maxWidth: .infinity) | ||
| .padding() | ||
| .background { | ||
| RoundedRectangle(cornerRadius: 16) | ||
| .fill(Color.buttonBackground) | ||
| } | ||
| .disabled(currentRating == 0) | ||
| } | ||
| .padding(24) | ||
| .frame(maxWidth: .infinity, maxHeight: .infinity) | ||
| .background(Color(.systemBackground)) | ||
| } | ||
|
|
||
| private var ratingText: String { | ||
| if currentRating == 0 { | ||
| return "Tap stars to rate" | ||
| } else { | ||
| let ratingString = currentRating.truncatingRemainder(dividingBy: 1) == 0 | ||
| ? String(format: "%.0f", currentRating) | ||
| : String(format: "%.1f", currentRating) | ||
| return "\(ratingString) out of 5 stars" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| final class BookRatingViewController: UIViewController { | ||
| private let bookTitle: String | ||
| private let initialRating: Double | ||
| private let onRatingChanged: (Double) -> Void | ||
|
|
||
| init(title: String, initialRating: Double, onRatingChanged: @escaping (Double) -> Void) { | ||
| self.bookTitle = title | ||
| self.initialRating = initialRating | ||
| self.onRatingChanged = onRatingChanged | ||
| super.init(nibName: nil, bundle: nil) | ||
| } | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| fatalError("init(coder:) has not been implemented") | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| setupSwiftUIView() | ||
| } | ||
|
|
||
| private func setupSwiftUIView() { | ||
| let ratingView = BookRatingView( | ||
| title: bookTitle, | ||
| initialRating: initialRating, | ||
| onRatingChanged: onRatingChanged | ||
| ) | ||
|
|
||
| let hostingController = UIHostingController(rootView: ratingView) | ||
| addChild(hostingController) | ||
| view.addSubview(hostingController.view) | ||
| hostingController.didMove(toParent: self) | ||
|
|
||
| hostingController.view.translatesAutoresizingMaskIntoConstraints = false | ||
| NSLayoutConstraint.activate([ | ||
| hostingController.view.topAnchor.constraint(equalTo: view.topAnchor), | ||
| hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), | ||
| hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), | ||
| hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor) | ||
| ]) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μνΈμ λμ΄λ₯Ό κ²°μ νλ λ° μ¬μ©λ λ§€μ§ λλ²
0.4λ₯Ό μμλ‘ μΆμΆνμ¬ μ½λμ κ°λ μ±κ³Ό μ μ§λ³΄μμ±μ ν₯μμν€λ κ²μ κΆμ₯ν©λλ€.μλ₯Ό λ€μ΄, ν΄λμ€ λ΄μ λ€μκ³Ό κ°μ΄ μμλ₯Ό μ μΈν μ μμ΅λλ€.
κ·Έλ° λ€μ λ€μκ³Ό κ°μ΄ μ¬μ©ν μ μμ΅λλ€.