react-native-nitro-simple-toast 0.1.0 → 0.1.1-beta.1

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.
Files changed (34) hide show
  1. package/android/build.gradle +6 -0
  2. package/android/src/main/java/com/margelo/nitro/nitrosimpletoast/NitroSimpleToast.kt +111 -17
  3. package/android/src/main/java/com/margelo/nitro/nitrosimpletoast/NitroSimpleToastPackage.kt +0 -4
  4. package/android/src/main/res/anim/toast_bottom_in.xml +12 -0
  5. package/android/src/main/res/anim/toast_bottom_out.xml +12 -0
  6. package/android/src/main/res/anim/toast_top_in.xml +12 -0
  7. package/android/src/main/res/anim/toast_top_out.xml +12 -0
  8. package/android/src/main/res/drawable/ic_toast_done.xml +10 -0
  9. package/android/src/main/res/drawable/ic_toast_error.xml +10 -0
  10. package/android/src/main/res/drawable/toast_bg_dark.xml +6 -0
  11. package/android/src/main/res/drawable/toast_bg_light.xml +6 -0
  12. package/android/src/main/res/layout/toast_layout.xml +46 -0
  13. package/android/src/main/res/values/styles.xml +12 -0
  14. package/ios/NitroSimpleToast.swift +9 -0
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/typescript/src/NitroSimpleToast.nitro.d.ts +5 -0
  17. package/lib/typescript/src/NitroSimpleToast.nitro.d.ts.map +1 -1
  18. package/lib/typescript/src/index.d.ts +1 -1
  19. package/lib/typescript/src/index.d.ts.map +1 -1
  20. package/nitrogen/generated/android/c++/JHybridNitroSimpleToastSpec.cpp +4 -0
  21. package/nitrogen/generated/android/c++/JToastOptions.hpp +9 -3
  22. package/nitrogen/generated/android/c++/JToastTheme.hpp +61 -0
  23. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/ToastOptions.kt +6 -3
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosimpletoast/ToastTheme.kt +24 -0
  25. package/nitrogen/generated/ios/NitroSimpleToast-Swift-Cxx-Bridge.hpp +18 -0
  26. package/nitrogen/generated/ios/NitroSimpleToast-Swift-Cxx-Umbrella.hpp +3 -0
  27. package/nitrogen/generated/ios/c++/HybridNitroSimpleToastSpecSwift.hpp +3 -0
  28. package/nitrogen/generated/ios/swift/ToastOptions.swift +12 -1
  29. package/nitrogen/generated/ios/swift/ToastTheme.swift +44 -0
  30. package/nitrogen/generated/shared/c++/ToastOptions.hpp +9 -2
  31. package/nitrogen/generated/shared/c++/ToastTheme.hpp +80 -0
  32. package/package.json +1 -1
  33. package/src/NitroSimpleToast.nitro.ts +6 -0
  34. package/src/index.tsx +1 -0
@@ -17,6 +17,7 @@ buildscript {
17
17
  repositories {
18
18
  google()
19
19
  mavenCentral()
20
+ maven { url 'https://jitpack.io' }
20
21
  }
21
22
 
22
23
  dependencies {
@@ -112,7 +113,12 @@ android {
112
113
  }
113
114
  }
114
115
 
116
+ repositories {
117
+ maven { url 'https://jitpack.io' }
118
+ }
119
+
115
120
  dependencies {
116
121
  implementation "com.facebook.react:react-android"
117
122
  implementation project(":react-native-nitro-modules")
123
+ implementation 'com.github.getActivity:EasyWindow:10.62'
118
124
  }
@@ -1,44 +1,134 @@
1
1
  package com.margelo.nitro.nitrosimpletoast
2
2
 
3
+ import android.app.Activity
4
+ import android.content.res.Configuration
5
+ import android.graphics.Color
3
6
  import android.os.Build
4
- import android.os.Handler
5
- import android.os.Looper
6
7
  import android.os.VibrationEffect
7
8
  import android.os.Vibrator
8
9
  import android.os.VibratorManager
9
- import android.widget.Toast
10
+ import android.util.Log
11
+ import android.view.Gravity
12
+ import android.view.LayoutInflater
13
+ import android.view.View
14
+ import android.widget.ImageView
15
+ import android.widget.LinearLayout
16
+ import android.widget.TextView
10
17
  import com.facebook.proguard.annotations.DoNotStrip
18
+ import com.hjq.window.EasyWindow
19
+ import com.margelo.nitro.NitroModules
11
20
 
12
21
  @DoNotStrip
13
22
  class NitroSimpleToast : HybridNitroSimpleToastSpec() {
14
23
 
24
+ private var toastWindow: EasyWindow<*>? = null
25
+
15
26
  override fun show(options: ToastOptions): Unit {
16
- val context = NitroSimpleToastPackage.appContext ?: return
27
+ val activity = NitroModules.applicationContext?.currentActivity
28
+ if (activity == null) {
29
+ Log.e(TAG, "currentActivity is null, cannot show toast")
30
+ return
31
+ }
17
32
 
18
- Handler(Looper.getMainLooper()).post {
19
- val text = if (options.message != null) {
20
- "${options.title}\n${options.message}"
21
- } else {
22
- options.title
33
+ activity.runOnUiThread {
34
+ try {
35
+ showToast(activity, options)
36
+ } catch (e: Exception) {
37
+ Log.e(TAG, "Failed to show toast", e)
23
38
  }
39
+ }
40
+ }
41
+
42
+ private fun showToast(activity: Activity, options: ToastOptions) {
43
+ // Dismiss existing toast
44
+ toastWindow?.cancel()
45
+
46
+ // Inflate layout
47
+ val container = LayoutInflater.from(activity)
48
+ .inflate(R.layout.toast_layout, null) as LinearLayout
49
+
50
+ // Resolve theme
51
+ val isDark = resolveIsDark(activity, options.theme)
52
+
53
+ // Apply background
54
+ container.setBackgroundResource(
55
+ if (isDark) R.drawable.toast_bg_dark else R.drawable.toast_bg_light
56
+ )
57
+
58
+ // Text colors
59
+ val textColor = if (isDark) Color.parseColor("#F5F5F6") else Color.parseColor("#16171A")
60
+
61
+ // Title
62
+ val titleView = container.findViewById<TextView>(R.id.toast_title)
63
+ titleView.text = options.title
64
+ titleView.setTextColor(textColor)
65
+
66
+ // Message
67
+ val messageView = container.findViewById<TextView>(R.id.toast_message)
68
+ if (options.message != null) {
69
+ messageView.text = options.message
70
+ messageView.setTextColor(textColor)
71
+ messageView.visibility = View.VISIBLE
72
+ }
24
73
 
25
- val toastDuration = if (options.duration != null && options.duration!! > 2.0) {
26
- Toast.LENGTH_LONG
27
- } else {
28
- Toast.LENGTH_SHORT
74
+ // Icon based on preset
75
+ val iconView = container.findViewById<ImageView>(R.id.toast_icon)
76
+ when (options.preset ?: ToastPreset.DONE) {
77
+ ToastPreset.DONE -> {
78
+ iconView.setImageResource(R.drawable.ic_toast_done)
79
+ iconView.visibility = View.VISIBLE
29
80
  }
81
+ ToastPreset.ERROR -> {
82
+ iconView.setImageResource(R.drawable.ic_toast_error)
83
+ iconView.visibility = View.VISIBLE
84
+ }
85
+ ToastPreset.NONE -> {
86
+ iconView.visibility = View.GONE
87
+ }
88
+ }
89
+
90
+ // Position
91
+ val isBottom = options.from == ToastFrom.BOTTOM
92
+ val gravity = if (isBottom) Gravity.BOTTOM else Gravity.TOP
93
+ val animStyle = if (isBottom) R.style.ToastAnimBottom else R.style.ToastAnimTop
94
+
95
+ // Duration in milliseconds (default 3 seconds)
96
+ val durationMs = ((options.duration ?: 3.0) * 1000).toInt()
97
+
98
+ // Show with EasyWindow
99
+ toastWindow = EasyWindow<EasyWindow<*>>(activity).apply {
100
+ setDuration(durationMs)
101
+ setContentView(container)
102
+ setGravity(gravity)
103
+ setYOffset(48)
104
+ setAnimStyle(animStyle)
105
+ setOutsideTouchable(true)
106
+ }
107
+ toastWindow?.show()
108
+
109
+ Log.d(TAG, "Toast shown: ${options.title}")
30
110
 
31
- Toast.makeText(context, text, toastDuration).show()
111
+ // Haptic
112
+ performHaptic(options.haptic ?: ToastHaptic.SUCCESS)
113
+ }
32
114
 
33
- val haptic = options.haptic ?: ToastHaptic.SUCCESS
34
- performHaptic(haptic)
115
+ private fun resolveIsDark(activity: Activity, theme: ToastTheme?): Boolean {
116
+ return when (theme ?: ToastTheme.SYSTEM) {
117
+ ToastTheme.DARK -> true
118
+ ToastTheme.LIGHT -> false
119
+ ToastTheme.SYSTEM -> {
120
+ val nightMode = activity.resources.configuration.uiMode and
121
+ Configuration.UI_MODE_NIGHT_MASK
122
+ nightMode == Configuration.UI_MODE_NIGHT_YES
123
+ }
35
124
  }
36
125
  }
37
126
 
38
127
  private fun performHaptic(haptic: ToastHaptic) {
39
128
  if (haptic == ToastHaptic.NONE) return
40
129
 
41
- val context = NitroSimpleToastPackage.appContext ?: return
130
+ val reactContext = NitroModules.applicationContext ?: return
131
+ val context = reactContext.applicationContext
42
132
 
43
133
  val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
44
134
  val vibratorManager = context.getSystemService(
@@ -63,4 +153,8 @@ class NitroSimpleToast : HybridNitroSimpleToastSpec() {
63
153
  vibrator.vibrate(50)
64
154
  }
65
155
  }
156
+
157
+ companion object {
158
+ private const val TAG = "NitroSimpleToast"
159
+ }
66
160
  }
@@ -7,7 +7,6 @@ import com.facebook.react.module.model.ReactModuleInfoProvider
7
7
 
8
8
  class NitroSimpleToastPackage : BaseReactPackage() {
9
9
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
10
- appContext = reactContext
11
10
  return null
12
11
  }
13
12
 
@@ -19,8 +18,5 @@ class NitroSimpleToastPackage : BaseReactPackage() {
19
18
  init {
20
19
  System.loadLibrary("nitrosimpletoast")
21
20
  }
22
-
23
- @Volatile
24
- var appContext: ReactApplicationContext? = null
25
21
  }
26
22
  }
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <set xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <translate
4
+ android:fromYDelta="100%"
5
+ android:toYDelta="0"
6
+ android:duration="300"
7
+ android:interpolator="@android:anim/decelerate_interpolator" />
8
+ <alpha
9
+ android:fromAlpha="0.0"
10
+ android:toAlpha="1.0"
11
+ android:duration="200" />
12
+ </set>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <set xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <translate
4
+ android:fromYDelta="0"
5
+ android:toYDelta="100%"
6
+ android:duration="300"
7
+ android:interpolator="@android:anim/accelerate_interpolator" />
8
+ <alpha
9
+ android:fromAlpha="1.0"
10
+ android:toAlpha="0.0"
11
+ android:duration="300" />
12
+ </set>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <set xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <translate
4
+ android:fromYDelta="-100%"
5
+ android:toYDelta="0"
6
+ android:duration="300"
7
+ android:interpolator="@android:anim/decelerate_interpolator" />
8
+ <alpha
9
+ android:fromAlpha="0.0"
10
+ android:toAlpha="1.0"
11
+ android:duration="200" />
12
+ </set>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <set xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <translate
4
+ android:fromYDelta="0"
5
+ android:toYDelta="-100%"
6
+ android:duration="300"
7
+ android:interpolator="@android:anim/accelerate_interpolator" />
8
+ <alpha
9
+ android:fromAlpha="1.0"
10
+ android:toAlpha="0.0"
11
+ android:duration="300" />
12
+ </set>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:width="24dp"
4
+ android:height="24dp"
5
+ android:viewportWidth="24"
6
+ android:viewportHeight="24">
7
+ <path
8
+ android:fillColor="#34C759"
9
+ android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" />
10
+ </vector>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:width="24dp"
4
+ android:height="24dp"
5
+ android:viewportWidth="24"
6
+ android:viewportHeight="24">
7
+ <path
8
+ android:fillColor="#FF3B30"
9
+ android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
10
+ </vector>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <shape xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:shape="rectangle">
4
+ <solid android:color="#2B2D33" />
5
+ <corners android:radius="12dp" />
6
+ </shape>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <shape xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:shape="rectangle">
4
+ <solid android:color="#E2E3E6" />
5
+ <corners android:radius="12dp" />
6
+ </shape>
@@ -0,0 +1,46 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:id="@+id/toast_container"
4
+ android:layout_width="wrap_content"
5
+ android:layout_height="wrap_content"
6
+ android:orientation="horizontal"
7
+ android:gravity="center_vertical"
8
+ android:paddingHorizontal="16dp"
9
+ android:paddingVertical="12dp"
10
+ android:minWidth="120dp"
11
+ android:elevation="4dp">
12
+
13
+ <ImageView
14
+ android:id="@+id/toast_icon"
15
+ android:layout_width="24dp"
16
+ android:layout_height="24dp"
17
+ android:layout_marginEnd="10dp"
18
+ android:visibility="gone" />
19
+
20
+ <LinearLayout
21
+ android:layout_width="wrap_content"
22
+ android:layout_height="wrap_content"
23
+ android:orientation="vertical">
24
+
25
+ <TextView
26
+ android:id="@+id/toast_title"
27
+ android:layout_width="wrap_content"
28
+ android:layout_height="wrap_content"
29
+ android:textSize="13sp"
30
+ android:textStyle="bold"
31
+ android:maxLines="1"
32
+ android:ellipsize="end" />
33
+
34
+ <TextView
35
+ android:id="@+id/toast_message"
36
+ android:layout_width="wrap_content"
37
+ android:layout_height="wrap_content"
38
+ android:textSize="12sp"
39
+ android:maxLines="2"
40
+ android:ellipsize="end"
41
+ android:layout_marginTop="2dp"
42
+ android:visibility="gone" />
43
+
44
+ </LinearLayout>
45
+
46
+ </LinearLayout>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <style name="ToastAnimTop">
4
+ <item name="android:windowEnterAnimation">@anim/toast_top_in</item>
5
+ <item name="android:windowExitAnimation">@anim/toast_top_out</item>
6
+ </style>
7
+
8
+ <style name="ToastAnimBottom">
9
+ <item name="android:windowEnterAnimation">@anim/toast_bottom_in</item>
10
+ <item name="android:windowExitAnimation">@anim/toast_bottom_out</item>
11
+ </style>
12
+ </resources>
@@ -27,6 +27,15 @@ class NitroSimpleToast: HybridNitroSimpleToastSpec {
27
27
  )
28
28
  }
29
29
 
30
+ switch options.theme ?? .system {
31
+ case .light:
32
+ indicatorView.overrideUserInterfaceStyle = .light
33
+ case .dark:
34
+ indicatorView.overrideUserInterfaceStyle = .dark
35
+ case .system:
36
+ break
37
+ }
38
+
30
39
  if let duration = options.duration {
31
40
  indicatorView.duration = duration
32
41
  }
@@ -1 +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":[]}
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;AAUvE,OAAO,SAASC,KAAKA,CAACC,OAAqB,EAAQ;EACjDH,4BAA4B,CAACI,IAAI,CAACD,OAAO,CAAC;AAC5C","ignoreList":[]}
@@ -2,6 +2,7 @@ import type { HybridObject } from 'react-native-nitro-modules';
2
2
  export type ToastPreset = 'done' | 'error' | 'none';
3
3
  export type ToastHaptic = 'success' | 'warning' | 'error' | 'none';
4
4
  export type ToastFrom = 'top' | 'bottom';
5
+ export type ToastTheme = 'light' | 'dark' | 'system';
5
6
  export interface ToastOptions {
6
7
  title: string;
7
8
  message?: string;
@@ -23,6 +24,10 @@ export interface ToastOptions {
23
24
  * @platform ios
24
25
  */
25
26
  from?: ToastFrom;
27
+ /**
28
+ * Defaults to `system`.
29
+ */
30
+ theme?: ToastTheme;
26
31
  }
27
32
  export interface NitroSimpleToast extends HybridObject<{
28
33
  ios: 'swift';
@@ -1 +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"}
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,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAErD,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;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;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"}
@@ -1,4 +1,4 @@
1
1
  import type { ToastOptions } from './NitroSimpleToast.nitro';
2
- export type { ToastOptions, ToastPreset, ToastHaptic, ToastFrom, } from './NitroSimpleToast.nitro';
2
+ export type { ToastOptions, ToastPreset, ToastHaptic, ToastFrom, ToastTheme, } from './NitroSimpleToast.nitro';
3
3
  export declare function toast(options: ToastOptions): void;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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,EACT,UAAU,GACX,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAEjD"}
@@ -15,6 +15,8 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastPreset; }
15
15
  namespace margelo::nitro::nitrosimpletoast { enum class ToastHaptic; }
16
16
  // Forward declaration of `ToastFrom` to properly resolve imports.
17
17
  namespace margelo::nitro::nitrosimpletoast { enum class ToastFrom; }
18
+ // Forward declaration of `ToastTheme` to properly resolve imports.
19
+ namespace margelo::nitro::nitrosimpletoast { enum class ToastTheme; }
18
20
 
19
21
  #include "ToastOptions.hpp"
20
22
  #include "JToastOptions.hpp"
@@ -26,6 +28,8 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastFrom; }
26
28
  #include "JToastHaptic.hpp"
27
29
  #include "ToastFrom.hpp"
28
30
  #include "JToastFrom.hpp"
31
+ #include "ToastTheme.hpp"
32
+ #include "JToastTheme.hpp"
29
33
 
30
34
  namespace margelo::nitro::nitrosimpletoast {
31
35
 
@@ -13,9 +13,11 @@
13
13
  #include "JToastFrom.hpp"
14
14
  #include "JToastHaptic.hpp"
15
15
  #include "JToastPreset.hpp"
16
+ #include "JToastTheme.hpp"
16
17
  #include "ToastFrom.hpp"
17
18
  #include "ToastHaptic.hpp"
18
19
  #include "ToastPreset.hpp"
20
+ #include "ToastTheme.hpp"
19
21
  #include <optional>
20
22
  #include <string>
21
23
 
@@ -52,6 +54,8 @@ namespace margelo::nitro::nitrosimpletoast {
52
54
  jni::local_ref<jni::JBoolean> shouldDismissByDrag = this->getFieldValue(fieldShouldDismissByDrag);
53
55
  static const auto fieldFrom = clazz->getField<JToastFrom>("from");
54
56
  jni::local_ref<JToastFrom> from = this->getFieldValue(fieldFrom);
57
+ static const auto fieldTheme = clazz->getField<JToastTheme>("theme");
58
+ jni::local_ref<JToastTheme> theme = this->getFieldValue(fieldTheme);
55
59
  return ToastOptions(
56
60
  title->toStdString(),
57
61
  message != nullptr ? std::make_optional(message->toStdString()) : std::nullopt,
@@ -59,7 +63,8 @@ namespace margelo::nitro::nitrosimpletoast {
59
63
  duration != nullptr ? std::make_optional(duration->value()) : std::nullopt,
60
64
  haptic != nullptr ? std::make_optional(haptic->toCpp()) : std::nullopt,
61
65
  shouldDismissByDrag != nullptr ? std::make_optional(static_cast<bool>(shouldDismissByDrag->value())) : std::nullopt,
62
- from != nullptr ? std::make_optional(from->toCpp()) : std::nullopt
66
+ from != nullptr ? std::make_optional(from->toCpp()) : std::nullopt,
67
+ theme != nullptr ? std::make_optional(theme->toCpp()) : std::nullopt
63
68
  );
64
69
  }
65
70
 
@@ -69,7 +74,7 @@ namespace margelo::nitro::nitrosimpletoast {
69
74
  */
70
75
  [[maybe_unused]]
71
76
  static jni::local_ref<JToastOptions::javaobject> fromCpp(const ToastOptions& value) {
72
- using JSignature = JToastOptions(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JToastPreset>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JToastHaptic>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JToastFrom>);
77
+ using JSignature = JToastOptions(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JToastPreset>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JToastHaptic>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JToastFrom>, jni::alias_ref<JToastTheme>);
73
78
  static const auto clazz = javaClassStatic();
74
79
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
75
80
  return create(
@@ -80,7 +85,8 @@ namespace margelo::nitro::nitrosimpletoast {
80
85
  value.duration.has_value() ? jni::JDouble::valueOf(value.duration.value()) : nullptr,
81
86
  value.haptic.has_value() ? JToastHaptic::fromCpp(value.haptic.value()) : nullptr,
82
87
  value.shouldDismissByDrag.has_value() ? jni::JBoolean::valueOf(value.shouldDismissByDrag.value()) : nullptr,
83
- value.from.has_value() ? JToastFrom::fromCpp(value.from.value()) : nullptr
88
+ value.from.has_value() ? JToastFrom::fromCpp(value.from.value()) : nullptr,
89
+ value.theme.has_value() ? JToastTheme::fromCpp(value.theme.value()) : nullptr
84
90
  );
85
91
  }
86
92
  };
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JToastTheme.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 <fbjni/fbjni.h>
11
+ #include "ToastTheme.hpp"
12
+
13
+ namespace margelo::nitro::nitrosimpletoast {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "ToastTheme" and the the Kotlin enum "ToastTheme".
19
+ */
20
+ struct JToastTheme final: public jni::JavaClass<JToastTheme> {
21
+ public:
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosimpletoast/ToastTheme;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum ToastTheme.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ ToastTheme toCpp() const {
31
+ static const auto clazz = javaClassStatic();
32
+ static const auto fieldOrdinal = clazz->getField<int>("value");
33
+ int ordinal = this->getFieldValue(fieldOrdinal);
34
+ return static_cast<ToastTheme>(ordinal);
35
+ }
36
+
37
+ public:
38
+ /**
39
+ * Create a Java/Kotlin-based enum with the given C++ enum's value.
40
+ */
41
+ [[maybe_unused]]
42
+ static jni::alias_ref<JToastTheme> fromCpp(ToastTheme value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case ToastTheme::LIGHT:
46
+ static const auto fieldLIGHT = clazz->getStaticField<JToastTheme>("LIGHT");
47
+ return clazz->getStaticFieldValue(fieldLIGHT);
48
+ case ToastTheme::DARK:
49
+ static const auto fieldDARK = clazz->getStaticField<JToastTheme>("DARK");
50
+ return clazz->getStaticFieldValue(fieldDARK);
51
+ case ToastTheme::SYSTEM:
52
+ static const auto fieldSYSTEM = clazz->getStaticField<JToastTheme>("SYSTEM");
53
+ return clazz->getStaticFieldValue(fieldSYSTEM);
54
+ default:
55
+ std::string stringValue = std::to_string(static_cast<int>(value));
56
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
57
+ }
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::nitrosimpletoast
@@ -37,7 +37,10 @@ data class ToastOptions(
37
37
  val shouldDismissByDrag: Boolean?,
38
38
  @DoNotStrip
39
39
  @Keep
40
- val from: ToastFrom?
40
+ val from: ToastFrom?,
41
+ @DoNotStrip
42
+ @Keep
43
+ val theme: ToastTheme?
41
44
  ) {
42
45
  /* primary constructor */
43
46
 
@@ -49,8 +52,8 @@ data class ToastOptions(
49
52
  @Keep
50
53
  @Suppress("unused")
51
54
  @JvmStatic
52
- private fun fromCpp(title: String, message: String?, preset: ToastPreset?, duration: Double?, haptic: ToastHaptic?, shouldDismissByDrag: Boolean?, from: ToastFrom?): ToastOptions {
53
- return ToastOptions(title, message, preset, duration, haptic, shouldDismissByDrag, from)
55
+ private fun fromCpp(title: String, message: String?, preset: ToastPreset?, duration: Double?, haptic: ToastHaptic?, shouldDismissByDrag: Boolean?, from: ToastFrom?, theme: ToastTheme?): ToastOptions {
56
+ return ToastOptions(title, message, preset, duration, haptic, shouldDismissByDrag, from, theme)
54
57
  }
55
58
  }
56
59
  }
@@ -0,0 +1,24 @@
1
+ ///
2
+ /// ToastTheme.kt
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
+ package com.margelo.nitro.nitrosimpletoast
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+ /**
14
+ * Represents the JavaScript enum/union "ToastTheme".
15
+ */
16
+ @DoNotStrip
17
+ @Keep
18
+ enum class ToastTheme(@DoNotStrip @Keep val value: Int) {
19
+ LIGHT(0),
20
+ DARK(1),
21
+ SYSTEM(2);
22
+
23
+ companion object
24
+ }
@@ -16,6 +16,8 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastFrom; }
16
16
  namespace margelo::nitro::nitrosimpletoast { enum class ToastHaptic; }
17
17
  // Forward declaration of `ToastPreset` to properly resolve imports.
18
18
  namespace margelo::nitro::nitrosimpletoast { enum class ToastPreset; }
19
+ // Forward declaration of `ToastTheme` to properly resolve imports.
20
+ namespace margelo::nitro::nitrosimpletoast { enum class ToastTheme; }
19
21
 
20
22
  // Forward declarations of Swift defined types
21
23
  // Forward declaration of `HybridNitroSimpleToastSpec_cxx` to properly resolve imports.
@@ -26,6 +28,7 @@ namespace NitroSimpleToast { class HybridNitroSimpleToastSpec_cxx; }
26
28
  #include "ToastFrom.hpp"
27
29
  #include "ToastHaptic.hpp"
28
30
  #include "ToastPreset.hpp"
31
+ #include "ToastTheme.hpp"
29
32
  #include <NitroModules/Result.hpp>
30
33
  #include <exception>
31
34
  #include <memory>
@@ -128,6 +131,21 @@ namespace margelo::nitro::nitrosimpletoast::bridge::swift {
128
131
  return optional.value();
129
132
  }
130
133
 
134
+ // pragma MARK: std::optional<ToastTheme>
135
+ /**
136
+ * Specialized version of `std::optional<ToastTheme>`.
137
+ */
138
+ using std__optional_ToastTheme_ = std::optional<ToastTheme>;
139
+ inline std::optional<ToastTheme> create_std__optional_ToastTheme_(const ToastTheme& value) noexcept {
140
+ return std::optional<ToastTheme>(value);
141
+ }
142
+ inline bool has_value_std__optional_ToastTheme_(const std::optional<ToastTheme>& optional) noexcept {
143
+ return optional.has_value();
144
+ }
145
+ inline ToastTheme get_std__optional_ToastTheme_(const std::optional<ToastTheme>& optional) noexcept {
146
+ return optional.value();
147
+ }
148
+
131
149
  // pragma MARK: std::shared_ptr<HybridNitroSimpleToastSpec>
132
150
  /**
133
151
  * Specialized version of `std::shared_ptr<HybridNitroSimpleToastSpec>`.
@@ -18,6 +18,8 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastHaptic; }
18
18
  namespace margelo::nitro::nitrosimpletoast { struct ToastOptions; }
19
19
  // Forward declaration of `ToastPreset` to properly resolve imports.
20
20
  namespace margelo::nitro::nitrosimpletoast { enum class ToastPreset; }
21
+ // Forward declaration of `ToastTheme` to properly resolve imports.
22
+ namespace margelo::nitro::nitrosimpletoast { enum class ToastTheme; }
21
23
 
22
24
  // Include C++ defined types
23
25
  #include "HybridNitroSimpleToastSpec.hpp"
@@ -25,6 +27,7 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastPreset; }
25
27
  #include "ToastHaptic.hpp"
26
28
  #include "ToastOptions.hpp"
27
29
  #include "ToastPreset.hpp"
30
+ #include "ToastTheme.hpp"
28
31
  #include <NitroModules/Result.hpp>
29
32
  #include <exception>
30
33
  #include <memory>
@@ -20,6 +20,8 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastPreset; }
20
20
  namespace margelo::nitro::nitrosimpletoast { enum class ToastHaptic; }
21
21
  // Forward declaration of `ToastFrom` to properly resolve imports.
22
22
  namespace margelo::nitro::nitrosimpletoast { enum class ToastFrom; }
23
+ // Forward declaration of `ToastTheme` to properly resolve imports.
24
+ namespace margelo::nitro::nitrosimpletoast { enum class ToastTheme; }
23
25
 
24
26
  #include "ToastOptions.hpp"
25
27
  #include <string>
@@ -27,6 +29,7 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastFrom; }
27
29
  #include "ToastPreset.hpp"
28
30
  #include "ToastHaptic.hpp"
29
31
  #include "ToastFrom.hpp"
32
+ #include "ToastTheme.hpp"
30
33
 
31
34
  #include "NitroSimpleToast-Swift-Cxx-Umbrella.hpp"
32
35
 
@@ -18,7 +18,7 @@ public extension ToastOptions {
18
18
  /**
19
19
  * Create a new instance of `ToastOptions`.
20
20
  */
21
- init(title: String, message: String?, preset: ToastPreset?, duration: Double?, haptic: ToastHaptic?, shouldDismissByDrag: Bool?, from: ToastFrom?) {
21
+ init(title: String, message: String?, preset: ToastPreset?, duration: Double?, haptic: ToastHaptic?, shouldDismissByDrag: Bool?, from: ToastFrom?, theme: ToastTheme?) {
22
22
  self.init(std.string(title), { () -> bridge.std__optional_std__string_ in
23
23
  if let __unwrappedValue = message {
24
24
  return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
@@ -55,6 +55,12 @@ public extension ToastOptions {
55
55
  } else {
56
56
  return .init()
57
57
  }
58
+ }(), { () -> bridge.std__optional_ToastTheme_ in
59
+ if let __unwrappedValue = theme {
60
+ return bridge.create_std__optional_ToastTheme_(__unwrappedValue)
61
+ } else {
62
+ return .init()
63
+ }
58
64
  }())
59
65
  }
60
66
 
@@ -113,4 +119,9 @@ public extension ToastOptions {
113
119
  var from: ToastFrom? {
114
120
  return self.__from.value
115
121
  }
122
+
123
+ @inline(__always)
124
+ var theme: ToastTheme? {
125
+ return self.__theme.value
126
+ }
116
127
  }
@@ -0,0 +1,44 @@
1
+ ///
2
+ /// ToastTheme.swift
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
+ /**
9
+ * Represents the JS union `ToastTheme`, backed by a C++ enum.
10
+ */
11
+ public typealias ToastTheme = margelo.nitro.nitrosimpletoast.ToastTheme
12
+
13
+ public extension ToastTheme {
14
+ /**
15
+ * Get a ToastTheme for the given String value, or
16
+ * return `nil` if the given value was invalid/unknown.
17
+ */
18
+ init?(fromString string: String) {
19
+ switch string {
20
+ case "light":
21
+ self = .light
22
+ case "dark":
23
+ self = .dark
24
+ case "system":
25
+ self = .system
26
+ default:
27
+ return nil
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Get the String value this ToastTheme represents.
33
+ */
34
+ var stringValue: String {
35
+ switch self {
36
+ case .light:
37
+ return "light"
38
+ case .dark:
39
+ return "dark"
40
+ case .system:
41
+ return "system"
42
+ }
43
+ }
44
+ }
@@ -34,12 +34,15 @@ namespace margelo::nitro::nitrosimpletoast { enum class ToastPreset; }
34
34
  namespace margelo::nitro::nitrosimpletoast { enum class ToastHaptic; }
35
35
  // Forward declaration of `ToastFrom` to properly resolve imports.
36
36
  namespace margelo::nitro::nitrosimpletoast { enum class ToastFrom; }
37
+ // Forward declaration of `ToastTheme` to properly resolve imports.
38
+ namespace margelo::nitro::nitrosimpletoast { enum class ToastTheme; }
37
39
 
38
40
  #include <string>
39
41
  #include <optional>
40
42
  #include "ToastPreset.hpp"
41
43
  #include "ToastHaptic.hpp"
42
44
  #include "ToastFrom.hpp"
45
+ #include "ToastTheme.hpp"
43
46
 
44
47
  namespace margelo::nitro::nitrosimpletoast {
45
48
 
@@ -55,10 +58,11 @@ namespace margelo::nitro::nitrosimpletoast {
55
58
  std::optional<ToastHaptic> haptic SWIFT_PRIVATE;
56
59
  std::optional<bool> shouldDismissByDrag SWIFT_PRIVATE;
57
60
  std::optional<ToastFrom> from SWIFT_PRIVATE;
61
+ std::optional<ToastTheme> theme SWIFT_PRIVATE;
58
62
 
59
63
  public:
60
64
  ToastOptions() = default;
61
- explicit ToastOptions(std::string title, std::optional<std::string> message, std::optional<ToastPreset> preset, std::optional<double> duration, std::optional<ToastHaptic> haptic, std::optional<bool> shouldDismissByDrag, std::optional<ToastFrom> from): title(title), message(message), preset(preset), duration(duration), haptic(haptic), shouldDismissByDrag(shouldDismissByDrag), from(from) {}
65
+ explicit ToastOptions(std::string title, std::optional<std::string> message, std::optional<ToastPreset> preset, std::optional<double> duration, std::optional<ToastHaptic> haptic, std::optional<bool> shouldDismissByDrag, std::optional<ToastFrom> from, std::optional<ToastTheme> theme): title(title), message(message), preset(preset), duration(duration), haptic(haptic), shouldDismissByDrag(shouldDismissByDrag), from(from), theme(theme) {}
62
66
 
63
67
  public:
64
68
  friend bool operator==(const ToastOptions& lhs, const ToastOptions& rhs) = default;
@@ -80,7 +84,8 @@ namespace margelo::nitro {
80
84
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "duration"))),
81
85
  JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastHaptic>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "haptic"))),
82
86
  JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "shouldDismissByDrag"))),
83
- JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastFrom>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "from")))
87
+ JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastFrom>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "from"))),
88
+ JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastTheme>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "theme")))
84
89
  );
85
90
  }
86
91
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosimpletoast::ToastOptions& arg) {
@@ -92,6 +97,7 @@ namespace margelo::nitro {
92
97
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "haptic"), JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastHaptic>>::toJSI(runtime, arg.haptic));
93
98
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "shouldDismissByDrag"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.shouldDismissByDrag));
94
99
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "from"), JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastFrom>>::toJSI(runtime, arg.from));
100
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "theme"), JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastTheme>>::toJSI(runtime, arg.theme));
95
101
  return obj;
96
102
  }
97
103
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -109,6 +115,7 @@ namespace margelo::nitro {
109
115
  if (!JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastHaptic>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "haptic")))) return false;
110
116
  if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "shouldDismissByDrag")))) return false;
111
117
  if (!JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastFrom>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "from")))) return false;
118
+ if (!JSIConverter<std::optional<margelo::nitro::nitrosimpletoast::ToastTheme>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "theme")))) return false;
112
119
  return true;
113
120
  }
114
121
  };
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// ToastTheme.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
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::nitrosimpletoast {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (ToastTheme).
30
+ */
31
+ enum class ToastTheme {
32
+ LIGHT SWIFT_NAME(light) = 0,
33
+ DARK SWIFT_NAME(dark) = 1,
34
+ SYSTEM SWIFT_NAME(system) = 2,
35
+ } CLOSED_ENUM;
36
+
37
+ } // namespace margelo::nitro::nitrosimpletoast
38
+
39
+ namespace margelo::nitro {
40
+
41
+ // C++ ToastTheme <> JS ToastTheme (union)
42
+ template <>
43
+ struct JSIConverter<margelo::nitro::nitrosimpletoast::ToastTheme> final {
44
+ static inline margelo::nitro::nitrosimpletoast::ToastTheme fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
45
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
46
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
47
+ case hashString("light"): return margelo::nitro::nitrosimpletoast::ToastTheme::LIGHT;
48
+ case hashString("dark"): return margelo::nitro::nitrosimpletoast::ToastTheme::DARK;
49
+ case hashString("system"): return margelo::nitro::nitrosimpletoast::ToastTheme::SYSTEM;
50
+ default: [[unlikely]]
51
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum ToastTheme - invalid value!");
52
+ }
53
+ }
54
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrosimpletoast::ToastTheme arg) {
55
+ switch (arg) {
56
+ case margelo::nitro::nitrosimpletoast::ToastTheme::LIGHT: return JSIConverter<std::string>::toJSI(runtime, "light");
57
+ case margelo::nitro::nitrosimpletoast::ToastTheme::DARK: return JSIConverter<std::string>::toJSI(runtime, "dark");
58
+ case margelo::nitro::nitrosimpletoast::ToastTheme::SYSTEM: return JSIConverter<std::string>::toJSI(runtime, "system");
59
+ default: [[unlikely]]
60
+ throw std::invalid_argument("Cannot convert ToastTheme to JS - invalid value: "
61
+ + std::to_string(static_cast<int>(arg)) + "!");
62
+ }
63
+ }
64
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
65
+ if (!value.isString()) {
66
+ return false;
67
+ }
68
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
69
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
70
+ case hashString("light"):
71
+ case hashString("dark"):
72
+ case hashString("system"):
73
+ return true;
74
+ default:
75
+ return false;
76
+ }
77
+ }
78
+ };
79
+
80
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-simple-toast",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-beta.1",
4
4
  "description": "react native simple toast powered by nitro",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -6,6 +6,8 @@ export type ToastHaptic = 'success' | 'warning' | 'error' | 'none';
6
6
 
7
7
  export type ToastFrom = 'top' | 'bottom';
8
8
 
9
+ export type ToastTheme = 'light' | 'dark' | 'system';
10
+
9
11
  export interface ToastOptions {
10
12
  title: string;
11
13
  message?: string;
@@ -27,6 +29,10 @@ export interface ToastOptions {
27
29
  * @platform ios
28
30
  */
29
31
  from?: ToastFrom;
32
+ /**
33
+ * Defaults to `system`.
34
+ */
35
+ theme?: ToastTheme;
30
36
  }
31
37
 
32
38
  export interface NitroSimpleToast
package/src/index.tsx CHANGED
@@ -9,6 +9,7 @@ export type {
9
9
  ToastPreset,
10
10
  ToastHaptic,
11
11
  ToastFrom,
12
+ ToastTheme,
12
13
  } from './NitroSimpleToast.nitro';
13
14
 
14
15
  export function toast(options: ToastOptions): void {