Skip to content

Commit

Permalink
Transition from NSRegularExpression to Swift Regular Expression avail…
Browse files Browse the repository at this point in the history
…able from Swift 5.7

Switched from ScrollView to List
FrameRow without background
Hide .placeholder icon

Signed-off-by: Tim Bert <[email protected]>
  • Loading branch information
timbms committed Nov 8, 2023
1 parent 6d20d08 commit 56bd336
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 25 deletions.
8 changes: 3 additions & 5 deletions openHABWatch/Model/ObservableOpenHABWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ class ObservableOpenHABWidget: NSObject, MKAnnotation, Identifiable, ObservableO

// Text between square brackets
var labelValue: String? {
// Swift 5 raw strings
let regex = try? NSRegularExpression(pattern: #"\[(.*?)\]"#, options: [])
guard let match = regex?.firstMatch(in: label, options: [], range: NSRange(location: 0, length: (label as NSString).length)) else { return nil }
guard let range = Range(match.range(at: 1), in: label) else { return nil }
return String(label[range])
let regex = /\[(.*?)\]/
guard let match = label.firstMatch(of: regex) else { return nil }
return String(match.1)
}

var coordinate: CLLocationCoordinate2D {
Expand Down
3 changes: 2 additions & 1 deletion openHABWatch/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ struct ContentView: View {
@State var title = "openHAB"

var body: some View {
ScrollView {
List {
ForEach(viewModel.widgets) { widget in
rowWidget(widget: widget)
.environmentObject(settings)
}
}
.listStyle(.carousel)
.navigationBarTitle(Text(title))
.alert(isPresented: $viewModel.showAlert) {
Alert(
Expand Down
16 changes: 5 additions & 11 deletions openHABWatch/Views/Rows/FrameRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ struct FrameRow: View {
@ObservedObject var widget: ObservableOpenHABWidget
@ObservedObject var settings = ObservableOpenHABDataObject.shared
var body: some View {
let gray = Color(UIColor.darkGray)
return VStack {
HStack {
Text(widget.labelText?.uppercased() ?? "")
.font(.callout)
.lineLimit(1)
Spacer()
}
HStack {
Text(widget.labelText?.uppercased() ?? "")
.font(.callout)
.lineLimit(1)
Spacer()
}
.background(gray.edgesIgnoringSafeArea(.all))
// .background(SwiftUI.Color.yellow.edgesIgnoringSafeArea(.all))
// .background( Color(color:.systemGray))
}
}

Expand Down
6 changes: 0 additions & 6 deletions openHABWatch/Views/Rows/RollershutterRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,17 @@ struct RollershutterRow: View {
}
HStack {
Spacer()

ImageWithAction(systemName: "chevron.up.circle.fill") {
widget.sendCommand("UP")
}

Spacer()

ImageWithAction(systemName: "square") {
widget.sendCommand("STOP")
}

Spacer()

ImageWithAction(systemName: "chevron.down.circle.fill") {
widget.sendCommand("DOWN")
}

Spacer()
}
.frame(height: 50)
Expand Down
2 changes: 0 additions & 2 deletions openHABWatch/Views/Rows/SliderRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ struct SliderRow: View {
set: {
os_log("Slider new value = %g", log: .default, type: .info, $0)
widget.sendCommand($0.valueText(step: widget.step))

// self.widget.stateEnumBinding = .slider($0)
}
)
}
Expand Down
1 change: 1 addition & 0 deletions openHABWatch/Views/Utils/IconView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct IconView: View {
Image(systemName: "arrow.2.circlepath.circle")
.font(.callout)
.opacity(0.3)
.hidden()
}
.cancelOnDisappear(true)
.resizable()
Expand Down

0 comments on commit 56bd336

Please sign in to comment.