-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from DroidKaigi/feature/toast_ios
- Loading branch information
Showing
7 changed files
with
114 additions
and
56 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
68 changes: 68 additions & 0 deletions
68
app-ios/Sources/CommonComponents/Modifier/ToastModifier.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,68 @@ | ||
import SwiftUI | ||
import Theme | ||
|
||
public struct ToastState: Equatable { | ||
public let text: String | ||
|
||
public init(text: String) { | ||
self.text = text | ||
} | ||
} | ||
|
||
struct ToastModifier: ViewModifier { | ||
@Binding var item: ToastState? | ||
@State private var task: Task<Void, Never>? = nil | ||
private let animationDelay = 1.0 | ||
|
||
func body(content: Content) -> some View { | ||
ZStack { | ||
content | ||
|
||
if item != nil { | ||
ToastView(item: $item) | ||
.zIndex(1) | ||
.transition(.move(edge: .bottom).combined(with: .opacity)) | ||
.onTapGesture { | ||
item = nil | ||
} | ||
} | ||
} | ||
.onChange(of: item) { | ||
task?.cancel() | ||
if item != nil { | ||
task = Task { | ||
try? await Task.sleep(for: .seconds(4)) | ||
withAnimation(.easeInOut(duration: animationDelay)) { | ||
item = nil | ||
} | ||
} | ||
} | ||
} | ||
.animation(.easeInOut(duration: animationDelay), value: item) | ||
} | ||
} | ||
|
||
struct ToastView: View { | ||
@Binding var item: ToastState? | ||
var body: some View { | ||
ZStack { | ||
Text(item?.text ?? "") | ||
.textStyle(.bodyMedium) | ||
.foregroundColor(AssetColors.Inverse.inverseOnSurface.swiftUIColor) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.padding(.horizontal, 16) | ||
.padding(.vertical, 14) | ||
.background(AssetColors.Inverse.inverseSurface.swiftUIColor) | ||
.padding(.horizontal, 12) | ||
.clipShape(RoundedRectangle(cornerRadius: 4)) | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom) | ||
.padding(.vertical, 16) | ||
} | ||
} | ||
|
||
extension View { | ||
public func toast(_ item: Binding<ToastState?>) -> some View { | ||
modifier(ToastModifier(item: item)) | ||
} | ||
} |
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
19 changes: 14 additions & 5 deletions
19
app-ios/Sources/TimetableDetailFeature/TimetableDetailReducer.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
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