(ios) Bugfix: re-read clipboard when returning to the app
@@ -267,6 +267,8 @@ struct ScanView: View, ViewName {
@Binding var paymentRequest: String?
+ @State var clipboardHasString = UIPasteboard.general.hasStrings
+
@State var showingImagePicker = false
@State var imagePickerSelection: UIImage? = nil
@@ -277,6 +279,10 @@ struct ScanView: View, ViewName {
@Environment(\.shortSheetState) private var shortSheetState: ShortSheetState
@Environment(\.popoverState) var popoverState: PopoverState
+ let willEnterForegroundPublisher = NotificationCenter.default.publisher(for:
+ UIApplication.willEnterForegroundNotification
+ )
+
// Subtle timing bug:
//
// Steps to reproduce:
@@ -332,6 +338,9 @@ struct ScanView: View, ViewName {
removal: .move(edge: .bottom)
)
)
+ .onReceive(willEnterForegroundPublisher) { _ in
+ willEnterForeground()
+ }
.onChange(of: mvi.model) { newModel in
modelDidChange(newModel)
}
@@ -376,7 +385,7 @@ struct ScanView: View, ViewName {
}
}
.font(.title3)
- .disabled(!UIPasteboard.general.hasStrings)
+ .disabled(!clipboardHasString)
Divider()
.padding([.top, .bottom], 10)
@@ -402,6 +411,12 @@ struct ScanView: View, ViewName {
}
}
+ func willEnterForeground() {
+ log.trace("[\(viewName)] willEnterForeground()")
+
+ clipboardHasString = UIPasteboard.general.hasStrings
+ }
+
func modelDidChange(_ newModel: Scan.Model) {
log.trace("[\(viewName)] modelDidChange()")
