Skip to content

Commit

Permalink
Fixes an issue of the search box
Browse files Browse the repository at this point in the history
- Fix an issue that it's not working on iOS 17.
- Remove search box on watchOS 10.2 or later (`searchable` is broken on watchOS 10.2).
  • Loading branch information
mntone committed Dec 25, 2023
1 parent 03b525b commit 3363bb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/App/ViewModels/GameViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class GameViewModel: ObservableObject, Identifiable {
private let game: Game

@Published
private(set) var state: StarSwingsState<[GameItemViewModel]>
private(set) var state: StarSwingsState<[GameItemViewModel]> = .ready

@Published
var sort: Sort = .inGame
Expand All @@ -63,13 +63,8 @@ final class GameViewModel: ObservableObject, Identifiable {

init(_ game: Game) {
self.game = game
self.state = game.state
.mapData { monsters in
monsters.map(GameItemViewModel.init)
}

let getState = game.$state
.dropFirst()
.mapData { monsters in
monsters.map(GameItemViewModel.init)
}
Expand Down
9 changes: 8 additions & 1 deletion src/App/Views/Modifiers/SharedMonsterListModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ struct SharedMonsterListModifier: ViewModifier {
}
#endif
#if os(watchOS)
.searchable(text: searchText, prompt: Text("Search"))
.block { content in
if #available(watchOS 10.2, *) {
// The "searchable" is broken on watchOS 10.2.
content
} else {
content.searchable(text: searchText, prompt: Text("Search"))
}
}
#else
.searchable(text: searchText, prompt: Text("Monster and Weakness"))
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/App/Views/Utils/View+Block.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

extension View {
func block<Content>(@ViewBuilder _ transform: (Self) -> Content) -> Content {
func block<Content: View>(@ViewBuilder _ transform: (Self) -> Content) -> some View {
transform(self)
}
}

0 comments on commit 3363bb5

Please sign in to comment.