react-native-nitro-simple-toast 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/NitroSimpleToast.podspec +30 -0
- package/README.md +81 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +118 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/nitrosimpletoast/NitroSimpleToast.kt +66 -0
- package/android/src/main/java/com/margelo/nitro/nitrosimpletoast/NitroSimpleToastPackage.kt +26 -0
- package/ios/NitroSimpleToast.swift +60 -0
- package/lib/module/NitroSimpleToast.nitro.js +4 -0
- package/lib/module/NitroSimpleToast.nitro.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NitroSimpleToast.nitro.d.ts +33 -0
- package/lib/typescript/src/NitroSimpleToast.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JHybridNitroSimpleToastSpec.cpp +68 -0
- package/nitrogen/generated/android/c++/JHybridNitroSimpleToastSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JToastFrom.hpp +58 -0
- package/nitrogen/generated/android/c++/JToastHaptic.hpp +64 -0
- package/nitrogen/generated/android/c++/JToastOptions.hpp +88 -0
- package/nitrogen/generated/android/c++/JToastPreset.hpp +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/HybridNitroSimpleToastSpec.kt +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/ToastFrom.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/ToastHaptic.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/ToastOptions.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/ToastPreset.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/nitrosimpletoastOnLoad.kt +35 -0
- package/nitrogen/generated/android/nitrosimpletoast+autolinking.cmake +81 -0
- package/nitrogen/generated/android/nitrosimpletoast+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nitrosimpletoastOnLoad.cpp +54 -0
- package/nitrogen/generated/android/nitrosimpletoastOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/NitroSimpleToast+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroSimpleToast-Swift-Cxx-Bridge.cpp +33 -0
- package/nitrogen/generated/ios/NitroSimpleToast-Swift-Cxx-Bridge.hpp +152 -0
- package/nitrogen/generated/ios/NitroSimpleToast-Swift-Cxx-Umbrella.hpp +57 -0
- package/nitrogen/generated/ios/NitroSimpleToastAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroSimpleToastAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridNitroSimpleToastSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroSimpleToastSpecSwift.hpp +92 -0
- package/nitrogen/generated/ios/swift/HybridNitroSimpleToastSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridNitroSimpleToastSpec_cxx.swift +137 -0
- package/nitrogen/generated/ios/swift/ToastFrom.swift +40 -0
- package/nitrogen/generated/ios/swift/ToastHaptic.swift +48 -0
- package/nitrogen/generated/ios/swift/ToastOptions.swift +116 -0
- package/nitrogen/generated/ios/swift/ToastPreset.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroSimpleToastSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNitroSimpleToastSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/ToastFrom.hpp +76 -0
- package/nitrogen/generated/shared/c++/ToastHaptic.hpp +84 -0
- package/nitrogen/generated/shared/c++/ToastOptions.hpp +116 -0
- package/nitrogen/generated/shared/c++/ToastPreset.hpp +80 -0
- package/package.json +174 -0
- package/src/NitroSimpleToast.nitro.ts +35 -0
- package/src/index.tsx +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Huckleberry Shin
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "NitroSimpleToast"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/jeongshin/react-native-nitro-simple-toast.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = [
|
|
17
|
+
"ios/**/*.{swift}",
|
|
18
|
+
"ios/**/*.{m,mm}",
|
|
19
|
+
"cpp/**/*.{hpp,cpp}",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
s.dependency 'React-jsi'
|
|
23
|
+
s.dependency 'React-callinvoker'
|
|
24
|
+
s.dependency 'SPIndicator', '~> 1.6'
|
|
25
|
+
|
|
26
|
+
load 'nitrogen/generated/ios/NitroSimpleToast+autolinking.rb'
|
|
27
|
+
add_nitrogen_files(s)
|
|
28
|
+
|
|
29
|
+
install_modules_dependencies(s)
|
|
30
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# react-native-nitro-simple-toast
|
|
2
|
+
|
|
3
|
+
A native toast library for React Native powered by [Nitro Modules](https://nitro.margelo.com/).
|
|
4
|
+
|
|
5
|
+
Inspired by [burnt](https://github.com/nandorojo/burnt), but without the Expo dependency.
|
|
6
|
+
|
|
7
|
+
- **iOS**: Native floating indicator via [SPIndicator](https://github.com/ivanvorobei/SPIndicator) — displays above modals and all other views
|
|
8
|
+
- **Android**: Native `android.widget.Toast` with haptic feedback
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install react-native-nitro-simple-toast react-native-nitro-modules
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
> `react-native-nitro-modules` is a peer dependency required by this library.
|
|
17
|
+
|
|
18
|
+
For iOS:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
cd ios && pod install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { toast } from 'react-native-nitro-simple-toast';
|
|
28
|
+
|
|
29
|
+
// Simple toast
|
|
30
|
+
toast({ title: 'Success!' });
|
|
31
|
+
|
|
32
|
+
// Full options
|
|
33
|
+
toast({
|
|
34
|
+
title: 'Complete',
|
|
35
|
+
message: 'File uploaded successfully',
|
|
36
|
+
preset: 'done',
|
|
37
|
+
duration: 2,
|
|
38
|
+
haptic: 'success',
|
|
39
|
+
shouldDismissByDrag: true,
|
|
40
|
+
from: 'top',
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
### `toast(options: ToastOptions): void`
|
|
47
|
+
|
|
48
|
+
| Option | Type | Default | Description |
|
|
49
|
+
|---|---|---|---|
|
|
50
|
+
| `title` | `string` | **required** | Toast title text |
|
|
51
|
+
| `message` | `string` | — | Optional subtitle/message |
|
|
52
|
+
| `preset` | `'done' \| 'error' \| 'none'` | `'done'` | Visual preset (iOS animated icon) |
|
|
53
|
+
| `duration` | `number` | — | Display duration in seconds |
|
|
54
|
+
| `haptic` | `'success' \| 'warning' \| 'error' \| 'none'` | `'success'` | Haptic feedback type |
|
|
55
|
+
| `shouldDismissByDrag` | `boolean` | `true` | Allow drag to dismiss (iOS only) |
|
|
56
|
+
| `from` | `'top' \| 'bottom'` | `'top'` | Presentation side (iOS only) |
|
|
57
|
+
|
|
58
|
+
## Platform Notes
|
|
59
|
+
|
|
60
|
+
### iOS
|
|
61
|
+
|
|
62
|
+
Full support for all options. Uses SPIndicator for native floating indicators with animated preset icons (checkmark, error cross).
|
|
63
|
+
|
|
64
|
+
### Android
|
|
65
|
+
|
|
66
|
+
Uses `android.widget.Toast` with haptic vibration feedback. The following options are iOS-only and ignored on Android:
|
|
67
|
+
|
|
68
|
+
- `from` — Android toast always appears at the bottom
|
|
69
|
+
- `shouldDismissByDrag` — Android toast is not draggable
|
|
70
|
+
- `preset` — No visual icon on Android toast
|
|
71
|
+
- `duration` — Maps to `Toast.LENGTH_SHORT` (<= 2s) or `Toast.LENGTH_LONG` (> 2s)
|
|
72
|
+
|
|
73
|
+
## Contributing
|
|
74
|
+
|
|
75
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
76
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
77
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
project(nitrosimpletoast)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set(PACKAGE_NAME nitrosimpletoast)
|
|
5
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Define C++ library and add all sources
|
|
9
|
+
add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
|
|
10
|
+
|
|
11
|
+
# Add Nitrogen specs :)
|
|
12
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/nitrosimpletoast+autolinking.cmake)
|
|
13
|
+
|
|
14
|
+
# Set up local includes
|
|
15
|
+
include_directories("src/main/cpp" "../cpp")
|
|
16
|
+
|
|
17
|
+
find_library(LOG_LIB log)
|
|
18
|
+
|
|
19
|
+
# Link all libraries together
|
|
20
|
+
target_link_libraries(
|
|
21
|
+
${PACKAGE_NAME}
|
|
22
|
+
${LOG_LIB}
|
|
23
|
+
android # <-- Android core
|
|
24
|
+
)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.NitroSimpleToast = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36,
|
|
6
|
+
targetSdkVersion: 36
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
ext.getExtOrDefault = { prop ->
|
|
10
|
+
if (rootProject.ext.has(prop)) {
|
|
11
|
+
return rootProject.ext.get(prop)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return NitroSimpleToast[prop]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
repositories {
|
|
18
|
+
google()
|
|
19
|
+
mavenCentral()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dependencies {
|
|
23
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
24
|
+
// noinspection DifferentKotlinGradleVersion
|
|
25
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def reactNativeArchitectures() {
|
|
30
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
31
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
apply plugin: "com.android.library"
|
|
35
|
+
apply plugin: "kotlin-android"
|
|
36
|
+
apply from: '../nitrogen/generated/android/nitrosimpletoast+autolinking.gradle'
|
|
37
|
+
|
|
38
|
+
apply plugin: "com.facebook.react"
|
|
39
|
+
|
|
40
|
+
android {
|
|
41
|
+
namespace "com.margelo.nitro.nitrosimpletoast"
|
|
42
|
+
|
|
43
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
44
|
+
|
|
45
|
+
defaultConfig {
|
|
46
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
47
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
48
|
+
|
|
49
|
+
externalNativeBuild {
|
|
50
|
+
cmake {
|
|
51
|
+
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
|
|
52
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
53
|
+
abiFilters (*reactNativeArchitectures())
|
|
54
|
+
|
|
55
|
+
buildTypes {
|
|
56
|
+
debug {
|
|
57
|
+
cppFlags "-O1 -g"
|
|
58
|
+
}
|
|
59
|
+
release {
|
|
60
|
+
cppFlags "-O2"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
externalNativeBuild {
|
|
68
|
+
cmake {
|
|
69
|
+
path "CMakeLists.txt"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
packagingOptions {
|
|
74
|
+
excludes = [
|
|
75
|
+
"META-INF",
|
|
76
|
+
"META-INF/**",
|
|
77
|
+
"**/libc++_shared.so",
|
|
78
|
+
"**/libfbjni.so",
|
|
79
|
+
"**/libjsi.so",
|
|
80
|
+
"**/libfolly_json.so",
|
|
81
|
+
"**/libfolly_runtime.so",
|
|
82
|
+
"**/libglog.so",
|
|
83
|
+
"**/libhermes.so",
|
|
84
|
+
"**/libhermes-executor-debug.so",
|
|
85
|
+
"**/libhermes_executor.so",
|
|
86
|
+
"**/libreactnative.so",
|
|
87
|
+
"**/libreactnativejni.so",
|
|
88
|
+
"**/libturbomodulejsijni.so",
|
|
89
|
+
"**/libreact_nativemodule_core.so",
|
|
90
|
+
"**/libjscexecutor.so"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
buildFeatures {
|
|
95
|
+
buildConfig true
|
|
96
|
+
prefab true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buildTypes {
|
|
100
|
+
release {
|
|
101
|
+
minifyEnabled false
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
lint {
|
|
106
|
+
disable "GradleCompatible"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
compileOptions {
|
|
110
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
111
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
dependencies {
|
|
116
|
+
implementation "com.facebook.react:react-android"
|
|
117
|
+
implementation project(":react-native-nitro-modules")
|
|
118
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package com.margelo.nitro.nitrosimpletoast
|
|
2
|
+
|
|
3
|
+
import android.os.Build
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.os.VibrationEffect
|
|
7
|
+
import android.os.Vibrator
|
|
8
|
+
import android.os.VibratorManager
|
|
9
|
+
import android.widget.Toast
|
|
10
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
11
|
+
|
|
12
|
+
@DoNotStrip
|
|
13
|
+
class NitroSimpleToast : HybridNitroSimpleToastSpec() {
|
|
14
|
+
|
|
15
|
+
override fun show(options: ToastOptions): Unit {
|
|
16
|
+
val context = NitroSimpleToastPackage.appContext ?: return
|
|
17
|
+
|
|
18
|
+
Handler(Looper.getMainLooper()).post {
|
|
19
|
+
val text = if (options.message != null) {
|
|
20
|
+
"${options.title}\n${options.message}"
|
|
21
|
+
} else {
|
|
22
|
+
options.title
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
val toastDuration = if (options.duration != null && options.duration!! > 2.0) {
|
|
26
|
+
Toast.LENGTH_LONG
|
|
27
|
+
} else {
|
|
28
|
+
Toast.LENGTH_SHORT
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Toast.makeText(context, text, toastDuration).show()
|
|
32
|
+
|
|
33
|
+
val haptic = options.haptic ?: ToastHaptic.SUCCESS
|
|
34
|
+
performHaptic(haptic)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private fun performHaptic(haptic: ToastHaptic) {
|
|
39
|
+
if (haptic == ToastHaptic.NONE) return
|
|
40
|
+
|
|
41
|
+
val context = NitroSimpleToastPackage.appContext ?: return
|
|
42
|
+
|
|
43
|
+
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
44
|
+
val vibratorManager = context.getSystemService(
|
|
45
|
+
android.content.Context.VIBRATOR_MANAGER_SERVICE
|
|
46
|
+
) as VibratorManager
|
|
47
|
+
vibratorManager.defaultVibrator
|
|
48
|
+
} else {
|
|
49
|
+
@Suppress("DEPRECATION")
|
|
50
|
+
context.getSystemService(android.content.Context.VIBRATOR_SERVICE) as Vibrator
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
54
|
+
val effect = when (haptic) {
|
|
55
|
+
ToastHaptic.SUCCESS -> VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)
|
|
56
|
+
ToastHaptic.WARNING -> VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE)
|
|
57
|
+
ToastHaptic.ERROR -> VibrationEffect.createWaveform(longArrayOf(0, 50, 50, 50), -1)
|
|
58
|
+
ToastHaptic.NONE -> return
|
|
59
|
+
}
|
|
60
|
+
vibrator.vibrate(effect)
|
|
61
|
+
} else {
|
|
62
|
+
@Suppress("DEPRECATION")
|
|
63
|
+
vibrator.vibrate(50)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package com.margelo.nitro.nitrosimpletoast
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
+
|
|
8
|
+
class NitroSimpleToastPackage : BaseReactPackage() {
|
|
9
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
10
|
+
appContext = reactContext
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
15
|
+
return ReactModuleInfoProvider { HashMap() }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
companion object {
|
|
19
|
+
init {
|
|
20
|
+
System.loadLibrary("nitrosimpletoast")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Volatile
|
|
24
|
+
var appContext: ReactApplicationContext? = null
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import SPIndicator
|
|
2
|
+
import UIKit
|
|
3
|
+
import NitroModules
|
|
4
|
+
|
|
5
|
+
class NitroSimpleToast: HybridNitroSimpleToastSpec {
|
|
6
|
+
func show(options: ToastOptions) throws -> Void {
|
|
7
|
+
DispatchQueue.main.async {
|
|
8
|
+
let indicatorView: SPIndicatorView
|
|
9
|
+
|
|
10
|
+
switch options.preset ?? .done {
|
|
11
|
+
case .done:
|
|
12
|
+
indicatorView = SPIndicatorView(
|
|
13
|
+
title: options.title,
|
|
14
|
+
message: options.message,
|
|
15
|
+
preset: .done
|
|
16
|
+
)
|
|
17
|
+
case .error:
|
|
18
|
+
indicatorView = SPIndicatorView(
|
|
19
|
+
title: options.title,
|
|
20
|
+
message: options.message,
|
|
21
|
+
preset: .error
|
|
22
|
+
)
|
|
23
|
+
case .none:
|
|
24
|
+
indicatorView = SPIndicatorView(
|
|
25
|
+
title: options.title,
|
|
26
|
+
message: options.message
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if let duration = options.duration {
|
|
31
|
+
indicatorView.duration = duration
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if let shouldDismissByDrag = options.shouldDismissByDrag {
|
|
35
|
+
indicatorView.dismissByDrag = shouldDismissByDrag
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch options.from ?? .top {
|
|
39
|
+
case .top:
|
|
40
|
+
indicatorView.presentSide = .top
|
|
41
|
+
case .bottom:
|
|
42
|
+
indicatorView.presentSide = .bottom
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let haptic: SPIndicatorHaptic
|
|
46
|
+
switch options.haptic ?? .success {
|
|
47
|
+
case .success:
|
|
48
|
+
haptic = .success
|
|
49
|
+
case .warning:
|
|
50
|
+
haptic = .warning
|
|
51
|
+
case .error:
|
|
52
|
+
haptic = .error
|
|
53
|
+
case .none:
|
|
54
|
+
haptic = .none
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
indicatorView.present(haptic: haptic)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["NitroSimpleToast.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
const NitroSimpleToastHybridObject = NitroModules.createHybridObject('NitroSimpleToast');
|
|
5
|
+
export function toast(options) {
|
|
6
|
+
NitroSimpleToastHybridObject.show(options);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","NitroSimpleToastHybridObject","createHybridObject","toast","options","show"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,MAAMC,4BAA4B,GAChCD,YAAY,CAACE,kBAAkB,CAAmB,kBAAkB,CAAC;AASvE,OAAO,SAASC,KAAKA,CAACC,OAAqB,EAAQ;EACjDH,4BAA4B,CAACI,IAAI,CAACD,OAAO,CAAC;AAC5C","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export type ToastPreset = 'done' | 'error' | 'none';
|
|
3
|
+
export type ToastHaptic = 'success' | 'warning' | 'error' | 'none';
|
|
4
|
+
export type ToastFrom = 'top' | 'bottom';
|
|
5
|
+
export interface ToastOptions {
|
|
6
|
+
title: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Defaults to `done`.
|
|
10
|
+
*/
|
|
11
|
+
preset?: ToastPreset;
|
|
12
|
+
/**
|
|
13
|
+
* Duration in seconds.
|
|
14
|
+
*/
|
|
15
|
+
duration?: number;
|
|
16
|
+
haptic?: ToastHaptic;
|
|
17
|
+
/**
|
|
18
|
+
* Defaults to `true`.
|
|
19
|
+
*/
|
|
20
|
+
shouldDismissByDrag?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Change the presentation side.
|
|
23
|
+
* @platform ios
|
|
24
|
+
*/
|
|
25
|
+
from?: ToastFrom;
|
|
26
|
+
}
|
|
27
|
+
export interface NitroSimpleToast extends HybridObject<{
|
|
28
|
+
ios: 'swift';
|
|
29
|
+
android: 'kotlin';
|
|
30
|
+
}> {
|
|
31
|
+
show(options: ToastOptions): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=NitroSimpleToast.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NitroSimpleToast.nitro.d.ts","sourceRoot":"","sources":["../../../src/NitroSimpleToast.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAEnE,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,gBACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAK/E,YAAY,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,GACV,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAEjD"}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cxxNamespace": ["nitrosimpletoast"],
|
|
3
|
+
"ios": {
|
|
4
|
+
"iosModuleName": "NitroSimpleToast"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"androidNamespace": ["nitrosimpletoast"],
|
|
8
|
+
"androidCxxLibName": "nitrosimpletoast"
|
|
9
|
+
},
|
|
10
|
+
"autolinking": {
|
|
11
|
+
"NitroSimpleToast": {
|
|
12
|
+
"ios": {
|
|
13
|
+
"language": "swift",
|
|
14
|
+
"implementationClassName": "NitroSimpleToast"
|
|
15
|
+
},
|
|
16
|
+
"android": {
|
|
17
|
+
"language": "kotlin",
|
|
18
|
+
"implementationClassName": "NitroSimpleToast"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"ignorePaths": ["node_modules"]
|
|
23
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridNitroSimpleToastSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "JHybridNitroSimpleToastSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `ToastOptions` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::nitrosimpletoast { struct ToastOptions; }
|
|
12
|
+
// Forward declaration of `ToastPreset` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::nitrosimpletoast { enum class ToastPreset; }
|
|
14
|
+
// Forward declaration of `ToastHaptic` to properly resolve imports.
|
|
15
|
+
namespace margelo::nitro::nitrosimpletoast { enum class ToastHaptic; }
|
|
16
|
+
// Forward declaration of `ToastFrom` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrosimpletoast { enum class ToastFrom; }
|
|
18
|
+
|
|
19
|
+
#include "ToastOptions.hpp"
|
|
20
|
+
#include "JToastOptions.hpp"
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <optional>
|
|
23
|
+
#include "ToastPreset.hpp"
|
|
24
|
+
#include "JToastPreset.hpp"
|
|
25
|
+
#include "ToastHaptic.hpp"
|
|
26
|
+
#include "JToastHaptic.hpp"
|
|
27
|
+
#include "ToastFrom.hpp"
|
|
28
|
+
#include "JToastFrom.hpp"
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::nitrosimpletoast {
|
|
31
|
+
|
|
32
|
+
std::shared_ptr<JHybridNitroSimpleToastSpec> JHybridNitroSimpleToastSpec::JavaPart::getJHybridNitroSimpleToastSpec() {
|
|
33
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
34
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridNitroSimpleToastSpec>(hybridObject);
|
|
35
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
36
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridNitroSimpleToastSpec!");
|
|
37
|
+
}
|
|
38
|
+
return castHybridObject;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
jni::local_ref<JHybridNitroSimpleToastSpec::CxxPart::jhybriddata> JHybridNitroSimpleToastSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
42
|
+
return makeCxxInstance(jThis);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
std::shared_ptr<JHybridObject> JHybridNitroSimpleToastSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
46
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridNitroSimpleToastSpec::JavaPart>(javaPart);
|
|
47
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
48
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridNitroSimpleToastSpec::JavaPart!");
|
|
49
|
+
}
|
|
50
|
+
return std::make_shared<JHybridNitroSimpleToastSpec>(castJavaPart);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void JHybridNitroSimpleToastSpec::CxxPart::registerNatives() {
|
|
54
|
+
registerHybrid({
|
|
55
|
+
makeNativeMethod("initHybrid", JHybridNitroSimpleToastSpec::CxxPart::initHybrid),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Properties
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// Methods
|
|
63
|
+
void JHybridNitroSimpleToastSpec::show(const ToastOptions& options) {
|
|
64
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JToastOptions> /* options */)>("show");
|
|
65
|
+
method(_javaPart, JToastOptions::fromCpp(options));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
} // namespace margelo::nitro::nitrosimpletoast
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroSimpleToastSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridNitroSimpleToastSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::nitrosimpletoast {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridNitroSimpleToastSpec: public virtual HybridNitroSimpleToastSpec, public virtual JHybridObject {
|
|
22
|
+
public:
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosimpletoast/HybridNitroSimpleToastSpec;";
|
|
25
|
+
std::shared_ptr<JHybridNitroSimpleToastSpec> getJHybridNitroSimpleToastSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosimpletoast/HybridNitroSimpleToastSpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
explicit JHybridNitroSimpleToastSpec(const jni::local_ref<JHybridNitroSimpleToastSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridNitroSimpleToastSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
41
|
+
~JHybridNitroSimpleToastSpec() override {
|
|
42
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
43
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridNitroSimpleToastSpec::JavaPart>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
void show(const ToastOptions& options) override;
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
jni::global_ref<JHybridNitroSimpleToastSpec::JavaPart> _javaPart;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
} // namespace margelo::nitro::nitrosimpletoast
|