Files
Folo/apps/mobile/native/ios/Toaster/ToasterModule.swift
T
Innei c4174f909e fix(mobile): adjust login UI and toast haptic feedback
- Update haptic feedback for different toast types in iOS
- Modify NoLoginInfo component spacing
- Restructure EmailLogin screen layout and styling

Signed-off-by: Innei <tukon479@gmail.com>
2025-03-05 21:44:22 +08:00

64 lines
1.3 KiB
Swift

//
// ToasterModule.swift
//
// Created by Innei on 2025/2/21.
//
import ExpoModulesCore
import SPIndicator
enum ToastType: String, Enumerable {
case error
case info
case warn
case success
}
extension ToastType {
func type() -> SPIndicatorIconPreset {
switch self
{
case .error: .error
case .warn: .custom(UIImage(systemName: "exclamationmark.triangle")!.withTintColor(.orange))
case .info: .custom(UIImage(systemName: "info.circle")!.withTintColor(.blue))
case .success: .done
}
}
func haptic() -> SPIndicatorHaptic {
switch self {
case .error: .error
case .info: .none
case .warn: .warning
case .success: .success
}
}
}
struct ToastOptions: Record {
@Field
var message: String?
@Field
var type: ToastType = .info
@Field
var duration: Double = 1.5
@Field
var title: String
}
public class ToasterModule: Module {
public func definition() -> ModuleDefinition {
Name("Toaster")
Function("toast") { (value: ToastOptions) in
DispatchQueue.main.sync {
let indicatorView = SPIndicatorView(
title: value.title, message: value.message, preset: value.type.type())
indicatorView.present(duration: value.duration, haptic: value.type.haptic())
}
}
}
}