-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): add native iOS toast module with SPIndicator
Signed-off-by: Innei <tukon479@gmail.com>
- Loading branch information
Showing
8 changed files
with
121 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// 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: .success | ||
case .warn: .warning | ||
case .success: .error | ||
} | ||
} | ||
} | ||
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()) | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ export default function Index() { | |
useEffect(() => { | ||
prepareEntryRenderWebView() | ||
}, []) | ||
|
||
return <EntryList /> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.