Skip to content

Commit

Permalink
Backport unsupported apis
Browse files Browse the repository at this point in the history
  • Loading branch information
radeknovis committed Nov 8, 2023
1 parent 4aa4c82 commit c892409
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 35 deletions.
22 changes: 21 additions & 1 deletion Sources/WalletConnectModal/Extensions/View+Backport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI

extension View {

#if os(iOS)
#if os(iOS) || os(tvOS)

/// A backwards compatible wrapper for iOS 14 `onChange`
@ViewBuilder
Expand All @@ -27,4 +27,24 @@ extension View {
}

#endif

#if os(iOS) || os(macOS)

@ViewBuilder
func onTapGestureBackported(count: Int = 1, perform action: @escaping () -> Void) -> some View {
self
}

#elseif os(tvOS)

@ViewBuilder
func onTapGestureBackported(count: Int = 1, perform action: @escaping () -> Void) -> some View {
if #available(tvOS 16.0, *) {
self.onTapGesture(count: count, perform: action)
} else {
self
}
}

#endif
}
12 changes: 4 additions & 8 deletions Sources/WalletConnectModal/Modal/ModalContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ struct ModalContainerView: View {
Color.thickOverlay
.colorScheme(.light)
.opacity(showModal ? 1 : 0)
.transform {
#if os(iOS)
$0.onTapGesture {
withAnimation {
showModal = false
}
}
#endif
.onTapGestureBackported {
withAnimation {
showModal = false
}
}
)
.edgesIgnoringSafeArea(.all)
Expand Down
10 changes: 7 additions & 3 deletions Sources/WalletConnectModal/Modal/Screens/QRCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ struct QRCodeView: View {
)
)

return doc.imageUI(
size, label: Text("QR code with URI")
)!
if #available(macOS 11, *) {
return doc.imageUI(
size, label: Text("QR code with URI")
)!
} else {
return Image.init(sfSymbolName: "qrcode")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct WalletDetail: View {
.contentShape(Rectangle())
.padding(.horizontal, 8)
.padding(.vertical, 8)
.onTapGesture {
.onTapGestureBackported {
withAnimation(.easeInOut(duration: 0.15)) {
viewModel.preferredPlatform = item
}
Expand Down Expand Up @@ -185,7 +185,7 @@ struct WalletDetail: View {
.foregroundColor(.foreground2)
}
}
.onTapGesture {
.onTapGestureBackported {
viewModel.handle(.didTapAppStore)
}
}
Expand Down
32 changes: 12 additions & 20 deletions Sources/WalletConnectModal/Modal/Screens/WalletList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ struct WalletList: View {

if wallets.count > numberOfColumns * 2 {
viewAllItem()
.transform {
#if os(iOS)
$0.onTapGesture {
withAnimation {
navigateTo(.viewAll)
}
}
#endif
.onTapGestureBackported {
withAnimation {
navigateTo(.viewAll)
}
}
}
}
Expand Down Expand Up @@ -181,19 +177,15 @@ struct WalletList: View {
.padding(.horizontal, 12)
}
.frame(maxWidth: 80, maxHeight: 96)
.transform {
#if os(iOS)
$0.onTapGesture {
withAnimation {
navigateTo(.walletDetail(wallet))

// Small delay to let detail screen present before actually deeplinking
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
onListingTap(wallet)
}
}
.onTapGestureBackported {
withAnimation {
navigateTo(.walletDetail(wallet))

// Small delay to let detail screen present before actually deeplinking
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
onListingTap(wallet)
}
#endif
}
}
}
}
2 changes: 1 addition & 1 deletion Sources/WalletConnectModal/UI/Common/Web3ModalPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct PreviewWeb3ModalPicker: View {
.contentShape(Rectangle())
.padding(.horizontal, 8)
.padding(.vertical, 8)
.onTapGesture {
.onTapGestureBackported {
withAnimation(.easeInOut(duration: 0.15)) {
selectedItem = item
}
Expand Down
1 change: 1 addition & 0 deletions WalletConnectSwiftV2.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,6 @@ Pod::Spec.new do |spec|
ss.source_files = 'Sources/WalletConnectModal/**/*.{h,m,swift}'
ss.dependency 'WalletConnectSwiftV2/WalletConnectSign'
ss.dependency 'DSF_QRCode', '~> 16.1.1'
ss.platform = :ios
end
end

0 comments on commit c892409

Please sign in to comment.