-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AlertOptions, ToastOptions } from "./types"; | ||
import { ToastAndroid } from "react-native"; | ||
|
||
export default { | ||
alertAsync(_: AlertOptions) { | ||
console.warn( | ||
"[burnt] Burnt.alertAsync() is not implemented on this Android. Please try toastAsync()." | ||
); | ||
}, | ||
toastAsync({ title, duration = 5 }: ToastOptions) { | ||
ToastAndroid.showWithGravityAndOffset( | ||
title, | ||
duration * 1000, | ||
ToastAndroid.BOTTOM, | ||
25, | ||
50 | ||
); | ||
}, | ||
dismissAllAlertsAsync() {}, | ||
}; |
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 |
---|---|---|
|
@@ -26,4 +26,4 @@ export default { | |
); | ||
} | ||
}, | ||
}; | ||
} as any; |
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,29 @@ | ||
const isDev = | ||
typeof __DEV__ !== "undefined" | ||
? __DEV__ | ||
: // @ts-expect-error | ||
typeof process !== "undefined" && process.env.NODE_ENV !== "production"; | ||
|
||
export default { | ||
toast() { | ||
if (isDev) { | ||
console.log( | ||
"[burnt] Burnt.alert() is not implemented on this platform. Just making sure you know." | ||
); | ||
} | ||
}, | ||
alert() { | ||
if (isDev) { | ||
console.log( | ||
"[burnt] Burnt.alert() is not implemented on this platform. Just making sure you know." | ||
); | ||
} | ||
}, | ||
dismissAllAlerts() { | ||
if (isDev) { | ||
console.log( | ||
"[burnt] Burnt.dismissAllAlerts() is not implemented on this platform. Just making sure you know." | ||
); | ||
} | ||
}, | ||
}; |
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,57 @@ | ||
export type AlertOptions = { | ||
title: string; | ||
message: string; | ||
/** | ||
* Defaults to `true`. | ||
*/ | ||
shouldDismissByTap?: boolean; | ||
} & ( | ||
| { | ||
preset: "heart" | "done" | "error"; | ||
|
||
/** | ||
* Duration in seconds. | ||
*/ | ||
duration?: number; | ||
} | ||
| { | ||
preset: "spinner"; | ||
/** | ||
* Max timeout of the spinner in seconds. Required for this preset to avoid an infinite spinner. | ||
* | ||
* It's highly, highly recommended that you manually dismiss the alert using `Burnt.dismissAllAlerts()`. | ||
* | ||
* If you don't, then you risk having an infinite loading spinner for users. | ||
* | ||
* ```ts | ||
* Burnt.alert({ | ||
* preset: "spinner", | ||
* title: 'Loading...', | ||
* duration: 10, // Maximum of 10 seconds | ||
* }) | ||
* | ||
* try { | ||
* await createUser() | ||
* } finally { | ||
* Burnt.dismissAllAlerts() | ||
* } | ||
* ``` | ||
*/ | ||
duration: number; | ||
} | ||
); | ||
|
||
export type ToastOptions = { | ||
title: string; | ||
message: string; | ||
preset: "done" | "error"; // TODO custom option | ||
/** | ||
* Duration in seconds. | ||
*/ | ||
duration?: number; | ||
haptic?: "success" | "warning" | "error" | "none"; | ||
/** | ||
* Defaults to `true`. | ||
*/ | ||
shouldDismissByDrag?: boolean; | ||
}; |