-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS: Clarify reset necessity for users (#1197)
^ALTAPPS-1350
- Loading branch information
1 parent
3908166
commit 2a33dd0
Showing
13 changed files
with
300 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...perskillApp/iosHyperskillApp/Sources/Extensions/SwiftUI/View/View+OnTapWhenDisabled.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import SwiftUI | ||
|
||
extension View { | ||
@ViewBuilder | ||
func onTapWhenDisabled(isDisabled: Bool, action: @escaping () -> Void) -> some View { | ||
if isDisabled { | ||
self.overlay( | ||
Color.clear | ||
.contentShape(Rectangle()) | ||
.onTapGesture(perform: action) | ||
) | ||
} else { | ||
self | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
@available(iOS 17.0, *) | ||
#Preview { | ||
@Previewable @State var isButtonDisabled = true | ||
|
||
VStack { | ||
Button( | ||
action: { | ||
print("Button tapped!") | ||
}, | ||
label: { | ||
Text("Submit") | ||
.padding() | ||
.background(isButtonDisabled ? Color.gray : Color.blue) | ||
.foregroundColor(.white) | ||
.cornerRadius(8) | ||
} | ||
) | ||
.disabled(isButtonDisabled) | ||
.onTapWhenDisabled(isDisabled: isButtonDisabled) { | ||
print("Button is disabled!") | ||
} | ||
|
||
Toggle("Disable View", isOn: $isButtonDisabled) | ||
.padding() | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
iosHyperskillApp/iosHyperskillApp/Sources/Views/SwiftUI/Effects/BounceEffect.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import SwiftUI | ||
|
||
private struct BounceEffectViewModifier: ViewModifier { | ||
@State private var isBouncing = false | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.scaleEffect(isBouncing ? 0.95 : 1) | ||
.animation( | ||
.easeInOut(duration: 0.15) | ||
.repeatForever(autoreverses: true) | ||
.delay(0.33), | ||
value: isBouncing | ||
) | ||
.onAppear { | ||
isBouncing = true | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
@ViewBuilder | ||
func bounceEffect(isActive: Bool = true) -> some View { | ||
if isActive { | ||
modifier(BounceEffectViewModifier()) | ||
} else { | ||
self | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
@available(iOS 17.0, *) | ||
#Preview { | ||
@Previewable @State var isBouncing = false | ||
|
||
Button { | ||
isBouncing.toggle() | ||
} label: { | ||
Text("Retry") | ||
} | ||
.buttonStyle(RoundedRectangleButtonStyle(style: .violet)) | ||
.bounceEffect(isActive: isBouncing) | ||
.padding() | ||
} | ||
#endif |
56 changes: 56 additions & 0 deletions
56
iosHyperskillApp/iosHyperskillApp/Sources/Views/SwiftUI/Effects/JiggleEffect.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import SwiftUI | ||
|
||
private struct JiggleEffectViewModifier: ViewModifier { | ||
let amount: Double | ||
|
||
@State private var isJiggling = false | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.rotationEffect(.degrees(isJiggling ? amount : 0)) | ||
.animation( | ||
.easeInOut(duration: randomize(interval: 0.14, withVariance: 0.025)) | ||
.repeatForever(autoreverses: true), | ||
value: isJiggling | ||
) | ||
.animation( | ||
.easeInOut(duration: randomize(interval: 0.18, withVariance: 0.025)) | ||
.repeatForever(autoreverses: true), | ||
value: isJiggling | ||
) | ||
.onAppear { | ||
isJiggling.toggle() | ||
} | ||
} | ||
|
||
private func randomize(interval: TimeInterval, withVariance variance: Double) -> TimeInterval { | ||
interval + variance * (Double.random(in: 500...1_000) / 500) | ||
} | ||
} | ||
|
||
extension View { | ||
@ViewBuilder | ||
func jiggleEffect(amount: Double = 2, isActive: Bool = true) -> some View { | ||
if isActive { | ||
modifier(JiggleEffectViewModifier(amount: amount)) | ||
} else { | ||
self | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
@available(iOS 17.0, *) | ||
#Preview { | ||
@Previewable @State var isJiggling = false | ||
|
||
Button { | ||
isJiggling.toggle() | ||
} label: { | ||
Text("Retry") | ||
} | ||
.buttonStyle(RoundedRectangleButtonStyle(style: .violet)) | ||
.jiggleEffect(amount: 2, isActive: isJiggling) | ||
.padding() | ||
} | ||
#endif |
Oops, something went wrong.