Skip to content

Commit

Permalink
Updated example projects
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Oct 17, 2024
1 parent 79ad9ec commit 8ff78d1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct AddOrReplaceTimecodeTrackView: View {
TimecodeField(timecode: $newStartTimecode)
.timecodeFormat([.showSubFrames])
.timecodeSubFramesStyle(.secondary, scale: .secondary)
.timecodeValidationStyle(.red)
.timecodeFieldValidationPolicy(.enforceValid)
}

LabeledContent("") {
Expand Down
14 changes: 8 additions & 6 deletions Examples/Movie Timecode/Movie Timecode/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ struct ContentView: View {
@State private var operationType: OperationType = .addOrReplaceTimecodeTrack

var body: some View {
Form {
sourceSection
operationsSection
NavigationStack {
Form {
sourceSection
operationsSection
}
.formStyle(.grouped)
.padding()
.navigationTitle("Movie Timecode")
}
.formStyle(.grouped)
.padding()

.fileImporter(
isPresented: $isFileImporterShown,
allowedContentTypes: [.quickTimeMovie, .mpeg4Movie]
Expand Down
3 changes: 2 additions & 1 deletion Examples/Timecode Math/Timecode Math/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ struct ExpressionsView: View {
.foregroundStyle(.primary)
.timecodeFormat([.showSubFrames])
.timecodeSeparatorStyle(.secondary)
.timecodeValidationStyle(.red)
.timecodeSubFramesStyle(.secondary, scale: .secondary)
.timecodeFieldInputStyle(.autoAdvance)
.timecodeFieldInputWrapping(.noWrap)
.timecodeFieldValidationPolicy(.enforceValid)
}
}

Expand Down
31 changes: 26 additions & 5 deletions Examples/Timecode UI/Timecode UI/TimecodeFieldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ struct TimecodeFieldView: View {

@State private var isEnabled: Bool = true
@State private var timecodeFormat: Timecode.StringFormat = [.showSubFrames]
@State private var inputStyle: TimecodeField.InputStyle = .autoAdvance
@State private var inputWrapping: TimecodeField.InputWrapping = .wrap
@State private var defaultStyle: DefaultStyle = .default
@State private var separatorStyle: SeparatorStyle = .secondary
@State private var highlightStyle: HighlightStyle = .default
@State private var validationStyle: ValidationStyle = .red
@State private var subFramesStyle: SubFramesStyle = .default
@State private var subFramesScale: TextScale = .default
@State private var validationStyle: ValidationStyle = .red
@State private var highlightStyle: HighlightStyle = .default
@State private var inputStyle: TimecodeField.InputStyle = .continuousWithinComponent
@State private var inputWrapping: TimecodeField.InputWrapping = .noWrap
@State private var validationPolicy: TimecodeField.ValidationPolicy = .allowInvalid
@State private var validationAnimation: Bool = true

@FocusState private var isEditing: Bool

Expand All @@ -43,6 +45,7 @@ struct TimecodeFieldView: View {
.timecodeFieldHighlightStyle(highlightStyle.color)
.timecodeFieldInputStyle(inputStyle)
.timecodeFieldInputWrapping(inputWrapping)
.timecodeFieldValidationPolicy(validationPolicy, animation: validationAnimation)
.timecodeFieldReturnAction(.focusNextComponent)
.timecodeFieldEscapeAction(.resetComponentFocus())
.font(.largeTitle)
Expand Down Expand Up @@ -139,6 +142,15 @@ struct TimecodeFieldView: View {
Text(wrapping.name).tag(wrapping)
}
}
Picker("Validation Policy", selection: $validationPolicy) {
ForEach(TimecodeField.ValidationPolicy.allCases) { policy in
Text(policy.name).tag(policy)
}
}
Toggle(isOn: $validationAnimation) {
Text("Validation Feedback Animation")
}
.disabled(validationPolicy != .enforceValid)
Toggle(isOn: $timecodeFormat.option(.showSubFrames)) {
Text("Show SubFrames")
}
Expand Down Expand Up @@ -312,7 +324,7 @@ extension TimecodeFieldView {

var name: String {
switch self {
case .default: "Default (Accent Color)"
case .default: "Default (Accent)"
case .secondary: "Secondary"
case .blue: "Blue"
}
Expand Down Expand Up @@ -371,6 +383,15 @@ extension TimecodeField.InputWrapping {
}
}

extension TimecodeField.ValidationPolicy {
var name: String {
switch self {
case .allowInvalid: "Allow Invalid"
case .enforceValid: "Enforce Valid"
}
}
}

#Preview {
TimecodeFieldView()
.frame(minHeight: 700)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ extension EnvironmentValues {
@available(watchOS, unavailable)
@available(tvOS, unavailable)
struct TimecodeFieldValidationPolicyKey: EnvironmentKey {
public static let defaultValue: TimecodeField.ValidationPolicy = .allowInvalid
public static let defaultValue: TimecodeField.ValidationPolicy = .enforceValid
}

@_documentation(visibility: internal)
Expand Down

0 comments on commit 8ff78d1

Please sign in to comment.