Skip to content

support: from iOS 13 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Sources/Marquee/Extension/View+Ex.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// View+Ex.swift
//
//
// Created by Shahriar Nasim Nafi on 14/7/21.
//
// Idea from Zane Carter

import SwiftUI
import Combine

extension View {
/// A backwards compatible wrapper for iOS 14 `onChange`
@ViewBuilder func onValueChange<T: Equatable>(value: T, onChange: @escaping (T) -> Void) -> some View {
if #available(iOS 14.0, *) {
self.onChange(of: value, perform: onChange)
} else {
self.onReceive(Just(value)) { (value) in
onChange(value)
}
}
}
}

6 changes: 3 additions & 3 deletions Sources/Marquee/Marquee.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public struct Marquee<Content> : View where Content : View {
.onDisappear {
self.isAppear = false
}
.onChange(of: duration) { [] newDuration in
.onValueChange(value: duration) { newDuration in
resetAnimation(duration: newDuration, autoreverses: self.autoreverses, proxy: proxy)
}
.onChange(of: autoreverses) { [] newAutoreverses in
.onValueChange(value: autoreverses){ newAutoreverses in
resetAnimation(duration: self.duration, autoreverses: newAutoreverses, proxy: proxy)
}
.onChange(of: direction) { [] _ in
onValueChange(value: direction ) { _ in
resetAnimation(duration: duration, autoreverses: autoreverses, proxy: proxy)
}
}.clipped()
Expand Down