-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from blyscuit/release/0.7.0
Release - 0.7.0
- Loading branch information
Showing
19 changed files
with
445 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
71 changes: 71 additions & 0 deletions
71
...p/Survey/Sources/Presentation/Modules/SurveyDetail/SurveyQuestion/QuestionEmojiView.swift
This file contains 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,71 @@ | ||
// | ||
// QuestionEmojiView.swift | ||
// Survey | ||
// | ||
// Created by Bliss on 2/2/23. | ||
// Copyright © 2023 Nimble. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct QuestionEmojiView: View { | ||
|
||
enum EmojiType: String { | ||
|
||
case like | ||
case smile | ||
case heart | ||
case star | ||
|
||
func items(count: Int) -> [String] { | ||
let items: [String] | ||
switch self { | ||
case .like: | ||
items = Array(repeatElement("👍🏻", count: count)) | ||
case .smile: | ||
items = Array(["😡", "😕", "😐", "🙂", "😄"].prefix(count)) | ||
case .heart: | ||
items = Array(repeatElement("❤️", count: count)) | ||
case .star: | ||
items = Array(repeatElement("⭐️", count: count)) | ||
} | ||
return items | ||
} | ||
} | ||
|
||
@State var rating: Int = 0 | ||
@Binding var answers: [String] | ||
|
||
let type: EmojiType | ||
let options: [Answer] | ||
|
||
var body: some View { | ||
let items = type.items(count: options.count) | ||
HStack(spacing: .itemSpacing) { | ||
Spacer() | ||
ForEach(0 ..< items.count, id: \.self) { index in | ||
Text(items[index]) | ||
.font(.boldTitle) | ||
.opacity(getOpacity(index)) | ||
.onTapGesture { | ||
rating = index | ||
} | ||
.frame(width: 28.0, height: 34.0) | ||
.tag(index) | ||
} | ||
Spacer() | ||
} | ||
.onChange(of: rating) { | ||
answers = [options[$0].id] | ||
} | ||
} | ||
|
||
private func getOpacity(_ index: Int) -> Double { | ||
switch type { | ||
case .smile: | ||
return index == rating ? 1.0 : 0.5 | ||
default: | ||
return index > rating ? 0.5 : 1.0 | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ey/Sources/Presentation/Modules/SurveyDetail/SurveyQuestion/QuestionMultiChoiceView.swift
This file contains 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,61 @@ | ||
// | ||
// QuestionMultiChoiceView.swift | ||
// Survey | ||
// | ||
// Created by Bliss on 2/2/23. | ||
// Copyright © 2023 Nimble. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct QuestionMultiChoiceView: View { | ||
|
||
let options: [Answer] | ||
|
||
@State var inputs = Set<String>() | ||
@Binding var answers: [String] | ||
|
||
var body: some View { | ||
VStack { | ||
ForEach(Array(options.enumerated()), id: \.element.id) { index, option in | ||
let isSelected = inputs.contains(option.id) | ||
Button { | ||
didPress(id: option.id) | ||
} label: { | ||
HStack { | ||
Text(option.text) | ||
.lineLimit(1) | ||
.foregroundColor(isSelected ? .white : .white.opacity(0.5)) | ||
.font(isSelected ? .boldLarge : .regularLarge) | ||
Spacer() | ||
if isSelected { | ||
Image(systemName: .checkmarkCircleFill) | ||
.foregroundColor(.white) | ||
.font(.system(size: 24.0)) | ||
} else { | ||
Image(systemName: .circle) | ||
.foregroundColor(.white.opacity(0.5)) | ||
.font(.system(size: 24.0)) | ||
} | ||
} | ||
} | ||
.frame(height: 56.0) | ||
if index != options.count - 1 { | ||
Divider() | ||
.frame(height: 0.5) | ||
.overlay(Color.white) | ||
} | ||
} | ||
} | ||
.padding(.horizontal, .extraLargePadding) | ||
} | ||
|
||
func didPress(id: String) { | ||
if inputs.contains(id) { | ||
inputs.remove(id) | ||
} else { | ||
inputs.insert(id) | ||
} | ||
answers = Array(inputs) | ||
} | ||
} |
Oops, something went wrong.