Skip to content

Commit

Permalink
优化SystemRow 设置detail
Browse files Browse the repository at this point in the history
  • Loading branch information
fun committed Oct 10, 2022
1 parent 096932e commit 6730892
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions Sources/Jenga/Core/Row/System/SystemRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public extension SystemRow {
reform { $0.icon = .constant(value) }
}

func detailText(_ value: Binding<DetailText>) -> Self {
reform { $0.detailText = value }
}

func detailText(_ value: DetailText) -> Self {
reform { $0.detailText = .constant(value) }
reform {
$0.detailText = detailText.map(value) { detailText, value in
return value
}
}
}

func detailText(_ value: String) -> Self {
reform {
$0.detailText = detailText.map { detailText in
$0.detailText = detailText.map(value) { detailText, value in
var temp = detailText
temp.type = .value1
temp.text.string = value
Expand All @@ -47,24 +47,32 @@ public extension SystemRow {
}
}

func detailText(_ value: Binding<String>) -> Self {
var temp = detailText.wrappedValue
return reform {
$0.detailText = value.map { value in
func detailText(_ binding: Binding<String>) -> Self {
reform {
$0.detailText = detailText.join(binding) { detail, value in
var temp = detail
temp.type = .value1
temp.text.string = value
return temp
}
}
}

func detailText(_ binding: Binding<DetailText>) -> Self {
reform {
$0.detailText = detailText.join(binding) { detail, value in
return value
}
}
}

func text<Value>(_ keyPath: WritableKeyPath<TextValues, Value>, _ value: Value) -> Self {
reform { $0.text = text.map { $0.with(keyPath, value) } }
reform { $0.text = text.map(value) { $0.with(keyPath, $1) } }
}

func detail<Value>(_ keyPath: WritableKeyPath<TextValues, Value>, _ value: Value) -> Self {
reform {
$0.detailText = detailText.map { detailText in
$0.detailText = detailText.map(value) { detailText, value in
var temp = detailText
temp.text = temp.text.with(keyPath, value)
return temp
Expand All @@ -73,14 +81,17 @@ public extension SystemRow {
}

func text<Value>(_ keyPath: WritableKeyPath<TextValues, Value>, _ binding: Binding<Value>) -> Self {
let temp = text.wrappedValue
return reform { $0.text = binding.map { temp.with(keyPath, $0) } }
reform {
$0.text = text.join(binding) { text, value in
text.with(keyPath, value)
}
}
}

func detail<Value>(_ keyPath: WritableKeyPath<TextValues, Value>, _ binding: Binding<Value>) -> Self {
var temp = detailText.wrappedValue
return reform {
$0.detailText = binding.map { value in
reform {
$0.detailText = detailText.join(binding) { detail, value in
var temp = detail
temp.text = temp.text.with(keyPath, value)
return temp
}
Expand All @@ -89,7 +100,7 @@ public extension SystemRow {

func detail(_ value: DetailText.`Type`) -> Self {
reform {
$0.detailText = detailText.map { detailText in
$0.detailText = detailText.map(value) { detailText, value in
var temp = detailText
temp.type = value
return temp
Expand Down

0 comments on commit 6730892

Please sign in to comment.