-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds section to UserInfo view to edit basic list of session personas
- Loading branch information
Showing
4 changed files
with
207 additions
and
6 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
71 changes: 71 additions & 0 deletions
71
Examples/BrandGame/BrandGame/View/Menu/UserInfo/PersonaGrid.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 @@ | ||
// | ||
// Copyright © 2023 Embrace Mobile, Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import EmbraceIO | ||
|
||
struct PersonaGrid: View { | ||
|
||
let lifespan: MetadataLifespan | ||
@ObservedObject var user: UserInfo.EmbraceUser | ||
|
||
var body: some View { | ||
Grid(verticalSpacing: 6.0) { | ||
ForEach(personaGridRows(), id: \.self) { row in | ||
GridRow { | ||
ForEach(row) { personaOption in | ||
PillText( | ||
personaOption.rawValue, | ||
selected: user.hasPersona(personaOption), | ||
style: colorForPersona(persona: personaOption) | ||
).onTapGesture { | ||
user.toggle(persona: personaOption, lifespan: lifespan) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func personaGridRows(size: Int = 3) -> [[PersonaTag]] { | ||
let count = Self.quickPersonas.count | ||
|
||
return stride(from: 0, to: count, by: size).map { | ||
Array(Self.quickPersonas[$0 ..< Swift.min($0 + size, count)]) | ||
} | ||
} | ||
|
||
func colorForPersona(persona: PersonaTag) -> Color { | ||
let idx = persona.rawValue.count % Self.personaColors.count | ||
return Self.personaColors[idx] | ||
} | ||
} | ||
|
||
extension PersonaGrid { | ||
static var quickPersonas: [PersonaTag] { | ||
[ | ||
PersonaTag.free, | ||
PersonaTag.preview, | ||
PersonaTag.subscriber, | ||
PersonaTag.payer, | ||
PersonaTag.guest, | ||
PersonaTag.pro, | ||
PersonaTag.mvp, | ||
PersonaTag.vip | ||
] | ||
} | ||
|
||
static var personaColors: [Color] { | ||
[ | ||
Color.embraceLead, | ||
Color.embracePink, | ||
Color.embracePurple, | ||
Color.embraceSilver | ||
] | ||
} | ||
} | ||
|
||
#Preview { | ||
PersonaGrid(lifespan: .session, user: .init()) | ||
} |
45 changes: 45 additions & 0 deletions
45
Examples/BrandGame/BrandGame/View/Menu/UserInfo/PillText.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,45 @@ | ||
// | ||
// Copyright © 2023 Embrace Mobile, Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PillText<S: ShapeStyle>: View { | ||
let text: String | ||
let selected: Bool | ||
let cornerSize: CGSize | ||
let style: S | ||
|
||
init( | ||
_ text: String, | ||
selected: Bool = false, | ||
style: S = Color.primary, | ||
cornerSize: CGSize = .init(width: 24.0, height: 24.0) | ||
) { | ||
|
||
self.text = text | ||
self.selected = selected | ||
self.cornerSize = cornerSize | ||
self.style = style | ||
} | ||
|
||
var body: some View { | ||
Text(text) | ||
.padding(.horizontal, cornerSize.width / 2) | ||
.padding(.vertical, cornerSize.height / 4) | ||
.background( style.opacity(selected ? 1 : 0)) | ||
.clipShape(RoundedRectangle(cornerSize: cornerSize)) | ||
.overlay( | ||
RoundedRectangle(cornerSize: cornerSize) | ||
.stroke(style, lineWidth: 2) | ||
) // Border | ||
} | ||
} | ||
|
||
#Preview("Unselected") { | ||
PillText("Text", selected: false, style: Color.embracePink) | ||
} | ||
|
||
#Preview("Selected") { | ||
PillText("Text", selected: true, style: Color.embracePink) | ||
} |
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