Skip to content

Commit

Permalink
fix: fix crash by ensuring UI operations run on the main thread when …
Browse files Browse the repository at this point in the history
…ending text editing
  • Loading branch information
vvbbnn00 committed Oct 27, 2024
1 parent 2137888 commit e9e83a4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions EhPanda/App/Tools/Clients/UIApplicationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ComposableArchitecture

struct UIApplicationClient {
let openURL: @MainActor (URL) -> Void
let hideKeyboard: () -> Void
let hideKeyboard: @Sendable () async -> Void
let alternateIconName: () -> String?
let setAlternateIconName: @MainActor (String?) async -> Bool
let setUserInterfaceStyle: @MainActor (UIUserInterfaceStyle) -> Void
Expand All @@ -23,7 +23,9 @@ extension UIApplicationClient {
UIApplication.shared.open(url, options: [:])
},
hideKeyboard: {
UIApplication.shared.endEditing()
await MainActor.run {
UIApplication.shared.endEditing()
}
},
alternateIconName: {
UIApplication.shared.alternateIconName
Expand Down
1 change: 1 addition & 0 deletions EhPanda/App/Tools/Extensions/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension Encodable {

// MARK: UIApplication
extension UIApplication {
@MainActor
func endEditing() {
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Setting/EhSetting/EhSettingReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct EhSettingReducer {
return .none

case .setKeyboardHidden:
return .run(operation: { _ in uiApplicationClient.hideKeyboard() })
return .run(operation: { _ in await uiApplicationClient.hideKeyboard() })

case .setDefaultProfile(let profileSet):
return .run { _ in
Expand Down

0 comments on commit e9e83a4

Please sign in to comment.