Skip to content

Commit

Permalink
Revert "Add wrapping ScoreView style (#3261)"
Browse files Browse the repository at this point in the history
This reverts commit 3315848.
  • Loading branch information
rlepinski committed Dec 20, 2024
1 parent 2b80009 commit dd80275
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 3,364 deletions.
8 changes: 0 additions & 8 deletions Airship/Airship.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1456,9 +1456,6 @@
998572BF2B3CF95D0091E9C9 /* DefaultAssetDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 998572BE2B3CF95D0091E9C9 /* DefaultAssetDownloader.swift */; };
998572C12B3CF97B0091E9C9 /* DefaultAssetFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 998572C02B3CF97B0091E9C9 /* DefaultAssetFileManager.swift */; };
999DC85E2B5B721D0048C6AF /* HTMLView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 999DC85D2B5B721D0048C6AF /* HTMLView.swift */; };
99AB3D5C2CD1B6E6008916BD /* WrappingLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99AB3D5B2CD1B6E6008916BD /* WrappingLayout.swift */; };
99AB3D5D2CD1B6EC008916BD /* WrappingLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99AB3D5B2CD1B6E6008916BD /* WrappingLayout.swift */; };
99AB3D5E2CD1B6ED008916BD /* WrappingLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99AB3D5B2CD1B6E6008916BD /* WrappingLayout.swift */; };
99C3CC762BCF23DF00B5BED5 /* SMSValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99C3CC752BCF23DF00B5BED5 /* SMSValidator.swift */; };
99C3CC792BCF3E5B00B5BED5 /* SMSValidatorAPIClientTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99C3CC772BCF3DF700B5BED5 /* SMSValidatorAPIClientTest.swift */; };
99C3CC7A2BCF3FA200B5BED5 /* SMSValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99C3CC752BCF23DF00B5BED5 /* SMSValidator.swift */; };
Expand Down Expand Up @@ -2988,7 +2985,6 @@
998572BE2B3CF95D0091E9C9 /* DefaultAssetDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultAssetDownloader.swift; sourceTree = "<group>"; };
998572C02B3CF97B0091E9C9 /* DefaultAssetFileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultAssetFileManager.swift; sourceTree = "<group>"; };
999DC85D2B5B721D0048C6AF /* HTMLView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLView.swift; sourceTree = "<group>"; };
99AB3D5B2CD1B6E6008916BD /* WrappingLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappingLayout.swift; sourceTree = "<group>"; };
99C3CC752BCF23DF00B5BED5 /* SMSValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMSValidator.swift; sourceTree = "<group>"; };
99C3CC772BCF3DF700B5BED5 /* SMSValidatorAPIClientTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMSValidatorAPIClientTest.swift; sourceTree = "<group>"; };
99C3CC7C2BCF401B00B5BED5 /* SMSValidatorTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMSValidatorTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5000,7 +4996,6 @@
6EF27DE22730E6F900548DA3 /* RadioInputController.swift */,
6EF27DE82730E85700548DA3 /* RadioInput.swift */,
A6849386273290520021675E /* Score.swift */,
99AB3D5B2CD1B6E6008916BD /* WrappingLayout.swift */,
);
name = Forms;
sourceTree = "<group>";
Expand Down Expand Up @@ -6366,7 +6361,6 @@
6E1CBD812BA3A30300519D9C /* AirshipEmbeddedInfo.swift in Sources */,
6E4325CE2B7AD5A200A9B000 /* AirshipComponent.swift in Sources */,
6EC7E48226A60C060038CFDD /* ChannelProtocol.swift in Sources */,
99AB3D5C2CD1B6E6008916BD /* WrappingLayout.swift in Sources */,
6E2F5A8A2A66088100CABD3D /* AudienceDeviceInfoProvider.swift in Sources */,
6E664BDD26C4CD8700A2C8E5 /* OpenExternalURLAction.swift in Sources */,
6E75F50529C4EAF600E3585A /* AudienceOverridesProvider.swift in Sources */,
Expand Down Expand Up @@ -7266,7 +7260,6 @@
A6722A64281A9EB80033F54D /* ChannelAPIClient.swift in Sources */,
6E299FE128D14258001305A7 /* AirshipRequestSession.swift in Sources */,
A6722A66281A9EB80033F54D /* ChannelRegistrar.swift in Sources */,
99AB3D5E2CD1B6ED008916BD /* WrappingLayout.swift in Sources */,
6E9B4876288F0CE000C905B1 /* RateAppAction.swift in Sources */,
A6722A67281A9EB80033F54D /* ChannelProtocol.swift in Sources */,
A6722A68281A9EB80033F54D /* ChannelBulkUpdateAPIClient.swift in Sources */,
Expand Down Expand Up @@ -7667,7 +7660,6 @@
6E1CBD822BA3A30300519D9C /* AirshipEmbeddedInfo.swift in Sources */,
6E4325CF2B7AD5A200A9B000 /* AirshipComponent.swift in Sources */,
6EF27DDC27306CA600548DA3 /* AirshipCheckboxToggleStyle.swift in Sources */,
99AB3D5D2CD1B6EC008916BD /* WrappingLayout.swift in Sources */,
6E2F5A8B2A66088100CABD3D /* AudienceDeviceInfoProvider.swift in Sources */,
6E6ED1602683DBC300A2CBD0 /* AirshipCoreResources.swift in Sources */,
6E91E45028EF423400B6F25E /* AirshipWorkerType.swift in Sources */,
Expand Down
76 changes: 26 additions & 50 deletions Airship/AirshipCore/Source/Score.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,46 @@
import Foundation
import SwiftUI


struct Score: View {

let info: ThomasViewInfo.Score
let constraints: ViewConstraints

@State var score: Int?
@EnvironmentObject var formState: FormState
@Environment(\.colorScheme) var colorScheme

@ViewBuilder
private func makeNumberRangeScoreItems(style: ThomasViewInfo.Score.ScoreStyle.NumberRange, constraints: ViewConstraints) -> some View {
ForEach((style.start...style.end), id: \.self) { index in
let isOn = Binding(
get: { self.score == index },
set: { if $0 { updateScore(index) } }
)
Toggle(isOn: isOn.animation()) {}
.toggleStyle(
AirshipNumberRangeToggleStyle(
style: style,
viewConstraints: constraints,
value: index,
colorScheme: colorScheme,
disabled: !formState.isFormInputEnabled
)
)
}
}

@ViewBuilder
private func createScore(_ constraints: ViewConstraints) -> some View {
switch self.info.properties.style {
case .numberRange(let style):
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *), style.wrapping != nil {
let minTappableSize = CGSize(
width: max(constraints.width ?? 0, 44),
height: max(constraints.height ?? 0, 44)
)
let itemSpacing = CGFloat(style.spacing ?? 0)
let lineSpacing = CGFloat(style.wrapping?.lineSpacing ?? 0)
let maxItemsPerLine = style.wrapping?.maxItemsPerLine
WrappingLayout(
viewConstraints: constraints,
itemSpacing: itemSpacing,
lineSpacing: lineSpacing,
maxItemsPerLine: maxItemsPerLine
) {
let constraints = ViewConstraints(
width: max(minTappableSize.width, constraints.width ?? 0),
height: max(minTappableSize.height, constraints.height ?? 0),
maxWidth: constraints.maxWidth,
maxHeight: constraints.maxHeight,
isHorizontalFixedSize: constraints.isHorizontalFixedSize,
isVerticalFixedSize: constraints.isVerticalFixedSize,
safeAreaInsets: constraints.safeAreaInsets
HStack(spacing: style.spacing ?? 0) {
ForEach((style.start...style.end), id: \.self) { index in
let isOn = Binding<Bool>(
get: { self.score == index },
set: { if $0 { updateScore(index) } }
)
makeNumberRangeScoreItems(style: style, constraints: constraints)
}
} else {
HStack(spacing: style.spacing ?? 0) {
makeNumberRangeScoreItems(style: style, constraints: constraints)

Toggle(isOn: isOn.animation()) {}
.toggleStyle(
AirshipNumberRangeToggleStyle(
style: style,
viewConstraints: constraints,
value: index,
colorScheme: colorScheme,
disabled: !formState.isFormInputEnabled
)
)
}
.constraints(constraints)
}
}
}

var body: some View {
let constraints = modifiedConstraints()
createScore(constraints)
.constraints(constraints)
.thomasCommon(self.info, formInputID: self.info.properties.identifier)
.accessible(self.info.accessible)
.formElement()
Expand All @@ -98,11 +69,12 @@ struct Score: View {
}

func calculateHeight(style: ThomasViewInfo.Score.ScoreStyle.NumberRange, width: CGFloat?)
-> CGFloat?
-> CGFloat?
{
guard let width = width else {
return nil
}

let count = Double((style.start...style.end).count)
let spacing = (count - 1.0) * (style.spacing ?? 0.0)
let remainingSpace = width - spacing
Expand Down Expand Up @@ -146,10 +118,12 @@ struct Score: View {

self.score = value
}

}


private struct AirshipNumberRangeToggleStyle: ToggleStyle {

let style: ThomasViewInfo.Score.ScoreStyle.NumberRange
let viewConstraints: ViewConstraints
let value: Int
Expand All @@ -174,12 +148,14 @@ private struct AirshipNumberRangeToggleStyle: ToggleStyle {
.opacity(isOn ? 1 : 0)
}
Text(String(self.value))
.textAppearance(style.bindings.selected.textAppearance)
.textAppearance(style.bindings.selected.textAppearance
)
}
.opacity(isOn ? 1 : 0)
.airshipApplyIf(disabled) { view in
view.colorMultiply(ThomasConstants.disabledColor)
}

Group {
if let shapes = style.bindings.unselected.shapes {
ForEach(0..<shapes.count, id: \.self) { index in
Expand Down
12 changes: 0 additions & 12 deletions Airship/AirshipCore/Source/ThomasViewInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1455,25 +1455,13 @@ indirect enum ThomasViewInfo: ThomasSerializable {
var bindings: Bindings
var start: Int
var end: Int
let wrapping: Wrapping?

struct Wrapping: ThomasSerializable {
let lineSpacing: Double?
let maxItemsPerLine: Int?

enum CodingKeys: String, CodingKey {
case lineSpacing = "line_spacing"
case maxItemsPerLine = "max_items_per_line"
}
}

enum CodingKeys: String, CodingKey {
case spacing
case bindings
case start
case end
case type
case wrapping
}

struct Bindings: ThomasSerializable {
Expand Down
185 changes: 0 additions & 185 deletions Airship/AirshipCore/Source/WrappingLayout.swift

This file was deleted.

Loading

0 comments on commit dd80275

Please sign in to comment.